blob: ba3897d48a593967d0ff714881d5849d13f82051 [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 Brown46b9ac02010-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 Brown46b9ac02010-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 Brown46b9ac02010-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;
508 boolean mDragEnded;
509
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();
565
566 if (DEBUG_DRAG) {
567 Slog.d(TAG, "broadcasting DRAG_STARTED of " + mDataDescription);
568 }
569
570 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED, 0, 0,
571 mDataDescription, null);
Christopher Tate2c095f32010-10-04 14:13:40 -0700572 final int N = mWindows.size();
573 for (int i = 0; i < N; i++) {
574 // sendDragStartedLw() clones evt for local-process dispatch
575 sendDragStartedLw(mWindows.get(i), evt);
Christopher Tatea53146c2010-09-07 11:57:52 -0700576 }
577 evt.recycle();
578 }
579
580 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
581 * designated window is potentially a drop recipient. There are race situations
582 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
583 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700584 *
585 * This method clones the 'event' parameter if it's being delivered to the same
586 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700587 */
Christopher Tate2c095f32010-10-04 14:13:40 -0700588 private void sendDragStartedLw(WindowState newWin, DragEvent event) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700589 if (!mDragEnded && newWin.isPotentialDragTarget()) {
590 try {
Christopher Tate2c095f32010-10-04 14:13:40 -0700591 // clone for local callees since dispatch will recycle the event
592 if (Process.myPid() == newWin.mSession.mPid) {
593 event = DragEvent.obtain(event);
594 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700595 newWin.mClient.dispatchDragEvent(event);
596 // track each window that we've notified that the drag is starting
597 mNotifiedWindows.add(newWin);
598 } catch (RemoteException e) {
599 Slog.w(TAG, "Unable to drag-start window " + newWin);
600 }
601 }
602 }
603
604 /* helper - construct and send a DRAG_STARTED event only if the window has not
605 * previously been notified, i.e. it became visible after the drag operation
606 * was begun. This is a rare case.
607 */
608 private void sendDragStartedIfNeededLw(WindowState newWin) {
609 // If we have sent the drag-started, we needn't do so again
610 for (WindowState ws : mNotifiedWindows) {
611 if (ws == newWin) {
612 return;
613 }
614 }
615 if (DEBUG_DRAG) {
616 Slog.d(TAG, "sending DRAG_STARTED to new window " + newWin);
617 }
618 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED, 0, 0,
619 mDataDescription, null);
Christopher Tate2c095f32010-10-04 14:13:40 -0700620 // sendDragStartedLw() clones 'event' if the window is process-local
Christopher Tatea53146c2010-09-07 11:57:52 -0700621 sendDragStartedLw(newWin, event);
622 event.recycle();
623 }
624
625 void broadcastDragEnded() {
626 if (DEBUG_DRAG) {
627 Slog.d(TAG, "broadcasting DRAG_ENDED");
628 }
629 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED, 0, 0, null, null);
630 synchronized (mWindowMap) {
631 for (WindowState ws: mNotifiedWindows) {
632 try {
633 ws.mClient.dispatchDragEvent(evt);
634 } catch (RemoteException e) {
635 Slog.w(TAG, "Unable to drag-end window " + ws);
636 }
637 }
638 mNotifiedWindows.clear();
639 mDragEnded = true;
640 }
641 evt.recycle();
642 }
643
644 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700645 final int myPid = Process.myPid();
646
647 // Move the surface to the given touch
648 mSurface.openTransaction();
649 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
650 mSurface.closeTransaction();
651
652 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700653 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
654 try {
655 // have we dragged over a new window?
656 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
657 if (DEBUG_DRAG) {
658 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
659 }
660 // force DRAG_EXITED_EVENT if appropriate
661 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
662 0, 0, null, null);
663 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700664 if (myPid != mTargetWindow.mSession.mPid) {
665 evt.recycle();
666 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700667 }
668 if (touchedWin != null) {
669 if (DEBUG_DRAG) {
670 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
671 }
672 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
673 x, y, null, null);
674 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700675 if (myPid != touchedWin.mSession.mPid) {
676 evt.recycle();
677 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700678 }
679 } catch (RemoteException e) {
680 Slog.w(TAG, "can't send drag notification to windows");
681 }
682 mTargetWindow = touchedWin;
683 }
684
685 // Tell the drop target about the data, and then broadcast the drag-ended notification
686 void notifyDropLw(float x, float y) {
687 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
688 if (touchedWin != null) {
689 if (DEBUG_DRAG) {
690 Slog.d(TAG, "sending DROP to " + touchedWin);
691 }
Christopher Tate2c095f32010-10-04 14:13:40 -0700692 final int myPid = Process.myPid();
Christopher Tatea53146c2010-09-07 11:57:52 -0700693 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP, x, y, null, mData);
694 try {
695 touchedWin.mClient.dispatchDragEvent(evt);
696 } catch (RemoteException e) {
697 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
698 }
Christopher Tate2c095f32010-10-04 14:13:40 -0700699 if (myPid != touchedWin.mSession.mPid) {
700 evt.recycle();
701 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700702 }
703 }
704
705 // Find the visible, touch-deliverable window under the given point
706 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
707 WindowState touchedWin = null;
708 final int x = (int) xf;
709 final int y = (int) yf;
710 final ArrayList<WindowState> windows = mWindows;
711 final int N = windows.size();
712 for (int i = N - 1; i >= 0; i--) {
713 WindowState child = windows.get(i);
714 final int flags = child.mAttrs.flags;
715 if (!child.isVisibleLw()) {
716 // not visible == don't tell about drags
717 continue;
718 }
719 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
720 // not touchable == don't tell about drags
721 continue;
722 }
723 // account for the window's decor etc
724 tmpRect.set(child.mFrame);
725 if (child.mTouchableInsets == ViewTreeObserver
726 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
727 // The point is inside of the window if it is
728 // inside the frame, AND the content part of that
729 // frame that was given by the application.
730 tmpRect.left += child.mGivenContentInsets.left;
731 tmpRect.top += child.mGivenContentInsets.top;
732 tmpRect.right -= child.mGivenContentInsets.right;
733 tmpRect.bottom -= child.mGivenContentInsets.bottom;
734 } else if (child.mTouchableInsets == ViewTreeObserver
735 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
736 // The point is inside of the window if it is
737 // inside the frame, AND the visible part of that
738 // frame that was given by the application.
739 tmpRect.left += child.mGivenVisibleInsets.left;
740 tmpRect.top += child.mGivenVisibleInsets.top;
741 tmpRect.right -= child.mGivenVisibleInsets.right;
742 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
743 }
744 final int touchFlags = flags &
745 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
746 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
747 if (tmpRect.contains(x, y) || touchFlags == 0) {
748 // Found it
749 touchedWin = child;
750 break;
751 }
752 }
753
754 return touchedWin;
755 }
756 }
757
758 DragState mDragState = null;
759 private final InputHandler mDragInputHandler = new BaseInputHandler() {
760 @Override
761 public void handleMotion(MotionEvent event, Runnable finishedCallback) {
762 boolean endDrag = false;
763 final float newX = event.getRawX();
764 final float newY = event.getRawY();
765
766 try {
767 if (mDragState != null) {
768 switch (event.getAction()) {
769 case MotionEvent.ACTION_DOWN: {
770 if (DEBUG_DRAG) {
771 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
772 }
773 } break;
774
775 case MotionEvent.ACTION_MOVE: {
776 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700777 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700778 mDragState.notifyMoveLw(newX, newY);
779 }
780 } break;
781
782 case MotionEvent.ACTION_UP: {
783 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
784 + newX + "," + newY);
785 synchronized (mWindowMap) {
786 mDragState.notifyDropLw(newX, newY);
787 }
788 endDrag = true;
789 } break;
790
791 case MotionEvent.ACTION_CANCEL: {
792 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
793 endDrag = true;
794 } break;
795 }
796
797 if (endDrag) {
798 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
799 // tell all the windows that the drag has ended
800 mDragState.broadcastDragEnded();
801
802 // stop intercepting input
803 mDragState.unregister();
804 mInputMonitor.updateInputWindowsLw();
805
806 // free our resources and drop all the object references
807 mDragState.reset();
808 mDragState = null;
809 }
810 }
811 } catch (Exception e) {
812 Slog.e(TAG, "Exception caught by drag handleMotion", e);
813 } finally {
814 finishedCallback.run();
815 }
816 }
817 };
818
819 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800820 * Whether the UI is currently running in touch mode (not showing
821 * navigational focus because the user is directly pressing the screen).
822 */
823 boolean mInTouchMode = false;
824
825 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700826 private ArrayList<WindowChangeListener> mWindowChangeListeners =
827 new ArrayList<WindowChangeListener>();
828 private boolean mWindowsChanged = false;
829
830 public interface WindowChangeListener {
831 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700832 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700833 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800834
Dianne Hackbornc485a602009-03-24 22:39:49 -0700835 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700836 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700837
838 // The frame use to limit the size of the app running in compatibility mode.
839 Rect mCompatibleScreenFrame = new Rect();
840 // The surface used to fill the outer rim of the app running in compatibility mode.
841 Surface mBackgroundFillerSurface = null;
842 boolean mBackgroundFillerShown = false;
843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800844 public static WindowManagerService main(Context context,
845 PowerManagerService pm, boolean haveInputMethods) {
846 WMThread thr = new WMThread(context, pm, haveInputMethods);
847 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700848
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800849 synchronized (thr) {
850 while (thr.mService == null) {
851 try {
852 thr.wait();
853 } catch (InterruptedException e) {
854 }
855 }
856 }
Romain Guy06882f82009-06-10 13:36:04 -0700857
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800858 return thr.mService;
859 }
Romain Guy06882f82009-06-10 13:36:04 -0700860
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800861 static class WMThread extends Thread {
862 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800864 private final Context mContext;
865 private final PowerManagerService mPM;
866 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700867
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800868 public WMThread(Context context, PowerManagerService pm,
869 boolean haveInputMethods) {
870 super("WindowManager");
871 mContext = context;
872 mPM = pm;
873 mHaveInputMethods = haveInputMethods;
874 }
Romain Guy06882f82009-06-10 13:36:04 -0700875
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800876 public void run() {
877 Looper.prepare();
878 WindowManagerService s = new WindowManagerService(mContext, mPM,
879 mHaveInputMethods);
880 android.os.Process.setThreadPriority(
881 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700882 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700883
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800884 synchronized (this) {
885 mService = s;
886 notifyAll();
887 }
Romain Guy06882f82009-06-10 13:36:04 -0700888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800889 Looper.loop();
890 }
891 }
892
893 static class PolicyThread extends Thread {
894 private final WindowManagerPolicy mPolicy;
895 private final WindowManagerService mService;
896 private final Context mContext;
897 private final PowerManagerService mPM;
898 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800900 public PolicyThread(WindowManagerPolicy policy,
901 WindowManagerService service, Context context,
902 PowerManagerService pm) {
903 super("WindowManagerPolicy");
904 mPolicy = policy;
905 mService = service;
906 mContext = context;
907 mPM = pm;
908 }
Romain Guy06882f82009-06-10 13:36:04 -0700909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800910 public void run() {
911 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800912 WindowManagerPolicyThread.set(this, Looper.myLooper());
913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800914 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800915 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800916 android.os.Process.setThreadPriority(
917 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700918 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800919 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800921 synchronized (this) {
922 mRunning = true;
923 notifyAll();
924 }
Romain Guy06882f82009-06-10 13:36:04 -0700925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 Looper.loop();
927 }
928 }
929
930 private WindowManagerService(Context context, PowerManagerService pm,
931 boolean haveInputMethods) {
932 mContext = context;
933 mHaveInputMethods = haveInputMethods;
934 mLimitedAlphaCompositing = context.getResources().getBoolean(
935 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700936
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800937 mPowerManager = pm;
938 mPowerManager.setPolicy(mPolicy);
939 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
940 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
941 "SCREEN_FROZEN");
942 mScreenFrozenLock.setReferenceCounted(false);
943
944 mActivityManager = ActivityManagerNative.getDefault();
945 mBatteryStats = BatteryStatsService.getService();
946
947 // Get persisted window scale setting
948 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
949 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
950 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
951 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700952
Jim Miller284b62e2010-06-08 14:27:42 -0700953 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
954 IntentFilter filter = new IntentFilter();
955 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
956 mContext.registerReceiver(mBroadcastReceiver, filter);
957
Jeff Brown46b9ac02010-04-22 18:58:52 -0700958 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
959 "KEEP_SCREEN_ON_FLAG");
960 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800961
Jeff Browne33348b2010-07-15 23:54:05 -0700962 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -0700963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800964 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
965 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800967 synchronized (thr) {
968 while (!thr.mRunning) {
969 try {
970 thr.wait();
971 } catch (InterruptedException e) {
972 }
973 }
974 }
Romain Guy06882f82009-06-10 13:36:04 -0700975
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700976 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -0700977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800978 // Add ourself to the Watchdog monitors.
979 Watchdog.getInstance().addMonitor(this);
980 }
981
982 @Override
983 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
984 throws RemoteException {
985 try {
986 return super.onTransact(code, data, reply, flags);
987 } catch (RuntimeException e) {
988 // The window manager only throws security exceptions, so let's
989 // log all others.
990 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800991 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800992 }
993 throw e;
994 }
995 }
996
Jeff Browne33348b2010-07-15 23:54:05 -0700997 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800998 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800999 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001000 TAG, "Adding window " + window + " at "
1001 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1002 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001003 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001004 }
1005
Jeff Browne33348b2010-07-15 23:54:05 -07001006 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001007 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001008 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001009 TAG, "Adding window " + window + " at "
1010 + i + " of " + mWindows.size() + " (before " + pos + ")");
1011 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001012 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001013 }
1014
1015 //This method finds out the index of a window that has the same app token as
1016 //win. used for z ordering the windows in mWindows
1017 private int findIdxBasedOnAppTokens(WindowState win) {
1018 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001019 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001020 int jmax = localmWindows.size();
1021 if(jmax == 0) {
1022 return -1;
1023 }
1024 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001025 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001026 if(wentry.mAppToken == win.mAppToken) {
1027 return j;
1028 }
1029 }
1030 return -1;
1031 }
Romain Guy06882f82009-06-10 13:36:04 -07001032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001033 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1034 final IWindow client = win.mClient;
1035 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001036 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001038 final int N = localmWindows.size();
1039 final WindowState attached = win.mAttachedWindow;
1040 int i;
1041 if (attached == null) {
1042 int tokenWindowsPos = token.windows.size();
1043 if (token.appWindowToken != null) {
1044 int index = tokenWindowsPos-1;
1045 if (index >= 0) {
1046 // If this application has existing windows, we
1047 // simply place the new window on top of them... but
1048 // keep the starting window on top.
1049 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1050 // Base windows go behind everything else.
1051 placeWindowBefore(token.windows.get(0), win);
1052 tokenWindowsPos = 0;
1053 } else {
1054 AppWindowToken atoken = win.mAppToken;
1055 if (atoken != null &&
1056 token.windows.get(index) == atoken.startingWindow) {
1057 placeWindowBefore(token.windows.get(index), win);
1058 tokenWindowsPos--;
1059 } else {
1060 int newIdx = findIdxBasedOnAppTokens(win);
1061 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001062 //there is a window above this one associated with the same
1063 //apptoken note that the window could be a floating window
1064 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001065 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001066 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001067 TAG, "Adding window " + win + " at "
1068 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001069 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001070 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001071 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001072 }
1073 }
1074 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001075 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001076 TAG, "Figuring out where to add app window "
1077 + client.asBinder() + " (token=" + token + ")");
1078 // Figure out where the window should go, based on the
1079 // order of applications.
1080 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001081 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001082 for (i=NA-1; i>=0; i--) {
1083 AppWindowToken t = mAppTokens.get(i);
1084 if (t == token) {
1085 i--;
1086 break;
1087 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001088
Dianne Hackborna8f60182009-09-01 19:01:50 -07001089 // We haven't reached the token yet; if this token
1090 // is not going to the bottom and has windows, we can
1091 // use it as an anchor for when we do reach the token.
1092 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001093 pos = t.windows.get(0);
1094 }
1095 }
1096 // We now know the index into the apps. If we found
1097 // an app window above, that gives us the position; else
1098 // we need to look some more.
1099 if (pos != null) {
1100 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001101 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001102 if (atoken != null) {
1103 final int NC = atoken.windows.size();
1104 if (NC > 0) {
1105 WindowState bottom = atoken.windows.get(0);
1106 if (bottom.mSubLayer < 0) {
1107 pos = bottom;
1108 }
1109 }
1110 }
1111 placeWindowBefore(pos, win);
1112 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001113 // Continue looking down until we find the first
1114 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 while (i >= 0) {
1116 AppWindowToken t = mAppTokens.get(i);
1117 final int NW = t.windows.size();
1118 if (NW > 0) {
1119 pos = t.windows.get(NW-1);
1120 break;
1121 }
1122 i--;
1123 }
1124 if (pos != null) {
1125 // Move in front of any windows attached to this
1126 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001127 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001128 if (atoken != null) {
1129 final int NC = atoken.windows.size();
1130 if (NC > 0) {
1131 WindowState top = atoken.windows.get(NC-1);
1132 if (top.mSubLayer >= 0) {
1133 pos = top;
1134 }
1135 }
1136 }
1137 placeWindowAfter(pos, win);
1138 } else {
1139 // Just search for the start of this layer.
1140 final int myLayer = win.mBaseLayer;
1141 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001142 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001143 if (w.mBaseLayer > myLayer) {
1144 break;
1145 }
1146 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001147 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001148 TAG, "Adding window " + win + " at "
1149 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001150 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001151 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001152 }
1153 }
1154 }
1155 } else {
1156 // Figure out where window should go, based on layer.
1157 final int myLayer = win.mBaseLayer;
1158 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001159 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 i++;
1161 break;
1162 }
1163 }
1164 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001165 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001166 TAG, "Adding window " + win + " at "
1167 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001168 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001169 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001170 }
1171 if (addToToken) {
1172 token.windows.add(tokenWindowsPos, win);
1173 }
1174
1175 } else {
1176 // Figure out this window's ordering relative to the window
1177 // it is attached to.
1178 final int NA = token.windows.size();
1179 final int sublayer = win.mSubLayer;
1180 int largestSublayer = Integer.MIN_VALUE;
1181 WindowState windowWithLargestSublayer = null;
1182 for (i=0; i<NA; i++) {
1183 WindowState w = token.windows.get(i);
1184 final int wSublayer = w.mSubLayer;
1185 if (wSublayer >= largestSublayer) {
1186 largestSublayer = wSublayer;
1187 windowWithLargestSublayer = w;
1188 }
1189 if (sublayer < 0) {
1190 // For negative sublayers, we go below all windows
1191 // in the same sublayer.
1192 if (wSublayer >= sublayer) {
1193 if (addToToken) {
1194 token.windows.add(i, win);
1195 }
1196 placeWindowBefore(
1197 wSublayer >= 0 ? attached : w, win);
1198 break;
1199 }
1200 } else {
1201 // For positive sublayers, we go above all windows
1202 // in the same sublayer.
1203 if (wSublayer > sublayer) {
1204 if (addToToken) {
1205 token.windows.add(i, win);
1206 }
1207 placeWindowBefore(w, win);
1208 break;
1209 }
1210 }
1211 }
1212 if (i >= NA) {
1213 if (addToToken) {
1214 token.windows.add(win);
1215 }
1216 if (sublayer < 0) {
1217 placeWindowBefore(attached, win);
1218 } else {
1219 placeWindowAfter(largestSublayer >= 0
1220 ? windowWithLargestSublayer
1221 : attached,
1222 win);
1223 }
1224 }
1225 }
Romain Guy06882f82009-06-10 13:36:04 -07001226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001227 if (win.mAppToken != null && addToToken) {
1228 win.mAppToken.allAppWindows.add(win);
1229 }
1230 }
Romain Guy06882f82009-06-10 13:36:04 -07001231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001232 static boolean canBeImeTarget(WindowState w) {
1233 final int fl = w.mAttrs.flags
1234 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1235 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1236 return w.isVisibleOrAdding();
1237 }
1238 return false;
1239 }
Romain Guy06882f82009-06-10 13:36:04 -07001240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001241 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001242 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001243 final int N = localmWindows.size();
1244 WindowState w = null;
1245 int i = N;
1246 while (i > 0) {
1247 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001248 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001249
Joe Onorato8a9b2202010-02-26 18:56:32 -08001250 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001251 // + Integer.toHexString(w.mAttrs.flags));
1252 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001253 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001255 // Yet more tricksyness! If this window is a "starting"
1256 // window, we do actually want to be on top of it, but
1257 // it is not -really- where input will go. So if the caller
1258 // is not actually looking to move the IME, look down below
1259 // for a real window to target...
1260 if (!willMove
1261 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1262 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001263 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001264 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1265 i--;
1266 w = wb;
1267 }
1268 }
1269 break;
1270 }
1271 }
Romain Guy06882f82009-06-10 13:36:04 -07001272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001273 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -07001274
Joe Onorato8a9b2202010-02-26 18:56:32 -08001275 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001276 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001278 if (willMove && w != null) {
1279 final WindowState curTarget = mInputMethodTarget;
1280 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001282 // Now some fun for dealing with window animations that
1283 // modify the Z order. We need to look at all windows below
1284 // the current target that are in this app, finding the highest
1285 // visible one in layering.
1286 AppWindowToken token = curTarget.mAppToken;
1287 WindowState highestTarget = null;
1288 int highestPos = 0;
1289 if (token.animating || token.animation != null) {
1290 int pos = 0;
1291 pos = localmWindows.indexOf(curTarget);
1292 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001293 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001294 if (win.mAppToken != token) {
1295 break;
1296 }
1297 if (!win.mRemoved) {
1298 if (highestTarget == null || win.mAnimLayer >
1299 highestTarget.mAnimLayer) {
1300 highestTarget = win;
1301 highestPos = pos;
1302 }
1303 }
1304 pos--;
1305 }
1306 }
Romain Guy06882f82009-06-10 13:36:04 -07001307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001308 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001309 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001310 + mNextAppTransition + " " + highestTarget
1311 + " animating=" + highestTarget.isAnimating()
1312 + " layer=" + highestTarget.mAnimLayer
1313 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001314
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001315 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001316 // If we are currently setting up for an animation,
1317 // hold everything until we can find out what will happen.
1318 mInputMethodTargetWaitingAnim = true;
1319 mInputMethodTarget = highestTarget;
1320 return highestPos + 1;
1321 } else if (highestTarget.isAnimating() &&
1322 highestTarget.mAnimLayer > w.mAnimLayer) {
1323 // If the window we are currently targeting is involved
1324 // with an animation, and it is on top of the next target
1325 // we will be over, then hold off on moving until
1326 // that is done.
1327 mInputMethodTarget = highestTarget;
1328 return highestPos + 1;
1329 }
1330 }
1331 }
1332 }
Romain Guy06882f82009-06-10 13:36:04 -07001333
Joe Onorato8a9b2202010-02-26 18:56:32 -08001334 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001335 if (w != null) {
1336 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001337 if (DEBUG_INPUT_METHOD) {
1338 RuntimeException e = null;
1339 if (!HIDE_STACK_CRAWLS) {
1340 e = new RuntimeException();
1341 e.fillInStackTrace();
1342 }
1343 Slog.w(TAG, "Moving IM target from "
1344 + mInputMethodTarget + " to " + w, e);
1345 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001346 mInputMethodTarget = w;
1347 if (w.mAppToken != null) {
1348 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1349 } else {
1350 setInputMethodAnimLayerAdjustment(0);
1351 }
1352 }
1353 return i+1;
1354 }
1355 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001356 if (DEBUG_INPUT_METHOD) {
1357 RuntimeException e = null;
1358 if (!HIDE_STACK_CRAWLS) {
1359 e = new RuntimeException();
1360 e.fillInStackTrace();
1361 }
1362 Slog.w(TAG, "Moving IM target from "
1363 + mInputMethodTarget + " to null", e);
1364 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001365 mInputMethodTarget = null;
1366 setInputMethodAnimLayerAdjustment(0);
1367 }
1368 return -1;
1369 }
Romain Guy06882f82009-06-10 13:36:04 -07001370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001371 void addInputMethodWindowToListLocked(WindowState win) {
1372 int pos = findDesiredInputMethodWindowIndexLocked(true);
1373 if (pos >= 0) {
1374 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001375 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001376 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001377 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001378 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001379 moveInputMethodDialogsLocked(pos+1);
1380 return;
1381 }
1382 win.mTargetAppToken = null;
1383 addWindowToListInOrderLocked(win, true);
1384 moveInputMethodDialogsLocked(pos);
1385 }
Romain Guy06882f82009-06-10 13:36:04 -07001386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001387 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001388 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001389 mInputMethodAnimLayerAdjustment = adj;
1390 WindowState imw = mInputMethodWindow;
1391 if (imw != null) {
1392 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001393 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001394 + " anim layer: " + imw.mAnimLayer);
1395 int wi = imw.mChildWindows.size();
1396 while (wi > 0) {
1397 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001398 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001399 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001400 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001401 + " anim layer: " + cw.mAnimLayer);
1402 }
1403 }
1404 int di = mInputMethodDialogs.size();
1405 while (di > 0) {
1406 di --;
1407 imw = mInputMethodDialogs.get(di);
1408 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001409 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001410 + " anim layer: " + imw.mAnimLayer);
1411 }
1412 }
Romain Guy06882f82009-06-10 13:36:04 -07001413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001414 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1415 int wpos = mWindows.indexOf(win);
1416 if (wpos >= 0) {
1417 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001418 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001419 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001420 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001421 int NC = win.mChildWindows.size();
1422 while (NC > 0) {
1423 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001424 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001425 int cpos = mWindows.indexOf(cw);
1426 if (cpos >= 0) {
1427 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001428 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001429 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001430 mWindows.remove(cpos);
1431 }
1432 }
1433 }
1434 return interestingPos;
1435 }
Romain Guy06882f82009-06-10 13:36:04 -07001436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001437 private void reAddWindowToListInOrderLocked(WindowState win) {
1438 addWindowToListInOrderLocked(win, false);
1439 // This is a hack to get all of the child windows added as well
1440 // at the right position. Child windows should be rare and
1441 // this case should be rare, so it shouldn't be that big a deal.
1442 int wpos = mWindows.indexOf(win);
1443 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001444 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001445 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001446 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001447 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001448 reAddWindowLocked(wpos, win);
1449 }
1450 }
Romain Guy06882f82009-06-10 13:36:04 -07001451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001452 void logWindowList(String prefix) {
1453 int N = mWindows.size();
1454 while (N > 0) {
1455 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001456 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001457 }
1458 }
Romain Guy06882f82009-06-10 13:36:04 -07001459
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001460 void moveInputMethodDialogsLocked(int pos) {
1461 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001464 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001465 for (int i=0; i<N; i++) {
1466 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1467 }
1468 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001469 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001470 logWindowList(" ");
1471 }
Romain Guy06882f82009-06-10 13:36:04 -07001472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001473 if (pos >= 0) {
1474 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1475 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001476 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001477 if (wp == mInputMethodWindow) {
1478 pos++;
1479 }
1480 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001481 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001482 for (int i=0; i<N; i++) {
1483 WindowState win = dialogs.get(i);
1484 win.mTargetAppToken = targetAppToken;
1485 pos = reAddWindowLocked(pos, win);
1486 }
1487 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001488 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001489 logWindowList(" ");
1490 }
1491 return;
1492 }
1493 for (int i=0; i<N; i++) {
1494 WindowState win = dialogs.get(i);
1495 win.mTargetAppToken = null;
1496 reAddWindowToListInOrderLocked(win);
1497 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001498 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001499 logWindowList(" ");
1500 }
1501 }
1502 }
Romain Guy06882f82009-06-10 13:36:04 -07001503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001504 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1505 final WindowState imWin = mInputMethodWindow;
1506 final int DN = mInputMethodDialogs.size();
1507 if (imWin == null && DN == 0) {
1508 return false;
1509 }
Romain Guy06882f82009-06-10 13:36:04 -07001510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001511 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1512 if (imPos >= 0) {
1513 // In this case, the input method windows are to be placed
1514 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001516 // First check to see if the input method windows are already
1517 // located here, and contiguous.
1518 final int N = mWindows.size();
1519 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001520 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001522 // Figure out the actual input method window that should be
1523 // at the bottom of their stack.
1524 WindowState baseImWin = imWin != null
1525 ? imWin : mInputMethodDialogs.get(0);
1526 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001527 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001528 if (cw.mSubLayer < 0) baseImWin = cw;
1529 }
Romain Guy06882f82009-06-10 13:36:04 -07001530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001531 if (firstImWin == baseImWin) {
1532 // The windows haven't moved... but are they still contiguous?
1533 // First find the top IM window.
1534 int pos = imPos+1;
1535 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001536 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001537 break;
1538 }
1539 pos++;
1540 }
1541 pos++;
1542 // Now there should be no more input method windows above.
1543 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001544 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001545 break;
1546 }
1547 pos++;
1548 }
1549 if (pos >= N) {
1550 // All is good!
1551 return false;
1552 }
1553 }
Romain Guy06882f82009-06-10 13:36:04 -07001554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001555 if (imWin != null) {
1556 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001557 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001558 logWindowList(" ");
1559 }
1560 imPos = tmpRemoveWindowLocked(imPos, imWin);
1561 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001562 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001563 logWindowList(" ");
1564 }
1565 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1566 reAddWindowLocked(imPos, imWin);
1567 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001568 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001569 logWindowList(" ");
1570 }
1571 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1572 } else {
1573 moveInputMethodDialogsLocked(imPos);
1574 }
Romain Guy06882f82009-06-10 13:36:04 -07001575
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001576 } else {
1577 // In this case, the input method windows go in a fixed layer,
1578 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001580 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001581 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001582 tmpRemoveWindowLocked(0, imWin);
1583 imWin.mTargetAppToken = null;
1584 reAddWindowToListInOrderLocked(imWin);
1585 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001586 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001587 logWindowList(" ");
1588 }
1589 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1590 } else {
1591 moveInputMethodDialogsLocked(-1);;
1592 }
Romain Guy06882f82009-06-10 13:36:04 -07001593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001594 }
Romain Guy06882f82009-06-10 13:36:04 -07001595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001596 if (needAssignLayers) {
1597 assignLayersLocked();
1598 }
Romain Guy06882f82009-06-10 13:36:04 -07001599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001600 return true;
1601 }
Romain Guy06882f82009-06-10 13:36:04 -07001602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001603 void adjustInputMethodDialogsLocked() {
1604 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1605 }
Romain Guy06882f82009-06-10 13:36:04 -07001606
Dianne Hackborn25994b42009-09-04 14:21:19 -07001607 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001608 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001609 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1610 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1611 ? wallpaperTarget.mAppToken.animation : null)
1612 + " upper=" + mUpperWallpaperTarget
1613 + " lower=" + mLowerWallpaperTarget);
1614 return (wallpaperTarget != null
1615 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1616 && wallpaperTarget.mAppToken.animation != null)))
1617 || mUpperWallpaperTarget != null
1618 || mLowerWallpaperTarget != null;
1619 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001620
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001621 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1622 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001623
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001624 int adjustWallpaperWindowsLocked() {
1625 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001626
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001627 final int dw = mDisplay.getWidth();
1628 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001629
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001630 // First find top-most window that has asked to be on top of the
1631 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001632 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001633 int N = localmWindows.size();
1634 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001635 WindowState foundW = null;
1636 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001637 WindowState topCurW = null;
1638 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001639 int i = N;
1640 while (i > 0) {
1641 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001642 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001643 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1644 if (topCurW == null) {
1645 topCurW = w;
1646 topCurI = i;
1647 }
1648 continue;
1649 }
1650 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001651 if (w.mAppToken != null) {
1652 // If this window's app token is hidden and not animating,
1653 // it is of no interest to us.
1654 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001655 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001656 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001657 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001658 continue;
1659 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001660 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001661 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001662 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1663 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001664 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001665 && (mWallpaperTarget == w
1666 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001667 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001668 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001669 foundW = w;
1670 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001671 if (w == mWallpaperTarget && ((w.mAppToken != null
1672 && w.mAppToken.animation != null)
1673 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001674 // The current wallpaper target is animating, so we'll
1675 // look behind it for another possible target and figure
1676 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001677 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001678 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001679 continue;
1680 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001681 break;
1682 }
1683 }
1684
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001685 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001686 // If we are currently waiting for an app transition, and either
1687 // the current target or the next target are involved with it,
1688 // then hold off on doing anything with the wallpaper.
1689 // Note that we are checking here for just whether the target
1690 // is part of an app token... which is potentially overly aggressive
1691 // (the app token may not be involved in the transition), but good
1692 // enough (we'll just wait until whatever transition is pending
1693 // executes).
1694 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001695 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001696 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001697 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001698 }
1699 if (foundW != null && foundW.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 found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001702 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001703 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001704 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001705
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001706 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001707 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001708 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001709 + " oldTarget: " + mWallpaperTarget);
1710 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001711
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001712 mLowerWallpaperTarget = null;
1713 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001714
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001715 WindowState oldW = mWallpaperTarget;
1716 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001717
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001718 // Now what is happening... if the current and new targets are
1719 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001720 if (foundW != null && oldW != null) {
1721 boolean oldAnim = oldW.mAnimation != null
1722 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1723 boolean foundAnim = foundW.mAnimation != null
1724 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001725 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001726 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001727 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001728 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001729 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001730 int oldI = localmWindows.indexOf(oldW);
1731 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001732 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001733 }
1734 if (oldI >= 0) {
1735 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001736 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001737 + "=" + oldW + "; new#" + foundI
1738 + "=" + foundW);
1739 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001740
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001741 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001742 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001743 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001744 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001745 }
1746 mWallpaperTarget = oldW;
1747 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001748
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001749 // Now set the upper and lower wallpaper targets
1750 // correctly, and make sure that we are positioning
1751 // the wallpaper below the lower.
1752 if (foundI > oldI) {
1753 // The new target is on top of the old one.
1754 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001755 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001756 }
1757 mUpperWallpaperTarget = foundW;
1758 mLowerWallpaperTarget = oldW;
1759 foundW = oldW;
1760 foundI = oldI;
1761 } else {
1762 // The new target is below the old one.
1763 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001764 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001765 }
1766 mUpperWallpaperTarget = oldW;
1767 mLowerWallpaperTarget = foundW;
1768 }
1769 }
1770 }
1771 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001772
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001773 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001774 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001775 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1776 || (mLowerWallpaperTarget.mAppToken != null
1777 && mLowerWallpaperTarget.mAppToken.animation != null);
1778 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1779 || (mUpperWallpaperTarget.mAppToken != null
1780 && mUpperWallpaperTarget.mAppToken.animation != null);
1781 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001782 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001783 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001784 }
1785 mLowerWallpaperTarget = null;
1786 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001787 }
1788 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001789
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001790 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001791 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001792 // The window is visible to the compositor... but is it visible
1793 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001794 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001795 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001796
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001797 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001798 // its layer adjustment. Only do this if we are not transfering
1799 // between two wallpaper targets.
1800 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001801 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001802 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001803
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001804 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1805 * TYPE_LAYER_MULTIPLIER
1806 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001807
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001808 // Now w is the window we are supposed to be behind... but we
1809 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001810 // AND any starting window associated with it, AND below the
1811 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001812 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001813 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001814 if (wb.mBaseLayer < maxLayer &&
1815 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001816 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001817 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001818 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001819 // This window is not related to the previous one in any
1820 // interesting way, so stop here.
1821 break;
1822 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001823 foundW = wb;
1824 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001825 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001826 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001827 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001828 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001829
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001830 if (foundW == null && topCurW != null) {
1831 // There is no wallpaper target, so it goes at the bottom.
1832 // We will assume it is the same place as last time, if known.
1833 foundW = topCurW;
1834 foundI = topCurI+1;
1835 } else {
1836 // Okay i is the position immediately above the wallpaper. Look at
1837 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001838 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001839 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001840
Dianne Hackborn284ac932009-08-28 10:34:25 -07001841 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001842 if (mWallpaperTarget.mWallpaperX >= 0) {
1843 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001844 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001845 }
1846 if (mWallpaperTarget.mWallpaperY >= 0) {
1847 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001848 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001849 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001850 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001851
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001852 // Start stepping backwards from here, ensuring that our wallpaper windows
1853 // are correctly placed.
1854 int curTokenIndex = mWallpaperTokens.size();
1855 while (curTokenIndex > 0) {
1856 curTokenIndex--;
1857 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001858 if (token.hidden == visible) {
1859 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1860 token.hidden = !visible;
1861 // Need to do a layout to ensure the wallpaper now has the
1862 // correct size.
1863 mLayoutNeeded = true;
1864 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001865
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001866 int curWallpaperIndex = token.windows.size();
1867 while (curWallpaperIndex > 0) {
1868 curWallpaperIndex--;
1869 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001870
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001871 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001872 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001873 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001874
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001875 // First, make sure the client has the current visibility
1876 // state.
1877 if (wallpaper.mWallpaperVisible != visible) {
1878 wallpaper.mWallpaperVisible = visible;
1879 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001880 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001881 "Setting visibility of wallpaper " + wallpaper
1882 + ": " + visible);
1883 wallpaper.mClient.dispatchAppVisibility(visible);
1884 } catch (RemoteException e) {
1885 }
1886 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001887
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001888 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001889 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001890 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001891
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001892 // First, if this window is at the current index, then all
1893 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001894 if (wallpaper == foundW) {
1895 foundI--;
1896 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001897 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001898 continue;
1899 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001900
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001901 // The window didn't match... the current wallpaper window,
1902 // wherever it is, is in the wrong place, so make sure it is
1903 // not in the list.
1904 int oldIndex = localmWindows.indexOf(wallpaper);
1905 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001906 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001907 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001908 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001909 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001910 if (oldIndex < foundI) {
1911 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001912 }
1913 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001914
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001915 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001916 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001917 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001918 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001919
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001920 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001921 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001922 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001923 }
1924 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001925
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001926 return changed;
1927 }
1928
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001929 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001930 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001931 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001932 mWallpaperAnimLayerAdjustment = adj;
1933 int curTokenIndex = mWallpaperTokens.size();
1934 while (curTokenIndex > 0) {
1935 curTokenIndex--;
1936 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1937 int curWallpaperIndex = token.windows.size();
1938 while (curWallpaperIndex > 0) {
1939 curWallpaperIndex--;
1940 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1941 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001942 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001943 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001944 }
1945 }
1946 }
1947
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001948 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1949 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001950 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001951 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001952 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001953 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001954 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1955 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1956 changed = wallpaperWin.mXOffset != offset;
1957 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001958 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001959 + wallpaperWin + " x: " + offset);
1960 wallpaperWin.mXOffset = offset;
1961 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001962 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001963 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001964 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001965 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001966 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001967
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001968 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001969 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001970 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1971 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1972 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001973 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001974 + wallpaperWin + " y: " + offset);
1975 changed = true;
1976 wallpaperWin.mYOffset = offset;
1977 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001978 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001979 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001980 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001981 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001982 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001983
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001984 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001985 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001986 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001987 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1988 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001989 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001990 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001991 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001992 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001993 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1994 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001995 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001996 if (mWaitingOnWallpaper != null) {
1997 long start = SystemClock.uptimeMillis();
1998 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1999 < start) {
2000 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002001 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002002 "Waiting for offset complete...");
2003 mWindowMap.wait(WALLPAPER_TIMEOUT);
2004 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002005 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002006 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002007 if ((start+WALLPAPER_TIMEOUT)
2008 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002009 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002010 + wallpaperWin);
2011 mLastWallpaperTimeoutTime = start;
2012 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002013 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002014 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002015 }
2016 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002017 } catch (RemoteException e) {
2018 }
2019 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002020
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002021 return changed;
2022 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002023
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002024 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002025 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002026 if (mWaitingOnWallpaper != null &&
2027 mWaitingOnWallpaper.mClient.asBinder() == window) {
2028 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002029 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002030 }
2031 }
2032 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002033
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002034 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002035 final int dw = mDisplay.getWidth();
2036 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002037
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002038 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002039
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002040 WindowState target = mWallpaperTarget;
2041 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002042 if (target.mWallpaperX >= 0) {
2043 mLastWallpaperX = target.mWallpaperX;
2044 } else if (changingTarget.mWallpaperX >= 0) {
2045 mLastWallpaperX = changingTarget.mWallpaperX;
2046 }
2047 if (target.mWallpaperY >= 0) {
2048 mLastWallpaperY = target.mWallpaperY;
2049 } else if (changingTarget.mWallpaperY >= 0) {
2050 mLastWallpaperY = changingTarget.mWallpaperY;
2051 }
2052 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002053
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002054 int curTokenIndex = mWallpaperTokens.size();
2055 while (curTokenIndex > 0) {
2056 curTokenIndex--;
2057 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2058 int curWallpaperIndex = token.windows.size();
2059 while (curWallpaperIndex > 0) {
2060 curWallpaperIndex--;
2061 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2062 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2063 wallpaper.computeShownFrameLocked();
2064 changed = true;
2065 // We only want to be synchronous with one wallpaper.
2066 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002067 }
2068 }
2069 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002070
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002071 return changed;
2072 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002073
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002074 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002075 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002076 final int dw = mDisplay.getWidth();
2077 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002078
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002079 int curTokenIndex = mWallpaperTokens.size();
2080 while (curTokenIndex > 0) {
2081 curTokenIndex--;
2082 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002083 if (token.hidden == visible) {
2084 token.hidden = !visible;
2085 // Need to do a layout to ensure the wallpaper now has the
2086 // correct size.
2087 mLayoutNeeded = true;
2088 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002089
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002090 int curWallpaperIndex = token.windows.size();
2091 while (curWallpaperIndex > 0) {
2092 curWallpaperIndex--;
2093 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2094 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002095 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002096 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002097
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002098 if (wallpaper.mWallpaperVisible != visible) {
2099 wallpaper.mWallpaperVisible = visible;
2100 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002101 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002102 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002103 + ": " + visible);
2104 wallpaper.mClient.dispatchAppVisibility(visible);
2105 } catch (RemoteException e) {
2106 }
2107 }
2108 }
2109 }
2110 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002112 public int addWindow(Session session, IWindow client,
2113 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac02010-04-22 18:58:52 -07002114 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002115 int res = mPolicy.checkAddPermission(attrs);
2116 if (res != WindowManagerImpl.ADD_OKAY) {
2117 return res;
2118 }
Romain Guy06882f82009-06-10 13:36:04 -07002119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002120 boolean reportNewConfig = false;
2121 WindowState attachedWindow = null;
2122 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002123 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002125 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002126 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002127 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002128 }
Romain Guy06882f82009-06-10 13:36:04 -07002129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002130 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002131 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002132 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2133 }
2134
2135 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002136 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002137 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002138 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002139 + attrs.token + ". Aborting.");
2140 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2141 }
2142 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2143 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002144 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002145 + attrs.token + ". Aborting.");
2146 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2147 }
2148 }
2149
2150 boolean addToken = false;
2151 WindowToken token = mTokenMap.get(attrs.token);
2152 if (token == null) {
2153 if (attrs.type >= FIRST_APPLICATION_WINDOW
2154 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002155 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002156 + attrs.token + ". Aborting.");
2157 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2158 }
2159 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002160 Slog.w(TAG, "Attempted to add input method 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 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002164 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002165 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002166 + attrs.token + ". Aborting.");
2167 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2168 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002169 token = new WindowToken(attrs.token, -1, false);
2170 addToken = true;
2171 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2172 && attrs.type <= LAST_APPLICATION_WINDOW) {
2173 AppWindowToken atoken = token.appWindowToken;
2174 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002175 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002176 + token + ". Aborting.");
2177 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2178 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002179 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002180 + token + ". Aborting.");
2181 return WindowManagerImpl.ADD_APP_EXITING;
2182 }
2183 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2184 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002185 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002186 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2187 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2188 }
2189 } else if (attrs.type == TYPE_INPUT_METHOD) {
2190 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002191 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002192 + attrs.token + ". Aborting.");
2193 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2194 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002195 } else if (attrs.type == TYPE_WALLPAPER) {
2196 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002197 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002198 + attrs.token + ". Aborting.");
2199 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2200 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002201 }
2202
2203 win = new WindowState(session, client, token,
2204 attachedWindow, attrs, viewVisibility);
2205 if (win.mDeathRecipient == null) {
2206 // Client has apparently died, so there is no reason to
2207 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002208 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002209 + " that is dead, aborting.");
2210 return WindowManagerImpl.ADD_APP_EXITING;
2211 }
2212
2213 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002215 res = mPolicy.prepareAddWindowLw(win, attrs);
2216 if (res != WindowManagerImpl.ADD_OKAY) {
2217 return res;
2218 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07002219
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002220 if (outInputChannel != null) {
2221 String name = win.makeInputChannelName();
2222 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2223 win.mInputChannel = inputChannels[0];
2224 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2225
2226 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -07002227 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002228
2229 // From now on, no exceptions or errors allowed!
2230
2231 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002232
Dianne Hackborn5132b372010-07-29 12:51:35 -07002233 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002234
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002235 if (addToken) {
2236 mTokenMap.put(attrs.token, token);
2237 mTokenList.add(token);
2238 }
2239 win.attach();
2240 mWindowMap.put(client.asBinder(), win);
2241
2242 if (attrs.type == TYPE_APPLICATION_STARTING &&
2243 token.appWindowToken != null) {
2244 token.appWindowToken.startingWindow = win;
2245 }
2246
2247 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002249 if (attrs.type == TYPE_INPUT_METHOD) {
2250 mInputMethodWindow = win;
2251 addInputMethodWindowToListLocked(win);
2252 imMayMove = false;
2253 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2254 mInputMethodDialogs.add(win);
2255 addWindowToListInOrderLocked(win, true);
2256 adjustInputMethodDialogsLocked();
2257 imMayMove = false;
2258 } else {
2259 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002260 if (attrs.type == TYPE_WALLPAPER) {
2261 mLastWallpaperTimeoutTime = 0;
2262 adjustWallpaperWindowsLocked();
2263 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002264 adjustWallpaperWindowsLocked();
2265 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002266 }
Romain Guy06882f82009-06-10 13:36:04 -07002267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002268 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002270 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002272 if (mInTouchMode) {
2273 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2274 }
2275 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2276 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2277 }
Romain Guy06882f82009-06-10 13:36:04 -07002278
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002279 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002280 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07002281 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
2282 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002283 imMayMove = false;
2284 }
2285 }
Romain Guy06882f82009-06-10 13:36:04 -07002286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002287 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002288 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002289 }
Romain Guy06882f82009-06-10 13:36:04 -07002290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002291 assignLayersLocked();
2292 // Don't do layout here, the window must call
2293 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002295 //dump();
2296
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002297 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07002298 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002299 }
Jeff Brown349703e2010-06-22 01:27:15 -07002300
Joe Onorato8a9b2202010-02-26 18:56:32 -08002301 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002302 TAG, "New client " + client.asBinder()
2303 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002304
2305 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2306 reportNewConfig = true;
2307 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002308 }
2309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002310 if (reportNewConfig) {
2311 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002312 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002314 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002316 return res;
2317 }
Romain Guy06882f82009-06-10 13:36:04 -07002318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002319 public void removeWindow(Session session, IWindow client) {
2320 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002321 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002322 if (win == null) {
2323 return;
2324 }
2325 removeWindowLocked(session, win);
2326 }
2327 }
Romain Guy06882f82009-06-10 13:36:04 -07002328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002329 public void removeWindowLocked(Session session, WindowState win) {
2330
Joe Onorato8a9b2202010-02-26 18:56:32 -08002331 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002332 TAG, "Remove " + win + " client="
2333 + Integer.toHexString(System.identityHashCode(
2334 win.mClient.asBinder()))
2335 + ", surface=" + win.mSurface);
2336
2337 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002338
2339 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002340
Joe Onorato8a9b2202010-02-26 18:56:32 -08002341 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002342 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2343 + " mExiting=" + win.mExiting
2344 + " isAnimating=" + win.isAnimating()
2345 + " app-animation="
2346 + (win.mAppToken != null ? win.mAppToken.animation : null)
2347 + " inPendingTransaction="
2348 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2349 + " mDisplayFrozen=" + mDisplayFrozen);
2350 // Visibility of the removed window. Will be used later to update orientation later on.
2351 boolean wasVisible = false;
2352 // First, see if we need to run an animation. If we do, we have
2353 // to hold off on removing the window until the animation is done.
2354 // If the display is frozen, just remove immediately, since the
2355 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002356 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002357 // If we are not currently running the exit animation, we
2358 // need to see about starting one.
2359 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002361 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2362 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2363 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2364 }
2365 // Try starting an animation.
2366 if (applyAnimationLocked(win, transit, false)) {
2367 win.mExiting = true;
2368 }
2369 }
2370 if (win.mExiting || win.isAnimating()) {
2371 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002372 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002373 win.mExiting = true;
2374 win.mRemoveOnExit = true;
2375 mLayoutNeeded = true;
2376 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2377 performLayoutAndPlaceSurfacesLocked();
2378 if (win.mAppToken != null) {
2379 win.mAppToken.updateReportedVisibilityLocked();
2380 }
2381 //dump();
2382 Binder.restoreCallingIdentity(origId);
2383 return;
2384 }
2385 }
2386
2387 removeWindowInnerLocked(session, win);
2388 // Removing a visible window will effect the computed orientation
2389 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002390 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002391 != mForcedAppOrientation
2392 && updateOrientationFromAppTokensLocked()) {
2393 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002394 }
2395 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2396 Binder.restoreCallingIdentity(origId);
2397 }
Romain Guy06882f82009-06-10 13:36:04 -07002398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002399 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002400 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002402 if (mInputMethodTarget == win) {
2403 moveInputMethodWindowsIfNeededLocked(false);
2404 }
Romain Guy06882f82009-06-10 13:36:04 -07002405
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002406 if (false) {
2407 RuntimeException e = new RuntimeException("here");
2408 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002409 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002410 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002411
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002412 mPolicy.removeWindowLw(win);
2413 win.removeLocked();
2414
2415 mWindowMap.remove(win.mClient.asBinder());
2416 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002417 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002418 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002419
2420 if (mInputMethodWindow == win) {
2421 mInputMethodWindow = null;
2422 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2423 mInputMethodDialogs.remove(win);
2424 }
Romain Guy06882f82009-06-10 13:36:04 -07002425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002426 final WindowToken token = win.mToken;
2427 final AppWindowToken atoken = win.mAppToken;
2428 token.windows.remove(win);
2429 if (atoken != null) {
2430 atoken.allAppWindows.remove(win);
2431 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002432 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002433 TAG, "**** Removing window " + win + ": count="
2434 + token.windows.size());
2435 if (token.windows.size() == 0) {
2436 if (!token.explicit) {
2437 mTokenMap.remove(token.token);
2438 mTokenList.remove(token);
2439 } else if (atoken != null) {
2440 atoken.firstWindowDrawn = false;
2441 }
2442 }
2443
2444 if (atoken != null) {
2445 if (atoken.startingWindow == win) {
2446 atoken.startingWindow = null;
2447 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2448 // If this is the last window and we had requested a starting
2449 // transition window, well there is no point now.
2450 atoken.startingData = null;
2451 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2452 // If this is the last window except for a starting transition
2453 // window, we need to get rid of the starting transition.
2454 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002455 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002456 + ": no more real windows");
2457 }
2458 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2459 mH.sendMessage(m);
2460 }
2461 }
Romain Guy06882f82009-06-10 13:36:04 -07002462
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002463 if (win.mAttrs.type == TYPE_WALLPAPER) {
2464 mLastWallpaperTimeoutTime = 0;
2465 adjustWallpaperWindowsLocked();
2466 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002467 adjustWallpaperWindowsLocked();
2468 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002469
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002470 if (!mInLayout) {
2471 assignLayersLocked();
2472 mLayoutNeeded = true;
2473 performLayoutAndPlaceSurfacesLocked();
2474 if (win.mAppToken != null) {
2475 win.mAppToken.updateReportedVisibilityLocked();
2476 }
2477 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002478
2479 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002480 }
2481
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002482 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2483 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2484 + ": " + msg + " / " + w.mAttrs.getTitle();
2485 if (where != null) {
2486 Slog.i(TAG, str, where);
2487 } else {
2488 Slog.i(TAG, str);
2489 }
2490 }
2491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002492 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2493 long origId = Binder.clearCallingIdentity();
2494 try {
2495 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002496 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002497 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002498 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002499 Surface.openTransaction();
2500 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002501 if (SHOW_TRANSACTIONS) logSurface(w,
2502 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002503 w.mSurface.setTransparentRegionHint(region);
2504 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002505 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002506 Surface.closeTransaction();
2507 }
2508 }
2509 }
2510 } finally {
2511 Binder.restoreCallingIdentity(origId);
2512 }
2513 }
2514
2515 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002516 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002517 Rect visibleInsets) {
2518 long origId = Binder.clearCallingIdentity();
2519 try {
2520 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002521 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002522 if (w != null) {
2523 w.mGivenInsetsPending = false;
2524 w.mGivenContentInsets.set(contentInsets);
2525 w.mGivenVisibleInsets.set(visibleInsets);
2526 w.mTouchableInsets = touchableInsets;
2527 mLayoutNeeded = true;
2528 performLayoutAndPlaceSurfacesLocked();
2529 }
2530 }
2531 } finally {
2532 Binder.restoreCallingIdentity(origId);
2533 }
2534 }
Romain Guy06882f82009-06-10 13:36:04 -07002535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002536 public void getWindowDisplayFrame(Session session, IWindow client,
2537 Rect outDisplayFrame) {
2538 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002539 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002540 if (win == null) {
2541 outDisplayFrame.setEmpty();
2542 return;
2543 }
2544 outDisplayFrame.set(win.mDisplayFrame);
2545 }
2546 }
2547
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002548 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2549 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002550 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2551 window.mWallpaperX = x;
2552 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002553 window.mWallpaperXStep = xStep;
2554 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002555 if (updateWallpaperOffsetLocked(window, true)) {
2556 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002557 }
2558 }
2559 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002560
Dianne Hackborn75804932009-10-20 20:15:20 -07002561 void wallpaperCommandComplete(IBinder window, Bundle result) {
2562 synchronized (mWindowMap) {
2563 if (mWaitingOnWallpaper != null &&
2564 mWaitingOnWallpaper.mClient.asBinder() == window) {
2565 mWaitingOnWallpaper = null;
2566 mWindowMap.notifyAll();
2567 }
2568 }
2569 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002570
Dianne Hackborn75804932009-10-20 20:15:20 -07002571 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2572 String action, int x, int y, int z, Bundle extras, boolean sync) {
2573 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2574 || window == mUpperWallpaperTarget) {
2575 boolean doWait = sync;
2576 int curTokenIndex = mWallpaperTokens.size();
2577 while (curTokenIndex > 0) {
2578 curTokenIndex--;
2579 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2580 int curWallpaperIndex = token.windows.size();
2581 while (curWallpaperIndex > 0) {
2582 curWallpaperIndex--;
2583 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2584 try {
2585 wallpaper.mClient.dispatchWallpaperCommand(action,
2586 x, y, z, extras, sync);
2587 // We only want to be synchronous with one wallpaper.
2588 sync = false;
2589 } catch (RemoteException e) {
2590 }
2591 }
2592 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002593
Dianne Hackborn75804932009-10-20 20:15:20 -07002594 if (doWait) {
2595 // XXX Need to wait for result.
2596 }
2597 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002598
Dianne Hackborn75804932009-10-20 20:15:20 -07002599 return null;
2600 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002602 public int relayoutWindow(Session session, IWindow client,
2603 WindowManager.LayoutParams attrs, int requestedWidth,
2604 int requestedHeight, int viewVisibility, boolean insetsPending,
2605 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002606 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002607 boolean displayed = false;
2608 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002609 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002610 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002612 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002613 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002614 if (win == null) {
2615 return 0;
2616 }
2617 win.mRequestedWidth = requestedWidth;
2618 win.mRequestedHeight = requestedHeight;
2619
2620 if (attrs != null) {
2621 mPolicy.adjustWindowParamsLw(attrs);
2622 }
Romain Guy06882f82009-06-10 13:36:04 -07002623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002624 int attrChanges = 0;
2625 int flagChanges = 0;
2626 if (attrs != null) {
2627 flagChanges = win.mAttrs.flags ^= attrs.flags;
2628 attrChanges = win.mAttrs.copyFrom(attrs);
2629 }
2630
Joe Onorato8a9b2202010-02-26 18:56:32 -08002631 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002632
2633 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2634 win.mAlpha = attrs.alpha;
2635 }
2636
2637 final boolean scaledWindow =
2638 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2639
2640 if (scaledWindow) {
2641 // requested{Width|Height} Surface's physical size
2642 // attrs.{width|height} Size on screen
2643 win.mHScale = (attrs.width != requestedWidth) ?
2644 (attrs.width / (float)requestedWidth) : 1.0f;
2645 win.mVScale = (attrs.height != requestedHeight) ?
2646 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002647 } else {
2648 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002649 }
2650
2651 boolean imMayMove = (flagChanges&(
2652 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2653 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002655 boolean focusMayChange = win.mViewVisibility != viewVisibility
2656 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2657 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002658
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002659 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2660 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002662 win.mRelayoutCalled = true;
2663 final int oldVisibility = win.mViewVisibility;
2664 win.mViewVisibility = viewVisibility;
2665 if (viewVisibility == View.VISIBLE &&
2666 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2667 displayed = !win.isVisibleLw();
2668 if (win.mExiting) {
2669 win.mExiting = false;
2670 win.mAnimation = null;
2671 }
2672 if (win.mDestroying) {
2673 win.mDestroying = false;
2674 mDestroySurface.remove(win);
2675 }
2676 if (oldVisibility == View.GONE) {
2677 win.mEnterAnimationPending = true;
2678 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002679 if (displayed) {
2680 if (win.mSurface != null && !win.mDrawPending
2681 && !win.mCommitDrawPending && !mDisplayFrozen
2682 && mPolicy.isScreenOn()) {
2683 applyEnterAnimationLocked(win);
2684 }
2685 if ((win.mAttrs.flags
2686 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2687 if (DEBUG_VISIBILITY) Slog.v(TAG,
2688 "Relayout window turning screen on: " + win);
2689 win.mTurnOnScreen = true;
2690 }
2691 int diff = 0;
2692 if (win.mConfiguration != mCurConfiguration
2693 && (win.mConfiguration == null
2694 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2695 win.mConfiguration = mCurConfiguration;
2696 if (DEBUG_CONFIGURATION) {
2697 Slog.i(TAG, "Window " + win + " visible with new config: "
2698 + win.mConfiguration + " / 0x"
2699 + Integer.toHexString(diff));
2700 }
2701 outConfig.setTo(mCurConfiguration);
2702 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002703 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002704 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2705 // To change the format, we need to re-build the surface.
2706 win.destroySurfaceLocked();
2707 displayed = true;
2708 }
2709 try {
2710 Surface surface = win.createSurfaceLocked();
2711 if (surface != null) {
2712 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002713 win.mReportDestroySurface = false;
2714 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002715 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002716 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002717 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002718 // For some reason there isn't a surface. Clear the
2719 // caller's object so they see the same state.
2720 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002721 }
2722 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002723 mInputMonitor.updateInputWindowsLw();
2724
Joe Onorato8a9b2202010-02-26 18:56:32 -08002725 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002726 + client + " (" + win.mAttrs.getTitle() + ")",
2727 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002728 Binder.restoreCallingIdentity(origId);
2729 return 0;
2730 }
2731 if (displayed) {
2732 focusMayChange = true;
2733 }
2734 if (win.mAttrs.type == TYPE_INPUT_METHOD
2735 && mInputMethodWindow == null) {
2736 mInputMethodWindow = win;
2737 imMayMove = true;
2738 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002739 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2740 && win.mAppToken != null
2741 && win.mAppToken.startingWindow != null) {
2742 // Special handling of starting window over the base
2743 // window of the app: propagate lock screen flags to it,
2744 // to provide the correct semantics while starting.
2745 final int mask =
2746 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002747 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2748 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002749 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2750 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2751 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002752 } else {
2753 win.mEnterAnimationPending = false;
2754 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002755 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002756 + ": mExiting=" + win.mExiting
2757 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002758 // If we are not currently running the exit animation, we
2759 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002760 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002761 // Try starting an animation; if there isn't one, we
2762 // can destroy the surface right away.
2763 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2764 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2765 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2766 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002767 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002768 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002769 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002770 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002771 } else if (win.isAnimating()) {
2772 // Currently in a hide animation... turn this into
2773 // an exit.
2774 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002775 } else if (win == mWallpaperTarget) {
2776 // If the wallpaper is currently behind this
2777 // window, we need to change both of them inside
2778 // of a transaction to avoid artifacts.
2779 win.mExiting = true;
2780 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002781 } else {
2782 if (mInputMethodWindow == win) {
2783 mInputMethodWindow = null;
2784 }
2785 win.destroySurfaceLocked();
2786 }
2787 }
2788 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002789
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002790 if (win.mSurface == null || (win.getAttrs().flags
2791 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2792 || win.mSurfacePendingDestroy) {
2793 // We are being called from a local process, which
2794 // means outSurface holds its current surface. Ensure the
2795 // surface object is cleared, but we don't want it actually
2796 // destroyed at this point.
2797 win.mSurfacePendingDestroy = false;
2798 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002799 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002800 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002801 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002802 "Keeping surface, will report destroy: " + win);
2803 win.mReportDestroySurface = true;
2804 outSurface.copyFrom(win.mSurface);
2805 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002806 }
2807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002808 if (focusMayChange) {
2809 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2810 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002811 imMayMove = false;
2812 }
2813 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2814 }
Romain Guy06882f82009-06-10 13:36:04 -07002815
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002816 // updateFocusedWindowLocked() already assigned layers so we only need to
2817 // reassign them at this point if the IM window state gets shuffled
2818 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002819
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002820 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002821 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2822 // Little hack here -- we -should- be able to rely on the
2823 // function to return true if the IME has moved and needs
2824 // its layer recomputed. However, if the IME was hidden
2825 // and isn't actually moved in the list, its layer may be
2826 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002827 assignLayers = true;
2828 }
2829 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002830 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002831 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002832 assignLayers = true;
2833 }
2834 }
Romain Guy06882f82009-06-10 13:36:04 -07002835
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002836 mLayoutNeeded = true;
2837 win.mGivenInsetsPending = insetsPending;
2838 if (assignLayers) {
2839 assignLayersLocked();
2840 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002841 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002842 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002843 if (displayed && win.mIsWallpaper) {
2844 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002845 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002846 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002847 if (win.mAppToken != null) {
2848 win.mAppToken.updateReportedVisibilityLocked();
2849 }
2850 outFrame.set(win.mFrame);
2851 outContentInsets.set(win.mContentInsets);
2852 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002853 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002854 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002855 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002856 + ", requestedHeight=" + requestedHeight
2857 + ", viewVisibility=" + viewVisibility
2858 + "\nRelayout returning frame=" + outFrame
2859 + ", surface=" + outSurface);
2860
Joe Onorato8a9b2202010-02-26 18:56:32 -08002861 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002862 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2863
2864 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002865
2866 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002867 }
2868
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002869 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002870 sendNewConfiguration();
2871 }
Romain Guy06882f82009-06-10 13:36:04 -07002872
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002873 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002875 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2876 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2877 }
2878
2879 public void finishDrawingWindow(Session session, IWindow client) {
2880 final long origId = Binder.clearCallingIdentity();
2881 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002882 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002883 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002884 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2885 adjustWallpaperWindowsLocked();
2886 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002887 mLayoutNeeded = true;
2888 performLayoutAndPlaceSurfacesLocked();
2889 }
2890 }
2891 Binder.restoreCallingIdentity(origId);
2892 }
2893
2894 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002895 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002896 + (lp != null ? lp.packageName : null)
2897 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2898 if (lp != null && lp.windowAnimations != 0) {
2899 // If this is a system resource, don't try to load it from the
2900 // application resources. It is nice to avoid loading application
2901 // resources if we can.
2902 String packageName = lp.packageName != null ? lp.packageName : "android";
2903 int resId = lp.windowAnimations;
2904 if ((resId&0xFF000000) == 0x01000000) {
2905 packageName = "android";
2906 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002907 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002908 + packageName);
2909 return AttributeCache.instance().get(packageName, resId,
2910 com.android.internal.R.styleable.WindowAnimation);
2911 }
2912 return null;
2913 }
Romain Guy06882f82009-06-10 13:36:04 -07002914
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002915 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002916 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002917 + packageName + " resId=0x" + Integer.toHexString(resId));
2918 if (packageName != null) {
2919 if ((resId&0xFF000000) == 0x01000000) {
2920 packageName = "android";
2921 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002922 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002923 + packageName);
2924 return AttributeCache.instance().get(packageName, resId,
2925 com.android.internal.R.styleable.WindowAnimation);
2926 }
2927 return null;
2928 }
2929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002930 private void applyEnterAnimationLocked(WindowState win) {
2931 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2932 if (win.mEnterAnimationPending) {
2933 win.mEnterAnimationPending = false;
2934 transit = WindowManagerPolicy.TRANSIT_ENTER;
2935 }
2936
2937 applyAnimationLocked(win, transit, true);
2938 }
2939
2940 private boolean applyAnimationLocked(WindowState win,
2941 int transit, boolean isEntrance) {
2942 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2943 // If we are trying to apply an animation, but already running
2944 // an animation of the same type, then just leave that one alone.
2945 return true;
2946 }
Romain Guy06882f82009-06-10 13:36:04 -07002947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002948 // Only apply an animation if the display isn't frozen. If it is
2949 // frozen, there is no reason to animate and it can cause strange
2950 // artifacts when we unfreeze the display if some different animation
2951 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002952 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002953 int anim = mPolicy.selectAnimationLw(win, transit);
2954 int attr = -1;
2955 Animation a = null;
2956 if (anim != 0) {
2957 a = AnimationUtils.loadAnimation(mContext, anim);
2958 } else {
2959 switch (transit) {
2960 case WindowManagerPolicy.TRANSIT_ENTER:
2961 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2962 break;
2963 case WindowManagerPolicy.TRANSIT_EXIT:
2964 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2965 break;
2966 case WindowManagerPolicy.TRANSIT_SHOW:
2967 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2968 break;
2969 case WindowManagerPolicy.TRANSIT_HIDE:
2970 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2971 break;
2972 }
2973 if (attr >= 0) {
2974 a = loadAnimation(win.mAttrs, attr);
2975 }
2976 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002977 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002978 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2979 + " mAnimation=" + win.mAnimation
2980 + " isEntrance=" + isEntrance);
2981 if (a != null) {
2982 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002983 RuntimeException e = null;
2984 if (!HIDE_STACK_CRAWLS) {
2985 e = new RuntimeException();
2986 e.fillInStackTrace();
2987 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002988 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002989 }
2990 win.setAnimation(a);
2991 win.mAnimationIsEntrance = isEntrance;
2992 }
2993 } else {
2994 win.clearAnimation();
2995 }
2996
2997 return win.mAnimation != null;
2998 }
2999
3000 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3001 int anim = 0;
3002 Context context = mContext;
3003 if (animAttr >= 0) {
3004 AttributeCache.Entry ent = getCachedAnimations(lp);
3005 if (ent != null) {
3006 context = ent.context;
3007 anim = ent.array.getResourceId(animAttr, 0);
3008 }
3009 }
3010 if (anim != 0) {
3011 return AnimationUtils.loadAnimation(context, anim);
3012 }
3013 return null;
3014 }
Romain Guy06882f82009-06-10 13:36:04 -07003015
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003016 private Animation loadAnimation(String packageName, int resId) {
3017 int anim = 0;
3018 Context context = mContext;
3019 if (resId >= 0) {
3020 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3021 if (ent != null) {
3022 context = ent.context;
3023 anim = resId;
3024 }
3025 }
3026 if (anim != 0) {
3027 return AnimationUtils.loadAnimation(context, anim);
3028 }
3029 return null;
3030 }
3031
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003032 private boolean applyAnimationLocked(AppWindowToken wtoken,
3033 WindowManager.LayoutParams lp, int transit, boolean enter) {
3034 // Only apply an animation if the display isn't frozen. If it is
3035 // frozen, there is no reason to animate and it can cause strange
3036 // artifacts when we unfreeze the display if some different animation
3037 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003038 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003039 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003040 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003041 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003042 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003043 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003044 } else if (mNextAppTransitionPackage != null) {
3045 a = loadAnimation(mNextAppTransitionPackage, enter ?
3046 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003047 } else {
3048 int animAttr = 0;
3049 switch (transit) {
3050 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3051 animAttr = enter
3052 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3053 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3054 break;
3055 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3056 animAttr = enter
3057 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3058 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3059 break;
3060 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3061 animAttr = enter
3062 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3063 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3064 break;
3065 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3066 animAttr = enter
3067 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3068 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3069 break;
3070 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3071 animAttr = enter
3072 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3073 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3074 break;
3075 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3076 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003077 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003078 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3079 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003080 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003081 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003082 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3083 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003084 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003085 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003086 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003087 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3088 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3089 break;
3090 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3091 animAttr = enter
3092 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3093 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3094 break;
3095 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3096 animAttr = enter
3097 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3098 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003099 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003100 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003101 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003102 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003103 + " anim=" + a
3104 + " animAttr=0x" + Integer.toHexString(animAttr)
3105 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003106 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003107 if (a != null) {
3108 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003109 RuntimeException e = null;
3110 if (!HIDE_STACK_CRAWLS) {
3111 e = new RuntimeException();
3112 e.fillInStackTrace();
3113 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003114 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003115 }
3116 wtoken.setAnimation(a);
3117 }
3118 } else {
3119 wtoken.clearAnimation();
3120 }
3121
3122 return wtoken.animation != null;
3123 }
3124
3125 // -------------------------------------------------------------
3126 // Application Window Tokens
3127 // -------------------------------------------------------------
3128
3129 public void validateAppTokens(List tokens) {
3130 int v = tokens.size()-1;
3131 int m = mAppTokens.size()-1;
3132 while (v >= 0 && m >= 0) {
3133 AppWindowToken wtoken = mAppTokens.get(m);
3134 if (wtoken.removed) {
3135 m--;
3136 continue;
3137 }
3138 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003139 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003140 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3141 }
3142 v--;
3143 m--;
3144 }
3145 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003146 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003147 v--;
3148 }
3149 while (m >= 0) {
3150 AppWindowToken wtoken = mAppTokens.get(m);
3151 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003152 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003153 }
3154 m--;
3155 }
3156 }
3157
3158 boolean checkCallingPermission(String permission, String func) {
3159 // Quick check: if the calling permission is me, it's all okay.
3160 if (Binder.getCallingPid() == Process.myPid()) {
3161 return true;
3162 }
Romain Guy06882f82009-06-10 13:36:04 -07003163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003164 if (mContext.checkCallingPermission(permission)
3165 == PackageManager.PERMISSION_GRANTED) {
3166 return true;
3167 }
3168 String msg = "Permission Denial: " + func + " from pid="
3169 + Binder.getCallingPid()
3170 + ", uid=" + Binder.getCallingUid()
3171 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003172 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003173 return false;
3174 }
Romain Guy06882f82009-06-10 13:36:04 -07003175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003176 AppWindowToken findAppWindowToken(IBinder token) {
3177 WindowToken wtoken = mTokenMap.get(token);
3178 if (wtoken == null) {
3179 return null;
3180 }
3181 return wtoken.appWindowToken;
3182 }
Romain Guy06882f82009-06-10 13:36:04 -07003183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003184 public void addWindowToken(IBinder token, int type) {
3185 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3186 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003187 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003188 }
Romain Guy06882f82009-06-10 13:36:04 -07003189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003190 synchronized(mWindowMap) {
3191 WindowToken wtoken = mTokenMap.get(token);
3192 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003193 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003194 return;
3195 }
3196 wtoken = new WindowToken(token, type, true);
3197 mTokenMap.put(token, wtoken);
3198 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003199 if (type == TYPE_WALLPAPER) {
3200 mWallpaperTokens.add(wtoken);
3201 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003202 }
3203 }
Romain Guy06882f82009-06-10 13:36:04 -07003204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003205 public void removeWindowToken(IBinder token) {
3206 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3207 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003208 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003209 }
3210
3211 final long origId = Binder.clearCallingIdentity();
3212 synchronized(mWindowMap) {
3213 WindowToken wtoken = mTokenMap.remove(token);
3214 mTokenList.remove(wtoken);
3215 if (wtoken != null) {
3216 boolean delayed = false;
3217 if (!wtoken.hidden) {
3218 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003220 final int N = wtoken.windows.size();
3221 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003223 for (int i=0; i<N; i++) {
3224 WindowState win = wtoken.windows.get(i);
3225
3226 if (win.isAnimating()) {
3227 delayed = true;
3228 }
Romain Guy06882f82009-06-10 13:36:04 -07003229
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003230 if (win.isVisibleNow()) {
3231 applyAnimationLocked(win,
3232 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003233 changed = true;
3234 }
3235 }
3236
3237 if (changed) {
3238 mLayoutNeeded = true;
3239 performLayoutAndPlaceSurfacesLocked();
3240 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3241 }
Romain Guy06882f82009-06-10 13:36:04 -07003242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003243 if (delayed) {
3244 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003245 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3246 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003247 }
3248 }
Romain Guy06882f82009-06-10 13:36:04 -07003249
Jeff Brownc5ed5912010-07-14 18:48:53 -07003250 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003251 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003252 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003253 }
3254 }
3255 Binder.restoreCallingIdentity(origId);
3256 }
3257
3258 public void addAppToken(int addPos, IApplicationToken token,
3259 int groupId, int requestedOrientation, boolean fullscreen) {
3260 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3261 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003262 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003263 }
Jeff Brown349703e2010-06-22 01:27:15 -07003264
3265 // Get the dispatching timeout here while we are not holding any locks so that it
3266 // can be cached by the AppWindowToken. The timeout value is used later by the
3267 // input dispatcher in code that does hold locks. If we did not cache the value
3268 // here we would run the chance of introducing a deadlock between the window manager
3269 // (which holds locks while updating the input dispatcher state) and the activity manager
3270 // (which holds locks while querying the application token).
3271 long inputDispatchingTimeoutNanos;
3272 try {
3273 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3274 } catch (RemoteException ex) {
3275 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3276 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3277 }
Romain Guy06882f82009-06-10 13:36:04 -07003278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003279 synchronized(mWindowMap) {
3280 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3281 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003282 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003283 return;
3284 }
3285 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003286 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003287 wtoken.groupId = groupId;
3288 wtoken.appFullscreen = fullscreen;
3289 wtoken.requestedOrientation = requestedOrientation;
3290 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003291 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003292 mTokenMap.put(token.asBinder(), wtoken);
3293 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003295 // Application tokens start out hidden.
3296 wtoken.hidden = true;
3297 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003299 //dump();
3300 }
3301 }
Romain Guy06882f82009-06-10 13:36:04 -07003302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003303 public void setAppGroupId(IBinder token, int groupId) {
3304 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3305 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003306 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003307 }
3308
3309 synchronized(mWindowMap) {
3310 AppWindowToken wtoken = findAppWindowToken(token);
3311 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003312 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003313 return;
3314 }
3315 wtoken.groupId = groupId;
3316 }
3317 }
Romain Guy06882f82009-06-10 13:36:04 -07003318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003319 public int getOrientationFromWindowsLocked() {
3320 int pos = mWindows.size() - 1;
3321 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003322 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003323 pos--;
3324 if (wtoken.mAppToken != null) {
3325 // We hit an application window. so the orientation will be determined by the
3326 // app window. No point in continuing further.
3327 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3328 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003329 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003330 continue;
3331 }
3332 int req = wtoken.mAttrs.screenOrientation;
3333 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3334 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3335 continue;
3336 } else {
3337 return req;
3338 }
3339 }
3340 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3341 }
Romain Guy06882f82009-06-10 13:36:04 -07003342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003343 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003344 int pos = mAppTokens.size() - 1;
3345 int curGroup = 0;
3346 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3347 boolean findingBehind = false;
3348 boolean haveGroup = false;
3349 boolean lastFullscreen = false;
3350 while (pos >= 0) {
3351 AppWindowToken wtoken = mAppTokens.get(pos);
3352 pos--;
3353 // if we're about to tear down this window and not seek for
3354 // the behind activity, don't use it for orientation
3355 if (!findingBehind
3356 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3357 continue;
3358 }
3359
3360 if (!haveGroup) {
3361 // We ignore any hidden applications on the top.
3362 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003363 continue;
3364 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003365 haveGroup = true;
3366 curGroup = wtoken.groupId;
3367 lastOrientation = wtoken.requestedOrientation;
3368 } else if (curGroup != wtoken.groupId) {
3369 // If we have hit a new application group, and the bottom
3370 // of the previous group didn't explicitly say to use
3371 // the orientation behind it, and the last app was
3372 // full screen, then we'll stick with the
3373 // user's orientation.
3374 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3375 && lastFullscreen) {
3376 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003377 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003378 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003379 int or = wtoken.requestedOrientation;
3380 // If this application is fullscreen, and didn't explicitly say
3381 // to use the orientation behind it, then just take whatever
3382 // orientation it has and ignores whatever is under it.
3383 lastFullscreen = wtoken.appFullscreen;
3384 if (lastFullscreen
3385 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3386 return or;
3387 }
3388 // If this application has requested an explicit orientation,
3389 // then use it.
3390 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
3391 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
3392 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
3393 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
3394 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
3395 return or;
3396 }
3397 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3398 }
3399 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003400 }
Romain Guy06882f82009-06-10 13:36:04 -07003401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003402 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003403 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003404 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3405 "updateOrientationFromAppTokens()")) {
3406 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3407 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003408
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003409 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003410 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003411
3412 synchronized(mWindowMap) {
3413 if (updateOrientationFromAppTokensLocked()) {
3414 if (freezeThisOneIfNeeded != null) {
3415 AppWindowToken wtoken = findAppWindowToken(
3416 freezeThisOneIfNeeded);
3417 if (wtoken != null) {
3418 startAppFreezingScreenLocked(wtoken,
3419 ActivityInfo.CONFIG_ORIENTATION);
3420 }
3421 }
3422 config = computeNewConfigurationLocked();
3423
3424 } else if (currentConfig != null) {
3425 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003426 // state mismatches the activity manager's, update it,
3427 // disregarding font scale, which should remain set to
3428 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003429 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003430 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003431 if (computeNewConfigurationLocked(mTempConfiguration)) {
3432 if (currentConfig.diff(mTempConfiguration) != 0) {
3433 mWaitingForConfig = true;
3434 mLayoutNeeded = true;
3435 startFreezingDisplayLocked();
3436 config = new Configuration(mTempConfiguration);
3437 }
3438 }
3439 }
3440 }
3441
Dianne Hackborncfaef692009-06-15 14:24:44 -07003442 Binder.restoreCallingIdentity(ident);
3443 return config;
3444 }
3445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003446 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003447 * Determine the new desired orientation of the display, returning
3448 * a non-null new Configuration if it has changed from the current
3449 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3450 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3451 * SCREEN. This will typically be done for you if you call
3452 * sendNewConfiguration().
3453 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003454 * The orientation is computed from non-application windows first. If none of
3455 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003456 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003457 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3458 * android.os.IBinder)
3459 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003460 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003461 if (mDisplayFrozen) {
3462 // If the display is frozen, some activities may be in the middle
3463 // of restarting, and thus have removed their old window. If the
3464 // window has the flag to hide the lock screen, then the lock screen
3465 // can re-appear and inflict its own orientation on us. Keep the
3466 // orientation stable until this all settles down.
3467 return false;
3468 }
3469
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003470 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003471 long ident = Binder.clearCallingIdentity();
3472 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003473 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003475 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003476 mForcedAppOrientation = req;
3477 //send a message to Policy indicating orientation change to take
3478 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003479 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003480 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3481 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3482 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003483 }
3484 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003485
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003486 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003487 } finally {
3488 Binder.restoreCallingIdentity(ident);
3489 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003490 }
Romain Guy06882f82009-06-10 13:36:04 -07003491
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003492 int computeForcedAppOrientationLocked() {
3493 int req = getOrientationFromWindowsLocked();
3494 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3495 req = getOrientationFromAppTokensLocked();
3496 }
3497 return req;
3498 }
Romain Guy06882f82009-06-10 13:36:04 -07003499
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003500 public void setNewConfiguration(Configuration config) {
3501 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3502 "setNewConfiguration()")) {
3503 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3504 }
3505
3506 synchronized(mWindowMap) {
3507 mCurConfiguration = new Configuration(config);
3508 mWaitingForConfig = false;
3509 performLayoutAndPlaceSurfacesLocked();
3510 }
3511 }
3512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003513 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3514 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3515 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003516 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003517 }
Romain Guy06882f82009-06-10 13:36:04 -07003518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003519 synchronized(mWindowMap) {
3520 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3521 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003522 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003523 return;
3524 }
Romain Guy06882f82009-06-10 13:36:04 -07003525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003526 wtoken.requestedOrientation = requestedOrientation;
3527 }
3528 }
Romain Guy06882f82009-06-10 13:36:04 -07003529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003530 public int getAppOrientation(IApplicationToken token) {
3531 synchronized(mWindowMap) {
3532 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3533 if (wtoken == null) {
3534 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3535 }
Romain Guy06882f82009-06-10 13:36:04 -07003536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003537 return wtoken.requestedOrientation;
3538 }
3539 }
Romain Guy06882f82009-06-10 13:36:04 -07003540
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003541 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3542 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3543 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003544 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003545 }
3546
3547 synchronized(mWindowMap) {
3548 boolean changed = false;
3549 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003550 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003551 changed = mFocusedApp != null;
3552 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003553 if (changed) {
3554 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003555 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003556 } else {
3557 AppWindowToken newFocus = findAppWindowToken(token);
3558 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003559 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003560 return;
3561 }
3562 changed = mFocusedApp != newFocus;
3563 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003564 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003565 if (changed) {
3566 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003567 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003568 }
3569
3570 if (moveFocusNow && changed) {
3571 final long origId = Binder.clearCallingIdentity();
3572 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3573 Binder.restoreCallingIdentity(origId);
3574 }
3575 }
3576 }
3577
3578 public void prepareAppTransition(int transit) {
3579 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3580 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003581 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003582 }
Romain Guy06882f82009-06-10 13:36:04 -07003583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003584 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003585 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003586 TAG, "Prepare app transition: transit=" + transit
3587 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003588 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003589 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3590 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003591 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003592 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3593 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3594 // Opening a new task always supersedes a close for the anim.
3595 mNextAppTransition = transit;
3596 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3597 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3598 // Opening a new activity always supersedes a close for the anim.
3599 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003600 }
3601 mAppTransitionReady = false;
3602 mAppTransitionTimeout = false;
3603 mStartingIconInTransition = false;
3604 mSkipAppTransitionAnimation = false;
3605 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3606 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3607 5000);
3608 }
3609 }
3610 }
3611
3612 public int getPendingAppTransition() {
3613 return mNextAppTransition;
3614 }
Romain Guy06882f82009-06-10 13:36:04 -07003615
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003616 public void overridePendingAppTransition(String packageName,
3617 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003618 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003619 mNextAppTransitionPackage = packageName;
3620 mNextAppTransitionEnter = enterAnim;
3621 mNextAppTransitionExit = exitAnim;
3622 }
3623 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003625 public void executeAppTransition() {
3626 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3627 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003628 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003629 }
Romain Guy06882f82009-06-10 13:36:04 -07003630
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003631 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003632 if (DEBUG_APP_TRANSITIONS) {
3633 RuntimeException e = new RuntimeException("here");
3634 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003635 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003636 + mNextAppTransition, e);
3637 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003638 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003639 mAppTransitionReady = true;
3640 final long origId = Binder.clearCallingIdentity();
3641 performLayoutAndPlaceSurfacesLocked();
3642 Binder.restoreCallingIdentity(origId);
3643 }
3644 }
3645 }
3646
3647 public void setAppStartingWindow(IBinder token, String pkg,
3648 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3649 IBinder transferFrom, boolean createIfNeeded) {
3650 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3651 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003652 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003653 }
3654
3655 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003656 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003657 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3658 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003660 AppWindowToken wtoken = findAppWindowToken(token);
3661 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003662 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003663 return;
3664 }
3665
3666 // If the display is frozen, we won't do anything until the
3667 // actual window is displayed so there is no reason to put in
3668 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003669 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003670 return;
3671 }
Romain Guy06882f82009-06-10 13:36:04 -07003672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003673 if (wtoken.startingData != null) {
3674 return;
3675 }
Romain Guy06882f82009-06-10 13:36:04 -07003676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003677 if (transferFrom != null) {
3678 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3679 if (ttoken != null) {
3680 WindowState startingWindow = ttoken.startingWindow;
3681 if (startingWindow != null) {
3682 if (mStartingIconInTransition) {
3683 // In this case, the starting icon has already
3684 // been displayed, so start letting windows get
3685 // shown immediately without any more transitions.
3686 mSkipAppTransitionAnimation = true;
3687 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003688 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003689 "Moving existing starting from " + ttoken
3690 + " to " + wtoken);
3691 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003693 // Transfer the starting window over to the new
3694 // token.
3695 wtoken.startingData = ttoken.startingData;
3696 wtoken.startingView = ttoken.startingView;
3697 wtoken.startingWindow = startingWindow;
3698 ttoken.startingData = null;
3699 ttoken.startingView = null;
3700 ttoken.startingWindow = null;
3701 ttoken.startingMoved = true;
3702 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003703 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003704 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003705 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003706 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003707 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003708 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003709 ttoken.windows.remove(startingWindow);
3710 ttoken.allAppWindows.remove(startingWindow);
3711 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003713 // Propagate other interesting state between the
3714 // tokens. If the old token is displayed, we should
3715 // immediately force the new one to be displayed. If
3716 // it is animating, we need to move that animation to
3717 // the new one.
3718 if (ttoken.allDrawn) {
3719 wtoken.allDrawn = true;
3720 }
3721 if (ttoken.firstWindowDrawn) {
3722 wtoken.firstWindowDrawn = true;
3723 }
3724 if (!ttoken.hidden) {
3725 wtoken.hidden = false;
3726 wtoken.hiddenRequested = false;
3727 wtoken.willBeHidden = false;
3728 }
3729 if (wtoken.clientHidden != ttoken.clientHidden) {
3730 wtoken.clientHidden = ttoken.clientHidden;
3731 wtoken.sendAppVisibilityToClients();
3732 }
3733 if (ttoken.animation != null) {
3734 wtoken.animation = ttoken.animation;
3735 wtoken.animating = ttoken.animating;
3736 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3737 ttoken.animation = null;
3738 ttoken.animLayerAdjustment = 0;
3739 wtoken.updateLayers();
3740 ttoken.updateLayers();
3741 }
Romain Guy06882f82009-06-10 13:36:04 -07003742
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003743 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003744 mLayoutNeeded = true;
3745 performLayoutAndPlaceSurfacesLocked();
3746 Binder.restoreCallingIdentity(origId);
3747 return;
3748 } else if (ttoken.startingData != null) {
3749 // The previous app was getting ready to show a
3750 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003751 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003752 "Moving pending starting from " + ttoken
3753 + " to " + wtoken);
3754 wtoken.startingData = ttoken.startingData;
3755 ttoken.startingData = null;
3756 ttoken.startingMoved = true;
3757 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3758 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3759 // want to process the message ASAP, before any other queued
3760 // messages.
3761 mH.sendMessageAtFrontOfQueue(m);
3762 return;
3763 }
3764 }
3765 }
3766
3767 // There is no existing starting window, and the caller doesn't
3768 // want us to create one, so that's it!
3769 if (!createIfNeeded) {
3770 return;
3771 }
Romain Guy06882f82009-06-10 13:36:04 -07003772
Dianne Hackborn284ac932009-08-28 10:34:25 -07003773 // If this is a translucent or wallpaper window, then don't
3774 // show a starting window -- the current effect (a full-screen
3775 // opaque starting window that fades away to the real contents
3776 // when it is ready) does not work for this.
3777 if (theme != 0) {
3778 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3779 com.android.internal.R.styleable.Window);
3780 if (ent.array.getBoolean(
3781 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3782 return;
3783 }
3784 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003785 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3786 return;
3787 }
3788 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003789 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3790 return;
3791 }
3792 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003794 mStartingIconInTransition = true;
3795 wtoken.startingData = new StartingData(
3796 pkg, theme, nonLocalizedLabel,
3797 labelRes, icon);
3798 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3799 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3800 // want to process the message ASAP, before any other queued
3801 // messages.
3802 mH.sendMessageAtFrontOfQueue(m);
3803 }
3804 }
3805
3806 public void setAppWillBeHidden(IBinder token) {
3807 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3808 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003809 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003810 }
3811
3812 AppWindowToken wtoken;
3813
3814 synchronized(mWindowMap) {
3815 wtoken = findAppWindowToken(token);
3816 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003817 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 -08003818 return;
3819 }
3820 wtoken.willBeHidden = true;
3821 }
3822 }
Romain Guy06882f82009-06-10 13:36:04 -07003823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003824 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3825 boolean visible, int transit, boolean performLayout) {
3826 boolean delayed = false;
3827
3828 if (wtoken.clientHidden == visible) {
3829 wtoken.clientHidden = !visible;
3830 wtoken.sendAppVisibilityToClients();
3831 }
Romain Guy06882f82009-06-10 13:36:04 -07003832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003833 wtoken.willBeHidden = false;
3834 if (wtoken.hidden == visible) {
3835 final int N = wtoken.allAppWindows.size();
3836 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003837 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003838 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3839 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003840
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003841 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003842
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003843 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003844 if (wtoken.animation == sDummyAnimation) {
3845 wtoken.animation = null;
3846 }
3847 applyAnimationLocked(wtoken, lp, transit, visible);
3848 changed = true;
3849 if (wtoken.animation != null) {
3850 delayed = runningAppAnimation = true;
3851 }
3852 }
Romain Guy06882f82009-06-10 13:36:04 -07003853
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003854 for (int i=0; i<N; i++) {
3855 WindowState win = wtoken.allAppWindows.get(i);
3856 if (win == wtoken.startingWindow) {
3857 continue;
3858 }
3859
3860 if (win.isAnimating()) {
3861 delayed = true;
3862 }
Romain Guy06882f82009-06-10 13:36:04 -07003863
Joe Onorato8a9b2202010-02-26 18:56:32 -08003864 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003865 //win.dump(" ");
3866 if (visible) {
3867 if (!win.isVisibleNow()) {
3868 if (!runningAppAnimation) {
3869 applyAnimationLocked(win,
3870 WindowManagerPolicy.TRANSIT_ENTER, true);
3871 }
3872 changed = true;
3873 }
3874 } else if (win.isVisibleNow()) {
3875 if (!runningAppAnimation) {
3876 applyAnimationLocked(win,
3877 WindowManagerPolicy.TRANSIT_EXIT, false);
3878 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003879 changed = true;
3880 }
3881 }
3882
3883 wtoken.hidden = wtoken.hiddenRequested = !visible;
3884 if (!visible) {
3885 unsetAppFreezingScreenLocked(wtoken, true, true);
3886 } else {
3887 // If we are being set visible, and the starting window is
3888 // not yet displayed, then make sure it doesn't get displayed.
3889 WindowState swin = wtoken.startingWindow;
3890 if (swin != null && (swin.mDrawPending
3891 || swin.mCommitDrawPending)) {
3892 swin.mPolicyVisibility = false;
3893 swin.mPolicyVisibilityAfterAnim = false;
3894 }
3895 }
Romain Guy06882f82009-06-10 13:36:04 -07003896
Joe Onorato8a9b2202010-02-26 18:56:32 -08003897 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003898 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3899 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003900
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003901 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003902 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003903 if (performLayout) {
3904 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3905 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003906 } else {
3907 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003908 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003909 }
3910 }
3911
3912 if (wtoken.animation != null) {
3913 delayed = true;
3914 }
Romain Guy06882f82009-06-10 13:36:04 -07003915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003916 return delayed;
3917 }
3918
3919 public void setAppVisibility(IBinder token, boolean visible) {
3920 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3921 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003922 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003923 }
3924
3925 AppWindowToken wtoken;
3926
3927 synchronized(mWindowMap) {
3928 wtoken = findAppWindowToken(token);
3929 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003930 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003931 return;
3932 }
3933
3934 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003935 RuntimeException e = null;
3936 if (!HIDE_STACK_CRAWLS) {
3937 e = new RuntimeException();
3938 e.fillInStackTrace();
3939 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003940 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003941 + "): mNextAppTransition=" + mNextAppTransition
3942 + " hidden=" + wtoken.hidden
3943 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3944 }
Romain Guy06882f82009-06-10 13:36:04 -07003945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003946 // If we are preparing an app transition, then delay changing
3947 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003948 if (!mDisplayFrozen && mPolicy.isScreenOn()
3949 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003950 // Already in requested state, don't do anything more.
3951 if (wtoken.hiddenRequested != visible) {
3952 return;
3953 }
3954 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003955
Joe Onorato8a9b2202010-02-26 18:56:32 -08003956 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003957 TAG, "Setting dummy animation on: " + wtoken);
3958 wtoken.setDummyAnimation();
3959 mOpeningApps.remove(wtoken);
3960 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003961 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003962 wtoken.inPendingTransaction = true;
3963 if (visible) {
3964 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003965 wtoken.startingDisplayed = false;
3966 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003967
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003968 // If the token is currently hidden (should be the
3969 // common case), then we need to set up to wait for
3970 // its windows to be ready.
3971 if (wtoken.hidden) {
3972 wtoken.allDrawn = false;
3973 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003974
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003975 if (wtoken.clientHidden) {
3976 // In the case where we are making an app visible
3977 // but holding off for a transition, we still need
3978 // to tell the client to make its windows visible so
3979 // they get drawn. Otherwise, we will wait on
3980 // performing the transition until all windows have
3981 // been drawn, they never will be, and we are sad.
3982 wtoken.clientHidden = false;
3983 wtoken.sendAppVisibilityToClients();
3984 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003985 }
3986 } else {
3987 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003988
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003989 // If the token is currently visible (should be the
3990 // common case), then set up to wait for it to be hidden.
3991 if (!wtoken.hidden) {
3992 wtoken.waitingToHide = true;
3993 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003994 }
3995 return;
3996 }
Romain Guy06882f82009-06-10 13:36:04 -07003997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003998 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003999 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004000 wtoken.updateReportedVisibilityLocked();
4001 Binder.restoreCallingIdentity(origId);
4002 }
4003 }
4004
4005 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4006 boolean unfreezeSurfaceNow, boolean force) {
4007 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004008 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004009 + " force=" + force);
4010 final int N = wtoken.allAppWindows.size();
4011 boolean unfrozeWindows = false;
4012 for (int i=0; i<N; i++) {
4013 WindowState w = wtoken.allAppWindows.get(i);
4014 if (w.mAppFreezing) {
4015 w.mAppFreezing = false;
4016 if (w.mSurface != null && !w.mOrientationChanging) {
4017 w.mOrientationChanging = true;
4018 }
4019 unfrozeWindows = true;
4020 }
4021 }
4022 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004023 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004024 wtoken.freezingScreen = false;
4025 mAppsFreezingScreen--;
4026 }
4027 if (unfreezeSurfaceNow) {
4028 if (unfrozeWindows) {
4029 mLayoutNeeded = true;
4030 performLayoutAndPlaceSurfacesLocked();
4031 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004032 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004033 }
4034 }
4035 }
Romain Guy06882f82009-06-10 13:36:04 -07004036
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004037 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4038 int configChanges) {
4039 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004040 RuntimeException e = null;
4041 if (!HIDE_STACK_CRAWLS) {
4042 e = new RuntimeException();
4043 e.fillInStackTrace();
4044 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004045 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004046 + ": hidden=" + wtoken.hidden + " freezing="
4047 + wtoken.freezingScreen, e);
4048 }
4049 if (!wtoken.hiddenRequested) {
4050 if (!wtoken.freezingScreen) {
4051 wtoken.freezingScreen = true;
4052 mAppsFreezingScreen++;
4053 if (mAppsFreezingScreen == 1) {
4054 startFreezingDisplayLocked();
4055 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4056 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4057 5000);
4058 }
4059 }
4060 final int N = wtoken.allAppWindows.size();
4061 for (int i=0; i<N; i++) {
4062 WindowState w = wtoken.allAppWindows.get(i);
4063 w.mAppFreezing = true;
4064 }
4065 }
4066 }
Romain Guy06882f82009-06-10 13:36:04 -07004067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004068 public void startAppFreezingScreen(IBinder token, int configChanges) {
4069 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4070 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004071 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004072 }
4073
4074 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004075 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004076 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004077 return;
4078 }
Romain Guy06882f82009-06-10 13:36:04 -07004079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004080 AppWindowToken wtoken = findAppWindowToken(token);
4081 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004082 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004083 return;
4084 }
4085 final long origId = Binder.clearCallingIdentity();
4086 startAppFreezingScreenLocked(wtoken, configChanges);
4087 Binder.restoreCallingIdentity(origId);
4088 }
4089 }
Romain Guy06882f82009-06-10 13:36:04 -07004090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004091 public void stopAppFreezingScreen(IBinder token, boolean force) {
4092 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4093 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004094 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004095 }
4096
4097 synchronized(mWindowMap) {
4098 AppWindowToken wtoken = findAppWindowToken(token);
4099 if (wtoken == null || wtoken.appToken == null) {
4100 return;
4101 }
4102 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004103 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004104 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4105 unsetAppFreezingScreenLocked(wtoken, true, force);
4106 Binder.restoreCallingIdentity(origId);
4107 }
4108 }
Romain Guy06882f82009-06-10 13:36:04 -07004109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004110 public void removeAppToken(IBinder token) {
4111 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4112 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004113 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004114 }
4115
4116 AppWindowToken wtoken = null;
4117 AppWindowToken startingToken = null;
4118 boolean delayed = false;
4119
4120 final long origId = Binder.clearCallingIdentity();
4121 synchronized(mWindowMap) {
4122 WindowToken basewtoken = mTokenMap.remove(token);
4123 mTokenList.remove(basewtoken);
4124 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004125 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004126 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004127 wtoken.inPendingTransaction = false;
4128 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004129 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004130 if (mClosingApps.contains(wtoken)) {
4131 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004132 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004133 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004134 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004135 delayed = true;
4136 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004137 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004138 TAG, "Removing app " + wtoken + " delayed=" + delayed
4139 + " animation=" + wtoken.animation
4140 + " animating=" + wtoken.animating);
4141 if (delayed) {
4142 // set the token aside because it has an active animation to be finished
4143 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004144 } else {
4145 // Make sure there is no animation running on this token,
4146 // so any windows associated with it will be removed as
4147 // soon as their animations are complete
4148 wtoken.animation = null;
4149 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004150 }
4151 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07004152 if (mLastEnterAnimToken == wtoken) {
4153 mLastEnterAnimToken = null;
4154 mLastEnterAnimParams = null;
4155 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004156 wtoken.removed = true;
4157 if (wtoken.startingData != null) {
4158 startingToken = wtoken;
4159 }
4160 unsetAppFreezingScreenLocked(wtoken, true, true);
4161 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004162 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004163 mFocusedApp = null;
4164 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004165 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004166 }
4167 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004168 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004169 }
Romain Guy06882f82009-06-10 13:36:04 -07004170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004171 if (!delayed && wtoken != null) {
4172 wtoken.updateReportedVisibilityLocked();
4173 }
4174 }
4175 Binder.restoreCallingIdentity(origId);
4176
4177 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004178 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004179 + startingToken + ": app token removed");
4180 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4181 mH.sendMessage(m);
4182 }
4183 }
4184
4185 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4186 final int NW = token.windows.size();
4187 for (int i=0; i<NW; i++) {
4188 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004189 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004190 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004191 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004192 int j = win.mChildWindows.size();
4193 while (j > 0) {
4194 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004195 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004196 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004197 "Tmp removing child window " + cwin);
4198 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004199 }
4200 }
4201 return NW > 0;
4202 }
4203
4204 void dumpAppTokensLocked() {
4205 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004206 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004207 }
4208 }
Romain Guy06882f82009-06-10 13:36:04 -07004209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004210 void dumpWindowsLocked() {
4211 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004212 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004213 }
4214 }
Romain Guy06882f82009-06-10 13:36:04 -07004215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004216 private int findWindowOffsetLocked(int tokenPos) {
4217 final int NW = mWindows.size();
4218
4219 if (tokenPos >= mAppTokens.size()) {
4220 int i = NW;
4221 while (i > 0) {
4222 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004223 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004224 if (win.getAppToken() != null) {
4225 return i+1;
4226 }
4227 }
4228 }
4229
4230 while (tokenPos > 0) {
4231 // Find the first app token below the new position that has
4232 // a window displayed.
4233 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004234 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004235 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004236 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004237 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004238 "Skipping token -- currently sending to bottom");
4239 tokenPos--;
4240 continue;
4241 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004242 int i = wtoken.windows.size();
4243 while (i > 0) {
4244 i--;
4245 WindowState win = wtoken.windows.get(i);
4246 int j = win.mChildWindows.size();
4247 while (j > 0) {
4248 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004249 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004250 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004251 for (int pos=NW-1; pos>=0; pos--) {
4252 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004253 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004254 "Found child win @" + (pos+1));
4255 return pos+1;
4256 }
4257 }
4258 }
4259 }
4260 for (int pos=NW-1; pos>=0; pos--) {
4261 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004262 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004263 return pos+1;
4264 }
4265 }
4266 }
4267 tokenPos--;
4268 }
4269
4270 return 0;
4271 }
4272
4273 private final int reAddWindowLocked(int index, WindowState win) {
4274 final int NCW = win.mChildWindows.size();
4275 boolean added = false;
4276 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004277 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004278 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004279 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004280 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004281 mWindows.add(index, win);
4282 index++;
4283 added = true;
4284 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004285 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004286 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004287 mWindows.add(index, cwin);
4288 index++;
4289 }
4290 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004291 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004292 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004293 mWindows.add(index, win);
4294 index++;
4295 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004296 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004297 return index;
4298 }
Romain Guy06882f82009-06-10 13:36:04 -07004299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004300 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4301 final int NW = token.windows.size();
4302 for (int i=0; i<NW; i++) {
4303 index = reAddWindowLocked(index, token.windows.get(i));
4304 }
4305 return index;
4306 }
4307
4308 public void moveAppToken(int index, IBinder token) {
4309 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4310 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004311 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004312 }
4313
4314 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004315 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004316 if (DEBUG_REORDER) dumpAppTokensLocked();
4317 final AppWindowToken wtoken = findAppWindowToken(token);
4318 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004319 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004320 + token + " (" + wtoken + ")");
4321 return;
4322 }
4323 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004324 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004325 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004327 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004328 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004329 if (DEBUG_REORDER) dumpWindowsLocked();
4330 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004331 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004332 if (DEBUG_REORDER) dumpWindowsLocked();
4333 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004334 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004335 if (DEBUG_REORDER) dumpWindowsLocked();
4336 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004337 mLayoutNeeded = true;
4338 performLayoutAndPlaceSurfacesLocked();
4339 }
4340 Binder.restoreCallingIdentity(origId);
4341 }
4342 }
4343
4344 private void removeAppTokensLocked(List<IBinder> tokens) {
4345 // XXX This should be done more efficiently!
4346 // (take advantage of the fact that both lists should be
4347 // ordered in the same way.)
4348 int N = tokens.size();
4349 for (int i=0; i<N; i++) {
4350 IBinder token = tokens.get(i);
4351 final AppWindowToken wtoken = findAppWindowToken(token);
4352 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004353 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004354 + token + " (" + wtoken + ")");
4355 i--;
4356 N--;
4357 }
4358 }
4359 }
4360
Dianne Hackborna8f60182009-09-01 19:01:50 -07004361 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4362 boolean updateFocusAndLayout) {
4363 // First remove all of the windows from the list.
4364 tmpRemoveAppWindowsLocked(wtoken);
4365
4366 // Where to start adding?
4367 int pos = findWindowOffsetLocked(tokenPos);
4368
4369 // And now add them back at the correct place.
4370 pos = reAddAppWindowsLocked(pos, wtoken);
4371
4372 if (updateFocusAndLayout) {
4373 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4374 assignLayersLocked();
4375 }
4376 mLayoutNeeded = true;
4377 performLayoutAndPlaceSurfacesLocked();
4378 }
4379 }
4380
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004381 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4382 // First remove all of the windows from the list.
4383 final int N = tokens.size();
4384 int i;
4385 for (i=0; i<N; i++) {
4386 WindowToken token = mTokenMap.get(tokens.get(i));
4387 if (token != null) {
4388 tmpRemoveAppWindowsLocked(token);
4389 }
4390 }
4391
4392 // Where to start adding?
4393 int pos = findWindowOffsetLocked(tokenPos);
4394
4395 // And now add them back at the correct place.
4396 for (i=0; i<N; i++) {
4397 WindowToken token = mTokenMap.get(tokens.get(i));
4398 if (token != null) {
4399 pos = reAddAppWindowsLocked(pos, token);
4400 }
4401 }
4402
Dianne Hackborna8f60182009-09-01 19:01:50 -07004403 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4404 assignLayersLocked();
4405 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004406 mLayoutNeeded = true;
4407 performLayoutAndPlaceSurfacesLocked();
4408
4409 //dump();
4410 }
4411
4412 public void moveAppTokensToTop(List<IBinder> tokens) {
4413 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4414 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004415 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004416 }
4417
4418 final long origId = Binder.clearCallingIdentity();
4419 synchronized(mWindowMap) {
4420 removeAppTokensLocked(tokens);
4421 final int N = tokens.size();
4422 for (int i=0; i<N; i++) {
4423 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4424 if (wt != null) {
4425 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004426 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004427 mToTopApps.remove(wt);
4428 mToBottomApps.remove(wt);
4429 mToTopApps.add(wt);
4430 wt.sendingToBottom = false;
4431 wt.sendingToTop = true;
4432 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004433 }
4434 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004435
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004436 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004437 moveAppWindowsLocked(tokens, mAppTokens.size());
4438 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004439 }
4440 Binder.restoreCallingIdentity(origId);
4441 }
4442
4443 public void moveAppTokensToBottom(List<IBinder> tokens) {
4444 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4445 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004446 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004447 }
4448
4449 final long origId = Binder.clearCallingIdentity();
4450 synchronized(mWindowMap) {
4451 removeAppTokensLocked(tokens);
4452 final int N = tokens.size();
4453 int pos = 0;
4454 for (int i=0; i<N; i++) {
4455 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4456 if (wt != null) {
4457 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004458 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004459 mToTopApps.remove(wt);
4460 mToBottomApps.remove(wt);
4461 mToBottomApps.add(i, wt);
4462 wt.sendingToTop = false;
4463 wt.sendingToBottom = true;
4464 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004465 pos++;
4466 }
4467 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004468
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004469 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004470 moveAppWindowsLocked(tokens, 0);
4471 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004472 }
4473 Binder.restoreCallingIdentity(origId);
4474 }
4475
4476 // -------------------------------------------------------------
4477 // Misc IWindowSession methods
4478 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004479
Jim Miller284b62e2010-06-08 14:27:42 -07004480 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004481 {
Jim Miller284b62e2010-06-08 14:27:42 -07004482 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4483 // called before DevicePolicyManagerService has started.
4484 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4485 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4486 Context.DEVICE_POLICY_SERVICE);
4487 if (dpm != null) {
4488 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4489 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4490 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4491 }
Jim Millerd6b57052010-06-07 17:52:42 -07004492 }
Jim Miller284b62e2010-06-08 14:27:42 -07004493 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004494 }
4495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004496 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004497 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004498 != PackageManager.PERMISSION_GRANTED) {
4499 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4500 }
Jim Millerd6b57052010-06-07 17:52:42 -07004501
Jim Miller284b62e2010-06-08 14:27:42 -07004502 synchronized (mKeyguardTokenWatcher) {
4503 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004504 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004505 }
4506
4507 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004508 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004509 != PackageManager.PERMISSION_GRANTED) {
4510 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4511 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004512
Jim Miller284b62e2010-06-08 14:27:42 -07004513 synchronized (mKeyguardTokenWatcher) {
4514 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004515
Jim Miller284b62e2010-06-08 14:27:42 -07004516 if (!mKeyguardTokenWatcher.isAcquired()) {
4517 // If we are the last one to reenable the keyguard wait until
4518 // we have actually finished reenabling until returning.
4519 // It is possible that reenableKeyguard() can be called before
4520 // the previous disableKeyguard() is handled, in which case
4521 // neither mKeyguardTokenWatcher.acquired() or released() would
4522 // be called. In that case mKeyguardDisabled will be false here
4523 // and we have nothing to wait for.
4524 while (mKeyguardDisabled) {
4525 try {
4526 mKeyguardTokenWatcher.wait();
4527 } catch (InterruptedException e) {
4528 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004529 }
4530 }
4531 }
4532 }
4533 }
4534
4535 /**
4536 * @see android.app.KeyguardManager#exitKeyguardSecurely
4537 */
4538 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004539 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004540 != PackageManager.PERMISSION_GRANTED) {
4541 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4542 }
4543 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4544 public void onKeyguardExitResult(boolean success) {
4545 try {
4546 callback.onKeyguardExitResult(success);
4547 } catch (RemoteException e) {
4548 // Client has died, we don't care.
4549 }
4550 }
4551 });
4552 }
4553
4554 public boolean inKeyguardRestrictedInputMode() {
4555 return mPolicy.inKeyguardRestrictedKeyInputMode();
4556 }
Romain Guy06882f82009-06-10 13:36:04 -07004557
Dianne Hackbornffa42482009-09-23 22:20:11 -07004558 public void closeSystemDialogs(String reason) {
4559 synchronized(mWindowMap) {
4560 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004561 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004562 if (w.mSurface != null) {
4563 try {
4564 w.mClient.closeSystemDialogs(reason);
4565 } catch (RemoteException e) {
4566 }
4567 }
4568 }
4569 }
4570 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004572 static float fixScale(float scale) {
4573 if (scale < 0) scale = 0;
4574 else if (scale > 20) scale = 20;
4575 return Math.abs(scale);
4576 }
Romain Guy06882f82009-06-10 13:36:04 -07004577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004578 public void setAnimationScale(int which, float scale) {
4579 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4580 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004581 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004582 }
4583
4584 if (scale < 0) scale = 0;
4585 else if (scale > 20) scale = 20;
4586 scale = Math.abs(scale);
4587 switch (which) {
4588 case 0: mWindowAnimationScale = fixScale(scale); break;
4589 case 1: mTransitionAnimationScale = fixScale(scale); break;
4590 }
Romain Guy06882f82009-06-10 13:36:04 -07004591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004592 // Persist setting
4593 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4594 }
Romain Guy06882f82009-06-10 13:36:04 -07004595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004596 public void setAnimationScales(float[] scales) {
4597 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4598 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004599 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004600 }
4601
4602 if (scales != null) {
4603 if (scales.length >= 1) {
4604 mWindowAnimationScale = fixScale(scales[0]);
4605 }
4606 if (scales.length >= 2) {
4607 mTransitionAnimationScale = fixScale(scales[1]);
4608 }
4609 }
Romain Guy06882f82009-06-10 13:36:04 -07004610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004611 // Persist setting
4612 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4613 }
Romain Guy06882f82009-06-10 13:36:04 -07004614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004615 public float getAnimationScale(int which) {
4616 switch (which) {
4617 case 0: return mWindowAnimationScale;
4618 case 1: return mTransitionAnimationScale;
4619 }
4620 return 0;
4621 }
Romain Guy06882f82009-06-10 13:36:04 -07004622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004623 public float[] getAnimationScales() {
4624 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4625 }
Romain Guy06882f82009-06-10 13:36:04 -07004626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004627 public int getSwitchState(int sw) {
4628 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4629 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004630 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004631 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004632 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004633 }
Romain Guy06882f82009-06-10 13:36:04 -07004634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004635 public int getSwitchStateForDevice(int devid, int sw) {
4636 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4637 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004638 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004639 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004640 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004641 }
Romain Guy06882f82009-06-10 13:36:04 -07004642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004643 public int getScancodeState(int sw) {
4644 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4645 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004646 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004647 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004648 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004649 }
Romain Guy06882f82009-06-10 13:36:04 -07004650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004651 public int getScancodeStateForDevice(int devid, int sw) {
4652 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4653 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004654 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004655 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004656 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004657 }
Romain Guy06882f82009-06-10 13:36:04 -07004658
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004659 public int getTrackballScancodeState(int sw) {
4660 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4661 "getTrackballScancodeState()")) {
4662 throw new SecurityException("Requires READ_INPUT_STATE permission");
4663 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004664 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004665 }
4666
4667 public int getDPadScancodeState(int sw) {
4668 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4669 "getDPadScancodeState()")) {
4670 throw new SecurityException("Requires READ_INPUT_STATE permission");
4671 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004672 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004673 }
4674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004675 public int getKeycodeState(int sw) {
4676 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4677 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004678 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004679 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004680 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004681 }
Romain Guy06882f82009-06-10 13:36:04 -07004682
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004683 public int getKeycodeStateForDevice(int devid, int sw) {
4684 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4685 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004686 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004687 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004688 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004689 }
Romain Guy06882f82009-06-10 13:36:04 -07004690
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004691 public int getTrackballKeycodeState(int sw) {
4692 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4693 "getTrackballKeycodeState()")) {
4694 throw new SecurityException("Requires READ_INPUT_STATE permission");
4695 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004696 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004697 }
4698
4699 public int getDPadKeycodeState(int sw) {
4700 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4701 "getDPadKeycodeState()")) {
4702 throw new SecurityException("Requires READ_INPUT_STATE permission");
4703 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004704 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004705 }
Jeff Browna41ca772010-08-11 14:46:32 -07004706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004707 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004708 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004709 }
Romain Guy06882f82009-06-10 13:36:04 -07004710
Jeff Browna41ca772010-08-11 14:46:32 -07004711 public InputChannel monitorInput(String inputChannelName) {
4712 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4713 "monitorInput()")) {
4714 throw new SecurityException("Requires READ_INPUT_STATE permission");
4715 }
4716 return mInputManager.monitorInput(inputChannelName);
4717 }
4718
Jeff Brown8d608662010-08-30 03:02:23 -07004719 public InputDevice getInputDevice(int deviceId) {
4720 return mInputManager.getInputDevice(deviceId);
4721 }
4722
4723 public int[] getInputDeviceIds() {
4724 return mInputManager.getInputDeviceIds();
4725 }
4726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004727 public void enableScreenAfterBoot() {
4728 synchronized(mWindowMap) {
4729 if (mSystemBooted) {
4730 return;
4731 }
4732 mSystemBooted = true;
4733 }
Romain Guy06882f82009-06-10 13:36:04 -07004734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004735 performEnableScreen();
4736 }
Romain Guy06882f82009-06-10 13:36:04 -07004737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004738 public void enableScreenIfNeededLocked() {
4739 if (mDisplayEnabled) {
4740 return;
4741 }
4742 if (!mSystemBooted) {
4743 return;
4744 }
4745 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4746 }
Romain Guy06882f82009-06-10 13:36:04 -07004747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004748 public void performEnableScreen() {
4749 synchronized(mWindowMap) {
4750 if (mDisplayEnabled) {
4751 return;
4752 }
4753 if (!mSystemBooted) {
4754 return;
4755 }
Romain Guy06882f82009-06-10 13:36:04 -07004756
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004757 // Don't enable the screen until all existing windows
4758 // have been drawn.
4759 final int N = mWindows.size();
4760 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004761 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004762 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004763 return;
4764 }
4765 }
Romain Guy06882f82009-06-10 13:36:04 -07004766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004767 mDisplayEnabled = true;
4768 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004769 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004770 StringWriter sw = new StringWriter();
4771 PrintWriter pw = new PrintWriter(sw);
4772 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004773 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004774 }
4775 try {
4776 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4777 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004778 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004779 Parcel data = Parcel.obtain();
4780 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4781 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4782 data, null, 0);
4783 data.recycle();
4784 }
4785 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004786 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004787 }
4788 }
Romain Guy06882f82009-06-10 13:36:04 -07004789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004790 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004792 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004793 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4794 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004795 }
Romain Guy06882f82009-06-10 13:36:04 -07004796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004797 public void setInTouchMode(boolean mode) {
4798 synchronized(mWindowMap) {
4799 mInTouchMode = mode;
4800 }
4801 }
4802
Romain Guy06882f82009-06-10 13:36:04 -07004803 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004804 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004805 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004806 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004807 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004808 }
4809
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004810 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004811 }
Romain Guy06882f82009-06-10 13:36:04 -07004812
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004813 public void setRotationUnchecked(int rotation,
4814 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004815 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004816 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004818 long origId = Binder.clearCallingIdentity();
4819 boolean changed;
4820 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004821 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004822 }
Romain Guy06882f82009-06-10 13:36:04 -07004823
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004824 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004825 sendNewConfiguration();
4826 }
Romain Guy06882f82009-06-10 13:36:04 -07004827
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004828 Binder.restoreCallingIdentity(origId);
4829 }
Romain Guy06882f82009-06-10 13:36:04 -07004830
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004831 /**
4832 * Apply a new rotation to the screen, respecting the requests of
4833 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4834 * re-evaluate the desired rotation.
4835 *
4836 * Returns null if the rotation has been changed. In this case YOU
4837 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4838 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004839 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004840 boolean changed;
4841 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4842 rotation = mRequestedRotation;
4843 } else {
4844 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004845 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004846 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004847 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004848 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004849 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004850 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004851 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004853 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004854 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004855 "Rotation changed to " + rotation
4856 + " from " + mRotation
4857 + " (forceApp=" + mForcedAppOrientation
4858 + ", req=" + mRequestedRotation + ")");
4859 mRotation = rotation;
4860 mWindowsFreezingScreen = true;
4861 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4862 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4863 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004864 mWaitingForConfig = true;
4865 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004866 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004867 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004868 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004869 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004870 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004871 }
4872 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004873 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004874 if (w.mSurface != null) {
4875 w.mOrientationChanging = true;
4876 }
4877 }
4878 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4879 try {
4880 mRotationWatchers.get(i).onRotationChanged(rotation);
4881 } catch (RemoteException e) {
4882 }
4883 }
4884 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004886 return changed;
4887 }
Romain Guy06882f82009-06-10 13:36:04 -07004888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004889 public int getRotation() {
4890 return mRotation;
4891 }
4892
4893 public int watchRotation(IRotationWatcher watcher) {
4894 final IBinder watcherBinder = watcher.asBinder();
4895 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4896 public void binderDied() {
4897 synchronized (mWindowMap) {
4898 for (int i=0; i<mRotationWatchers.size(); i++) {
4899 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004900 IRotationWatcher removed = mRotationWatchers.remove(i);
4901 if (removed != null) {
4902 removed.asBinder().unlinkToDeath(this, 0);
4903 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004904 i--;
4905 }
4906 }
4907 }
4908 }
4909 };
Romain Guy06882f82009-06-10 13:36:04 -07004910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004911 synchronized (mWindowMap) {
4912 try {
4913 watcher.asBinder().linkToDeath(dr, 0);
4914 mRotationWatchers.add(watcher);
4915 } catch (RemoteException e) {
4916 // Client died, no cleanup needed.
4917 }
Romain Guy06882f82009-06-10 13:36:04 -07004918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004919 return mRotation;
4920 }
4921 }
4922
4923 /**
4924 * Starts the view server on the specified port.
4925 *
4926 * @param port The port to listener to.
4927 *
4928 * @return True if the server was successfully started, false otherwise.
4929 *
4930 * @see com.android.server.ViewServer
4931 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4932 */
4933 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004934 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004935 return false;
4936 }
4937
4938 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4939 return false;
4940 }
4941
4942 if (port < 1024) {
4943 return false;
4944 }
4945
4946 if (mViewServer != null) {
4947 if (!mViewServer.isRunning()) {
4948 try {
4949 return mViewServer.start();
4950 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004951 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004952 }
4953 }
4954 return false;
4955 }
4956
4957 try {
4958 mViewServer = new ViewServer(this, port);
4959 return mViewServer.start();
4960 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004961 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004962 }
4963 return false;
4964 }
4965
Romain Guy06882f82009-06-10 13:36:04 -07004966 private boolean isSystemSecure() {
4967 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4968 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4969 }
4970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004971 /**
4972 * Stops the view server if it exists.
4973 *
4974 * @return True if the server stopped, false if it wasn't started or
4975 * couldn't be stopped.
4976 *
4977 * @see com.android.server.ViewServer
4978 */
4979 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004980 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004981 return false;
4982 }
4983
4984 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4985 return false;
4986 }
4987
4988 if (mViewServer != null) {
4989 return mViewServer.stop();
4990 }
4991 return false;
4992 }
4993
4994 /**
4995 * Indicates whether the view server is running.
4996 *
4997 * @return True if the server is running, false otherwise.
4998 *
4999 * @see com.android.server.ViewServer
5000 */
5001 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005002 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005003 return false;
5004 }
5005
5006 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5007 return false;
5008 }
5009
5010 return mViewServer != null && mViewServer.isRunning();
5011 }
5012
5013 /**
5014 * Lists all availble windows in the system. The listing is written in the
5015 * specified Socket's output stream with the following syntax:
5016 * windowHashCodeInHexadecimal windowName
5017 * Each line of the ouput represents a different window.
5018 *
5019 * @param client The remote client to send the listing to.
5020 * @return False if an error occured, true otherwise.
5021 */
5022 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005023 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005024 return false;
5025 }
5026
5027 boolean result = true;
5028
Jeff Browne33348b2010-07-15 23:54:05 -07005029 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005030 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005031 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005032 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005033 }
5034
5035 BufferedWriter out = null;
5036
5037 // Any uncaught exception will crash the system process
5038 try {
5039 OutputStream clientStream = client.getOutputStream();
5040 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5041
5042 final int count = windows.length;
5043 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005044 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005045 out.write(Integer.toHexString(System.identityHashCode(w)));
5046 out.write(' ');
5047 out.append(w.mAttrs.getTitle());
5048 out.write('\n');
5049 }
5050
5051 out.write("DONE.\n");
5052 out.flush();
5053 } catch (Exception e) {
5054 result = false;
5055 } finally {
5056 if (out != null) {
5057 try {
5058 out.close();
5059 } catch (IOException e) {
5060 result = false;
5061 }
5062 }
5063 }
5064
5065 return result;
5066 }
5067
5068 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005069 * Returns the focused window in the following format:
5070 * windowHashCodeInHexadecimal windowName
5071 *
5072 * @param client The remote client to send the listing to.
5073 * @return False if an error occurred, true otherwise.
5074 */
5075 boolean viewServerGetFocusedWindow(Socket client) {
5076 if (isSystemSecure()) {
5077 return false;
5078 }
5079
5080 boolean result = true;
5081
5082 WindowState focusedWindow = getFocusedWindow();
5083
5084 BufferedWriter out = null;
5085
5086 // Any uncaught exception will crash the system process
5087 try {
5088 OutputStream clientStream = client.getOutputStream();
5089 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5090
5091 if(focusedWindow != null) {
5092 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5093 out.write(' ');
5094 out.append(focusedWindow.mAttrs.getTitle());
5095 }
5096 out.write('\n');
5097 out.flush();
5098 } catch (Exception e) {
5099 result = false;
5100 } finally {
5101 if (out != null) {
5102 try {
5103 out.close();
5104 } catch (IOException e) {
5105 result = false;
5106 }
5107 }
5108 }
5109
5110 return result;
5111 }
5112
5113 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005114 * Sends a command to a target window. The result of the command, if any, will be
5115 * written in the output stream of the specified socket.
5116 *
5117 * The parameters must follow this syntax:
5118 * windowHashcode extra
5119 *
5120 * Where XX is the length in characeters of the windowTitle.
5121 *
5122 * The first parameter is the target window. The window with the specified hashcode
5123 * will be the target. If no target can be found, nothing happens. The extra parameters
5124 * will be delivered to the target window and as parameters to the command itself.
5125 *
5126 * @param client The remote client to sent the result, if any, to.
5127 * @param command The command to execute.
5128 * @param parameters The command parameters.
5129 *
5130 * @return True if the command was successfully delivered, false otherwise. This does
5131 * not indicate whether the command itself was successful.
5132 */
5133 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005134 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005135 return false;
5136 }
5137
5138 boolean success = true;
5139 Parcel data = null;
5140 Parcel reply = null;
5141
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005142 BufferedWriter out = null;
5143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005144 // Any uncaught exception will crash the system process
5145 try {
5146 // Find the hashcode of the window
5147 int index = parameters.indexOf(' ');
5148 if (index == -1) {
5149 index = parameters.length();
5150 }
5151 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005152 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005153
5154 // Extract the command's parameter after the window description
5155 if (index < parameters.length()) {
5156 parameters = parameters.substring(index + 1);
5157 } else {
5158 parameters = "";
5159 }
5160
5161 final WindowManagerService.WindowState window = findWindow(hashCode);
5162 if (window == null) {
5163 return false;
5164 }
5165
5166 data = Parcel.obtain();
5167 data.writeInterfaceToken("android.view.IWindow");
5168 data.writeString(command);
5169 data.writeString(parameters);
5170 data.writeInt(1);
5171 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5172
5173 reply = Parcel.obtain();
5174
5175 final IBinder binder = window.mClient.asBinder();
5176 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5177 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5178
5179 reply.readException();
5180
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005181 if (!client.isOutputShutdown()) {
5182 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5183 out.write("DONE\n");
5184 out.flush();
5185 }
5186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005187 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005188 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005189 success = false;
5190 } finally {
5191 if (data != null) {
5192 data.recycle();
5193 }
5194 if (reply != null) {
5195 reply.recycle();
5196 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005197 if (out != null) {
5198 try {
5199 out.close();
5200 } catch (IOException e) {
5201
5202 }
5203 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005204 }
5205
5206 return success;
5207 }
5208
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005209 public void addWindowChangeListener(WindowChangeListener listener) {
5210 synchronized(mWindowMap) {
5211 mWindowChangeListeners.add(listener);
5212 }
5213 }
5214
5215 public void removeWindowChangeListener(WindowChangeListener listener) {
5216 synchronized(mWindowMap) {
5217 mWindowChangeListeners.remove(listener);
5218 }
5219 }
5220
5221 private void notifyWindowsChanged() {
5222 WindowChangeListener[] windowChangeListeners;
5223 synchronized(mWindowMap) {
5224 if(mWindowChangeListeners.isEmpty()) {
5225 return;
5226 }
5227 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5228 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5229 }
5230 int N = windowChangeListeners.length;
5231 for(int i = 0; i < N; i++) {
5232 windowChangeListeners[i].windowsChanged();
5233 }
5234 }
5235
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005236 private void notifyFocusChanged() {
5237 WindowChangeListener[] windowChangeListeners;
5238 synchronized(mWindowMap) {
5239 if(mWindowChangeListeners.isEmpty()) {
5240 return;
5241 }
5242 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5243 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5244 }
5245 int N = windowChangeListeners.length;
5246 for(int i = 0; i < N; i++) {
5247 windowChangeListeners[i].focusChanged();
5248 }
5249 }
5250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005251 private WindowState findWindow(int hashCode) {
5252 if (hashCode == -1) {
5253 return getFocusedWindow();
5254 }
5255
5256 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005257 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005258 final int count = windows.size();
5259
5260 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005261 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005262 if (System.identityHashCode(w) == hashCode) {
5263 return w;
5264 }
5265 }
5266 }
5267
5268 return null;
5269 }
5270
5271 /*
5272 * Instruct the Activity Manager to fetch the current configuration and broadcast
5273 * that to config-changed listeners if appropriate.
5274 */
5275 void sendNewConfiguration() {
5276 try {
5277 mActivityManager.updateConfiguration(null);
5278 } catch (RemoteException e) {
5279 }
5280 }
Romain Guy06882f82009-06-10 13:36:04 -07005281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005282 public Configuration computeNewConfiguration() {
5283 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07005284 return computeNewConfigurationLocked();
5285 }
5286 }
Romain Guy06882f82009-06-10 13:36:04 -07005287
Dianne Hackbornc485a602009-03-24 22:39:49 -07005288 Configuration computeNewConfigurationLocked() {
5289 Configuration config = new Configuration();
5290 if (!computeNewConfigurationLocked(config)) {
5291 return null;
5292 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005293 return config;
5294 }
Romain Guy06882f82009-06-10 13:36:04 -07005295
Dianne Hackbornc485a602009-03-24 22:39:49 -07005296 boolean computeNewConfigurationLocked(Configuration config) {
5297 if (mDisplay == null) {
5298 return false;
5299 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005300
5301 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005302
5303 // Use the effective "visual" dimensions based on current rotation
5304 final boolean rotated = (mRotation == Surface.ROTATION_90
5305 || mRotation == Surface.ROTATION_270);
5306 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5307 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5308
Dianne Hackbornc485a602009-03-24 22:39:49 -07005309 int orientation = Configuration.ORIENTATION_SQUARE;
5310 if (dw < dh) {
5311 orientation = Configuration.ORIENTATION_PORTRAIT;
5312 } else if (dw > dh) {
5313 orientation = Configuration.ORIENTATION_LANDSCAPE;
5314 }
5315 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005316
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005317 DisplayMetrics dm = new DisplayMetrics();
5318 mDisplay.getMetrics(dm);
5319 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5320
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005321 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005322 // Note we only do this once because at this point we don't
5323 // expect the screen to change in this way at runtime, and want
5324 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005325 int longSize = dw;
5326 int shortSize = dh;
5327 if (longSize < shortSize) {
5328 int tmp = longSize;
5329 longSize = shortSize;
5330 shortSize = tmp;
5331 }
5332 longSize = (int)(longSize/dm.density);
5333 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005334
Dianne Hackborn723738c2009-06-25 19:48:04 -07005335 // These semi-magic numbers define our compatibility modes for
5336 // applications with different screens. Don't change unless you
5337 // make sure to test lots and lots of apps!
5338 if (longSize < 470) {
5339 // This is shorter than an HVGA normal density screen (which
5340 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005341 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5342 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005343 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005344 // What size is this screen screen?
5345 if (longSize >= 800 && shortSize >= 600) {
5346 // SVGA or larger screens at medium density are the point
5347 // at which we consider it to be an extra large screen.
5348 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
5349 } else if (longSize >= 640 && shortSize >= 480) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005350 // VGA or larger screens at medium density are the point
5351 // at which we consider it to be a large screen.
5352 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5353 } else {
5354 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005355
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005356 // If this screen is wider than normal HVGA, or taller
5357 // than FWVGA, then for old apps we want to run in size
5358 // compatibility mode.
5359 if (shortSize > 321 || longSize > 570) {
5360 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5361 }
5362 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005363
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005364 // Is this a long screen?
5365 if (((longSize*3)/5) >= (shortSize-1)) {
5366 // Anything wider than WVGA (5:3) is considering to be long.
5367 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5368 } else {
5369 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5370 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005371 }
5372 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005373 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005374
Dianne Hackbornc485a602009-03-24 22:39:49 -07005375 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5376 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5377 mPolicy.adjustConfigurationLw(config);
5378 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005379 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005380
5381 // -------------------------------------------------------------
5382 // Drag and drop
5383 // -------------------------------------------------------------
5384
5385 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
5386 boolean localOnly, int width, int height, Surface outSurface) {
5387 if (DEBUG_DRAG) {
5388 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
5389 + " local=" + localOnly + " win=" + window
5390 + " asbinder=" + window.asBinder());
5391 }
5392
5393 final int callerPid = Binder.getCallingPid();
5394 final long origId = Binder.clearCallingIdentity();
5395 IBinder token = null;
5396
5397 try {
5398 synchronized (mWindowMap) {
5399 try {
5400 // !!! TODO: fail if the given window does not currently have touch focus?
5401
5402 if (mDragState == null) {
5403 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5404 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5405 outSurface.copyFrom(surface);
5406 token = new Binder();
5407 mDragState = new DragState(token, surface, localOnly);
5408 mDragState.mSurface = surface;
5409 mDragState.mLocalOnly = localOnly;
5410 token = mDragState.mToken = new Binder();
5411
5412 // 5 second timeout for this window to actually begin the drag
5413 mH.removeMessages(H.DRAG_START_TIMEOUT, window);
5414 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, window.asBinder());
5415 mH.sendMessageDelayed(msg, 5000);
5416 } else {
5417 Slog.w(TAG, "Drag already in progress");
5418 }
5419 } catch (Surface.OutOfResourcesException e) {
5420 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5421 if (mDragState != null) {
5422 mDragState.reset();
5423 mDragState = null;
5424 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005425 }
5426 }
5427 } finally {
5428 Binder.restoreCallingIdentity(origId);
5429 }
5430
5431 return token;
5432 }
5433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005434 // -------------------------------------------------------------
5435 // Input Events and Focus Management
5436 // -------------------------------------------------------------
Jeff Brown46b9ac02010-04-22 18:58:52 -07005437
Jeff Brown349703e2010-06-22 01:27:15 -07005438 InputMonitor mInputMonitor = new InputMonitor();
5439
5440 /* Tracks the progress of input dispatch and ensures that input dispatch state
5441 * is kept in sync with changes in window focus, visibility, registration, and
5442 * other relevant Window Manager state transitions. */
5443 final class InputMonitor {
5444 // Current window with input focus for keys and other non-touch events. May be null.
5445 private WindowState mInputFocus;
5446
5447 // When true, prevents input dispatch from proceeding until set to false again.
5448 private boolean mInputDispatchFrozen;
5449
5450 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5451 private boolean mInputDispatchEnabled = true;
5452
5453 // Temporary list of windows information to provide to the input dispatcher.
5454 private InputWindowList mTempInputWindows = new InputWindowList();
5455
5456 // Temporary input application object to provide to the input dispatcher.
5457 private InputApplication mTempInputApplication = new InputApplication();
5458
5459 /* Notifies the window manager about a broken input channel.
5460 *
5461 * Called by the InputManager.
5462 */
5463 public void notifyInputChannelBroken(InputChannel inputChannel) {
5464 synchronized (mWindowMap) {
5465 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5466 if (windowState == null) {
5467 return; // irrelevant
5468 }
5469
5470 Slog.i(TAG, "WINDOW DIED " + windowState);
5471 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005472 }
5473 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005474
Jeff Brown519e0242010-09-15 15:18:56 -07005475 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005476 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005477 *
5478 * Called by the InputManager.
5479 */
Jeff Brown519e0242010-09-15 15:18:56 -07005480 public long notifyANR(Object token, InputChannel inputChannel) {
5481 AppWindowToken appWindowToken = null;
5482 if (inputChannel != null) {
5483 synchronized (mWindowMap) {
5484 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5485 if (windowState != null) {
5486 Slog.i(TAG, "Input event dispatching timed out sending to "
5487 + windowState.mAttrs.getTitle());
5488 appWindowToken = windowState.mAppToken;
5489 }
Jeff Brown349703e2010-06-22 01:27:15 -07005490 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005491 }
5492
Jeff Brown519e0242010-09-15 15:18:56 -07005493 if (appWindowToken == null && token != null) {
5494 appWindowToken = (AppWindowToken) token;
5495 Slog.i(TAG, "Input event dispatching timed out sending to application "
5496 + appWindowToken.stringName);
5497 }
Jeff Brown349703e2010-06-22 01:27:15 -07005498
Jeff Brown519e0242010-09-15 15:18:56 -07005499 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005500 try {
5501 // Notify the activity manager about the timeout and let it decide whether
5502 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005503 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005504 if (! abort) {
5505 // The activity manager declined to abort dispatching.
5506 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005507 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005508 }
Jeff Brown349703e2010-06-22 01:27:15 -07005509 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005510 }
5511 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005512 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005513 }
5514
Jeff Brown349703e2010-06-22 01:27:15 -07005515 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5516 synchronized (mWindowMap) {
5517 return getWindowStateForInputChannelLocked(inputChannel);
5518 }
5519 }
5520
5521 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5522 int windowCount = mWindows.size();
5523 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005524 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005525 if (windowState.mInputChannel == inputChannel) {
5526 return windowState;
5527 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005528 }
5529
Jeff Brown349703e2010-06-22 01:27:15 -07005530 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005531 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005532
5533 private void addDragInputWindow(InputWindowList windowList) {
5534 final InputWindow inputWindow = windowList.add();
5535 inputWindow.inputChannel = mDragState.mServerChannel;
5536 inputWindow.name = "drag";
5537 inputWindow.layoutParamsFlags = 0;
5538 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5539 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5540 inputWindow.visible = true;
5541 inputWindow.canReceiveKeys = false;
5542 inputWindow.hasFocus = true;
5543 inputWindow.hasWallpaper = false;
5544 inputWindow.paused = false;
5545 inputWindow.layer = mPolicy.windowTypeToLayerLw(inputWindow.layoutParamsType)
5546 * TYPE_LAYER_MULTIPLIER
5547 + TYPE_LAYER_OFFSET;
5548 inputWindow.ownerPid = Process.myPid();
5549 inputWindow.ownerUid = Process.myUid();
5550
5551 // The drag window covers the entire display
5552 inputWindow.frameLeft = 0;
5553 inputWindow.frameTop = 0;
5554 inputWindow.frameRight = mDisplay.getWidth();
5555 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005556
Christopher Tatea53146c2010-09-07 11:57:52 -07005557 inputWindow.visibleFrameLeft = inputWindow.frameLeft;
5558 inputWindow.visibleFrameTop = inputWindow.frameTop;
5559 inputWindow.visibleFrameRight = inputWindow.frameRight;
5560 inputWindow.visibleFrameBottom = inputWindow.frameBottom;
5561
5562 inputWindow.touchableAreaLeft = inputWindow.frameLeft;
5563 inputWindow.touchableAreaTop = inputWindow.frameTop;
5564 inputWindow.touchableAreaRight = inputWindow.frameRight;
5565 inputWindow.touchableAreaBottom = inputWindow.frameBottom;
5566 }
5567
Jeff Brown349703e2010-06-22 01:27:15 -07005568 /* Updates the cached window information provided to the input dispatcher. */
5569 public void updateInputWindowsLw() {
5570 // Populate the input window list with information about all of the windows that
5571 // could potentially receive input.
5572 // As an optimization, we could try to prune the list of windows but this turns
5573 // out to be difficult because only the native code knows for sure which window
5574 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005575 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005576
5577 // If there's a drag in flight, provide a pseudowindow to catch drag input
5578 final boolean inDrag = (mDragState != null);
5579 if (inDrag) {
5580 if (DEBUG_DRAG) {
5581 Log.d(TAG, "Inserting drag window");
5582 }
5583 addDragInputWindow(mTempInputWindows);
5584 }
5585
Jeff Brown7fbdc842010-06-17 20:52:56 -07005586 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005587 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005588 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005589 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005590 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005591 continue;
5592 }
5593
Jeff Brown349703e2010-06-22 01:27:15 -07005594 final int flags = child.mAttrs.flags;
5595 final int type = child.mAttrs.type;
5596
5597 final boolean hasFocus = (child == mInputFocus);
5598 final boolean isVisible = child.isVisibleLw();
5599 final boolean hasWallpaper = (child == mWallpaperTarget)
5600 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005601
5602 // If there's a drag in progress and 'child' is a potential drop target,
5603 // make sure it's been told about the drag
5604 if (inDrag && isVisible) {
5605 mDragState.sendDragStartedIfNeededLw(child);
5606 }
5607
Jeff Brown349703e2010-06-22 01:27:15 -07005608 // Add a window to our list of input windows.
5609 final InputWindow inputWindow = mTempInputWindows.add();
5610 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005611 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005612 inputWindow.layoutParamsFlags = flags;
5613 inputWindow.layoutParamsType = type;
5614 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5615 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005616 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005617 inputWindow.hasFocus = hasFocus;
5618 inputWindow.hasWallpaper = hasWallpaper;
5619 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005620 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005621 inputWindow.ownerPid = child.mSession.mPid;
5622 inputWindow.ownerUid = child.mSession.mUid;
5623
5624 final Rect frame = child.mFrame;
5625 inputWindow.frameLeft = frame.left;
5626 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005627 inputWindow.frameRight = frame.right;
5628 inputWindow.frameBottom = frame.bottom;
5629
5630 final Rect visibleFrame = child.mVisibleFrame;
5631 inputWindow.visibleFrameLeft = visibleFrame.left;
5632 inputWindow.visibleFrameTop = visibleFrame.top;
5633 inputWindow.visibleFrameRight = visibleFrame.right;
5634 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005635
5636 switch (child.mTouchableInsets) {
5637 default:
5638 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5639 inputWindow.touchableAreaLeft = frame.left;
5640 inputWindow.touchableAreaTop = frame.top;
5641 inputWindow.touchableAreaRight = frame.right;
5642 inputWindow.touchableAreaBottom = frame.bottom;
5643 break;
5644
5645 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5646 Rect inset = child.mGivenContentInsets;
5647 inputWindow.touchableAreaLeft = frame.left + inset.left;
5648 inputWindow.touchableAreaTop = frame.top + inset.top;
5649 inputWindow.touchableAreaRight = frame.right - inset.right;
5650 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5651 break;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005652 }
Jeff Brown349703e2010-06-22 01:27:15 -07005653
5654 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5655 Rect inset = child.mGivenVisibleInsets;
5656 inputWindow.touchableAreaLeft = frame.left + inset.left;
5657 inputWindow.touchableAreaTop = frame.top + inset.top;
5658 inputWindow.touchableAreaRight = frame.right - inset.right;
5659 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005660 break;
5661 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005662 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005663 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005664
Jeff Brown349703e2010-06-22 01:27:15 -07005665 // Send windows to native code.
5666 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac02010-04-22 18:58:52 -07005667
Jeff Brown349703e2010-06-22 01:27:15 -07005668 // Clear the list in preparation for the next round.
5669 // Also avoids keeping InputChannel objects referenced unnecessarily.
5670 mTempInputWindows.clear();
5671 }
5672
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005673 /* Provides feedback for a virtual key down. */
5674 public void virtualKeyDownFeedback() {
5675 synchronized (mWindowMap) {
5676 mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5677 }
5678 }
5679
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005680 /* Notifies that the lid switch changed state. */
5681 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5682 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5683 }
5684
Jeff Brown349703e2010-06-22 01:27:15 -07005685 /* Provides an opportunity for the window manager policy to intercept early key
5686 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005687 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5688 int policyFlags, boolean isScreenOn) {
5689 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5690 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005691 }
5692
5693 /* Provides an opportunity for the window manager policy to process a key before
5694 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005695 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5696 int action, int flags, int keyCode, int metaState, int repeatCount,
5697 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005698 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005699 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5700 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005701 }
5702
5703 /* Called when the current input focus changes.
5704 * Layer assignment is assumed to be complete by the time this is called.
5705 */
5706 public void setInputFocusLw(WindowState newWindow) {
5707 if (DEBUG_INPUT) {
5708 Slog.d(TAG, "Input focus has changed to " + newWindow);
5709 }
5710
5711 if (newWindow != mInputFocus) {
5712 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005713 // Displaying a window implicitly causes dispatching to be unpaused.
5714 // This is to protect against bugs if someone pauses dispatching but
5715 // forgets to resume.
5716 newWindow.mToken.paused = false;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005717 }
Jeff Brown349703e2010-06-22 01:27:15 -07005718
5719 mInputFocus = newWindow;
5720 updateInputWindowsLw();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005721 }
5722 }
5723
Jeff Brown349703e2010-06-22 01:27:15 -07005724 public void setFocusedAppLw(AppWindowToken newApp) {
5725 // Focused app has changed.
5726 if (newApp == null) {
5727 mInputManager.setFocusedApplication(null);
5728 } else {
5729 mTempInputApplication.name = newApp.toString();
5730 mTempInputApplication.dispatchingTimeoutNanos =
5731 newApp.inputDispatchingTimeoutNanos;
5732 mTempInputApplication.token = newApp;
5733
5734 mInputManager.setFocusedApplication(mTempInputApplication);
5735 }
5736 }
5737
Jeff Brown349703e2010-06-22 01:27:15 -07005738 public void pauseDispatchingLw(WindowToken window) {
5739 if (! window.paused) {
5740 if (DEBUG_INPUT) {
5741 Slog.v(TAG, "Pausing WindowToken " + window);
5742 }
5743
5744 window.paused = true;
5745 updateInputWindowsLw();
5746 }
5747 }
5748
5749 public void resumeDispatchingLw(WindowToken window) {
5750 if (window.paused) {
5751 if (DEBUG_INPUT) {
5752 Slog.v(TAG, "Resuming WindowToken " + window);
5753 }
5754
5755 window.paused = false;
5756 updateInputWindowsLw();
5757 }
5758 }
5759
5760 public void freezeInputDispatchingLw() {
5761 if (! mInputDispatchFrozen) {
5762 if (DEBUG_INPUT) {
5763 Slog.v(TAG, "Freezing input dispatching");
5764 }
5765
5766 mInputDispatchFrozen = true;
5767 updateInputDispatchModeLw();
5768 }
5769 }
5770
5771 public void thawInputDispatchingLw() {
5772 if (mInputDispatchFrozen) {
5773 if (DEBUG_INPUT) {
5774 Slog.v(TAG, "Thawing input dispatching");
5775 }
5776
5777 mInputDispatchFrozen = false;
5778 updateInputDispatchModeLw();
5779 }
5780 }
5781
5782 public void setEventDispatchingLw(boolean enabled) {
5783 if (mInputDispatchEnabled != enabled) {
5784 if (DEBUG_INPUT) {
5785 Slog.v(TAG, "Setting event dispatching to " + enabled);
5786 }
5787
5788 mInputDispatchEnabled = enabled;
5789 updateInputDispatchModeLw();
5790 }
5791 }
5792
5793 private void updateInputDispatchModeLw() {
5794 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5795 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005796 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005798 public void pauseKeyDispatching(IBinder _token) {
5799 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5800 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005801 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005802 }
5803
5804 synchronized (mWindowMap) {
5805 WindowToken token = mTokenMap.get(_token);
5806 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005807 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005808 }
5809 }
5810 }
5811
5812 public void resumeKeyDispatching(IBinder _token) {
5813 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5814 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005815 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005816 }
5817
5818 synchronized (mWindowMap) {
5819 WindowToken token = mTokenMap.get(_token);
5820 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005821 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005822 }
5823 }
5824 }
5825
5826 public void setEventDispatching(boolean enabled) {
5827 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5828 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005829 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005830 }
5831
5832 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005833 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005834 }
5835 }
Romain Guy06882f82009-06-10 13:36:04 -07005836
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005837 /**
5838 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005839 * Even when sync is false, this method may block while waiting for current
5840 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005841 *
5842 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005843 * {@link SystemClock#uptimeMillis()} as the timebase.)
5844 * @param sync If true, wait for the event to be completed before returning to the caller.
5845 * @return Returns true if event was dispatched, false if it was dropped for any reason
5846 */
5847 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5848 long downTime = ev.getDownTime();
5849 long eventTime = ev.getEventTime();
5850
5851 int action = ev.getAction();
5852 int code = ev.getKeyCode();
5853 int repeatCount = ev.getRepeatCount();
5854 int metaState = ev.getMetaState();
5855 int deviceId = ev.getDeviceId();
5856 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005857 int source = ev.getSource();
5858
5859 if (source == InputDevice.SOURCE_UNKNOWN) {
5860 source = InputDevice.SOURCE_KEYBOARD;
5861 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005862
5863 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5864 if (downTime == 0) downTime = eventTime;
5865
5866 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005867 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005868
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005869 final int pid = Binder.getCallingPid();
5870 final int uid = Binder.getCallingUid();
5871 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005872
Jeff Brownbbda99d2010-07-28 15:48:59 -07005873 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5874 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5875 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5876 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005877
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005878 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005879 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005880 }
5881
5882 /**
5883 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005884 * Even when sync is false, this method may block while waiting for current
5885 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005886 *
5887 * @param ev A motion event describing the pointer (touch) action. (As noted in
5888 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005889 * {@link SystemClock#uptimeMillis()} as the timebase.)
5890 * @param sync If true, wait for the event to be completed before returning to the caller.
5891 * @return Returns true if event was dispatched, false if it was dropped for any reason
5892 */
5893 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005894 final int pid = Binder.getCallingPid();
5895 final int uid = Binder.getCallingUid();
5896 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005897
Jeff Brownc5ed5912010-07-14 18:48:53 -07005898 MotionEvent newEvent = MotionEvent.obtain(ev);
5899 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5900 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5901 }
5902
Jeff Brownbbda99d2010-07-28 15:48:59 -07005903 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5904 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5905 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5906 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005907
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005908 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005909 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005910 }
Romain Guy06882f82009-06-10 13:36:04 -07005911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005912 /**
5913 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005914 * Even when sync is false, this method may block while waiting for current
5915 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005916 *
5917 * @param ev A motion event describing the trackball action. (As noted in
5918 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005919 * {@link SystemClock#uptimeMillis()} as the timebase.)
5920 * @param sync If true, wait for the event to be completed before returning to the caller.
5921 * @return Returns true if event was dispatched, false if it was dropped for any reason
5922 */
5923 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005924 final int pid = Binder.getCallingPid();
5925 final int uid = Binder.getCallingUid();
5926 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005927
Jeff Brownc5ed5912010-07-14 18:48:53 -07005928 MotionEvent newEvent = MotionEvent.obtain(ev);
5929 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5930 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5931 }
5932
Jeff Brownbbda99d2010-07-28 15:48:59 -07005933 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5934 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5935 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5936 INJECTION_TIMEOUT_MILLIS);
5937
5938 Binder.restoreCallingIdentity(ident);
5939 return reportInjectionResult(result);
5940 }
5941
5942 /**
5943 * Inject an input event into the UI without waiting for dispatch to commence.
5944 * This variant is useful for fire-and-forget input event injection. It does not
5945 * block any longer than it takes to enqueue the input event.
5946 *
5947 * @param ev An input event. (Be sure to set the input source correctly.)
5948 * @return Returns true if event was dispatched, false if it was dropped for any reason
5949 */
5950 public boolean injectInputEventNoWait(InputEvent ev) {
5951 final int pid = Binder.getCallingPid();
5952 final int uid = Binder.getCallingUid();
5953 final long ident = Binder.clearCallingIdentity();
5954
5955 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5956 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5957 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005958
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005959 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005960 return reportInjectionResult(result);
5961 }
5962
5963 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005964 switch (result) {
5965 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5966 Slog.w(TAG, "Input event injection permission denied.");
5967 throw new SecurityException(
5968 "Injecting to another application requires INJECT_EVENTS permission");
5969 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07005970 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005971 return true;
5972 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5973 Slog.w(TAG, "Input event injection timed out.");
5974 return false;
5975 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5976 default:
5977 Slog.w(TAG, "Input event injection failed.");
5978 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005979 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005980 }
Romain Guy06882f82009-06-10 13:36:04 -07005981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005982 private WindowState getFocusedWindow() {
5983 synchronized (mWindowMap) {
5984 return getFocusedWindowLocked();
5985 }
5986 }
5987
5988 private WindowState getFocusedWindowLocked() {
5989 return mCurrentFocus;
5990 }
Romain Guy06882f82009-06-10 13:36:04 -07005991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005992 public boolean detectSafeMode() {
5993 mSafeMode = mPolicy.detectSafeMode();
5994 return mSafeMode;
5995 }
Romain Guy06882f82009-06-10 13:36:04 -07005996
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005997 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07005998 synchronized(mWindowMap) {
5999 if (mDisplay != null) {
6000 throw new IllegalStateException("Display already initialized");
6001 }
6002 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6003 mDisplay = wm.getDefaultDisplay();
6004 mInitialDisplayWidth = mDisplay.getWidth();
6005 mInitialDisplayHeight = mDisplay.getHeight();
6006 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
6007 }
6008
6009 try {
6010 mActivityManager.updateConfiguration(null);
6011 } catch (RemoteException e) {
6012 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006013
6014 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006015 }
6016
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006017 // -------------------------------------------------------------
6018 // Client Session State
6019 // -------------------------------------------------------------
6020
6021 private final class Session extends IWindowSession.Stub
6022 implements IBinder.DeathRecipient {
6023 final IInputMethodClient mClient;
6024 final IInputContext mInputContext;
6025 final int mUid;
6026 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006027 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006028 SurfaceSession mSurfaceSession;
6029 int mNumWindow = 0;
6030 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006031
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006032 public Session(IInputMethodClient client, IInputContext inputContext) {
6033 mClient = client;
6034 mInputContext = inputContext;
6035 mUid = Binder.getCallingUid();
6036 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006037 StringBuilder sb = new StringBuilder();
6038 sb.append("Session{");
6039 sb.append(Integer.toHexString(System.identityHashCode(this)));
6040 sb.append(" uid ");
6041 sb.append(mUid);
6042 sb.append("}");
6043 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006045 synchronized (mWindowMap) {
6046 if (mInputMethodManager == null && mHaveInputMethods) {
6047 IBinder b = ServiceManager.getService(
6048 Context.INPUT_METHOD_SERVICE);
6049 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6050 }
6051 }
6052 long ident = Binder.clearCallingIdentity();
6053 try {
6054 // Note: it is safe to call in to the input method manager
6055 // here because we are not holding our lock.
6056 if (mInputMethodManager != null) {
6057 mInputMethodManager.addClient(client, inputContext,
6058 mUid, mPid);
6059 } else {
6060 client.setUsingInputMethod(false);
6061 }
6062 client.asBinder().linkToDeath(this, 0);
6063 } catch (RemoteException e) {
6064 // The caller has died, so we can just forget about this.
6065 try {
6066 if (mInputMethodManager != null) {
6067 mInputMethodManager.removeClient(client);
6068 }
6069 } catch (RemoteException ee) {
6070 }
6071 } finally {
6072 Binder.restoreCallingIdentity(ident);
6073 }
6074 }
Romain Guy06882f82009-06-10 13:36:04 -07006075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006076 @Override
6077 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6078 throws RemoteException {
6079 try {
6080 return super.onTransact(code, data, reply, flags);
6081 } catch (RuntimeException e) {
6082 // Log all 'real' exceptions thrown to the caller
6083 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006084 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006085 }
6086 throw e;
6087 }
6088 }
6089
6090 public void binderDied() {
6091 // Note: it is safe to call in to the input method manager
6092 // here because we are not holding our lock.
6093 try {
6094 if (mInputMethodManager != null) {
6095 mInputMethodManager.removeClient(mClient);
6096 }
6097 } catch (RemoteException e) {
6098 }
6099 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006100 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006101 mClientDead = true;
6102 killSessionLocked();
6103 }
6104 }
6105
6106 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac02010-04-22 18:58:52 -07006107 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6108 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6109 outInputChannel);
6110 }
6111
6112 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006113 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07006114 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006115 }
Romain Guy06882f82009-06-10 13:36:04 -07006116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006117 public void remove(IWindow window) {
6118 removeWindow(this, window);
6119 }
Romain Guy06882f82009-06-10 13:36:04 -07006120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006121 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6122 int requestedWidth, int requestedHeight, int viewFlags,
6123 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006124 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006125 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6126 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006127 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006128 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006129 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6130 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006131 }
Romain Guy06882f82009-06-10 13:36:04 -07006132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006133 public void setTransparentRegion(IWindow window, Region region) {
6134 setTransparentRegionWindow(this, window, region);
6135 }
Romain Guy06882f82009-06-10 13:36:04 -07006136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006137 public void setInsets(IWindow window, int touchableInsets,
6138 Rect contentInsets, Rect visibleInsets) {
6139 setInsetsWindow(this, window, touchableInsets, contentInsets,
6140 visibleInsets);
6141 }
Romain Guy06882f82009-06-10 13:36:04 -07006142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006143 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6144 getWindowDisplayFrame(this, window, outDisplayFrame);
6145 }
Romain Guy06882f82009-06-10 13:36:04 -07006146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006147 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006148 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006149 TAG, "IWindow finishDrawing called for " + window);
6150 finishDrawingWindow(this, window);
6151 }
6152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006153 public void setInTouchMode(boolean mode) {
6154 synchronized(mWindowMap) {
6155 mInTouchMode = mode;
6156 }
6157 }
6158
6159 public boolean getInTouchMode() {
6160 synchronized(mWindowMap) {
6161 return mInTouchMode;
6162 }
6163 }
6164
6165 public boolean performHapticFeedback(IWindow window, int effectId,
6166 boolean always) {
6167 synchronized(mWindowMap) {
6168 long ident = Binder.clearCallingIdentity();
6169 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006170 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006171 windowForClientLocked(this, window, true),
6172 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006173 } finally {
6174 Binder.restoreCallingIdentity(ident);
6175 }
6176 }
6177 }
Romain Guy06882f82009-06-10 13:36:04 -07006178
Christopher Tatea53146c2010-09-07 11:57:52 -07006179 /* Drag/drop */
6180 public IBinder prepareDrag(IWindow window, boolean localOnly,
6181 int width, int height, Surface outSurface) {
6182 return prepareDragSurface(window, mSurfaceSession, localOnly,
6183 width, height, outSurface);
6184 }
6185
6186 public boolean performDrag(IWindow window, IBinder dragToken,
6187 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6188 ClipData data) {
6189 if (DEBUG_DRAG) {
6190 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6191 }
6192
6193 synchronized (mWindowMap) {
6194 if (mDragState == null) {
6195 Slog.w(TAG, "No drag prepared");
6196 throw new IllegalStateException("performDrag() without prepareDrag()");
6197 }
6198
6199 if (dragToken != mDragState.mToken) {
6200 Slog.w(TAG, "Performing mismatched drag");
6201 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6202 }
6203
6204 WindowState callingWin = windowForClientLocked(null, window, false);
6205 if (callingWin == null) {
6206 Slog.w(TAG, "Bad requesting window " + window);
6207 return false; // !!! TODO: throw here?
6208 }
6209
6210 // !!! TODO: if input is not still focused on the initiating window, fail
6211 // the drag initiation (e.g. an alarm window popped up just as the application
6212 // called performDrag()
6213
6214 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6215
Christopher Tate2c095f32010-10-04 14:13:40 -07006216 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6217 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006218
6219 mDragState.register();
6220 mInputMonitor.updateInputWindowsLw();
6221 mInputManager.transferTouchFocus(callingWin.mInputChannel,
6222 mDragState.mServerChannel);
6223
6224 mDragState.mData = data;
6225 mDragState.broadcastDragStartedLw();
6226
6227 // remember the thumb offsets for later
6228 mDragState.mThumbOffsetX = thumbCenterX;
6229 mDragState.mThumbOffsetY = thumbCenterY;
6230
6231 // Make the surface visible at the proper location
6232 final Surface surface = mDragState.mSurface;
6233 surface.openTransaction();
6234 try {
6235 surface.setPosition((int)(touchX - thumbCenterX),
6236 (int)(touchY - thumbCenterY));
6237 surface.setAlpha(.5f);
6238 surface.show();
6239 } finally {
6240 surface.closeTransaction();
6241 }
6242 }
6243
6244 return true; // success!
6245 }
6246
6247 public void dragRecipientEntered(IWindow window) {
6248 if (DEBUG_DRAG) {
6249 Slog.d(TAG, "Drag into new candidate view @ " + window);
6250 }
6251 }
6252
6253 public void dragRecipientExited(IWindow window) {
6254 if (DEBUG_DRAG) {
6255 Slog.d(TAG, "Drag from old candidate view @ " + window);
6256 }
6257 }
6258
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006259 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006260 synchronized(mWindowMap) {
6261 long ident = Binder.clearCallingIdentity();
6262 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006263 setWindowWallpaperPositionLocked(
6264 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006265 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006266 } finally {
6267 Binder.restoreCallingIdentity(ident);
6268 }
6269 }
6270 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006271
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006272 public void wallpaperOffsetsComplete(IBinder window) {
6273 WindowManagerService.this.wallpaperOffsetsComplete(window);
6274 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006275
Dianne Hackborn75804932009-10-20 20:15:20 -07006276 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6277 int z, Bundle extras, boolean sync) {
6278 synchronized(mWindowMap) {
6279 long ident = Binder.clearCallingIdentity();
6280 try {
6281 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006282 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006283 action, x, y, z, extras, sync);
6284 } finally {
6285 Binder.restoreCallingIdentity(ident);
6286 }
6287 }
6288 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006289
Dianne Hackborn75804932009-10-20 20:15:20 -07006290 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6291 WindowManagerService.this.wallpaperCommandComplete(window, result);
6292 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006294 void windowAddedLocked() {
6295 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006296 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006297 TAG, "First window added to " + this + ", creating SurfaceSession");
6298 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006299 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006300 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006301 mSessions.add(this);
6302 }
6303 mNumWindow++;
6304 }
6305
6306 void windowRemovedLocked() {
6307 mNumWindow--;
6308 killSessionLocked();
6309 }
Romain Guy06882f82009-06-10 13:36:04 -07006310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006311 void killSessionLocked() {
6312 if (mNumWindow <= 0 && mClientDead) {
6313 mSessions.remove(this);
6314 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006315 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006316 TAG, "Last window removed from " + this
6317 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006318 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006319 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006320 try {
6321 mSurfaceSession.kill();
6322 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006323 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006324 + mSurfaceSession + " in session " + this
6325 + ": " + e.toString());
6326 }
6327 mSurfaceSession = null;
6328 }
6329 }
6330 }
Romain Guy06882f82009-06-10 13:36:04 -07006331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006332 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006333 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6334 pw.print(" mClientDead="); pw.print(mClientDead);
6335 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006336 }
6337
6338 @Override
6339 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006340 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006341 }
6342 }
6343
6344 // -------------------------------------------------------------
6345 // Client Window State
6346 // -------------------------------------------------------------
6347
6348 private final class WindowState implements WindowManagerPolicy.WindowState {
6349 final Session mSession;
6350 final IWindow mClient;
6351 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006352 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006353 AppWindowToken mAppToken;
6354 AppWindowToken mTargetAppToken;
6355 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6356 final DeathRecipient mDeathRecipient;
6357 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006358 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006359 final int mBaseLayer;
6360 final int mSubLayer;
6361 final boolean mLayoutAttached;
6362 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006363 final boolean mIsWallpaper;
6364 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006365 int mViewVisibility;
6366 boolean mPolicyVisibility = true;
6367 boolean mPolicyVisibilityAfterAnim = true;
6368 boolean mAppFreezing;
6369 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006370 boolean mReportDestroySurface;
6371 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006372 boolean mAttachedHidden; // is our parent window hidden?
6373 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006374 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006375 int mRequestedWidth;
6376 int mRequestedHeight;
6377 int mLastRequestedWidth;
6378 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006379 int mLayer;
6380 int mAnimLayer;
6381 int mLastLayer;
6382 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006383 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006384 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006385
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006386 int mLayoutSeq = -1;
6387
6388 Configuration mConfiguration = null;
6389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006390 // Actual frame shown on-screen (may be modified by animation)
6391 final Rect mShownFrame = new Rect();
6392 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006394 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006395 * Set when we have changed the size of the surface, to know that
6396 * we must tell them application to resize (and thus redraw itself).
6397 */
6398 boolean mSurfaceResized;
6399
6400 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006401 * Insets that determine the actually visible area
6402 */
6403 final Rect mVisibleInsets = new Rect();
6404 final Rect mLastVisibleInsets = new Rect();
6405 boolean mVisibleInsetsChanged;
6406
6407 /**
6408 * Insets that are covered by system windows
6409 */
6410 final Rect mContentInsets = new Rect();
6411 final Rect mLastContentInsets = new Rect();
6412 boolean mContentInsetsChanged;
6413
6414 /**
6415 * Set to true if we are waiting for this window to receive its
6416 * given internal insets before laying out other windows based on it.
6417 */
6418 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006420 /**
6421 * These are the content insets that were given during layout for
6422 * this window, to be applied to windows behind it.
6423 */
6424 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006426 /**
6427 * These are the visible insets that were given during layout for
6428 * this window, to be applied to windows behind it.
6429 */
6430 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006432 /**
6433 * Flag indicating whether the touchable region should be adjusted by
6434 * the visible insets; if false the area outside the visible insets is
6435 * NOT touchable, so we must use those to adjust the frame during hit
6436 * tests.
6437 */
6438 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006440 // Current transformation being applied.
6441 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6442 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6443 float mHScale=1, mVScale=1;
6444 float mLastHScale=1, mLastVScale=1;
6445 final Matrix mTmpMatrix = new Matrix();
6446
6447 // "Real" frame that the application sees.
6448 final Rect mFrame = new Rect();
6449 final Rect mLastFrame = new Rect();
6450
6451 final Rect mContainingFrame = new Rect();
6452 final Rect mDisplayFrame = new Rect();
6453 final Rect mContentFrame = new Rect();
6454 final Rect mVisibleFrame = new Rect();
6455
6456 float mShownAlpha = 1;
6457 float mAlpha = 1;
6458 float mLastAlpha = 1;
6459
6460 // Set to true if, when the window gets displayed, it should perform
6461 // an enter animation.
6462 boolean mEnterAnimationPending;
6463
6464 // Currently running animation.
6465 boolean mAnimating;
6466 boolean mLocalAnimating;
6467 Animation mAnimation;
6468 boolean mAnimationIsEntrance;
6469 boolean mHasTransformation;
6470 boolean mHasLocalTransformation;
6471 final Transformation mTransformation = new Transformation();
6472
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006473 // If a window showing a wallpaper: the requested offset for the
6474 // wallpaper; if a wallpaper window: the currently applied offset.
6475 float mWallpaperX = -1;
6476 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006477
6478 // If a window showing a wallpaper: what fraction of the offset
6479 // range corresponds to a full virtual screen.
6480 float mWallpaperXStep = -1;
6481 float mWallpaperYStep = -1;
6482
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006483 // Wallpaper windows: pixels offset based on above variables.
6484 int mXOffset;
6485 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006487 // This is set after IWindowSession.relayout() has been called at
6488 // least once for the window. It allows us to detect the situation
6489 // where we don't yet have a surface, but should have one soon, so
6490 // we can give the window focus before waiting for the relayout.
6491 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006493 // This is set after the Surface has been created but before the
6494 // window has been drawn. During this time the surface is hidden.
6495 boolean mDrawPending;
6496
6497 // This is set after the window has finished drawing for the first
6498 // time but before its surface is shown. The surface will be
6499 // displayed when the next layout is run.
6500 boolean mCommitDrawPending;
6501
6502 // This is set during the time after the window's drawing has been
6503 // committed, and before its surface is actually shown. It is used
6504 // to delay showing the surface until all windows in a token are ready
6505 // to be shown.
6506 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006508 // Set when the window has been shown in the screen the first time.
6509 boolean mHasDrawn;
6510
6511 // Currently running an exit animation?
6512 boolean mExiting;
6513
6514 // Currently on the mDestroySurface list?
6515 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006517 // Completely remove from window manager after exit animation?
6518 boolean mRemoveOnExit;
6519
6520 // Set when the orientation is changing and this window has not yet
6521 // been updated for the new orientation.
6522 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006524 // Is this window now (or just being) removed?
6525 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006526
Dianne Hackborn16064f92010-03-25 00:47:24 -07006527 // For debugging, this is the last information given to the surface flinger.
6528 boolean mSurfaceShown;
6529 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6530 int mSurfaceLayer;
6531 float mSurfaceAlpha;
6532
Jeff Brown46b9ac02010-04-22 18:58:52 -07006533 // Input channel
6534 InputChannel mInputChannel;
6535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006536 WindowState(Session s, IWindow c, WindowToken token,
6537 WindowState attachedWindow, WindowManager.LayoutParams a,
6538 int viewVisibility) {
6539 mSession = s;
6540 mClient = c;
6541 mToken = token;
6542 mAttrs.copyFrom(a);
6543 mViewVisibility = viewVisibility;
6544 DeathRecipient deathRecipient = new DeathRecipient();
6545 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006546 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006547 TAG, "Window " + this + " client=" + c.asBinder()
6548 + " token=" + token + " (" + mAttrs.token + ")");
6549 try {
6550 c.asBinder().linkToDeath(deathRecipient, 0);
6551 } catch (RemoteException e) {
6552 mDeathRecipient = null;
6553 mAttachedWindow = null;
6554 mLayoutAttached = false;
6555 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006556 mIsWallpaper = false;
6557 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006558 mBaseLayer = 0;
6559 mSubLayer = 0;
6560 return;
6561 }
6562 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006563
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006564 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6565 mAttrs.type <= LAST_SUB_WINDOW)) {
6566 // The multiplier here is to reserve space for multiple
6567 // windows in the same type layer.
6568 mBaseLayer = mPolicy.windowTypeToLayerLw(
6569 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6570 + TYPE_LAYER_OFFSET;
6571 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6572 mAttachedWindow = attachedWindow;
6573 mAttachedWindow.mChildWindows.add(this);
6574 mLayoutAttached = mAttrs.type !=
6575 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6576 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6577 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006578 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6579 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006580 } else {
6581 // The multiplier here is to reserve space for multiple
6582 // windows in the same type layer.
6583 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6584 * TYPE_LAYER_MULTIPLIER
6585 + TYPE_LAYER_OFFSET;
6586 mSubLayer = 0;
6587 mAttachedWindow = null;
6588 mLayoutAttached = false;
6589 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6590 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006591 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6592 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006593 }
6594
6595 WindowState appWin = this;
6596 while (appWin.mAttachedWindow != null) {
6597 appWin = mAttachedWindow;
6598 }
6599 WindowToken appToken = appWin.mToken;
6600 while (appToken.appWindowToken == null) {
6601 WindowToken parent = mTokenMap.get(appToken.token);
6602 if (parent == null || appToken == parent) {
6603 break;
6604 }
6605 appToken = parent;
6606 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006607 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006608 mAppToken = appToken.appWindowToken;
6609
6610 mSurface = null;
6611 mRequestedWidth = 0;
6612 mRequestedHeight = 0;
6613 mLastRequestedWidth = 0;
6614 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006615 mXOffset = 0;
6616 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006617 mLayer = 0;
6618 mAnimLayer = 0;
6619 mLastLayer = 0;
6620 }
6621
6622 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006623 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006624 TAG, "Attaching " + this + " token=" + mToken
6625 + ", list=" + mToken.windows);
6626 mSession.windowAddedLocked();
6627 }
6628
6629 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6630 mHaveFrame = true;
6631
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006632 final Rect container = mContainingFrame;
6633 container.set(pf);
6634
6635 final Rect display = mDisplayFrame;
6636 display.set(df);
6637
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006638 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006639 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006640 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6641 display.intersect(mCompatibleScreenFrame);
6642 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006643 }
6644
6645 final int pw = container.right - container.left;
6646 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006647
6648 int w,h;
6649 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6650 w = mAttrs.width < 0 ? pw : mAttrs.width;
6651 h = mAttrs.height< 0 ? ph : mAttrs.height;
6652 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006653 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6654 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006655 }
Romain Guy06882f82009-06-10 13:36:04 -07006656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006657 final Rect content = mContentFrame;
6658 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006660 final Rect visible = mVisibleFrame;
6661 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006663 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006664 final int fw = frame.width();
6665 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006667 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6668 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6669
6670 Gravity.apply(mAttrs.gravity, w, h, container,
6671 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6672 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6673
6674 //System.out.println("Out: " + mFrame);
6675
6676 // Now make sure the window fits in the overall display.
6677 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006678
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006679 // Make sure the content and visible frames are inside of the
6680 // final window frame.
6681 if (content.left < frame.left) content.left = frame.left;
6682 if (content.top < frame.top) content.top = frame.top;
6683 if (content.right > frame.right) content.right = frame.right;
6684 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6685 if (visible.left < frame.left) visible.left = frame.left;
6686 if (visible.top < frame.top) visible.top = frame.top;
6687 if (visible.right > frame.right) visible.right = frame.right;
6688 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006690 final Rect contentInsets = mContentInsets;
6691 contentInsets.left = content.left-frame.left;
6692 contentInsets.top = content.top-frame.top;
6693 contentInsets.right = frame.right-content.right;
6694 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006695
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006696 final Rect visibleInsets = mVisibleInsets;
6697 visibleInsets.left = visible.left-frame.left;
6698 visibleInsets.top = visible.top-frame.top;
6699 visibleInsets.right = frame.right-visible.right;
6700 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006701
Dianne Hackborn284ac932009-08-28 10:34:25 -07006702 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6703 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006704 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006705 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006707 if (localLOGV) {
6708 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6709 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006710 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006711 + mRequestedWidth + ", mRequestedheight="
6712 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6713 + "): frame=" + mFrame.toShortString()
6714 + " ci=" + contentInsets.toShortString()
6715 + " vi=" + visibleInsets.toShortString());
6716 //}
6717 }
6718 }
Romain Guy06882f82009-06-10 13:36:04 -07006719
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006720 public Rect getFrameLw() {
6721 return mFrame;
6722 }
6723
6724 public Rect getShownFrameLw() {
6725 return mShownFrame;
6726 }
6727
6728 public Rect getDisplayFrameLw() {
6729 return mDisplayFrame;
6730 }
6731
6732 public Rect getContentFrameLw() {
6733 return mContentFrame;
6734 }
6735
6736 public Rect getVisibleFrameLw() {
6737 return mVisibleFrame;
6738 }
6739
6740 public boolean getGivenInsetsPendingLw() {
6741 return mGivenInsetsPending;
6742 }
6743
6744 public Rect getGivenContentInsetsLw() {
6745 return mGivenContentInsets;
6746 }
Romain Guy06882f82009-06-10 13:36:04 -07006747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006748 public Rect getGivenVisibleInsetsLw() {
6749 return mGivenVisibleInsets;
6750 }
Romain Guy06882f82009-06-10 13:36:04 -07006751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006752 public WindowManager.LayoutParams getAttrs() {
6753 return mAttrs;
6754 }
6755
6756 public int getSurfaceLayer() {
6757 return mLayer;
6758 }
Romain Guy06882f82009-06-10 13:36:04 -07006759
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006760 public IApplicationToken getAppToken() {
6761 return mAppToken != null ? mAppToken.appToken : null;
6762 }
Jeff Brown349703e2010-06-22 01:27:15 -07006763
6764 public long getInputDispatchingTimeoutNanos() {
6765 return mAppToken != null
6766 ? mAppToken.inputDispatchingTimeoutNanos
6767 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6768 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006769
6770 public boolean hasAppShownWindows() {
6771 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6772 }
6773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006774 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006775 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006776 TAG, "Setting animation in " + this + ": " + anim);
6777 mAnimating = false;
6778 mLocalAnimating = false;
6779 mAnimation = anim;
6780 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6781 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6782 }
6783
6784 public void clearAnimation() {
6785 if (mAnimation != null) {
6786 mAnimating = true;
6787 mLocalAnimating = false;
6788 mAnimation = null;
6789 }
6790 }
Romain Guy06882f82009-06-10 13:36:04 -07006791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006792 Surface createSurfaceLocked() {
6793 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006794 mReportDestroySurface = false;
6795 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006796 mDrawPending = true;
6797 mCommitDrawPending = false;
6798 mReadyToShow = false;
6799 if (mAppToken != null) {
6800 mAppToken.allDrawn = false;
6801 }
6802
6803 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006804 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006805 flags |= Surface.PUSH_BUFFERS;
6806 }
6807
6808 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6809 flags |= Surface.SECURE;
6810 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006811 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006812 TAG, "Creating surface in session "
6813 + mSession.mSurfaceSession + " window " + this
6814 + " w=" + mFrame.width()
6815 + " h=" + mFrame.height() + " format="
6816 + mAttrs.format + " flags=" + flags);
6817
6818 int w = mFrame.width();
6819 int h = mFrame.height();
6820 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6821 // for a scaled surface, we always want the requested
6822 // size.
6823 w = mRequestedWidth;
6824 h = mRequestedHeight;
6825 }
6826
Romain Guy9825ec62009-10-01 00:58:09 -07006827 // Something is wrong and SurfaceFlinger will not like this,
6828 // try to revert to sane values
6829 if (w <= 0) w = 1;
6830 if (h <= 0) h = 1;
6831
Dianne Hackborn16064f92010-03-25 00:47:24 -07006832 mSurfaceShown = false;
6833 mSurfaceLayer = 0;
6834 mSurfaceAlpha = 1;
6835 mSurfaceX = 0;
6836 mSurfaceY = 0;
6837 mSurfaceW = w;
6838 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006839 try {
6840 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006841 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006842 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006843 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006844 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006845 + mSurface + " IN SESSION "
6846 + mSession.mSurfaceSession
6847 + ": pid=" + mSession.mPid + " format="
6848 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006849 + Integer.toHexString(flags)
6850 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006851 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006852 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006853 reclaimSomeSurfaceMemoryLocked(this, "create");
6854 return null;
6855 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006856 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006857 return null;
6858 }
Romain Guy06882f82009-06-10 13:36:04 -07006859
Joe Onorato8a9b2202010-02-26 18:56:32 -08006860 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006861 TAG, "Got surface: " + mSurface
6862 + ", set left=" + mFrame.left + " top=" + mFrame.top
6863 + ", animLayer=" + mAnimLayer);
6864 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006865 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006866 if (SHOW_TRANSACTIONS) logSurface(this,
6867 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6868 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6869 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006870 }
6871 Surface.openTransaction();
6872 try {
6873 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006874 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006875 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006876 mSurface.setPosition(mSurfaceX, mSurfaceY);
6877 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006878 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006879 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006880 mSurface.hide();
6881 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006882 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006883 mSurface.setFlags(Surface.SURFACE_DITHER,
6884 Surface.SURFACE_DITHER);
6885 }
6886 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006887 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006888 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6889 }
6890 mLastHidden = true;
6891 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006892 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006893 Surface.closeTransaction();
6894 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006895 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006896 TAG, "Created surface " + this);
6897 }
6898 return mSurface;
6899 }
Romain Guy06882f82009-06-10 13:36:04 -07006900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006901 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006902 if (mAppToken != null && this == mAppToken.startingWindow) {
6903 mAppToken.startingDisplayed = false;
6904 }
Romain Guy06882f82009-06-10 13:36:04 -07006905
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006906 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006907 mDrawPending = false;
6908 mCommitDrawPending = false;
6909 mReadyToShow = false;
6910
6911 int i = mChildWindows.size();
6912 while (i > 0) {
6913 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006914 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006915 c.mAttachedHidden = true;
6916 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006917
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006918 if (mReportDestroySurface) {
6919 mReportDestroySurface = false;
6920 mSurfacePendingDestroy = true;
6921 try {
6922 mClient.dispatchGetNewSurface();
6923 // We'll really destroy on the next time around.
6924 return;
6925 } catch (RemoteException e) {
6926 }
6927 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006929 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006930 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006931 RuntimeException e = null;
6932 if (!HIDE_STACK_CRAWLS) {
6933 e = new RuntimeException();
6934 e.fillInStackTrace();
6935 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006936 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006937 + mSurface + ", session " + mSession, e);
6938 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006939 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006940 RuntimeException e = null;
6941 if (!HIDE_STACK_CRAWLS) {
6942 e = new RuntimeException();
6943 e.fillInStackTrace();
6944 }
6945 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006946 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006947 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006948 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006949 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006950 + " surface " + mSurface + " session " + mSession
6951 + ": " + e.toString());
6952 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006953
Dianne Hackborn16064f92010-03-25 00:47:24 -07006954 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006955 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006956 }
6957 }
6958
6959 boolean finishDrawingLocked() {
6960 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006961 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006962 TAG, "finishDrawingLocked: " + mSurface);
6963 mCommitDrawPending = true;
6964 mDrawPending = false;
6965 return true;
6966 }
6967 return false;
6968 }
6969
6970 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006971 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006972 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006973 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006974 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006975 }
6976 mCommitDrawPending = false;
6977 mReadyToShow = true;
6978 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6979 final AppWindowToken atoken = mAppToken;
6980 if (atoken == null || atoken.allDrawn || starting) {
6981 performShowLocked();
6982 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006983 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006984 }
6985
6986 // This must be called while inside a transaction.
6987 boolean performShowLocked() {
6988 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006989 RuntimeException e = null;
6990 if (!HIDE_STACK_CRAWLS) {
6991 e = new RuntimeException();
6992 e.fillInStackTrace();
6993 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006994 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006995 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
6996 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
6997 }
6998 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006999 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7000 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007001 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007002 + " during animation: policyVis=" + mPolicyVisibility
7003 + " attHidden=" + mAttachedHidden
7004 + " tok.hiddenRequested="
7005 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007006 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007007 + (mAppToken != null ? mAppToken.hidden : false)
7008 + " animating=" + mAnimating
7009 + " tok animating="
7010 + (mAppToken != null ? mAppToken.animating : false));
7011 if (!showSurfaceRobustlyLocked(this)) {
7012 return false;
7013 }
7014 mLastAlpha = -1;
7015 mHasDrawn = true;
7016 mLastHidden = false;
7017 mReadyToShow = false;
7018 enableScreenIfNeededLocked();
7019
7020 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007022 int i = mChildWindows.size();
7023 while (i > 0) {
7024 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007025 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007026 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007027 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007028 if (c.mSurface != null) {
7029 c.performShowLocked();
7030 // It hadn't been shown, which means layout not
7031 // performed on it, so now we want to make sure to
7032 // do a layout. If called from within the transaction
7033 // loop, this will cause it to restart with a new
7034 // layout.
7035 mLayoutNeeded = true;
7036 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007037 }
7038 }
Romain Guy06882f82009-06-10 13:36:04 -07007039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007040 if (mAttrs.type != TYPE_APPLICATION_STARTING
7041 && mAppToken != null) {
7042 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007043
Dianne Hackborn248b1882009-09-16 16:46:44 -07007044 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007045 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007046 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007047 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007048 // If this initial window is animating, stop it -- we
7049 // will do an animation to reveal it from behind the
7050 // starting window, so there is no need for it to also
7051 // be doing its own stuff.
7052 if (mAnimation != null) {
7053 mAnimation = null;
7054 // Make sure we clean up the animation.
7055 mAnimating = true;
7056 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007057 mFinishedStarting.add(mAppToken);
7058 mH.sendEmptyMessage(H.FINISHED_STARTING);
7059 }
7060 mAppToken.updateReportedVisibilityLocked();
7061 }
7062 }
7063 return true;
7064 }
Romain Guy06882f82009-06-10 13:36:04 -07007065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007066 // This must be called while inside a transaction. Returns true if
7067 // there is more animation to run.
7068 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007069 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007070 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007072 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7073 mHasTransformation = true;
7074 mHasLocalTransformation = true;
7075 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007076 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007077 TAG, "Starting animation in " + this +
7078 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7079 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7080 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7081 mAnimation.setStartTime(currentTime);
7082 mLocalAnimating = true;
7083 mAnimating = true;
7084 }
7085 mTransformation.clear();
7086 final boolean more = mAnimation.getTransformation(
7087 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007088 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007089 TAG, "Stepped animation in " + this +
7090 ": more=" + more + ", xform=" + mTransformation);
7091 if (more) {
7092 // we're not done!
7093 return true;
7094 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007095 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007096 TAG, "Finished animation in " + this +
7097 " @ " + currentTime);
7098 mAnimation = null;
7099 //WindowManagerService.this.dump();
7100 }
7101 mHasLocalTransformation = false;
7102 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007103 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007104 // When our app token is animating, we kind-of pretend like
7105 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7106 // part of this check means that we will only do this if
7107 // our window is not currently exiting, or it is not
7108 // locally animating itself. The idea being that one that
7109 // is exiting and doing a local animation should be removed
7110 // once that animation is done.
7111 mAnimating = true;
7112 mHasTransformation = true;
7113 mTransformation.clear();
7114 return false;
7115 } else if (mHasTransformation) {
7116 // Little trick to get through the path below to act like
7117 // we have finished an animation.
7118 mAnimating = true;
7119 } else if (isAnimating()) {
7120 mAnimating = true;
7121 }
7122 } else if (mAnimation != null) {
7123 // If the display is frozen, and there is a pending animation,
7124 // clear it and make sure we run the cleanup code.
7125 mAnimating = true;
7126 mLocalAnimating = true;
7127 mAnimation = null;
7128 }
Romain Guy06882f82009-06-10 13:36:04 -07007129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007130 if (!mAnimating && !mLocalAnimating) {
7131 return false;
7132 }
7133
Joe Onorato8a9b2202010-02-26 18:56:32 -08007134 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007135 TAG, "Animation done in " + this + ": exiting=" + mExiting
7136 + ", reportedVisible="
7137 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007139 mAnimating = false;
7140 mLocalAnimating = false;
7141 mAnimation = null;
7142 mAnimLayer = mLayer;
7143 if (mIsImWindow) {
7144 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007145 } else if (mIsWallpaper) {
7146 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007147 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007148 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007149 + " anim layer: " + mAnimLayer);
7150 mHasTransformation = false;
7151 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007152 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7153 if (DEBUG_VISIBILITY) {
7154 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7155 + mPolicyVisibilityAfterAnim);
7156 }
7157 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7158 if (!mPolicyVisibility) {
7159 if (mCurrentFocus == this) {
7160 mFocusMayChange = true;
7161 }
7162 // Window is no longer visible -- make sure if we were waiting
7163 // for it to be displayed before enabling the display, that
7164 // we allow the display to be enabled now.
7165 enableScreenIfNeededLocked();
7166 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007167 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007168 mTransformation.clear();
7169 if (mHasDrawn
7170 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7171 && mAppToken != null
7172 && mAppToken.firstWindowDrawn
7173 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007174 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007175 + mToken + ": first real window done animating");
7176 mFinishedStarting.add(mAppToken);
7177 mH.sendEmptyMessage(H.FINISHED_STARTING);
7178 }
Romain Guy06882f82009-06-10 13:36:04 -07007179
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007180 finishExit();
7181
7182 if (mAppToken != null) {
7183 mAppToken.updateReportedVisibilityLocked();
7184 }
7185
7186 return false;
7187 }
7188
7189 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007190 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007191 TAG, "finishExit in " + this
7192 + ": exiting=" + mExiting
7193 + " remove=" + mRemoveOnExit
7194 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007196 final int N = mChildWindows.size();
7197 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007198 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007199 }
Romain Guy06882f82009-06-10 13:36:04 -07007200
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007201 if (!mExiting) {
7202 return;
7203 }
Romain Guy06882f82009-06-10 13:36:04 -07007204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007205 if (isWindowAnimating()) {
7206 return;
7207 }
7208
Joe Onorato8a9b2202010-02-26 18:56:32 -08007209 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007210 TAG, "Exit animation finished in " + this
7211 + ": remove=" + mRemoveOnExit);
7212 if (mSurface != null) {
7213 mDestroySurface.add(this);
7214 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007215 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007216 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007217 try {
7218 mSurface.hide();
7219 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007220 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007221 }
7222 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007223 }
7224 mExiting = false;
7225 if (mRemoveOnExit) {
7226 mPendingRemove.add(this);
7227 mRemoveOnExit = false;
7228 }
7229 }
Romain Guy06882f82009-06-10 13:36:04 -07007230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007231 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7232 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7233 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7234 if (dtdx < -.000001f || dtdx > .000001f) return false;
7235 if (dsdy < -.000001f || dsdy > .000001f) return false;
7236 return true;
7237 }
Romain Guy06882f82009-06-10 13:36:04 -07007238
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007239 void computeShownFrameLocked() {
7240 final boolean selfTransformation = mHasLocalTransformation;
7241 Transformation attachedTransformation =
7242 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7243 ? mAttachedWindow.mTransformation : null;
7244 Transformation appTransformation =
7245 (mAppToken != null && mAppToken.hasTransformation)
7246 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007247
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007248 // Wallpapers are animated based on the "real" window they
7249 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007250 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007251 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007252 if (mWallpaperTarget.mHasLocalTransformation &&
7253 mWallpaperTarget.mAnimation != null &&
7254 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007255 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007256 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007257 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007258 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007259 }
7260 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007261 mWallpaperTarget.mAppToken.hasTransformation &&
7262 mWallpaperTarget.mAppToken.animation != null &&
7263 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007264 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007265 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007266 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007267 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007268 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007269 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007271 if (selfTransformation || attachedTransformation != null
7272 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007273 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007274 final Rect frame = mFrame;
7275 final float tmpFloats[] = mTmpFloats;
7276 final Matrix tmpMatrix = mTmpMatrix;
7277
7278 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007279 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007280 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007281 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007282 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007283 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007284 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007285 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007286 }
7287 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007288 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007289 }
7290
7291 // "convert" it into SurfaceFlinger's format
7292 // (a 2x2 matrix + an offset)
7293 // Here we must not transform the position of the surface
7294 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007295 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007297 tmpMatrix.getValues(tmpFloats);
7298 mDsDx = tmpFloats[Matrix.MSCALE_X];
7299 mDtDx = tmpFloats[Matrix.MSKEW_X];
7300 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7301 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007302 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7303 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007304 int w = frame.width();
7305 int h = frame.height();
7306 mShownFrame.set(x, y, x+w, y+h);
7307
7308 // Now set the alpha... but because our current hardware
7309 // can't do alpha transformation on a non-opaque surface,
7310 // turn it off if we are running an animation that is also
7311 // transforming since it is more important to have that
7312 // animation be smooth.
7313 mShownAlpha = mAlpha;
7314 if (!mLimitedAlphaCompositing
7315 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7316 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7317 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007318 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007319 if (selfTransformation) {
7320 mShownAlpha *= mTransformation.getAlpha();
7321 }
7322 if (attachedTransformation != null) {
7323 mShownAlpha *= attachedTransformation.getAlpha();
7324 }
7325 if (appTransformation != null) {
7326 mShownAlpha *= appTransformation.getAlpha();
7327 }
7328 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007329 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007330 }
Romain Guy06882f82009-06-10 13:36:04 -07007331
Joe Onorato8a9b2202010-02-26 18:56:32 -08007332 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007333 TAG, "Continuing animation in " + this +
7334 ": " + mShownFrame +
7335 ", alpha=" + mTransformation.getAlpha());
7336 return;
7337 }
Romain Guy06882f82009-06-10 13:36:04 -07007338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007339 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007340 if (mXOffset != 0 || mYOffset != 0) {
7341 mShownFrame.offset(mXOffset, mYOffset);
7342 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007343 mShownAlpha = mAlpha;
7344 mDsDx = 1;
7345 mDtDx = 0;
7346 mDsDy = 0;
7347 mDtDy = 1;
7348 }
Romain Guy06882f82009-06-10 13:36:04 -07007349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007350 /**
7351 * Is this window visible? It is not visible if there is no
7352 * surface, or we are in the process of running an exit animation
7353 * that will remove the surface, or its app token has been hidden.
7354 */
7355 public boolean isVisibleLw() {
7356 final AppWindowToken atoken = mAppToken;
7357 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7358 && (atoken == null || !atoken.hiddenRequested)
7359 && !mExiting && !mDestroying;
7360 }
7361
7362 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007363 * Like {@link #isVisibleLw}, but also counts a window that is currently
7364 * "hidden" behind the keyguard as visible. This allows us to apply
7365 * things like window flags that impact the keyguard.
7366 * XXX I am starting to think we need to have ANOTHER visibility flag
7367 * for this "hidden behind keyguard" state rather than overloading
7368 * mPolicyVisibility. Ungh.
7369 */
7370 public boolean isVisibleOrBehindKeyguardLw() {
7371 final AppWindowToken atoken = mAppToken;
7372 return mSurface != null && !mAttachedHidden
7373 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007374 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007375 && !mExiting && !mDestroying;
7376 }
7377
7378 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007379 * Is this window visible, ignoring its app token? It is not visible
7380 * if there is no surface, or we are in the process of running an exit animation
7381 * that will remove the surface.
7382 */
7383 public boolean isWinVisibleLw() {
7384 final AppWindowToken atoken = mAppToken;
7385 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7386 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7387 && !mExiting && !mDestroying;
7388 }
7389
7390 /**
7391 * The same as isVisible(), but follows the current hidden state of
7392 * the associated app token, not the pending requested hidden state.
7393 */
7394 boolean isVisibleNow() {
7395 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007396 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007397 }
7398
7399 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007400 * Can this window possibly be a drag/drop target? The test here is
7401 * a combination of the above "visible now" with the check that the
7402 * Input Manager uses when discarding windows from input consideration.
7403 */
7404 boolean isPotentialDragTarget() {
7405 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7406 }
7407
7408 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007409 * Same as isVisible(), but we also count it as visible between the
7410 * call to IWindowSession.add() and the first relayout().
7411 */
7412 boolean isVisibleOrAdding() {
7413 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007414 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007415 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7416 && mPolicyVisibility && !mAttachedHidden
7417 && (atoken == null || !atoken.hiddenRequested)
7418 && !mExiting && !mDestroying;
7419 }
7420
7421 /**
7422 * Is this window currently on-screen? It is on-screen either if it
7423 * is visible or it is currently running an animation before no longer
7424 * being visible.
7425 */
7426 boolean isOnScreen() {
7427 final AppWindowToken atoken = mAppToken;
7428 if (atoken != null) {
7429 return mSurface != null && mPolicyVisibility && !mDestroying
7430 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007431 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007432 } else {
7433 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007434 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007435 }
7436 }
Romain Guy06882f82009-06-10 13:36:04 -07007437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007438 /**
7439 * Like isOnScreen(), but we don't return true if the window is part
7440 * of a transition that has not yet been started.
7441 */
7442 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007443 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007444 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007445 return false;
7446 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007447 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007448 final boolean animating = atoken != null
7449 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007450 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007451 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7452 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007453 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007454 }
7455
7456 /** Is the window or its container currently animating? */
7457 boolean isAnimating() {
7458 final WindowState attached = mAttachedWindow;
7459 final AppWindowToken atoken = mAppToken;
7460 return mAnimation != null
7461 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007462 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007463 (atoken.animation != null
7464 || atoken.inPendingTransaction));
7465 }
7466
7467 /** Is this window currently animating? */
7468 boolean isWindowAnimating() {
7469 return mAnimation != null;
7470 }
7471
7472 /**
7473 * Like isOnScreen, but returns false if the surface hasn't yet
7474 * been drawn.
7475 */
7476 public boolean isDisplayedLw() {
7477 final AppWindowToken atoken = mAppToken;
7478 return mSurface != null && mPolicyVisibility && !mDestroying
7479 && !mDrawPending && !mCommitDrawPending
7480 && ((!mAttachedHidden &&
7481 (atoken == null || !atoken.hiddenRequested))
7482 || mAnimating);
7483 }
7484
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007485 /**
7486 * Returns true if the window has a surface that it has drawn a
7487 * complete UI in to.
7488 */
7489 public boolean isDrawnLw() {
7490 final AppWindowToken atoken = mAppToken;
7491 return mSurface != null && !mDestroying
7492 && !mDrawPending && !mCommitDrawPending;
7493 }
7494
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007495 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007496 * Return true if the window is opaque and fully drawn. This indicates
7497 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007498 */
7499 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007500 return (mAttrs.format == PixelFormat.OPAQUE
7501 || mAttrs.type == TYPE_WALLPAPER)
7502 && mSurface != null && mAnimation == null
7503 && (mAppToken == null || mAppToken.animation == null)
7504 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007505 }
7506
7507 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7508 return
7509 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007510 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7511 // only if it's visible
7512 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007513 // and only if the application fills the compatible screen
7514 mFrame.left <= mCompatibleScreenFrame.left &&
7515 mFrame.top <= mCompatibleScreenFrame.top &&
7516 mFrame.right >= mCompatibleScreenFrame.right &&
7517 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007518 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007519 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007520 }
7521
7522 boolean isFullscreen(int screenWidth, int screenHeight) {
7523 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007524 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007525 }
7526
7527 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007528 disposeInputChannel();
7529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007530 if (mAttachedWindow != null) {
7531 mAttachedWindow.mChildWindows.remove(this);
7532 }
7533 destroySurfaceLocked();
7534 mSession.windowRemovedLocked();
7535 try {
7536 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7537 } catch (RuntimeException e) {
7538 // Ignore if it has already been removed (usually because
7539 // we are doing this as part of processing a death note.)
7540 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007541 }
7542
7543 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007544 if (mInputChannel != null) {
7545 mInputManager.unregisterInputChannel(mInputChannel);
7546
7547 mInputChannel.dispose();
7548 mInputChannel = null;
Jeff Brown46b9ac02010-04-22 18:58:52 -07007549 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007550 }
7551
7552 private class DeathRecipient implements IBinder.DeathRecipient {
7553 public void binderDied() {
7554 try {
7555 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007556 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007557 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007558 if (win != null) {
7559 removeWindowLocked(mSession, win);
7560 }
7561 }
7562 } catch (IllegalArgumentException ex) {
7563 // This will happen if the window has already been
7564 // removed.
7565 }
7566 }
7567 }
7568
7569 /** Returns true if this window desires key events. */
7570 public final boolean canReceiveKeys() {
7571 return isVisibleOrAdding()
7572 && (mViewVisibility == View.VISIBLE)
7573 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7574 }
7575
7576 public boolean hasDrawnLw() {
7577 return mHasDrawn;
7578 }
7579
7580 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007581 return showLw(doAnimation, true);
7582 }
7583
7584 boolean showLw(boolean doAnimation, boolean requestAnim) {
7585 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7586 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007587 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007588 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007589 if (doAnimation) {
7590 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7591 + mPolicyVisibility + " mAnimation=" + mAnimation);
7592 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7593 doAnimation = false;
7594 } else if (mPolicyVisibility && mAnimation == null) {
7595 // Check for the case where we are currently visible and
7596 // not animating; we do not want to do animation at such a
7597 // point to become visible when we already are.
7598 doAnimation = false;
7599 }
7600 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007601 mPolicyVisibility = true;
7602 mPolicyVisibilityAfterAnim = true;
7603 if (doAnimation) {
7604 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7605 }
7606 if (requestAnim) {
7607 requestAnimationLocked(0);
7608 }
7609 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007610 }
7611
7612 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007613 return hideLw(doAnimation, true);
7614 }
7615
7616 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007617 if (doAnimation) {
7618 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7619 doAnimation = false;
7620 }
7621 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007622 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7623 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007624 if (!current) {
7625 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007626 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007627 if (doAnimation) {
7628 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7629 if (mAnimation == null) {
7630 doAnimation = false;
7631 }
7632 }
7633 if (doAnimation) {
7634 mPolicyVisibilityAfterAnim = false;
7635 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007636 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007637 mPolicyVisibilityAfterAnim = false;
7638 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007639 // Window is no longer visible -- make sure if we were waiting
7640 // for it to be displayed before enabling the display, that
7641 // we allow the display to be enabled now.
7642 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007643 if (mCurrentFocus == this) {
7644 mFocusMayChange = true;
7645 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007646 }
7647 if (requestAnim) {
7648 requestAnimationLocked(0);
7649 }
7650 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007651 }
7652
7653 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007654 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7655 pw.print(" mClient="); pw.println(mClient.asBinder());
7656 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7657 if (mAttachedWindow != null || mLayoutAttached) {
7658 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7659 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7660 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007661 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7662 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7663 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007664 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7665 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007666 }
7667 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7668 pw.print(" mSubLayer="); pw.print(mSubLayer);
7669 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7670 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7671 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7672 pw.print("="); pw.print(mAnimLayer);
7673 pw.print(" mLastLayer="); pw.println(mLastLayer);
7674 if (mSurface != null) {
7675 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007676 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7677 pw.print(" layer="); pw.print(mSurfaceLayer);
7678 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7679 pw.print(" rect=("); pw.print(mSurfaceX);
7680 pw.print(","); pw.print(mSurfaceY);
7681 pw.print(") "); pw.print(mSurfaceW);
7682 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007683 }
7684 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7685 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7686 if (mAppToken != null) {
7687 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7688 }
7689 if (mTargetAppToken != null) {
7690 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7691 }
7692 pw.print(prefix); pw.print("mViewVisibility=0x");
7693 pw.print(Integer.toHexString(mViewVisibility));
7694 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007695 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7696 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007697 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7698 pw.print(prefix); pw.print("mPolicyVisibility=");
7699 pw.print(mPolicyVisibility);
7700 pw.print(" mPolicyVisibilityAfterAnim=");
7701 pw.print(mPolicyVisibilityAfterAnim);
7702 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7703 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007704 if (!mRelayoutCalled) {
7705 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7706 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007707 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007708 pw.print(" h="); pw.print(mRequestedHeight);
7709 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007710 if (mXOffset != 0 || mYOffset != 0) {
7711 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7712 pw.print(" y="); pw.println(mYOffset);
7713 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007714 pw.print(prefix); pw.print("mGivenContentInsets=");
7715 mGivenContentInsets.printShortString(pw);
7716 pw.print(" mGivenVisibleInsets=");
7717 mGivenVisibleInsets.printShortString(pw);
7718 pw.println();
7719 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7720 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7721 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7722 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007723 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007724 pw.print(prefix); pw.print("mShownFrame=");
7725 mShownFrame.printShortString(pw);
7726 pw.print(" last="); mLastShownFrame.printShortString(pw);
7727 pw.println();
7728 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7729 pw.print(" last="); mLastFrame.printShortString(pw);
7730 pw.println();
7731 pw.print(prefix); pw.print("mContainingFrame=");
7732 mContainingFrame.printShortString(pw);
7733 pw.print(" mDisplayFrame=");
7734 mDisplayFrame.printShortString(pw);
7735 pw.println();
7736 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7737 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7738 pw.println();
7739 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7740 pw.print(" last="); mLastContentInsets.printShortString(pw);
7741 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7742 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7743 pw.println();
7744 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7745 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7746 pw.print(" mAlpha="); pw.print(mAlpha);
7747 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7748 }
7749 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7750 || mAnimation != null) {
7751 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7752 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7753 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7754 pw.print(" mAnimation="); pw.println(mAnimation);
7755 }
7756 if (mHasTransformation || mHasLocalTransformation) {
7757 pw.print(prefix); pw.print("XForm: has=");
7758 pw.print(mHasTransformation);
7759 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7760 pw.print(" "); mTransformation.printShortString(pw);
7761 pw.println();
7762 }
7763 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7764 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7765 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7766 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7767 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7768 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7769 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7770 pw.print(" mDestroying="); pw.print(mDestroying);
7771 pw.print(" mRemoved="); pw.println(mRemoved);
7772 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007773 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007774 pw.print(prefix); pw.print("mOrientationChanging=");
7775 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007776 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7777 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007778 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007779 if (mHScale != 1 || mVScale != 1) {
7780 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7781 pw.print(" mVScale="); pw.println(mVScale);
7782 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007783 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007784 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7785 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7786 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007787 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7788 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7789 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7790 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007791 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07007792
7793 String makeInputChannelName() {
7794 return Integer.toHexString(System.identityHashCode(this))
7795 + " " + mAttrs.getTitle();
7796 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007797
7798 @Override
7799 public String toString() {
7800 return "Window{"
7801 + Integer.toHexString(System.identityHashCode(this))
7802 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7803 }
7804 }
Romain Guy06882f82009-06-10 13:36:04 -07007805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007806 // -------------------------------------------------------------
7807 // Window Token State
7808 // -------------------------------------------------------------
7809
7810 class WindowToken {
7811 // The actual token.
7812 final IBinder token;
7813
7814 // The type of window this token is for, as per WindowManager.LayoutParams.
7815 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007816
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007817 // Set if this token was explicitly added by a client, so should
7818 // not be removed when all windows are removed.
7819 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007820
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007821 // For printing.
7822 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007824 // If this is an AppWindowToken, this is non-null.
7825 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007827 // All of the windows associated with this token.
7828 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7829
7830 // Is key dispatching paused for this token?
7831 boolean paused = false;
7832
7833 // Should this token's windows be hidden?
7834 boolean hidden;
7835
7836 // Temporary for finding which tokens no longer have visible windows.
7837 boolean hasVisible;
7838
Dianne Hackborna8f60182009-09-01 19:01:50 -07007839 // Set to true when this token is in a pending transaction where it
7840 // will be shown.
7841 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007842
Dianne Hackborna8f60182009-09-01 19:01:50 -07007843 // Set to true when this token is in a pending transaction where it
7844 // will be hidden.
7845 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007846
Dianne Hackborna8f60182009-09-01 19:01:50 -07007847 // Set to true when this token is in a pending transaction where its
7848 // windows will be put to the bottom of the list.
7849 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007850
Dianne Hackborna8f60182009-09-01 19:01:50 -07007851 // Set to true when this token is in a pending transaction where its
7852 // windows will be put to the top of the list.
7853 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007855 WindowToken(IBinder _token, int type, boolean _explicit) {
7856 token = _token;
7857 windowType = type;
7858 explicit = _explicit;
7859 }
7860
7861 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007862 pw.print(prefix); pw.print("token="); pw.println(token);
7863 pw.print(prefix); pw.print("windows="); pw.println(windows);
7864 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7865 pw.print(" hidden="); pw.print(hidden);
7866 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007867 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7868 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7869 pw.print(" waitingToHide="); pw.print(waitingToHide);
7870 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7871 pw.print(" sendingToTop="); pw.println(sendingToTop);
7872 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007873 }
7874
7875 @Override
7876 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007877 if (stringName == null) {
7878 StringBuilder sb = new StringBuilder();
7879 sb.append("WindowToken{");
7880 sb.append(Integer.toHexString(System.identityHashCode(this)));
7881 sb.append(" token="); sb.append(token); sb.append('}');
7882 stringName = sb.toString();
7883 }
7884 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007885 }
7886 };
7887
7888 class AppWindowToken extends WindowToken {
7889 // Non-null only for application tokens.
7890 final IApplicationToken appToken;
7891
7892 // All of the windows and child windows that are included in this
7893 // application token. Note this list is NOT sorted!
7894 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7895
7896 int groupId = -1;
7897 boolean appFullscreen;
7898 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007899
7900 // The input dispatching timeout for this application token in nanoseconds.
7901 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007903 // These are used for determining when all windows associated with
7904 // an activity have been drawn, so they can be made visible together
7905 // at the same time.
7906 int lastTransactionSequence = mTransactionSequence-1;
7907 int numInterestingWindows;
7908 int numDrawnWindows;
7909 boolean inPendingTransaction;
7910 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007912 // Is this token going to be hidden in a little while? If so, it
7913 // won't be taken into account for setting the screen orientation.
7914 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007916 // Is this window's surface needed? This is almost like hidden, except
7917 // it will sometimes be true a little earlier: when the token has
7918 // been shown, but is still waiting for its app transition to execute
7919 // before making its windows shown.
7920 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007922 // Have we told the window clients to hide themselves?
7923 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007924
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007925 // Last visibility state we reported to the app token.
7926 boolean reportedVisible;
7927
7928 // Set to true when the token has been removed from the window mgr.
7929 boolean removed;
7930
7931 // Have we been asked to have this token keep the screen frozen?
7932 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007934 boolean animating;
7935 Animation animation;
7936 boolean hasTransformation;
7937 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007939 // Offset to the window of all layers in the token, for use by
7940 // AppWindowToken animations.
7941 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007943 // Information about an application starting window if displayed.
7944 StartingData startingData;
7945 WindowState startingWindow;
7946 View startingView;
7947 boolean startingDisplayed;
7948 boolean startingMoved;
7949 boolean firstWindowDrawn;
7950
7951 AppWindowToken(IApplicationToken _token) {
7952 super(_token.asBinder(),
7953 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7954 appWindowToken = this;
7955 appToken = _token;
7956 }
Romain Guy06882f82009-06-10 13:36:04 -07007957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007958 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007959 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007960 TAG, "Setting animation in " + this + ": " + anim);
7961 animation = anim;
7962 animating = false;
7963 anim.restrictDuration(MAX_ANIMATION_DURATION);
7964 anim.scaleCurrentDuration(mTransitionAnimationScale);
7965 int zorder = anim.getZAdjustment();
7966 int adj = 0;
7967 if (zorder == Animation.ZORDER_TOP) {
7968 adj = TYPE_LAYER_OFFSET;
7969 } else if (zorder == Animation.ZORDER_BOTTOM) {
7970 adj = -TYPE_LAYER_OFFSET;
7971 }
Romain Guy06882f82009-06-10 13:36:04 -07007972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007973 if (animLayerAdjustment != adj) {
7974 animLayerAdjustment = adj;
7975 updateLayers();
7976 }
7977 }
Romain Guy06882f82009-06-10 13:36:04 -07007978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007979 public void setDummyAnimation() {
7980 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007981 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007982 TAG, "Setting dummy animation in " + this);
7983 animation = sDummyAnimation;
7984 }
7985 }
7986
7987 public void clearAnimation() {
7988 if (animation != null) {
7989 animation = null;
7990 animating = true;
7991 }
7992 }
Romain Guy06882f82009-06-10 13:36:04 -07007993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007994 void updateLayers() {
7995 final int N = allAppWindows.size();
7996 final int adj = animLayerAdjustment;
7997 for (int i=0; i<N; i++) {
7998 WindowState w = allAppWindows.get(i);
7999 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008000 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008001 + w.mAnimLayer);
8002 if (w == mInputMethodTarget) {
8003 setInputMethodAnimLayerAdjustment(adj);
8004 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008005 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008006 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008007 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008008 }
8009 }
Romain Guy06882f82009-06-10 13:36:04 -07008010
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008011 void sendAppVisibilityToClients() {
8012 final int N = allAppWindows.size();
8013 for (int i=0; i<N; i++) {
8014 WindowState win = allAppWindows.get(i);
8015 if (win == startingWindow && clientHidden) {
8016 // Don't hide the starting window.
8017 continue;
8018 }
8019 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008020 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008021 "Setting visibility of " + win + ": " + (!clientHidden));
8022 win.mClient.dispatchAppVisibility(!clientHidden);
8023 } catch (RemoteException e) {
8024 }
8025 }
8026 }
Romain Guy06882f82009-06-10 13:36:04 -07008027
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008028 void showAllWindowsLocked() {
8029 final int NW = allAppWindows.size();
8030 for (int i=0; i<NW; i++) {
8031 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008032 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008033 "performing show on: " + w);
8034 w.performShowLocked();
8035 }
8036 }
Romain Guy06882f82009-06-10 13:36:04 -07008037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008038 // This must be called while inside a transaction.
8039 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008040 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008041 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008043 if (animation == sDummyAnimation) {
8044 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008045 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008046 // when it is really time to animate, this will be set to
8047 // a real animation and the next call will execute normally.
8048 return false;
8049 }
Romain Guy06882f82009-06-10 13:36:04 -07008050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008051 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8052 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008053 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008054 TAG, "Starting animation in " + this +
8055 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8056 + " scale=" + mTransitionAnimationScale
8057 + " allDrawn=" + allDrawn + " animating=" + animating);
8058 animation.initialize(dw, dh, dw, dh);
8059 animation.setStartTime(currentTime);
8060 animating = true;
8061 }
8062 transformation.clear();
8063 final boolean more = animation.getTransformation(
8064 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008065 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008066 TAG, "Stepped animation in " + this +
8067 ": more=" + more + ", xform=" + transformation);
8068 if (more) {
8069 // we're done!
8070 hasTransformation = true;
8071 return true;
8072 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008073 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008074 TAG, "Finished animation in " + this +
8075 " @ " + currentTime);
8076 animation = null;
8077 }
8078 } else if (animation != null) {
8079 // If the display is frozen, and there is a pending animation,
8080 // clear it and make sure we run the cleanup code.
8081 animating = true;
8082 animation = null;
8083 }
8084
8085 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008087 if (!animating) {
8088 return false;
8089 }
8090
8091 clearAnimation();
8092 animating = false;
8093 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8094 moveInputMethodWindowsIfNeededLocked(true);
8095 }
Romain Guy06882f82009-06-10 13:36:04 -07008096
Joe Onorato8a9b2202010-02-26 18:56:32 -08008097 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008098 TAG, "Animation done in " + this
8099 + ": reportedVisible=" + reportedVisible);
8100
8101 transformation.clear();
8102 if (animLayerAdjustment != 0) {
8103 animLayerAdjustment = 0;
8104 updateLayers();
8105 }
Romain Guy06882f82009-06-10 13:36:04 -07008106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008107 final int N = windows.size();
8108 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008109 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008110 }
8111 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008113 return false;
8114 }
8115
8116 void updateReportedVisibilityLocked() {
8117 if (appToken == null) {
8118 return;
8119 }
Romain Guy06882f82009-06-10 13:36:04 -07008120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008121 int numInteresting = 0;
8122 int numVisible = 0;
8123 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008124
Joe Onorato8a9b2202010-02-26 18:56:32 -08008125 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008126 final int N = allAppWindows.size();
8127 for (int i=0; i<N; i++) {
8128 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008129 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008130 || win.mViewVisibility != View.VISIBLE
8131 || win.mAttrs.type == TYPE_APPLICATION_STARTING) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008132 continue;
8133 }
8134 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008135 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008136 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008137 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008138 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008139 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008140 + " pv=" + win.mPolicyVisibility
8141 + " dp=" + win.mDrawPending
8142 + " cdp=" + win.mCommitDrawPending
8143 + " ah=" + win.mAttachedHidden
8144 + " th="
8145 + (win.mAppToken != null
8146 ? win.mAppToken.hiddenRequested : false)
8147 + " a=" + win.mAnimating);
8148 }
8149 }
8150 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008151 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008152 if (!win.isAnimating()) {
8153 numVisible++;
8154 }
8155 nowGone = false;
8156 } else if (win.isAnimating()) {
8157 nowGone = false;
8158 }
8159 }
Romain Guy06882f82009-06-10 13:36:04 -07008160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008161 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008162 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008163 + numInteresting + " visible=" + numVisible);
8164 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008165 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008166 TAG, "Visibility changed in " + this
8167 + ": vis=" + nowVisible);
8168 reportedVisible = nowVisible;
8169 Message m = mH.obtainMessage(
8170 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8171 nowVisible ? 1 : 0,
8172 nowGone ? 1 : 0,
8173 this);
8174 mH.sendMessage(m);
8175 }
8176 }
Romain Guy06882f82009-06-10 13:36:04 -07008177
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008178 WindowState findMainWindow() {
8179 int j = windows.size();
8180 while (j > 0) {
8181 j--;
8182 WindowState win = windows.get(j);
8183 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8184 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8185 return win;
8186 }
8187 }
8188 return null;
8189 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008191 void dump(PrintWriter pw, String prefix) {
8192 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008193 if (appToken != null) {
8194 pw.print(prefix); pw.println("app=true");
8195 }
8196 if (allAppWindows.size() > 0) {
8197 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8198 }
8199 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008200 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008201 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8202 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8203 pw.print(" clientHidden="); pw.print(clientHidden);
8204 pw.print(" willBeHidden="); pw.print(willBeHidden);
8205 pw.print(" reportedVisible="); pw.println(reportedVisible);
8206 if (paused || freezingScreen) {
8207 pw.print(prefix); pw.print("paused="); pw.print(paused);
8208 pw.print(" freezingScreen="); pw.println(freezingScreen);
8209 }
8210 if (numInterestingWindows != 0 || numDrawnWindows != 0
8211 || inPendingTransaction || allDrawn) {
8212 pw.print(prefix); pw.print("numInterestingWindows=");
8213 pw.print(numInterestingWindows);
8214 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8215 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8216 pw.print(" allDrawn="); pw.println(allDrawn);
8217 }
8218 if (animating || animation != null) {
8219 pw.print(prefix); pw.print("animating="); pw.print(animating);
8220 pw.print(" animation="); pw.println(animation);
8221 }
8222 if (animLayerAdjustment != 0) {
8223 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8224 }
8225 if (hasTransformation) {
8226 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8227 pw.print(" transformation="); transformation.printShortString(pw);
8228 pw.println();
8229 }
8230 if (startingData != null || removed || firstWindowDrawn) {
8231 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8232 pw.print(" removed="); pw.print(removed);
8233 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8234 }
8235 if (startingWindow != null || startingView != null
8236 || startingDisplayed || startingMoved) {
8237 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8238 pw.print(" startingView="); pw.print(startingView);
8239 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8240 pw.print(" startingMoved"); pw.println(startingMoved);
8241 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008242 }
8243
8244 @Override
8245 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008246 if (stringName == null) {
8247 StringBuilder sb = new StringBuilder();
8248 sb.append("AppWindowToken{");
8249 sb.append(Integer.toHexString(System.identityHashCode(this)));
8250 sb.append(" token="); sb.append(token); sb.append('}');
8251 stringName = sb.toString();
8252 }
8253 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008254 }
8255 }
Romain Guy06882f82009-06-10 13:36:04 -07008256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008257 // -------------------------------------------------------------
8258 // DummyAnimation
8259 // -------------------------------------------------------------
8260
8261 // This is an animation that does nothing: it just immediately finishes
8262 // itself every time it is called. It is used as a stub animation in cases
8263 // where we want to synchronize multiple things that may be animating.
8264 static final class DummyAnimation extends Animation {
8265 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8266 return false;
8267 }
8268 }
8269 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008271 // -------------------------------------------------------------
8272 // Async Handler
8273 // -------------------------------------------------------------
8274
8275 static final class StartingData {
8276 final String pkg;
8277 final int theme;
8278 final CharSequence nonLocalizedLabel;
8279 final int labelRes;
8280 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008282 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8283 int _labelRes, int _icon) {
8284 pkg = _pkg;
8285 theme = _theme;
8286 nonLocalizedLabel = _nonLocalizedLabel;
8287 labelRes = _labelRes;
8288 icon = _icon;
8289 }
8290 }
8291
8292 private final class H extends Handler {
8293 public static final int REPORT_FOCUS_CHANGE = 2;
8294 public static final int REPORT_LOSING_FOCUS = 3;
8295 public static final int ANIMATE = 4;
8296 public static final int ADD_STARTING = 5;
8297 public static final int REMOVE_STARTING = 6;
8298 public static final int FINISHED_STARTING = 7;
8299 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008300 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8301 public static final int HOLD_SCREEN_CHANGED = 12;
8302 public static final int APP_TRANSITION_TIMEOUT = 13;
8303 public static final int PERSIST_ANIMATION_SCALE = 14;
8304 public static final int FORCE_GC = 15;
8305 public static final int ENABLE_SCREEN = 16;
8306 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008307 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008308 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008309 public static final int DRAG_START_TIMEOUT = 20;
Romain Guy06882f82009-06-10 13:36:04 -07008310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008311 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008313 public H() {
8314 }
Romain Guy06882f82009-06-10 13:36:04 -07008315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008316 @Override
8317 public void handleMessage(Message msg) {
8318 switch (msg.what) {
8319 case REPORT_FOCUS_CHANGE: {
8320 WindowState lastFocus;
8321 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008323 synchronized(mWindowMap) {
8324 lastFocus = mLastFocus;
8325 newFocus = mCurrentFocus;
8326 if (lastFocus == newFocus) {
8327 // Focus is not changing, so nothing to do.
8328 return;
8329 }
8330 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008331 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008332 // + " to " + newFocus);
8333 if (newFocus != null && lastFocus != null
8334 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008335 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008336 mLosingFocus.add(lastFocus);
8337 lastFocus = null;
8338 }
8339 }
8340
8341 if (lastFocus != newFocus) {
8342 //System.out.println("Changing focus from " + lastFocus
8343 // + " to " + newFocus);
8344 if (newFocus != null) {
8345 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008346 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008347 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8348 } catch (RemoteException e) {
8349 // Ignore if process has died.
8350 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008351 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008352 }
8353
8354 if (lastFocus != null) {
8355 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008356 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008357 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8358 } catch (RemoteException e) {
8359 // Ignore if process has died.
8360 }
8361 }
8362 }
8363 } break;
8364
8365 case REPORT_LOSING_FOCUS: {
8366 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008368 synchronized(mWindowMap) {
8369 losers = mLosingFocus;
8370 mLosingFocus = new ArrayList<WindowState>();
8371 }
8372
8373 final int N = losers.size();
8374 for (int i=0; i<N; i++) {
8375 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008376 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008377 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8378 } catch (RemoteException e) {
8379 // Ignore if process has died.
8380 }
8381 }
8382 } break;
8383
8384 case ANIMATE: {
8385 synchronized(mWindowMap) {
8386 mAnimationPending = false;
8387 performLayoutAndPlaceSurfacesLocked();
8388 }
8389 } break;
8390
8391 case ADD_STARTING: {
8392 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8393 final StartingData sd = wtoken.startingData;
8394
8395 if (sd == null) {
8396 // Animation has been canceled... do nothing.
8397 return;
8398 }
Romain Guy06882f82009-06-10 13:36:04 -07008399
Joe Onorato8a9b2202010-02-26 18:56:32 -08008400 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008401 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008403 View view = null;
8404 try {
8405 view = mPolicy.addStartingWindow(
8406 wtoken.token, sd.pkg,
8407 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8408 sd.icon);
8409 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008410 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008411 }
8412
8413 if (view != null) {
8414 boolean abort = false;
8415
8416 synchronized(mWindowMap) {
8417 if (wtoken.removed || wtoken.startingData == null) {
8418 // If the window was successfully added, then
8419 // we need to remove it.
8420 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008421 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008422 "Aborted starting " + wtoken
8423 + ": removed=" + wtoken.removed
8424 + " startingData=" + wtoken.startingData);
8425 wtoken.startingWindow = null;
8426 wtoken.startingData = null;
8427 abort = true;
8428 }
8429 } else {
8430 wtoken.startingView = view;
8431 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008432 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008433 "Added starting " + wtoken
8434 + ": startingWindow="
8435 + wtoken.startingWindow + " startingView="
8436 + wtoken.startingView);
8437 }
8438
8439 if (abort) {
8440 try {
8441 mPolicy.removeStartingWindow(wtoken.token, view);
8442 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008443 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008444 }
8445 }
8446 }
8447 } break;
8448
8449 case REMOVE_STARTING: {
8450 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8451 IBinder token = null;
8452 View view = null;
8453 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008454 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008455 + wtoken + ": startingWindow="
8456 + wtoken.startingWindow + " startingView="
8457 + wtoken.startingView);
8458 if (wtoken.startingWindow != null) {
8459 view = wtoken.startingView;
8460 token = wtoken.token;
8461 wtoken.startingData = null;
8462 wtoken.startingView = null;
8463 wtoken.startingWindow = null;
8464 }
8465 }
8466 if (view != null) {
8467 try {
8468 mPolicy.removeStartingWindow(token, view);
8469 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008470 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008471 }
8472 }
8473 } break;
8474
8475 case FINISHED_STARTING: {
8476 IBinder token = null;
8477 View view = null;
8478 while (true) {
8479 synchronized (mWindowMap) {
8480 final int N = mFinishedStarting.size();
8481 if (N <= 0) {
8482 break;
8483 }
8484 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8485
Joe Onorato8a9b2202010-02-26 18:56:32 -08008486 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008487 "Finished starting " + wtoken
8488 + ": startingWindow=" + wtoken.startingWindow
8489 + " startingView=" + wtoken.startingView);
8490
8491 if (wtoken.startingWindow == null) {
8492 continue;
8493 }
8494
8495 view = wtoken.startingView;
8496 token = wtoken.token;
8497 wtoken.startingData = null;
8498 wtoken.startingView = null;
8499 wtoken.startingWindow = null;
8500 }
8501
8502 try {
8503 mPolicy.removeStartingWindow(token, view);
8504 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008505 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008506 }
8507 }
8508 } break;
8509
8510 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8511 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8512
8513 boolean nowVisible = msg.arg1 != 0;
8514 boolean nowGone = msg.arg2 != 0;
8515
8516 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008517 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008518 TAG, "Reporting visible in " + wtoken
8519 + " visible=" + nowVisible
8520 + " gone=" + nowGone);
8521 if (nowVisible) {
8522 wtoken.appToken.windowsVisible();
8523 } else {
8524 wtoken.appToken.windowsGone();
8525 }
8526 } catch (RemoteException ex) {
8527 }
8528 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008530 case WINDOW_FREEZE_TIMEOUT: {
8531 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008532 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008533 int i = mWindows.size();
8534 while (i > 0) {
8535 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008536 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008537 if (w.mOrientationChanging) {
8538 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008539 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008540 }
8541 }
8542 performLayoutAndPlaceSurfacesLocked();
8543 }
8544 break;
8545 }
Romain Guy06882f82009-06-10 13:36:04 -07008546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008547 case HOLD_SCREEN_CHANGED: {
8548 Session oldHold;
8549 Session newHold;
8550 synchronized (mWindowMap) {
8551 oldHold = mLastReportedHold;
8552 newHold = (Session)msg.obj;
8553 mLastReportedHold = newHold;
8554 }
Romain Guy06882f82009-06-10 13:36:04 -07008555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008556 if (oldHold != newHold) {
8557 try {
8558 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008559 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008560 "window",
8561 BatteryStats.WAKE_TYPE_WINDOW);
8562 }
8563 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008564 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008565 "window",
8566 BatteryStats.WAKE_TYPE_WINDOW);
8567 }
8568 } catch (RemoteException e) {
8569 }
8570 }
8571 break;
8572 }
Romain Guy06882f82009-06-10 13:36:04 -07008573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008574 case APP_TRANSITION_TIMEOUT: {
8575 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008576 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008577 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008578 "*** APP TRANSITION TIMEOUT");
8579 mAppTransitionReady = true;
8580 mAppTransitionTimeout = true;
8581 performLayoutAndPlaceSurfacesLocked();
8582 }
8583 }
8584 break;
8585 }
Romain Guy06882f82009-06-10 13:36:04 -07008586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008587 case PERSIST_ANIMATION_SCALE: {
8588 Settings.System.putFloat(mContext.getContentResolver(),
8589 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8590 Settings.System.putFloat(mContext.getContentResolver(),
8591 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8592 break;
8593 }
Romain Guy06882f82009-06-10 13:36:04 -07008594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008595 case FORCE_GC: {
8596 synchronized(mWindowMap) {
8597 if (mAnimationPending) {
8598 // If we are animating, don't do the gc now but
8599 // delay a bit so we don't interrupt the animation.
8600 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8601 2000);
8602 return;
8603 }
8604 // If we are currently rotating the display, it will
8605 // schedule a new message when done.
8606 if (mDisplayFrozen) {
8607 return;
8608 }
8609 mFreezeGcPending = 0;
8610 }
8611 Runtime.getRuntime().gc();
8612 break;
8613 }
Romain Guy06882f82009-06-10 13:36:04 -07008614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008615 case ENABLE_SCREEN: {
8616 performEnableScreen();
8617 break;
8618 }
Romain Guy06882f82009-06-10 13:36:04 -07008619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008620 case APP_FREEZE_TIMEOUT: {
8621 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008622 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008623 int i = mAppTokens.size();
8624 while (i > 0) {
8625 i--;
8626 AppWindowToken tok = mAppTokens.get(i);
8627 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008628 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008629 unsetAppFreezingScreenLocked(tok, true, true);
8630 }
8631 }
8632 }
8633 break;
8634 }
Romain Guy06882f82009-06-10 13:36:04 -07008635
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008636 case SEND_NEW_CONFIGURATION: {
8637 removeMessages(SEND_NEW_CONFIGURATION);
8638 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008639 break;
8640 }
Romain Guy06882f82009-06-10 13:36:04 -07008641
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008642 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008643 if (mWindowsChanged) {
8644 synchronized (mWindowMap) {
8645 mWindowsChanged = false;
8646 }
8647 notifyWindowsChanged();
8648 }
8649 break;
8650 }
8651
Christopher Tatea53146c2010-09-07 11:57:52 -07008652 case DRAG_START_TIMEOUT: {
8653 IBinder win = (IBinder)msg.obj;
8654 if (DEBUG_DRAG) {
8655 Slog.w(TAG, "Timeout starting drag by win " + win);
8656 }
8657 synchronized (mWindowMap) {
8658 // !!! TODO: ANR the app that has failed to start the drag in time
8659 if (mDragState != null) {
8660 mDragState.reset();
8661 mDragState = null;
8662 }
8663 }
8664 }
8665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008666 }
8667 }
8668 }
8669
8670 // -------------------------------------------------------------
8671 // IWindowManager API
8672 // -------------------------------------------------------------
8673
8674 public IWindowSession openSession(IInputMethodClient client,
8675 IInputContext inputContext) {
8676 if (client == null) throw new IllegalArgumentException("null client");
8677 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac02010-04-22 18:58:52 -07008678 Session session = new Session(client, inputContext);
8679 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008680 }
8681
8682 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8683 synchronized (mWindowMap) {
8684 // The focus for the client is the window immediately below
8685 // where we would place the input method window.
8686 int idx = findDesiredInputMethodWindowIndexLocked(false);
8687 WindowState imFocus;
8688 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008689 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008690 if (imFocus != null) {
8691 if (imFocus.mSession.mClient != null &&
8692 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8693 return true;
8694 }
8695 }
8696 }
8697 }
8698 return false;
8699 }
Romain Guy06882f82009-06-10 13:36:04 -07008700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008701 // -------------------------------------------------------------
8702 // Internals
8703 // -------------------------------------------------------------
8704
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008705 final WindowState windowForClientLocked(Session session, IWindow client,
8706 boolean throwOnError) {
8707 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008708 }
Romain Guy06882f82009-06-10 13:36:04 -07008709
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008710 final WindowState windowForClientLocked(Session session, IBinder client,
8711 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008712 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008713 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008714 TAG, "Looking up client " + client + ": " + win);
8715 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008716 RuntimeException ex = new IllegalArgumentException(
8717 "Requested window " + client + " does not exist");
8718 if (throwOnError) {
8719 throw ex;
8720 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008721 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008722 return null;
8723 }
8724 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008725 RuntimeException ex = new IllegalArgumentException(
8726 "Requested window " + client + " is in session " +
8727 win.mSession + ", not " + session);
8728 if (throwOnError) {
8729 throw ex;
8730 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008731 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008732 return null;
8733 }
8734
8735 return win;
8736 }
8737
Dianne Hackborna8f60182009-09-01 19:01:50 -07008738 final void rebuildAppWindowListLocked() {
8739 int NW = mWindows.size();
8740 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008741 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008742 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008743
Dianne Hackborna8f60182009-09-01 19:01:50 -07008744 // First remove all existing app windows.
8745 i=0;
8746 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008747 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008748 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008749 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008750 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008751 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008752 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008753 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008754 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008755 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008756 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8757 && lastWallpaper == i-1) {
8758 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008759 }
8760 i++;
8761 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008762
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008763 // The wallpaper window(s) typically live at the bottom of the stack,
8764 // so skip them before adding app tokens.
8765 lastWallpaper++;
8766 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008767
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008768 // First add all of the exiting app tokens... these are no longer
8769 // in the main app list, but still have windows shown. We put them
8770 // in the back because now that the animation is over we no longer
8771 // will care about them.
8772 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008773 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008774 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8775 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008776
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008777 // And add in the still active app tokens in Z order.
8778 NT = mAppTokens.size();
8779 for (int j=0; j<NT; j++) {
8780 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008781 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008782
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008783 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008784 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008785 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008786 + " windows but added " + i);
8787 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008788 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008790 private final void assignLayersLocked() {
8791 int N = mWindows.size();
8792 int curBaseLayer = 0;
8793 int curLayer = 0;
8794 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008796 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008797 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008798 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8799 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008800 curLayer += WINDOW_LAYER_MULTIPLIER;
8801 w.mLayer = curLayer;
8802 } else {
8803 curBaseLayer = curLayer = w.mBaseLayer;
8804 w.mLayer = curLayer;
8805 }
8806 if (w.mTargetAppToken != null) {
8807 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8808 } else if (w.mAppToken != null) {
8809 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8810 } else {
8811 w.mAnimLayer = w.mLayer;
8812 }
8813 if (w.mIsImWindow) {
8814 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008815 } else if (w.mIsWallpaper) {
8816 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008817 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008818 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008819 + w.mAnimLayer);
8820 //System.out.println(
8821 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8822 }
8823 }
8824
8825 private boolean mInLayout = false;
8826 private final void performLayoutAndPlaceSurfacesLocked() {
8827 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008828 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008829 throw new RuntimeException("Recursive call!");
8830 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008831 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008832 return;
8833 }
8834
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008835 if (mWaitingForConfig) {
8836 // Our configuration has changed (most likely rotation), but we
8837 // don't yet have the complete configuration to report to
8838 // applications. Don't do any window layout until we have it.
8839 return;
8840 }
8841
Dianne Hackbornce2ef762010-09-20 11:39:14 -07008842 if (mDisplay == null) {
8843 // Not yet initialized, nothing to do.
8844 return;
8845 }
8846
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008847 boolean recoveringMemory = false;
8848 if (mForceRemoves != null) {
8849 recoveringMemory = true;
8850 // Wait a little it for things to settle down, and off we go.
8851 for (int i=0; i<mForceRemoves.size(); i++) {
8852 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008853 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008854 removeWindowInnerLocked(ws.mSession, ws);
8855 }
8856 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008857 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008858 Object tmp = new Object();
8859 synchronized (tmp) {
8860 try {
8861 tmp.wait(250);
8862 } catch (InterruptedException e) {
8863 }
8864 }
8865 }
Romain Guy06882f82009-06-10 13:36:04 -07008866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008867 mInLayout = true;
8868 try {
8869 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008870
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008871 int i = mPendingRemove.size()-1;
8872 if (i >= 0) {
8873 while (i >= 0) {
8874 WindowState w = mPendingRemove.get(i);
8875 removeWindowInnerLocked(w.mSession, w);
8876 i--;
8877 }
8878 mPendingRemove.clear();
8879
8880 mInLayout = false;
8881 assignLayersLocked();
8882 mLayoutNeeded = true;
8883 performLayoutAndPlaceSurfacesLocked();
8884
8885 } else {
8886 mInLayout = false;
8887 if (mLayoutNeeded) {
8888 requestAnimationLocked(0);
8889 }
8890 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008891 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008892 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8893 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008894 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008895 } catch (RuntimeException e) {
8896 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008897 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008898 }
8899 }
8900
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008901 private final int performLayoutLockedInner() {
8902 if (!mLayoutNeeded) {
8903 return 0;
8904 }
8905
8906 mLayoutNeeded = false;
8907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008908 final int dw = mDisplay.getWidth();
8909 final int dh = mDisplay.getHeight();
8910
8911 final int N = mWindows.size();
8912 int i;
8913
Joe Onorato8a9b2202010-02-26 18:56:32 -08008914 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008915 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8916
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008917 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008918
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008919 int seq = mLayoutSeq+1;
8920 if (seq < 0) seq = 0;
8921 mLayoutSeq = seq;
8922
8923 // First perform layout of any root windows (not attached
8924 // to another window).
8925 int topAttached = -1;
8926 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008927 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008928
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008929 // Don't do layout of a window if it is not visible, or
8930 // soon won't be visible, to avoid wasting time and funky
8931 // changes while a window is animating away.
8932 final AppWindowToken atoken = win.mAppToken;
8933 final boolean gone = win.mViewVisibility == View.GONE
8934 || !win.mRelayoutCalled
8935 || win.mRootToken.hidden
8936 || (atoken != null && atoken.hiddenRequested)
8937 || win.mAttachedHidden
8938 || win.mExiting || win.mDestroying;
8939
8940 if (!win.mLayoutAttached) {
8941 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
8942 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
8943 + " mLayoutAttached=" + win.mLayoutAttached);
8944 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
8945 + win.mViewVisibility + " mRelayoutCalled="
8946 + win.mRelayoutCalled + " hidden="
8947 + win.mRootToken.hidden + " hiddenRequested="
8948 + (atoken != null && atoken.hiddenRequested)
8949 + " mAttachedHidden=" + win.mAttachedHidden);
8950 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008951
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008952 // If this view is GONE, then skip it -- keep the current
8953 // frame, and let the caller know so they can ignore it
8954 // if they want. (We do the normal layout for INVISIBLE
8955 // windows, since that means "perform layout as normal,
8956 // just don't display").
8957 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008958 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008959 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8960 win.mLayoutSeq = seq;
8961 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8962 + win.mFrame + " mContainingFrame="
8963 + win.mContainingFrame + " mDisplayFrame="
8964 + win.mDisplayFrame);
8965 } else {
8966 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008967 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008968 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008969 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008970
8971 // Now perform layout of attached windows, which usually
8972 // depend on the position of the window they are attached to.
8973 // XXX does not deal with windows that are attached to windows
8974 // that are themselves attached.
8975 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008976 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008977
8978 // If this view is GONE, then skip it -- keep the current
8979 // frame, and let the caller know so they can ignore it
8980 // if they want. (We do the normal layout for INVISIBLE
8981 // windows, since that means "perform layout as normal,
8982 // just don't display").
8983 if (win.mLayoutAttached) {
8984 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
8985 + " mHaveFrame=" + win.mHaveFrame
8986 + " mViewVisibility=" + win.mViewVisibility
8987 + " mRelayoutCalled=" + win.mRelayoutCalled);
8988 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
8989 || !win.mHaveFrame) {
8990 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
8991 win.mLayoutSeq = seq;
8992 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8993 + win.mFrame + " mContainingFrame="
8994 + win.mContainingFrame + " mDisplayFrame="
8995 + win.mDisplayFrame);
8996 }
8997 }
8998 }
Jeff Brown349703e2010-06-22 01:27:15 -07008999
9000 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009001 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009002
9003 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009004 }
Romain Guy06882f82009-06-10 13:36:04 -07009005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009006 private final void performLayoutAndPlaceSurfacesLockedInner(
9007 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009008 if (mDisplay == null) {
9009 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9010 return;
9011 }
9012
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009013 final long currentTime = SystemClock.uptimeMillis();
9014 final int dw = mDisplay.getWidth();
9015 final int dh = mDisplay.getHeight();
9016
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009017 int i;
9018
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009019 if (mFocusMayChange) {
9020 mFocusMayChange = false;
9021 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9022 }
9023
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009024 // Initialize state of exiting tokens.
9025 for (i=mExitingTokens.size()-1; i>=0; i--) {
9026 mExitingTokens.get(i).hasVisible = false;
9027 }
9028
9029 // Initialize state of exiting applications.
9030 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9031 mExitingAppTokens.get(i).hasVisible = false;
9032 }
9033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009034 boolean orientationChangeComplete = true;
9035 Session holdScreen = null;
9036 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009037 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009038 boolean focusDisplayed = false;
9039 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009040 boolean createWatermark = false;
9041
9042 if (mFxSession == null) {
9043 mFxSession = new SurfaceSession();
9044 createWatermark = true;
9045 }
9046
9047 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009048
9049 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009050
9051 if (createWatermark) {
9052 createWatermark();
9053 }
9054 if (mWatermark != null) {
9055 mWatermark.positionSurface(dw, dh);
9056 }
9057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009058 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009059 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009060 int repeats = 0;
9061 int changes = 0;
9062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009063 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009064 repeats++;
9065 if (repeats > 6) {
9066 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9067 mLayoutNeeded = false;
9068 break;
9069 }
9070
9071 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9072 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9073 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9074 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9075 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9076 assignLayersLocked();
9077 mLayoutNeeded = true;
9078 }
9079 }
9080 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9081 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9082 if (updateOrientationFromAppTokensLocked()) {
9083 mLayoutNeeded = true;
9084 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9085 }
9086 }
9087 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9088 mLayoutNeeded = true;
9089 }
9090 }
9091
9092 // FIRST LOOP: Perform a layout, if needed.
9093 if (repeats < 4) {
9094 changes = performLayoutLockedInner();
9095 if (changes != 0) {
9096 continue;
9097 }
9098 } else {
9099 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9100 changes = 0;
9101 }
9102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009103 final int transactionSequence = ++mTransactionSequence;
9104
9105 // Update animations of all applications, including those
9106 // associated with exiting/removed apps
9107 boolean tokensAnimating = false;
9108 final int NAT = mAppTokens.size();
9109 for (i=0; i<NAT; i++) {
9110 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9111 tokensAnimating = true;
9112 }
9113 }
9114 final int NEAT = mExitingAppTokens.size();
9115 for (i=0; i<NEAT; i++) {
9116 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9117 tokensAnimating = true;
9118 }
9119 }
9120
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009121 // SECOND LOOP: Execute animations and update visibility of windows.
9122
Joe Onorato8a9b2202010-02-26 18:56:32 -08009123 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009124 + transactionSequence + " tokensAnimating="
9125 + tokensAnimating);
9126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009127 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009128
9129 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009130 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009131 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009132
9133 mPolicy.beginAnimationLw(dw, dh);
9134
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009135 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009137 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009138 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009139
9140 final WindowManager.LayoutParams attrs = w.mAttrs;
9141
9142 if (w.mSurface != null) {
9143 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009144 if (w.commitFinishDrawingLocked(currentTime)) {
9145 if ((w.mAttrs.flags
9146 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009147 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009148 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009149 wallpaperMayChange = true;
9150 }
9151 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009152
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009153 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009154 if (w.stepAnimationLocked(currentTime, dw, dh)) {
9155 animating = true;
9156 //w.dump(" ");
9157 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009158 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9159 wallpaperMayChange = true;
9160 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009161
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009162 if (mPolicy.doesForceHide(w, attrs)) {
9163 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009164 if (DEBUG_VISIBILITY) Slog.v(TAG,
9165 "Animation done that could impact force hide: "
9166 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009167 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009168 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009169 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9170 forceHiding = true;
9171 }
9172 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9173 boolean changed;
9174 if (forceHiding) {
9175 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009176 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9177 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009178 } else {
9179 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009180 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9181 "Now policy shown: " + w);
9182 if (changed) {
9183 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009184 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009185 // Assume we will need to animate. If
9186 // we don't (because the wallpaper will
9187 // stay with the lock screen), then we will
9188 // clean up later.
9189 Animation a = mPolicy.createForceHideEnterAnimation();
9190 if (a != null) {
9191 w.setAnimation(a);
9192 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009193 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009194 if (mCurrentFocus == null ||
9195 mCurrentFocus.mLayer < w.mLayer) {
9196 // We are showing on to of the current
9197 // focus, so re-evaluate focus to make
9198 // sure it is correct.
9199 mFocusMayChange = true;
9200 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009201 }
9202 }
9203 if (changed && (attrs.flags
9204 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9205 wallpaperMayChange = true;
9206 }
9207 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009209 mPolicy.animatingWindowLw(w, attrs);
9210 }
9211
9212 final AppWindowToken atoken = w.mAppToken;
9213 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9214 if (atoken.lastTransactionSequence != transactionSequence) {
9215 atoken.lastTransactionSequence = transactionSequence;
9216 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9217 atoken.startingDisplayed = false;
9218 }
9219 if ((w.isOnScreen() || w.mAttrs.type
9220 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9221 && !w.mExiting && !w.mDestroying) {
9222 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009223 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009224 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009225 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009226 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009227 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009228 + " pv=" + w.mPolicyVisibility
9229 + " dp=" + w.mDrawPending
9230 + " cdp=" + w.mCommitDrawPending
9231 + " ah=" + w.mAttachedHidden
9232 + " th=" + atoken.hiddenRequested
9233 + " a=" + w.mAnimating);
9234 }
9235 }
9236 if (w != atoken.startingWindow) {
9237 if (!atoken.freezingScreen || !w.mAppFreezing) {
9238 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009239 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009240 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009241 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009242 "tokenMayBeDrawn: " + atoken
9243 + " freezingScreen=" + atoken.freezingScreen
9244 + " mAppFreezing=" + w.mAppFreezing);
9245 tokenMayBeDrawn = true;
9246 }
9247 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009248 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009249 atoken.startingDisplayed = true;
9250 }
9251 }
9252 } else if (w.mReadyToShow) {
9253 w.performShowLocked();
9254 }
9255 }
9256
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009257 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009258
9259 if (tokenMayBeDrawn) {
9260 // See if any windows have been drawn, so they (and others
9261 // associated with them) can now be shown.
9262 final int NT = mTokenList.size();
9263 for (i=0; i<NT; i++) {
9264 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9265 if (wtoken == null) {
9266 continue;
9267 }
9268 if (wtoken.freezingScreen) {
9269 int numInteresting = wtoken.numInterestingWindows;
9270 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009271 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009272 "allDrawn: " + wtoken
9273 + " interesting=" + numInteresting
9274 + " drawn=" + wtoken.numDrawnWindows);
9275 wtoken.showAllWindowsLocked();
9276 unsetAppFreezingScreenLocked(wtoken, false, true);
9277 orientationChangeComplete = true;
9278 }
9279 } else if (!wtoken.allDrawn) {
9280 int numInteresting = wtoken.numInterestingWindows;
9281 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009282 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009283 "allDrawn: " + wtoken
9284 + " interesting=" + numInteresting
9285 + " drawn=" + wtoken.numDrawnWindows);
9286 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009287 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009288
9289 // We can now show all of the drawn windows!
9290 if (!mOpeningApps.contains(wtoken)) {
9291 wtoken.showAllWindowsLocked();
9292 }
9293 }
9294 }
9295 }
9296 }
9297
9298 // If we are ready to perform an app transition, check through
9299 // all of the app tokens to be shown and see if they are ready
9300 // to go.
9301 if (mAppTransitionReady) {
9302 int NN = mOpeningApps.size();
9303 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009304 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009305 "Checking " + NN + " opening apps (frozen="
9306 + mDisplayFrozen + " timeout="
9307 + mAppTransitionTimeout + ")...");
9308 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9309 // If the display isn't frozen, wait to do anything until
9310 // all of the apps are ready. Otherwise just go because
9311 // we'll unfreeze the display when everyone is ready.
9312 for (i=0; i<NN && goodToGo; i++) {
9313 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009314 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009315 "Check opening app" + wtoken + ": allDrawn="
9316 + wtoken.allDrawn + " startingDisplayed="
9317 + wtoken.startingDisplayed);
9318 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9319 && !wtoken.startingMoved) {
9320 goodToGo = false;
9321 }
9322 }
9323 }
9324 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009325 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009326 int transit = mNextAppTransition;
9327 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009328 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009329 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009330 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009331 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009332 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009333 mAppTransitionTimeout = false;
9334 mStartingIconInTransition = false;
9335 mSkipAppTransitionAnimation = false;
9336
9337 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9338
Dianne Hackborna8f60182009-09-01 19:01:50 -07009339 // If there are applications waiting to come to the
9340 // top of the stack, now is the time to move their windows.
9341 // (Note that we don't do apps going to the bottom
9342 // here -- we want to keep their windows in the old
9343 // Z-order until the animation completes.)
9344 if (mToTopApps.size() > 0) {
9345 NN = mAppTokens.size();
9346 for (i=0; i<NN; i++) {
9347 AppWindowToken wtoken = mAppTokens.get(i);
9348 if (wtoken.sendingToTop) {
9349 wtoken.sendingToTop = false;
9350 moveAppWindowsLocked(wtoken, NN, false);
9351 }
9352 }
9353 mToTopApps.clear();
9354 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009355
Dianne Hackborn25994b42009-09-04 14:21:19 -07009356 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009357
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009358 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009359 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009360
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009361 // The top-most window will supply the layout params,
9362 // and we will determine it below.
9363 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009364 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009365 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009366
Joe Onorato8a9b2202010-02-26 18:56:32 -08009367 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009368 "New wallpaper target=" + mWallpaperTarget
9369 + ", lower target=" + mLowerWallpaperTarget
9370 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009371 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009372 // Do a first pass through the tokens for two
9373 // things:
9374 // (1) Determine if both the closing and opening
9375 // app token sets are wallpaper targets, in which
9376 // case special animations are needed
9377 // (since the wallpaper needs to stay static
9378 // behind them).
9379 // (2) Find the layout params of the top-most
9380 // application window in the tokens, which is
9381 // what will control the animation theme.
9382 final int NC = mClosingApps.size();
9383 NN = NC + mOpeningApps.size();
9384 for (i=0; i<NN; i++) {
9385 AppWindowToken wtoken;
9386 int mode;
9387 if (i < NC) {
9388 wtoken = mClosingApps.get(i);
9389 mode = 1;
9390 } else {
9391 wtoken = mOpeningApps.get(i-NC);
9392 mode = 2;
9393 }
9394 if (mLowerWallpaperTarget != null) {
9395 if (mLowerWallpaperTarget.mAppToken == wtoken
9396 || mUpperWallpaperTarget.mAppToken == wtoken) {
9397 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009398 }
9399 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009400 if (wtoken.appFullscreen) {
9401 WindowState ws = wtoken.findMainWindow();
9402 if (ws != null) {
9403 // If this is a compatibility mode
9404 // window, we will always use its anim.
9405 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9406 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009407 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009408 bestAnimLayer = Integer.MAX_VALUE;
9409 } else if (ws.mLayer > bestAnimLayer) {
9410 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009411 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009412 bestAnimLayer = ws.mLayer;
9413 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009414 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009415 }
9416 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009417
Dianne Hackborn25994b42009-09-04 14:21:19 -07009418 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009419 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009420 "Wallpaper animation!");
9421 switch (transit) {
9422 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9423 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9424 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9425 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9426 break;
9427 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9428 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9429 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9430 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9431 break;
9432 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009433 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009434 "New transit: " + transit);
9435 } else if (oldWallpaper != null) {
9436 // We are transitioning from an activity with
9437 // a wallpaper to one without.
9438 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009439 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009440 "New transit away from wallpaper: " + transit);
9441 } else if (mWallpaperTarget != null) {
9442 // We are transitioning from an activity without
9443 // a wallpaper to now showing the wallpaper
9444 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009445 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009446 "New transit into wallpaper: " + transit);
9447 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009448
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009449 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9450 mLastEnterAnimToken = animToken;
9451 mLastEnterAnimParams = animLp;
9452 } else if (mLastEnterAnimParams != null) {
9453 animLp = mLastEnterAnimParams;
9454 mLastEnterAnimToken = null;
9455 mLastEnterAnimParams = null;
9456 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009457
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009458 // If all closing windows are obscured, then there is
9459 // no need to do an animation. This is the case, for
9460 // example, when this transition is being done behind
9461 // the lock screen.
9462 if (!mPolicy.allowAppAnimationsLw()) {
9463 animLp = null;
9464 }
9465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009466 NN = mOpeningApps.size();
9467 for (i=0; i<NN; i++) {
9468 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009469 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009470 "Now opening app" + wtoken);
9471 wtoken.reportedVisible = false;
9472 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009473 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009474 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009475 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009476 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009477 wtoken.showAllWindowsLocked();
9478 }
9479 NN = mClosingApps.size();
9480 for (i=0; i<NN; i++) {
9481 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009482 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009483 "Now closing app" + wtoken);
9484 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009485 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009486 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009487 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009488 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009489 // Force the allDrawn flag, because we want to start
9490 // this guy's animations regardless of whether it's
9491 // gotten drawn.
9492 wtoken.allDrawn = true;
9493 }
9494
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009495 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009497 mOpeningApps.clear();
9498 mClosingApps.clear();
9499
9500 // This has changed the visibility of windows, so perform
9501 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009502 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009503 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009504 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9505 assignLayersLocked();
9506 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009507 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009508 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009509 }
9510 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009511
Dianne Hackborn16064f92010-03-25 00:47:24 -07009512 int adjResult = 0;
9513
Dianne Hackborna8f60182009-09-01 19:01:50 -07009514 if (!animating && mAppTransitionRunning) {
9515 // We have finished the animation of an app transition. To do
9516 // this, we have delayed a lot of operations like showing and
9517 // hiding apps, moving apps in Z-order, etc. The app token list
9518 // reflects the correct Z-order, but the window list may now
9519 // be out of sync with it. So here we will just rebuild the
9520 // entire app window list. Fun!
9521 mAppTransitionRunning = false;
9522 // Clear information about apps that were moving.
9523 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009524
Dianne Hackborna8f60182009-09-01 19:01:50 -07009525 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009526 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009527 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009528 moveInputMethodWindowsIfNeededLocked(false);
9529 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009530 // Since the window list has been rebuilt, focus might
9531 // have to be recomputed since the actual order of windows
9532 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009533 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009534 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009535
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009536 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009537 // At this point, there was a window with a wallpaper that
9538 // was force hiding other windows behind it, but now it
9539 // is going away. This may be simple -- just animate
9540 // away the wallpaper and its window -- or it may be
9541 // hard -- the wallpaper now needs to be shown behind
9542 // something that was hidden.
9543 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009544 if (mLowerWallpaperTarget != null
9545 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009546 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009547 "wallpaperForceHiding changed with lower="
9548 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009549 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009550 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9551 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9552 if (mLowerWallpaperTarget.mAppToken.hidden) {
9553 // The lower target has become hidden before we
9554 // actually started the animation... let's completely
9555 // re-evaluate everything.
9556 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009557 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009558 }
9559 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009560 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009561 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009562 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009563 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009564 + " NEW: " + mWallpaperTarget
9565 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009566 if (mLowerWallpaperTarget == null) {
9567 // Whoops, we don't need a special wallpaper animation.
9568 // Clear them out.
9569 forceHiding = false;
9570 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009571 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009572 if (w.mSurface != null) {
9573 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009574 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009575 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009576 forceHiding = true;
9577 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9578 if (!w.mAnimating) {
9579 // We set the animation above so it
9580 // is not yet running.
9581 w.clearAnimation();
9582 }
9583 }
9584 }
9585 }
9586 }
9587 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009588
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009589 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009590 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009591 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009592 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009593 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009594
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009595 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009596 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009597 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009598 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009599 assignLayersLocked();
9600 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009601 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009602 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009603 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009604 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009605
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009606 if (mFocusMayChange) {
9607 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009608 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009609 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009610 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009611 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009612 }
9613
9614 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009615 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009616 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009617
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009618 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9619 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009620
Jeff Browne33348b2010-07-15 23:54:05 -07009621 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009622 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009623
9624 // THIRD LOOP: Update the surfaces of all windows.
9625
9626 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9627
9628 boolean obscured = false;
9629 boolean blurring = false;
9630 boolean dimming = false;
9631 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009632 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009633 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009634
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009635 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009637 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009638 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009639
9640 boolean displayed = false;
9641 final WindowManager.LayoutParams attrs = w.mAttrs;
9642 final int attrFlags = attrs.flags;
9643
9644 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009645 // XXX NOTE: The logic here could be improved. We have
9646 // the decision about whether to resize a window separated
9647 // from whether to hide the surface. This can cause us to
9648 // resize a surface even if we are going to hide it. You
9649 // can see this by (1) holding device in landscape mode on
9650 // home screen; (2) tapping browser icon (device will rotate
9651 // to landscape; (3) tap home. The wallpaper will be resized
9652 // in step 2 but then immediately hidden, causing us to
9653 // have to resize and then redraw it again in step 3. It
9654 // would be nice to figure out how to avoid this, but it is
9655 // difficult because we do need to resize surfaces in some
9656 // cases while they are hidden such as when first showing a
9657 // window.
9658
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009659 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009660 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009661 TAG, "Placing surface #" + i + " " + w.mSurface
9662 + ": new=" + w.mShownFrame + ", old="
9663 + w.mLastShownFrame);
9664
9665 boolean resize;
9666 int width, height;
9667 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9668 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9669 w.mLastRequestedHeight != w.mRequestedHeight;
9670 // for a scaled surface, we just want to use
9671 // the requested size.
9672 width = w.mRequestedWidth;
9673 height = w.mRequestedHeight;
9674 w.mLastRequestedWidth = width;
9675 w.mLastRequestedHeight = height;
9676 w.mLastShownFrame.set(w.mShownFrame);
9677 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009678 if (SHOW_TRANSACTIONS) logSurface(w,
9679 "POS " + w.mShownFrame.left
9680 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009681 w.mSurfaceX = w.mShownFrame.left;
9682 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009683 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9684 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009685 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009686 if (!recoveringMemory) {
9687 reclaimSomeSurfaceMemoryLocked(w, "position");
9688 }
9689 }
9690 } else {
9691 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9692 width = w.mShownFrame.width();
9693 height = w.mShownFrame.height();
9694 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009695 }
9696
9697 if (resize) {
9698 if (width < 1) width = 1;
9699 if (height < 1) height = 1;
9700 if (w.mSurface != null) {
9701 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009702 if (SHOW_TRANSACTIONS) logSurface(w,
9703 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009704 + w.mShownFrame.top + " SIZE "
9705 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009706 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009707 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009708 w.mSurfaceW = width;
9709 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009710 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009711 w.mSurfaceX = w.mShownFrame.left;
9712 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009713 w.mSurface.setPosition(w.mShownFrame.left,
9714 w.mShownFrame.top);
9715 } catch (RuntimeException e) {
9716 // If something goes wrong with the surface (such
9717 // as running out of memory), don't take down the
9718 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009719 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009720 + "size=(" + width + "x" + height
9721 + "), pos=(" + w.mShownFrame.left
9722 + "," + w.mShownFrame.top + ")", e);
9723 if (!recoveringMemory) {
9724 reclaimSomeSurfaceMemoryLocked(w, "size");
9725 }
9726 }
9727 }
9728 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009729 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009730 w.mContentInsetsChanged =
9731 !w.mLastContentInsets.equals(w.mContentInsets);
9732 w.mVisibleInsetsChanged =
9733 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009734 boolean configChanged =
9735 w.mConfiguration != mCurConfiguration
9736 && (w.mConfiguration == null
9737 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009738 if (DEBUG_CONFIGURATION && configChanged) {
9739 Slog.v(TAG, "Win " + w + " config changed: "
9740 + mCurConfiguration);
9741 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009742 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009743 + ": configChanged=" + configChanged
9744 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009745 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009746 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009747 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009748 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009749 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009750 w.mLastFrame.set(w.mFrame);
9751 w.mLastContentInsets.set(w.mContentInsets);
9752 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009753 // If the screen is currently frozen, then keep
9754 // it frozen until this window draws at its new
9755 // orientation.
9756 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009757 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009758 "Resizing while display frozen: " + w);
9759 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009760 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009761 mWindowsFreezingScreen = true;
9762 // XXX should probably keep timeout from
9763 // when we first froze the display.
9764 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9765 mH.sendMessageDelayed(mH.obtainMessage(
9766 H.WINDOW_FREEZE_TIMEOUT), 2000);
9767 }
9768 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009769 // If the orientation is changing, then we need to
9770 // hold off on unfreezing the display until this
9771 // window has been redrawn; to do that, we need
9772 // to go through the process of getting informed
9773 // by the application when it has finished drawing.
9774 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009775 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009776 "Orientation start waiting for draw in "
9777 + w + ", surface " + w.mSurface);
9778 w.mDrawPending = true;
9779 w.mCommitDrawPending = false;
9780 w.mReadyToShow = false;
9781 if (w.mAppToken != null) {
9782 w.mAppToken.allDrawn = false;
9783 }
9784 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009785 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009786 "Resizing window " + w + " to " + w.mFrame);
9787 mResizingWindows.add(w);
9788 } else if (w.mOrientationChanging) {
9789 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009790 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009791 "Orientation not waiting for draw in "
9792 + w + ", surface " + w.mSurface);
9793 w.mOrientationChanging = false;
9794 }
9795 }
9796 }
9797
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009798 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009799 if (!w.mLastHidden) {
9800 //dump();
9801 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009802 if (SHOW_TRANSACTIONS) logSurface(w,
9803 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009804 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009805 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009806 try {
9807 w.mSurface.hide();
9808 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009809 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009810 }
9811 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009812 }
9813 // If we are waiting for this window to handle an
9814 // orientation change, well, it is hidden, so
9815 // doesn't really matter. Note that this does
9816 // introduce a potential glitch if the window
9817 // becomes unhidden before it has drawn for the
9818 // new orientation.
9819 if (w.mOrientationChanging) {
9820 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009821 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009822 "Orientation change skips hidden " + w);
9823 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009824 } else if (w.mLastLayer != w.mAnimLayer
9825 || w.mLastAlpha != w.mShownAlpha
9826 || w.mLastDsDx != w.mDsDx
9827 || w.mLastDtDx != w.mDtDx
9828 || w.mLastDsDy != w.mDsDy
9829 || w.mLastDtDy != w.mDtDy
9830 || w.mLastHScale != w.mHScale
9831 || w.mLastVScale != w.mVScale
9832 || w.mLastHidden) {
9833 displayed = true;
9834 w.mLastAlpha = w.mShownAlpha;
9835 w.mLastLayer = w.mAnimLayer;
9836 w.mLastDsDx = w.mDsDx;
9837 w.mLastDtDx = w.mDtDx;
9838 w.mLastDsDy = w.mDsDy;
9839 w.mLastDtDy = w.mDtDy;
9840 w.mLastHScale = w.mHScale;
9841 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009842 if (SHOW_TRANSACTIONS) logSurface(w,
9843 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009844 + " matrix=[" + (w.mDsDx*w.mHScale)
9845 + "," + (w.mDtDx*w.mVScale)
9846 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009847 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009848 if (w.mSurface != null) {
9849 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009850 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009851 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009852 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009853 w.mSurface.setLayer(w.mAnimLayer);
9854 w.mSurface.setMatrix(
9855 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9856 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9857 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009858 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009859 if (!recoveringMemory) {
9860 reclaimSomeSurfaceMemoryLocked(w, "update");
9861 }
9862 }
9863 }
9864
9865 if (w.mLastHidden && !w.mDrawPending
9866 && !w.mCommitDrawPending
9867 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009868 if (SHOW_TRANSACTIONS) logSurface(w,
9869 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009870 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009871 + " during relayout");
9872 if (showSurfaceRobustlyLocked(w)) {
9873 w.mHasDrawn = true;
9874 w.mLastHidden = false;
9875 } else {
9876 w.mOrientationChanging = false;
9877 }
9878 }
9879 if (w.mSurface != null) {
9880 w.mToken.hasVisible = true;
9881 }
9882 } else {
9883 displayed = true;
9884 }
9885
9886 if (displayed) {
9887 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009888 if (attrs.width == LayoutParams.MATCH_PARENT
9889 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009890 covered = true;
9891 }
9892 }
9893 if (w.mOrientationChanging) {
9894 if (w.mDrawPending || w.mCommitDrawPending) {
9895 orientationChangeComplete = 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 continue waiting for draw in " + w);
9898 } else {
9899 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009900 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009901 "Orientation change complete in " + w);
9902 }
9903 }
9904 w.mToken.hasVisible = true;
9905 }
9906 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009907 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009908 "Orientation change skips hidden " + w);
9909 w.mOrientationChanging = false;
9910 }
9911
9912 final boolean canBeSeen = w.isDisplayedLw();
9913
9914 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9915 focusDisplayed = true;
9916 }
9917
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009918 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009920 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009921 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009922 if (w.mSurface != null) {
9923 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9924 holdScreen = w.mSession;
9925 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009926 if (!syswin && w.mAttrs.screenBrightness >= 0
9927 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009928 screenBrightness = w.mAttrs.screenBrightness;
9929 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009930 if (!syswin && w.mAttrs.buttonBrightness >= 0
9931 && buttonBrightness < 0) {
9932 buttonBrightness = w.mAttrs.buttonBrightness;
9933 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05009934 if (canBeSeen
9935 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9936 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9937 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009938 syswin = true;
9939 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009940 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009941
Dianne Hackborn25994b42009-09-04 14:21:19 -07009942 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
9943 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009944 // This window completely covers everything behind it,
9945 // so we want to leave all of them as unblurred (for
9946 // performance reasons).
9947 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009948 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009949 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009950 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009951 obscured = true;
9952 if (mBackgroundFillerSurface == null) {
9953 try {
9954 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009955 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009956 0, dw, dh,
9957 PixelFormat.OPAQUE,
9958 Surface.FX_SURFACE_NORMAL);
9959 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009960 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009961 }
9962 }
9963 try {
9964 mBackgroundFillerSurface.setPosition(0, 0);
9965 mBackgroundFillerSurface.setSize(dw, dh);
9966 // Using the same layer as Dim because they will never be shown at the
9967 // same time.
9968 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9969 mBackgroundFillerSurface.show();
9970 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009971 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009972 }
9973 backgroundFillerShown = true;
9974 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009975 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009976 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009977 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009978 + ": blurring=" + blurring
9979 + " obscured=" + obscured
9980 + " displayed=" + displayed);
9981 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9982 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009983 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009984 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009985 if (mDimAnimator == null) {
9986 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009987 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009988 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009989 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009990 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009991 }
9992 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
9993 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009994 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009995 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009996 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009997 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009998 + mBlurSurface + ": CREATE");
9999 try {
Romain Guy06882f82009-06-10 13:36:04 -070010000 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010001 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010002 -1, 16, 16,
10003 PixelFormat.OPAQUE,
10004 Surface.FX_SURFACE_BLUR);
10005 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010006 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010007 }
10008 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010009 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010010 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10011 + mBlurSurface + ": pos=(0,0) (" +
10012 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010013 mBlurSurface.setPosition(0, 0);
10014 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010015 mBlurSurface.setLayer(w.mAnimLayer-2);
10016 if (!mBlurShown) {
10017 try {
10018 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10019 + mBlurSurface + ": SHOW");
10020 mBlurSurface.show();
10021 } catch (RuntimeException e) {
10022 Slog.w(TAG, "Failure showing blur surface", e);
10023 }
10024 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010025 }
10026 }
10027 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010028 }
10029 }
10030 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010031
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010032 if (obscuredChanged && mWallpaperTarget == w) {
10033 // This is the wallpaper target and its obscured state
10034 // changed... make sure the current wallaper's visibility
10035 // has been updated accordingly.
10036 updateWallpaperVisibilityLocked();
10037 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010038 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010039
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010040 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10041 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010042 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010043 try {
10044 mBackgroundFillerSurface.hide();
10045 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010046 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010047 }
10048 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010049
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010050 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010051 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10052 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010053 }
Romain Guy06882f82009-06-10 13:36:04 -070010054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010055 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010056 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010057 + ": HIDE");
10058 try {
10059 mBlurSurface.hide();
10060 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010061 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010062 }
10063 mBlurShown = false;
10064 }
10065
Joe Onorato8a9b2202010-02-26 18:56:32 -080010066 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010067 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010068 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010069 }
10070
Jeff Browne33348b2010-07-15 23:54:05 -070010071 mInputMonitor.updateInputWindowsLw();
10072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010073 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010074
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010075 if (mWatermark != null) {
10076 mWatermark.drawIfNeeded();
10077 }
10078
Joe Onorato8a9b2202010-02-26 18:56:32 -080010079 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010080 "With display frozen, orientationChangeComplete="
10081 + orientationChangeComplete);
10082 if (orientationChangeComplete) {
10083 if (mWindowsFreezingScreen) {
10084 mWindowsFreezingScreen = false;
10085 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10086 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010087 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010088 }
Romain Guy06882f82009-06-10 13:36:04 -070010089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010090 i = mResizingWindows.size();
10091 if (i > 0) {
10092 do {
10093 i--;
10094 WindowState win = mResizingWindows.get(i);
10095 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010096 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10097 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010098 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010099 boolean configChanged =
10100 win.mConfiguration != mCurConfiguration
10101 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010102 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10103 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10104 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010105 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010106 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010107 + " / " + mCurConfiguration + " / 0x"
10108 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010109 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010110 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010111 win.mClient.resized(win.mFrame.width(),
10112 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010113 win.mLastVisibleInsets, win.mDrawPending,
10114 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010115 win.mContentInsetsChanged = false;
10116 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010117 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010118 } catch (RemoteException e) {
10119 win.mOrientationChanging = false;
10120 }
10121 } while (i > 0);
10122 mResizingWindows.clear();
10123 }
Romain Guy06882f82009-06-10 13:36:04 -070010124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010125 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010126 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010127 i = mDestroySurface.size();
10128 if (i > 0) {
10129 do {
10130 i--;
10131 WindowState win = mDestroySurface.get(i);
10132 win.mDestroying = false;
10133 if (mInputMethodWindow == win) {
10134 mInputMethodWindow = null;
10135 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010136 if (win == mWallpaperTarget) {
10137 wallpaperDestroyed = true;
10138 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010139 win.destroySurfaceLocked();
10140 } while (i > 0);
10141 mDestroySurface.clear();
10142 }
10143
10144 // Time to remove any exiting tokens?
10145 for (i=mExitingTokens.size()-1; i>=0; i--) {
10146 WindowToken token = mExitingTokens.get(i);
10147 if (!token.hasVisible) {
10148 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010149 if (token.windowType == TYPE_WALLPAPER) {
10150 mWallpaperTokens.remove(token);
10151 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010152 }
10153 }
10154
10155 // Time to remove any exiting applications?
10156 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10157 AppWindowToken token = mExitingAppTokens.get(i);
10158 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010159 // Make sure there is no animation running on this token,
10160 // so any windows associated with it will be removed as
10161 // soon as their animations are complete
10162 token.animation = null;
10163 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010164 mAppTokens.remove(token);
10165 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010166 if (mLastEnterAnimToken == token) {
10167 mLastEnterAnimToken = null;
10168 mLastEnterAnimParams = null;
10169 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010170 }
10171 }
10172
Dianne Hackborna8f60182009-09-01 19:01:50 -070010173 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010174
Dianne Hackborna8f60182009-09-01 19:01:50 -070010175 if (!animating && mAppTransitionRunning) {
10176 // We have finished the animation of an app transition. To do
10177 // this, we have delayed a lot of operations like showing and
10178 // hiding apps, moving apps in Z-order, etc. The app token list
10179 // reflects the correct Z-order, but the window list may now
10180 // be out of sync with it. So here we will just rebuild the
10181 // entire app window list. Fun!
10182 mAppTransitionRunning = false;
10183 needRelayout = true;
10184 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010185 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010186 // Clear information about apps that were moving.
10187 mToBottomApps.clear();
10188 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010190 if (focusDisplayed) {
10191 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10192 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010193 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010194 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010195 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010196 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010197 requestAnimationLocked(0);
10198 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010199 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10200 }
Jeff Browneb857f12010-07-16 10:06:33 -070010201
Jeff Browne33348b2010-07-15 23:54:05 -070010202 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010203
Jeff Brown8e03b752010-06-13 19:16:55 -070010204 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010205 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10206 mPowerManager.setScreenBrightnessOverride(-1);
10207 } else {
10208 mPowerManager.setScreenBrightnessOverride((int)
10209 (screenBrightness * Power.BRIGHTNESS_ON));
10210 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010211 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10212 mPowerManager.setButtonBrightnessOverride(-1);
10213 } else {
10214 mPowerManager.setButtonBrightnessOverride((int)
10215 (buttonBrightness * Power.BRIGHTNESS_ON));
10216 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010217 if (holdScreen != mHoldingScreenOn) {
10218 mHoldingScreenOn = holdScreen;
10219 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10220 mH.sendMessage(m);
10221 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010222
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010223 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010224 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010225 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10226 LocalPowerManager.BUTTON_EVENT, true);
10227 mTurnOnScreen = false;
10228 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010229
10230 // Check to see if we are now in a state where the screen should
10231 // be enabled, because the window obscured flags have changed.
10232 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010233 }
Jeff Brown46b9ac02010-04-22 18:58:52 -070010234
10235 /**
10236 * Must be called with the main window manager lock held.
10237 */
10238 void setHoldScreenLocked(boolean holding) {
10239 boolean state = mHoldingScreenWakeLock.isHeld();
10240 if (holding != state) {
10241 if (holding) {
10242 mHoldingScreenWakeLock.acquire();
10243 } else {
10244 mPolicy.screenOnStoppedLw();
10245 mHoldingScreenWakeLock.release();
10246 }
10247 }
10248 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010249
10250 void requestAnimationLocked(long delay) {
10251 if (!mAnimationPending) {
10252 mAnimationPending = true;
10253 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10254 }
10255 }
Romain Guy06882f82009-06-10 13:36:04 -070010256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010257 /**
10258 * Have the surface flinger show a surface, robustly dealing with
10259 * error conditions. In particular, if there is not enough memory
10260 * to show the surface, then we will try to get rid of other surfaces
10261 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010262 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010263 * @return Returns true if the surface was successfully shown.
10264 */
10265 boolean showSurfaceRobustlyLocked(WindowState win) {
10266 try {
10267 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010268 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010269 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010270 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010271 if (DEBUG_VISIBILITY) Slog.v(TAG,
10272 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010273 win.mTurnOnScreen = false;
10274 mTurnOnScreen = true;
10275 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010276 }
10277 return true;
10278 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010279 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010280 }
Romain Guy06882f82009-06-10 13:36:04 -070010281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010282 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010284 return false;
10285 }
Romain Guy06882f82009-06-10 13:36:04 -070010286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010287 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10288 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010289
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010290 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010291 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010293 if (mForceRemoves == null) {
10294 mForceRemoves = new ArrayList<WindowState>();
10295 }
Romain Guy06882f82009-06-10 13:36:04 -070010296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010297 long callingIdentity = Binder.clearCallingIdentity();
10298 try {
10299 // There was some problem... first, do a sanity check of the
10300 // window list to make sure we haven't left any dangling surfaces
10301 // around.
10302 int N = mWindows.size();
10303 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010304 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010305 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010306 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010307 if (ws.mSurface != null) {
10308 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010309 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010310 + ws + " surface=" + ws.mSurface
10311 + " token=" + win.mToken
10312 + " pid=" + ws.mSession.mPid
10313 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010314 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010315 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010316 ws.mSurface = null;
10317 mForceRemoves.add(ws);
10318 i--;
10319 N--;
10320 leakedSurface = true;
10321 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010322 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010323 + ws + " surface=" + ws.mSurface
10324 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010325 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010326 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010327 ws.mSurface = null;
10328 leakedSurface = true;
10329 }
10330 }
10331 }
Romain Guy06882f82009-06-10 13:36:04 -070010332
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010333 boolean killedApps = false;
10334 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010335 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010336 SparseIntArray pidCandidates = new SparseIntArray();
10337 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010338 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010339 if (ws.mSurface != null) {
10340 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10341 }
10342 }
10343 if (pidCandidates.size() > 0) {
10344 int[] pids = new int[pidCandidates.size()];
10345 for (int i=0; i<pids.length; i++) {
10346 pids[i] = pidCandidates.keyAt(i);
10347 }
10348 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010349 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010350 killedApps = true;
10351 }
10352 } catch (RemoteException e) {
10353 }
10354 }
10355 }
Romain Guy06882f82009-06-10 13:36:04 -070010356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010357 if (leakedSurface || killedApps) {
10358 // We managed to reclaim some memory, so get rid of the trouble
10359 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010360 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010361 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010362 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010363 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010364 win.mSurface = null;
10365 }
Romain Guy06882f82009-06-10 13:36:04 -070010366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010367 try {
10368 win.mClient.dispatchGetNewSurface();
10369 } catch (RemoteException e) {
10370 }
10371 }
10372 } finally {
10373 Binder.restoreCallingIdentity(callingIdentity);
10374 }
10375 }
Romain Guy06882f82009-06-10 13:36:04 -070010376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010377 private boolean updateFocusedWindowLocked(int mode) {
10378 WindowState newFocus = computeFocusedWindowLocked();
10379 if (mCurrentFocus != newFocus) {
10380 // This check makes sure that we don't already have the focus
10381 // change message pending.
10382 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10383 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010384 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010385 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10386 final WindowState oldFocus = mCurrentFocus;
10387 mCurrentFocus = newFocus;
10388 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010390 final WindowState imWindow = mInputMethodWindow;
10391 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010392 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010393 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010394 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10395 mLayoutNeeded = true;
10396 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010397 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
10398 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010399 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10400 // Client will do the layout, but we need to assign layers
10401 // for handleNewWindowLocked() below.
10402 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010403 }
10404 }
Jeff Brown349703e2010-06-22 01:27:15 -070010405
10406 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10407 // If we defer assigning layers, then the caller is responsible for
10408 // doing this part.
10409 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010410 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010411 return true;
10412 }
10413 return false;
10414 }
Jeff Brown349703e2010-06-22 01:27:15 -070010415
10416 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010417 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070010418 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010419
10420 private WindowState computeFocusedWindowLocked() {
10421 WindowState result = null;
10422 WindowState win;
10423
10424 int i = mWindows.size() - 1;
10425 int nextAppIndex = mAppTokens.size()-1;
10426 WindowToken nextApp = nextAppIndex >= 0
10427 ? mAppTokens.get(nextAppIndex) : null;
10428
10429 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070010430 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010431
Joe Onorato8a9b2202010-02-26 18:56:32 -080010432 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010433 TAG, "Looking for focus: " + i
10434 + " = " + win
10435 + ", flags=" + win.mAttrs.flags
10436 + ", canReceive=" + win.canReceiveKeys());
10437
10438 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010440 // If this window's application has been removed, just skip it.
10441 if (thisApp != null && thisApp.removed) {
10442 i--;
10443 continue;
10444 }
Romain Guy06882f82009-06-10 13:36:04 -070010445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010446 // If there is a focused app, don't allow focus to go to any
10447 // windows below it. If this is an application window, step
10448 // through the app tokens until we find its app.
10449 if (thisApp != null && nextApp != null && thisApp != nextApp
10450 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10451 int origAppIndex = nextAppIndex;
10452 while (nextAppIndex > 0) {
10453 if (nextApp == mFocusedApp) {
10454 // Whoops, we are below the focused app... no focus
10455 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010456 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010457 TAG, "Reached focused app: " + mFocusedApp);
10458 return null;
10459 }
10460 nextAppIndex--;
10461 nextApp = mAppTokens.get(nextAppIndex);
10462 if (nextApp == thisApp) {
10463 break;
10464 }
10465 }
10466 if (thisApp != nextApp) {
10467 // Uh oh, the app token doesn't exist! This shouldn't
10468 // happen, but if it does we can get totally hosed...
10469 // so restart at the original app.
10470 nextAppIndex = origAppIndex;
10471 nextApp = mAppTokens.get(nextAppIndex);
10472 }
10473 }
10474
10475 // Dispatch to this window if it is wants key events.
10476 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010477 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010478 TAG, "Found focus @ " + i + " = " + win);
10479 result = win;
10480 break;
10481 }
10482
10483 i--;
10484 }
10485
10486 return result;
10487 }
10488
10489 private void startFreezingDisplayLocked() {
10490 if (mDisplayFrozen) {
10491 return;
10492 }
Romain Guy06882f82009-06-10 13:36:04 -070010493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010494 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010496 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010497 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010498 if (mFreezeGcPending != 0) {
10499 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010500 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010501 mH.removeMessages(H.FORCE_GC);
10502 Runtime.getRuntime().gc();
10503 mFreezeGcPending = now;
10504 }
10505 } else {
10506 mFreezeGcPending = now;
10507 }
Romain Guy06882f82009-06-10 13:36:04 -070010508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010509 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010510
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010511 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010512
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010513 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10514 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010515 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010516 mAppTransitionReady = true;
10517 }
Romain Guy06882f82009-06-10 13:36:04 -070010518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010519 if (PROFILE_ORIENTATION) {
10520 File file = new File("/data/system/frozen");
10521 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10522 }
10523 Surface.freezeDisplay(0);
10524 }
Romain Guy06882f82009-06-10 13:36:04 -070010525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010526 private void stopFreezingDisplayLocked() {
10527 if (!mDisplayFrozen) {
10528 return;
10529 }
Romain Guy06882f82009-06-10 13:36:04 -070010530
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010531 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10532 return;
10533 }
10534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010535 mDisplayFrozen = false;
10536 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10537 if (PROFILE_ORIENTATION) {
10538 Debug.stopMethodTracing();
10539 }
10540 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010541
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010542 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010543
Christopher Tateb696aee2010-04-02 19:08:30 -070010544 // While the display is frozen we don't re-compute the orientation
10545 // to avoid inconsistent states. However, something interesting
10546 // could have actually changed during that time so re-evaluate it
10547 // now to catch that.
10548 if (updateOrientationFromAppTokensLocked()) {
10549 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10550 }
10551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010552 // A little kludge: a lot could have happened while the
10553 // display was frozen, so now that we are coming back we
10554 // do a gc so that any remote references the system
10555 // processes holds on others can be released if they are
10556 // no longer needed.
10557 mH.removeMessages(H.FORCE_GC);
10558 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10559 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010561 mScreenFrozenLock.release();
10562 }
Romain Guy06882f82009-06-10 13:36:04 -070010563
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010564 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10565 DisplayMetrics dm) {
10566 if (index < tokens.length) {
10567 String str = tokens[index];
10568 if (str != null && str.length() > 0) {
10569 try {
10570 int val = Integer.parseInt(str);
10571 return val;
10572 } catch (Exception e) {
10573 }
10574 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010575 }
10576 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10577 return defDps;
10578 }
10579 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10580 return val;
10581 }
10582
10583 class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010584 final String[] mTokens;
10585 final String mText;
10586 final Paint mTextPaint;
10587 final int mTextWidth;
10588 final int mTextHeight;
10589 final int mTextAscent;
10590 final int mTextDescent;
10591 final int mDeltaX;
10592 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010593
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010594 Surface mSurface;
10595 int mLastDW;
10596 int mLastDH;
10597 boolean mDrawNeeded;
10598
10599 Watermark(SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010600 final DisplayMetrics dm = new DisplayMetrics();
10601 mDisplay.getMetrics(dm);
10602
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010603 if (false) {
10604 Log.i(TAG, "*********************** WATERMARK");
10605 for (int i=0; i<tokens.length; i++) {
10606 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10607 }
10608 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010609
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010610 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010611
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010612 StringBuilder builder = new StringBuilder(32);
10613 int len = mTokens[0].length();
10614 len = len & ~1;
10615 for (int i=0; i<len; i+=2) {
10616 int c1 = mTokens[0].charAt(i);
10617 int c2 = mTokens[0].charAt(i+1);
10618 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10619 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10620 else c1 -= '0';
10621 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10622 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10623 else c2 -= '0';
10624 builder.append((char)(255-((c1*16)+c2)));
10625 }
10626 mText = builder.toString();
10627 if (false) {
10628 Log.i(TAG, "Final text: " + mText);
10629 }
10630
10631 int fontSize = getPropertyInt(tokens, 1,
10632 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10633
10634 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10635 mTextPaint.setTextSize(fontSize);
10636 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10637
10638 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
10639 mTextWidth = (int)mTextPaint.measureText(mText);
10640 mTextAscent = fm.ascent;
10641 mTextDescent = fm.descent;
10642 mTextHeight = fm.descent - fm.ascent;
10643
10644 mDeltaX = getPropertyInt(tokens, 2,
10645 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
10646 mDeltaY = getPropertyInt(tokens, 3,
10647 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
10648 int shadowColor = getPropertyInt(tokens, 4,
10649 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
10650 int color = getPropertyInt(tokens, 5,
10651 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
10652 int shadowRadius = getPropertyInt(tokens, 6,
10653 TypedValue.COMPLEX_UNIT_PX, 7, dm);
10654 int shadowDx = getPropertyInt(tokens, 8,
10655 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10656 int shadowDy = getPropertyInt(tokens, 9,
10657 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10658
10659 mTextPaint.setColor(color);
10660 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010661
10662 try {
10663 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010664 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010665 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010666 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010667 mSurface.show();
10668 } catch (OutOfResourcesException e) {
10669 }
10670 }
10671
10672 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010673 if (mLastDW != dw || mLastDH != dh) {
10674 mLastDW = dw;
10675 mLastDH = dh;
10676 mSurface.setSize(dw, dh);
10677 mDrawNeeded = true;
10678 }
10679 }
10680
10681 void drawIfNeeded() {
10682 if (mDrawNeeded) {
10683 final int dw = mLastDW;
10684 final int dh = mLastDH;
10685
10686 mDrawNeeded = false;
10687 Rect dirty = new Rect(0, 0, dw, dh);
10688 Canvas c = null;
10689 try {
10690 c = mSurface.lockCanvas(dirty);
10691 } catch (IllegalArgumentException e) {
10692 } catch (OutOfResourcesException e) {
10693 }
10694 if (c != null) {
10695 int deltaX = mDeltaX;
10696 int deltaY = mDeltaY;
10697
10698 // deltaX shouldn't be close to a round fraction of our
10699 // x step, or else things will line up too much.
10700 int div = (dw+mTextWidth)/deltaX;
10701 int rem = (dw+mTextWidth) - (div*deltaX);
10702 int qdelta = deltaX/4;
10703 if (rem < qdelta || rem > (deltaX-qdelta)) {
10704 deltaX += deltaX/3;
10705 }
10706
10707 int y = -mTextHeight;
10708 int x = -mTextWidth;
10709 while (y < (dh+mTextHeight)) {
10710 c.drawText(mText, x, y, mTextPaint);
10711 x += deltaX;
10712 if (x >= dw) {
10713 x -= (dw+mTextWidth);
10714 y += deltaY;
10715 }
10716 }
10717 mSurface.unlockCanvasAndPost(c);
10718 }
10719 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010720 }
10721 }
10722
10723 void createWatermark() {
10724 if (mWatermark != null) {
10725 return;
10726 }
10727
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010728 File file = new File("/system/etc/setup.conf");
10729 FileInputStream in = null;
10730 try {
10731 in = new FileInputStream(file);
10732 DataInputStream ind = new DataInputStream(in);
10733 String line = ind.readLine();
10734 if (line != null) {
10735 String[] toks = line.split("%");
10736 if (toks != null && toks.length > 0) {
10737 mWatermark = new Watermark(mFxSession, toks);
10738 }
10739 }
10740 } catch (FileNotFoundException e) {
10741 } catch (IOException e) {
10742 } finally {
10743 if (in != null) {
10744 try {
10745 in.close();
10746 } catch (IOException e) {
10747 }
10748 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010749 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010750 }
10751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010752 @Override
10753 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10754 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10755 != PackageManager.PERMISSION_GRANTED) {
10756 pw.println("Permission Denial: can't dump WindowManager from from pid="
10757 + Binder.getCallingPid()
10758 + ", uid=" + Binder.getCallingUid());
10759 return;
10760 }
Romain Guy06882f82009-06-10 13:36:04 -070010761
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010762 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010763 pw.println(" ");
10764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010765 synchronized(mWindowMap) {
10766 pw.println("Current Window Manager state:");
10767 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010768 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010769 pw.print(" Window #"); pw.print(i); pw.print(' ');
10770 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010771 w.dump(pw, " ");
10772 }
10773 if (mInputMethodDialogs.size() > 0) {
10774 pw.println(" ");
10775 pw.println(" Input method dialogs:");
10776 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10777 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010778 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010779 }
10780 }
10781 if (mPendingRemove.size() > 0) {
10782 pw.println(" ");
10783 pw.println(" Remove pending for:");
10784 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10785 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010786 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10787 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010788 w.dump(pw, " ");
10789 }
10790 }
10791 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10792 pw.println(" ");
10793 pw.println(" Windows force removing:");
10794 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10795 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010796 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10797 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010798 w.dump(pw, " ");
10799 }
10800 }
10801 if (mDestroySurface.size() > 0) {
10802 pw.println(" ");
10803 pw.println(" Windows waiting to destroy their surface:");
10804 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10805 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010806 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10807 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010808 w.dump(pw, " ");
10809 }
10810 }
10811 if (mLosingFocus.size() > 0) {
10812 pw.println(" ");
10813 pw.println(" Windows losing focus:");
10814 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10815 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010816 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10817 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010818 w.dump(pw, " ");
10819 }
10820 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010821 if (mResizingWindows.size() > 0) {
10822 pw.println(" ");
10823 pw.println(" Windows waiting to resize:");
10824 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10825 WindowState w = mResizingWindows.get(i);
10826 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10827 pw.print(w); pw.println(":");
10828 w.dump(pw, " ");
10829 }
10830 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010831 if (mSessions.size() > 0) {
10832 pw.println(" ");
10833 pw.println(" All active sessions:");
10834 Iterator<Session> it = mSessions.iterator();
10835 while (it.hasNext()) {
10836 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010837 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010838 s.dump(pw, " ");
10839 }
10840 }
10841 if (mTokenMap.size() > 0) {
10842 pw.println(" ");
10843 pw.println(" All tokens:");
10844 Iterator<WindowToken> it = mTokenMap.values().iterator();
10845 while (it.hasNext()) {
10846 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010847 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010848 token.dump(pw, " ");
10849 }
10850 }
10851 if (mTokenList.size() > 0) {
10852 pw.println(" ");
10853 pw.println(" Window token list:");
10854 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010855 pw.print(" #"); pw.print(i); pw.print(": ");
10856 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010857 }
10858 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010859 if (mWallpaperTokens.size() > 0) {
10860 pw.println(" ");
10861 pw.println(" Wallpaper tokens:");
10862 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10863 WindowToken token = mWallpaperTokens.get(i);
10864 pw.print(" Wallpaper #"); pw.print(i);
10865 pw.print(' '); pw.print(token); pw.println(':');
10866 token.dump(pw, " ");
10867 }
10868 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010869 if (mAppTokens.size() > 0) {
10870 pw.println(" ");
10871 pw.println(" Application tokens in Z order:");
10872 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010873 pw.print(" App #"); pw.print(i); pw.print(": ");
10874 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010875 }
10876 }
10877 if (mFinishedStarting.size() > 0) {
10878 pw.println(" ");
10879 pw.println(" Finishing start of application tokens:");
10880 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10881 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010882 pw.print(" Finished Starting #"); pw.print(i);
10883 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010884 token.dump(pw, " ");
10885 }
10886 }
10887 if (mExitingTokens.size() > 0) {
10888 pw.println(" ");
10889 pw.println(" Exiting tokens:");
10890 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10891 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010892 pw.print(" Exiting #"); pw.print(i);
10893 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010894 token.dump(pw, " ");
10895 }
10896 }
10897 if (mExitingAppTokens.size() > 0) {
10898 pw.println(" ");
10899 pw.println(" Exiting application tokens:");
10900 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10901 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010902 pw.print(" Exiting App #"); pw.print(i);
10903 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010904 token.dump(pw, " ");
10905 }
10906 }
10907 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010908 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10909 pw.print(" mLastFocus="); pw.println(mLastFocus);
10910 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10911 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10912 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010913 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010914 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10915 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10916 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10917 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010918 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10919 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10920 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010921 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10922 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10923 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10924 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010925 if (mDimAnimator != null) {
10926 mDimAnimator.printTo(pw);
10927 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080010928 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010929 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010930 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010931 pw.print(mInputMethodAnimLayerAdjustment);
10932 pw.print(" mWallpaperAnimLayerAdjustment=");
10933 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010934 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10935 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010936 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10937 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010938 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
10939 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010940 pw.print(" mRotation="); pw.print(mRotation);
10941 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10942 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10943 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10944 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10945 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10946 pw.print(" mNextAppTransition=0x");
10947 pw.print(Integer.toHexString(mNextAppTransition));
10948 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010949 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010950 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010951 if (mNextAppTransitionPackage != null) {
10952 pw.print(" mNextAppTransitionPackage=");
10953 pw.print(mNextAppTransitionPackage);
10954 pw.print(", mNextAppTransitionEnter=0x");
10955 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10956 pw.print(", mNextAppTransitionExit=0x");
10957 pw.print(Integer.toHexString(mNextAppTransitionExit));
10958 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010959 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10960 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010961 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10962 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10963 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10964 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010965 if (mOpeningApps.size() > 0) {
10966 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10967 }
10968 if (mClosingApps.size() > 0) {
10969 pw.print(" mClosingApps="); pw.println(mClosingApps);
10970 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010971 if (mToTopApps.size() > 0) {
10972 pw.print(" mToTopApps="); pw.println(mToTopApps);
10973 }
10974 if (mToBottomApps.size() > 0) {
10975 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10976 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010977 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10978 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010979 }
10980 }
10981
Jeff Brown349703e2010-06-22 01:27:15 -070010982 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010983 public void monitor() {
10984 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010985 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070010986 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010987
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010988 /**
10989 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010990 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010991 */
10992 private static class DimAnimator {
10993 Surface mDimSurface;
10994 boolean mDimShown = false;
10995 float mDimCurrentAlpha;
10996 float mDimTargetAlpha;
10997 float mDimDeltaPerMs;
10998 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010999
11000 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011001
11002 DimAnimator (SurfaceSession session) {
11003 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011004 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011005 + mDimSurface + ": CREATE");
11006 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011007 mDimSurface = new Surface(session, 0,
11008 "DimSurface",
11009 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011010 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011011 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011012 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011013 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011014 }
11015 }
11016 }
11017
11018 /**
11019 * Show the dim surface.
11020 */
11021 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011022 if (!mDimShown) {
11023 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11024 dw + "x" + dh + ")");
11025 mDimShown = true;
11026 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011027 mLastDimWidth = dw;
11028 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011029 mDimSurface.setPosition(0, 0);
11030 mDimSurface.setSize(dw, dh);
11031 mDimSurface.show();
11032 } catch (RuntimeException e) {
11033 Slog.w(TAG, "Failure showing dim surface", e);
11034 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011035 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11036 mLastDimWidth = dw;
11037 mLastDimHeight = dh;
11038 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011039 }
11040 }
11041
11042 /**
11043 * Set's the dim surface's layer and update dim parameters that will be used in
11044 * {@link updateSurface} after all windows are examined.
11045 */
11046 void updateParameters(WindowState w, long currentTime) {
11047 mDimSurface.setLayer(w.mAnimLayer-1);
11048
11049 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011050 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011051 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011052 if (mDimTargetAlpha != target) {
11053 // If the desired dim level has changed, then
11054 // start an animation to it.
11055 mLastDimAnimTime = currentTime;
11056 long duration = (w.mAnimating && w.mAnimation != null)
11057 ? w.mAnimation.computeDurationHint()
11058 : DEFAULT_DIM_DURATION;
11059 if (target > mDimTargetAlpha) {
11060 // This is happening behind the activity UI,
11061 // so we can make it run a little longer to
11062 // give a stronger impression without disrupting
11063 // the user.
11064 duration *= DIM_DURATION_MULTIPLIER;
11065 }
11066 if (duration < 1) {
11067 // Don't divide by zero
11068 duration = 1;
11069 }
11070 mDimTargetAlpha = target;
11071 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11072 }
11073 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011074
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011075 /**
11076 * Updating the surface's alpha. Returns true if the animation continues, or returns
11077 * false when the animation is finished and the dim surface is hidden.
11078 */
11079 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11080 if (!dimming) {
11081 if (mDimTargetAlpha != 0) {
11082 mLastDimAnimTime = currentTime;
11083 mDimTargetAlpha = 0;
11084 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11085 }
11086 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011087
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011088 boolean animating = false;
11089 if (mLastDimAnimTime != 0) {
11090 mDimCurrentAlpha += mDimDeltaPerMs
11091 * (currentTime-mLastDimAnimTime);
11092 boolean more = true;
11093 if (displayFrozen) {
11094 // If the display is frozen, there is no reason to animate.
11095 more = false;
11096 } else if (mDimDeltaPerMs > 0) {
11097 if (mDimCurrentAlpha > mDimTargetAlpha) {
11098 more = false;
11099 }
11100 } else if (mDimDeltaPerMs < 0) {
11101 if (mDimCurrentAlpha < mDimTargetAlpha) {
11102 more = false;
11103 }
11104 } else {
11105 more = false;
11106 }
11107
11108 // Do we need to continue animating?
11109 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011110 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011111 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11112 mLastDimAnimTime = currentTime;
11113 mDimSurface.setAlpha(mDimCurrentAlpha);
11114 animating = true;
11115 } else {
11116 mDimCurrentAlpha = mDimTargetAlpha;
11117 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011118 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011119 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11120 mDimSurface.setAlpha(mDimCurrentAlpha);
11121 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011122 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011123 + ": HIDE");
11124 try {
11125 mDimSurface.hide();
11126 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011127 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011128 }
11129 mDimShown = false;
11130 }
11131 }
11132 }
11133 return animating;
11134 }
11135
11136 public void printTo(PrintWriter pw) {
11137 pw.print(" mDimShown="); pw.print(mDimShown);
11138 pw.print(" current="); pw.print(mDimCurrentAlpha);
11139 pw.print(" target="); pw.print(mDimTargetAlpha);
11140 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11141 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11142 }
11143 }
11144
11145 /**
11146 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11147 * This is used for opening/closing transition for apps in compatible mode.
11148 */
11149 private static class FadeInOutAnimation extends Animation {
11150 int mWidth;
11151 boolean mFadeIn;
11152
11153 public FadeInOutAnimation(boolean fadeIn) {
11154 setInterpolator(new AccelerateInterpolator());
11155 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11156 mFadeIn = fadeIn;
11157 }
11158
11159 @Override
11160 protected void applyTransformation(float interpolatedTime, Transformation t) {
11161 float x = interpolatedTime;
11162 if (!mFadeIn) {
11163 x = 1.0f - x; // reverse the interpolation for fade out
11164 }
11165 if (x < 0.5) {
11166 // move the window out of the screen.
11167 t.getMatrix().setTranslate(mWidth, 0);
11168 } else {
11169 t.getMatrix().setTranslate(0, 0);// show
11170 t.setAlpha((x - 0.5f) * 2);
11171 }
11172 }
11173
11174 @Override
11175 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11176 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11177 mWidth = width;
11178 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011179
11180 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011181 public int getZAdjustment() {
11182 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011183 }
11184 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011185}