blob: 30aed69f781ceeaf4d53921f3f8a9ab65093765b [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
20import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
21import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070022import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
24import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070025import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
Joe Onorato93056472010-09-10 10:30:46 -040026import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR;
28import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
29import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070030import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
32import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS;
34import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
35import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
36import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
37import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070038import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039
40import com.android.internal.app.IBatteryStats;
41import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080042import com.android.internal.policy.impl.PhoneWindowManager;
Christopher Tatea53146c2010-09-07 11:57:52 -070043import com.android.internal.view.BaseInputHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import com.android.internal.view.IInputContext;
45import com.android.internal.view.IInputMethodClient;
46import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080047import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import com.android.server.am.BatteryStatsService;
49
50import android.Manifest;
51import android.app.ActivityManagerNative;
52import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070053import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070054import android.content.BroadcastReceiver;
Christopher Tatea53146c2010-09-07 11:57:52 -070055import android.content.ClipData;
56import android.content.ClipDescription;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070058import android.content.Intent;
59import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.content.pm.ActivityInfo;
61import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070062import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import android.content.res.Configuration;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070064import android.graphics.Canvas;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065import android.graphics.Matrix;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070066import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import android.graphics.PixelFormat;
68import android.graphics.Rect;
69import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070070import android.graphics.Typeface;
71import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072import android.os.BatteryStats;
73import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070074import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075import android.os.Debug;
76import android.os.Handler;
77import android.os.IBinder;
78import android.os.LocalPowerManager;
79import android.os.Looper;
80import android.os.Message;
81import android.os.Parcel;
82import android.os.ParcelFileDescriptor;
83import android.os.Power;
84import android.os.PowerManager;
85import android.os.Process;
86import android.os.RemoteException;
87import android.os.ServiceManager;
88import android.os.SystemClock;
89import android.os.SystemProperties;
90import android.os.TokenWatcher;
91import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070092import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070094import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080095import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070097import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098import android.view.Display;
Christopher Tatea53146c2010-09-07 11:57:52 -070099import android.view.DragEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100import android.view.Gravity;
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700101import android.view.HapticFeedbackConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102import android.view.IApplicationToken;
103import android.view.IOnKeyguardExitResult;
104import android.view.IRotationWatcher;
105import android.view.IWindow;
106import android.view.IWindowManager;
107import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700108import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700109import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700110import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700111import android.view.InputHandler;
112import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113import android.view.KeyEvent;
114import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115import android.view.Surface;
116import android.view.SurfaceSession;
117import android.view.View;
118import android.view.ViewTreeObserver;
119import android.view.WindowManager;
120import android.view.WindowManagerImpl;
121import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700122import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700124import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125import android.view.animation.Animation;
126import android.view.animation.AnimationUtils;
127import android.view.animation.Transformation;
128
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700129import java.io.BufferedReader;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700131import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132import java.io.File;
133import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700134import java.io.FileInputStream;
135import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136import java.io.IOException;
137import java.io.OutputStream;
138import java.io.OutputStreamWriter;
139import java.io.PrintWriter;
140import java.io.StringWriter;
141import java.net.Socket;
142import java.util.ArrayList;
143import java.util.HashMap;
144import java.util.HashSet;
145import java.util.Iterator;
146import java.util.List;
147
148/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700149public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700150 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 static final String TAG = "WindowManager";
152 static final boolean DEBUG = false;
153 static final boolean DEBUG_FOCUS = false;
154 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800155 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800156 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 static final boolean DEBUG_LAYERS = false;
158 static final boolean DEBUG_INPUT = false;
159 static final boolean DEBUG_INPUT_METHOD = false;
160 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700161 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700163 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 static final boolean DEBUG_APP_TRANSITIONS = false;
165 static final boolean DEBUG_STARTING_WINDOW = false;
166 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700167 static final boolean DEBUG_WALLPAPER = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700168 static final boolean DEBUG_DRAG = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700170 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172 static final boolean PROFILE_ORIENTATION = false;
173 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700174 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 /** How much to multiply the policy's type layer, to reserve room
177 * for multiple windows of the same type and Z-ordering adjustment
178 * with TYPE_LAYER_OFFSET. */
179 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
182 * or below others in the same layer. */
183 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 /** How much to increment the layer for each window, to reserve room
186 * for effect surfaces between them.
187 */
188 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 /** The maximum length we will accept for a loaded animation duration:
191 * this is 10 seconds.
192 */
193 static final int MAX_ANIMATION_DURATION = 10*1000;
194
195 /** Amount of time (in milliseconds) to animate the dim surface from one
196 * value to another, when no window animation is driving it.
197 */
198 static final int DEFAULT_DIM_DURATION = 200;
199
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700200 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
201 * compatible windows.
202 */
203 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 /** Adjustment to time to perform a dim, to make it more dramatic.
206 */
207 static final int DIM_DURATION_MULTIPLIER = 6;
Jeff Brown7fbdc842010-06-17 20:52:56 -0700208
209 // Maximum number of milliseconds to wait for input event injection.
210 // FIXME is this value reasonable?
211 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700212
213 // Default input dispatching timeout in nanoseconds.
214 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 static final int UPDATE_FOCUS_NORMAL = 0;
217 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
218 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
219 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700222 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223
224 /**
225 * Condition waited on by {@link #reenableKeyguard} to know the call to
226 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500227 * This is set to true only if mKeyguardTokenWatcher.acquired() has
228 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500230 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231
Jim Miller284b62e2010-06-08 14:27:42 -0700232 private static final int ALLOW_DISABLE_YES = 1;
233 private static final int ALLOW_DISABLE_NO = 0;
234 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
235 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
236
Mike Lockwood983ee092009-11-22 01:42:24 -0500237 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
238 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700240 if (shouldAllowDisableKeyguard()) {
241 mPolicy.enableKeyguard(false);
242 mKeyguardDisabled = true;
243 } else {
244 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
245 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 }
247 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700248 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500249 synchronized (mKeyguardTokenWatcher) {
250 mKeyguardDisabled = false;
251 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252 }
253 }
254 };
255
Jim Miller284b62e2010-06-08 14:27:42 -0700256 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
257 @Override
258 public void onReceive(Context context, Intent intent) {
259 mPolicy.enableKeyguard(true);
260 synchronized(mKeyguardTokenWatcher) {
261 // lazily evaluate this next time we're asked to disable keyguard
262 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
263 mKeyguardDisabled = false;
264 }
265 }
266 };
267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 final Context mContext;
269
270 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
275
276 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280 /**
281 * All currently active sessions with clients.
282 */
283 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 /**
286 * Mapping from an IWindow IBinder to the server's Window object.
287 * This is also used as the lock for all of our state.
288 */
289 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
290
291 /**
292 * Mapping from a token IBinder to a WindowToken object.
293 */
294 final HashMap<IBinder, WindowToken> mTokenMap =
295 new HashMap<IBinder, WindowToken>();
296
297 /**
298 * The same tokens as mTokenMap, stored in a list for efficient iteration
299 * over them.
300 */
301 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800303 /**
304 * Window tokens that are in the process of exiting, but still
305 * on screen for animations.
306 */
307 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
308
309 /**
310 * Z-ordered (bottom-most first) list of all application tokens, for
311 * controlling the ordering of windows in different applications. This
312 * contains WindowToken objects.
313 */
314 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
315
316 /**
317 * Application tokens that are in the process of exiting, but still
318 * on screen for animations.
319 */
320 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
321
322 /**
323 * List of window tokens that have finished starting their application,
324 * and now need to have the policy remove their windows.
325 */
326 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
327
328 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700329 * This was the app token that was used to retrieve the last enter
330 * animation. It will be used for the next exit animation.
331 */
332 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800333
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700334 /**
335 * These were the layout params used to retrieve the last enter animation.
336 * They will be used for the next exit animation.
337 */
338 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800339
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700340 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 * Z-ordered (bottom-most first) list of all Window objects.
342 */
Jeff Browne33348b2010-07-15 23:54:05 -0700343 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344
345 /**
346 * Windows that are being resized. Used so we can tell the client about
347 * the resize after closing the transaction in which we resized the
348 * underlying surface.
349 */
350 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
351
352 /**
353 * Windows whose animations have ended and now must be removed.
354 */
355 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
356
357 /**
358 * Windows whose surface should be destroyed.
359 */
360 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
361
362 /**
363 * Windows that have lost input focus and are waiting for the new
364 * focus window to be displayed before they are told about this.
365 */
366 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
367
368 /**
369 * This is set when we have run out of memory, and will either be an empty
370 * list or contain windows that need to be force removed.
371 */
372 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700377 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 Surface mBlurSurface;
379 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700380 Watermark mWatermark;
Romain Guy06882f82009-06-10 13:36:04 -0700381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 final float[] mTmpFloats = new float[9];
385
386 boolean mSafeMode;
387 boolean mDisplayEnabled = false;
388 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700389 int mInitialDisplayWidth = 0;
390 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 int mRotation = 0;
392 int mRequestedRotation = 0;
393 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700394 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 ArrayList<IRotationWatcher> mRotationWatchers
396 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800398 boolean mLayoutNeeded = true;
399 boolean mAnimationPending = false;
400 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800401 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 boolean mWindowsFreezingScreen = false;
403 long mFreezeGcPending = 0;
404 int mAppsFreezingScreen = 0;
405
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800406 int mLayoutSeq = 0;
407
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800408 // State while inside of layoutAndPlaceSurfacesLocked().
409 boolean mFocusMayChange;
410
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800411 Configuration mCurConfiguration = new Configuration();
412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 // This is held as long as we have the screen frozen, to give us time to
414 // perform a rotation animation when turning off shows the lock screen which
415 // changes the orientation.
416 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418 // State management of app transitions. When we are preparing for a
419 // transition, mNextAppTransition will be the kind of transition to
420 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
421 // mOpeningApps and mClosingApps are the lists of tokens that will be
422 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700423 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700424 String mNextAppTransitionPackage;
425 int mNextAppTransitionEnter;
426 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700428 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 boolean mAppTransitionTimeout = false;
430 boolean mStartingIconInTransition = false;
431 boolean mSkipAppTransitionAnimation = false;
432 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
433 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700434 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
435 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 H mH = new H();
440
441 WindowState mCurrentFocus = null;
442 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 // This just indicates the window the input method is on top of, not
445 // necessarily the window its input is going to.
446 WindowState mInputMethodTarget = null;
447 WindowState mUpcomingInputMethodTarget = null;
448 boolean mInputMethodTargetWaitingAnim;
449 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 WindowState mInputMethodWindow = null;
452 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
453
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700454 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800455
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700456 // If non-null, this is the currently visible window that is associated
457 // with the wallpaper.
458 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700459 // If non-null, we are in the middle of animating from one wallpaper target
460 // to another, and this is the lower one in Z-order.
461 WindowState mLowerWallpaperTarget = null;
462 // If non-null, we are in the middle of animating from one wallpaper target
463 // to another, and this is the higher one in Z-order.
464 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700465 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700466 float mLastWallpaperX = -1;
467 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800468 float mLastWallpaperXStep = -1;
469 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700470 // This is set when we are waiting for a wallpaper to tell us it is done
471 // changing its scroll position.
472 WindowState mWaitingOnWallpaper;
473 // The last time we had a timeout when waiting for a wallpaper.
474 long mLastWallpaperTimeoutTime;
475 // We give a wallpaper up to 150ms to finish scrolling.
476 static final long WALLPAPER_TIMEOUT = 150;
477 // Time we wait after a timeout before trying to wait again.
478 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800480 AppWindowToken mFocusedApp = null;
481
482 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800484 float mWindowAnimationScale = 1.0f;
485 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700486
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700487 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488
489 // Who is holding the screen on.
490 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700491 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700492
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700493 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700496 * Drag/drop state
497 */
498 class DragState {
499 IBinder mToken;
500 Surface mSurface;
501 boolean mLocalOnly;
502 ClipData mData;
503 ClipDescription mDataDescription;
504 float mThumbOffsetX, mThumbOffsetY;
505 InputChannel mServerChannel, mClientChannel;
506 WindowState mTargetWindow;
507 ArrayList<WindowState> mNotifiedWindows;
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 Brown46b9ac0a2010-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 Brown46b9ac0a2010-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 Brown46b9ac0a2010-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 Brown46b9ac0a2010-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.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003390 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3391 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003392 return or;
3393 }
3394 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3395 }
3396 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003397 }
Romain Guy06882f82009-06-10 13:36:04 -07003398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003399 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003400 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003401 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3402 "updateOrientationFromAppTokens()")) {
3403 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3404 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003405
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003406 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003407 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003408
3409 synchronized(mWindowMap) {
3410 if (updateOrientationFromAppTokensLocked()) {
3411 if (freezeThisOneIfNeeded != null) {
3412 AppWindowToken wtoken = findAppWindowToken(
3413 freezeThisOneIfNeeded);
3414 if (wtoken != null) {
3415 startAppFreezingScreenLocked(wtoken,
3416 ActivityInfo.CONFIG_ORIENTATION);
3417 }
3418 }
3419 config = computeNewConfigurationLocked();
3420
3421 } else if (currentConfig != null) {
3422 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003423 // state mismatches the activity manager's, update it,
3424 // disregarding font scale, which should remain set to
3425 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003426 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003427 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003428 if (computeNewConfigurationLocked(mTempConfiguration)) {
3429 if (currentConfig.diff(mTempConfiguration) != 0) {
3430 mWaitingForConfig = true;
3431 mLayoutNeeded = true;
3432 startFreezingDisplayLocked();
3433 config = new Configuration(mTempConfiguration);
3434 }
3435 }
3436 }
3437 }
3438
Dianne Hackborncfaef692009-06-15 14:24:44 -07003439 Binder.restoreCallingIdentity(ident);
3440 return config;
3441 }
3442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003443 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003444 * Determine the new desired orientation of the display, returning
3445 * a non-null new Configuration if it has changed from the current
3446 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3447 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3448 * SCREEN. This will typically be done for you if you call
3449 * sendNewConfiguration().
3450 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003451 * The orientation is computed from non-application windows first. If none of
3452 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003453 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003454 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3455 * android.os.IBinder)
3456 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003457 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003458 if (mDisplayFrozen) {
3459 // If the display is frozen, some activities may be in the middle
3460 // of restarting, and thus have removed their old window. If the
3461 // window has the flag to hide the lock screen, then the lock screen
3462 // can re-appear and inflict its own orientation on us. Keep the
3463 // orientation stable until this all settles down.
3464 return false;
3465 }
3466
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003467 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003468 long ident = Binder.clearCallingIdentity();
3469 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003470 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003472 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003473 mForcedAppOrientation = req;
3474 //send a message to Policy indicating orientation change to take
3475 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003476 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003477 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3478 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3479 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003480 }
3481 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003482
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003483 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003484 } finally {
3485 Binder.restoreCallingIdentity(ident);
3486 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003487 }
Romain Guy06882f82009-06-10 13:36:04 -07003488
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003489 int computeForcedAppOrientationLocked() {
3490 int req = getOrientationFromWindowsLocked();
3491 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3492 req = getOrientationFromAppTokensLocked();
3493 }
3494 return req;
3495 }
Romain Guy06882f82009-06-10 13:36:04 -07003496
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003497 public void setNewConfiguration(Configuration config) {
3498 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3499 "setNewConfiguration()")) {
3500 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3501 }
3502
3503 synchronized(mWindowMap) {
3504 mCurConfiguration = new Configuration(config);
3505 mWaitingForConfig = false;
3506 performLayoutAndPlaceSurfacesLocked();
3507 }
3508 }
3509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003510 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3511 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3512 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003513 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003514 }
Romain Guy06882f82009-06-10 13:36:04 -07003515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003516 synchronized(mWindowMap) {
3517 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3518 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003519 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003520 return;
3521 }
Romain Guy06882f82009-06-10 13:36:04 -07003522
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003523 wtoken.requestedOrientation = requestedOrientation;
3524 }
3525 }
Romain Guy06882f82009-06-10 13:36:04 -07003526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003527 public int getAppOrientation(IApplicationToken token) {
3528 synchronized(mWindowMap) {
3529 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3530 if (wtoken == null) {
3531 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3532 }
Romain Guy06882f82009-06-10 13:36:04 -07003533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003534 return wtoken.requestedOrientation;
3535 }
3536 }
Romain Guy06882f82009-06-10 13:36:04 -07003537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003538 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3539 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3540 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003541 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003542 }
3543
3544 synchronized(mWindowMap) {
3545 boolean changed = false;
3546 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003547 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003548 changed = mFocusedApp != null;
3549 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003550 if (changed) {
3551 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003552 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003553 } else {
3554 AppWindowToken newFocus = findAppWindowToken(token);
3555 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003556 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003557 return;
3558 }
3559 changed = mFocusedApp != newFocus;
3560 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003561 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003562 if (changed) {
3563 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003564 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003565 }
3566
3567 if (moveFocusNow && changed) {
3568 final long origId = Binder.clearCallingIdentity();
3569 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3570 Binder.restoreCallingIdentity(origId);
3571 }
3572 }
3573 }
3574
3575 public void prepareAppTransition(int transit) {
3576 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3577 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003578 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003579 }
Romain Guy06882f82009-06-10 13:36:04 -07003580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003581 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003582 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003583 TAG, "Prepare app transition: transit=" + transit
3584 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003585 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003586 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3587 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003588 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003589 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3590 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3591 // Opening a new task always supersedes a close for the anim.
3592 mNextAppTransition = transit;
3593 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3594 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3595 // Opening a new activity always supersedes a close for the anim.
3596 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003597 }
3598 mAppTransitionReady = false;
3599 mAppTransitionTimeout = false;
3600 mStartingIconInTransition = false;
3601 mSkipAppTransitionAnimation = false;
3602 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3603 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3604 5000);
3605 }
3606 }
3607 }
3608
3609 public int getPendingAppTransition() {
3610 return mNextAppTransition;
3611 }
Romain Guy06882f82009-06-10 13:36:04 -07003612
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003613 public void overridePendingAppTransition(String packageName,
3614 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003615 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003616 mNextAppTransitionPackage = packageName;
3617 mNextAppTransitionEnter = enterAnim;
3618 mNextAppTransitionExit = exitAnim;
3619 }
3620 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003622 public void executeAppTransition() {
3623 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3624 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003625 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003626 }
Romain Guy06882f82009-06-10 13:36:04 -07003627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003628 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003629 if (DEBUG_APP_TRANSITIONS) {
3630 RuntimeException e = new RuntimeException("here");
3631 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003632 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003633 + mNextAppTransition, e);
3634 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003635 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003636 mAppTransitionReady = true;
3637 final long origId = Binder.clearCallingIdentity();
3638 performLayoutAndPlaceSurfacesLocked();
3639 Binder.restoreCallingIdentity(origId);
3640 }
3641 }
3642 }
3643
3644 public void setAppStartingWindow(IBinder token, String pkg,
3645 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3646 IBinder transferFrom, boolean createIfNeeded) {
3647 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3648 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003649 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003650 }
3651
3652 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003653 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003654 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3655 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003657 AppWindowToken wtoken = findAppWindowToken(token);
3658 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003659 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003660 return;
3661 }
3662
3663 // If the display is frozen, we won't do anything until the
3664 // actual window is displayed so there is no reason to put in
3665 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003666 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003667 return;
3668 }
Romain Guy06882f82009-06-10 13:36:04 -07003669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003670 if (wtoken.startingData != null) {
3671 return;
3672 }
Romain Guy06882f82009-06-10 13:36:04 -07003673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003674 if (transferFrom != null) {
3675 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3676 if (ttoken != null) {
3677 WindowState startingWindow = ttoken.startingWindow;
3678 if (startingWindow != null) {
3679 if (mStartingIconInTransition) {
3680 // In this case, the starting icon has already
3681 // been displayed, so start letting windows get
3682 // shown immediately without any more transitions.
3683 mSkipAppTransitionAnimation = true;
3684 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003685 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003686 "Moving existing starting from " + ttoken
3687 + " to " + wtoken);
3688 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003690 // Transfer the starting window over to the new
3691 // token.
3692 wtoken.startingData = ttoken.startingData;
3693 wtoken.startingView = ttoken.startingView;
3694 wtoken.startingWindow = startingWindow;
3695 ttoken.startingData = null;
3696 ttoken.startingView = null;
3697 ttoken.startingWindow = null;
3698 ttoken.startingMoved = true;
3699 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003700 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003701 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003702 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003703 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003704 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003705 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003706 ttoken.windows.remove(startingWindow);
3707 ttoken.allAppWindows.remove(startingWindow);
3708 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003710 // Propagate other interesting state between the
3711 // tokens. If the old token is displayed, we should
3712 // immediately force the new one to be displayed. If
3713 // it is animating, we need to move that animation to
3714 // the new one.
3715 if (ttoken.allDrawn) {
3716 wtoken.allDrawn = true;
3717 }
3718 if (ttoken.firstWindowDrawn) {
3719 wtoken.firstWindowDrawn = true;
3720 }
3721 if (!ttoken.hidden) {
3722 wtoken.hidden = false;
3723 wtoken.hiddenRequested = false;
3724 wtoken.willBeHidden = false;
3725 }
3726 if (wtoken.clientHidden != ttoken.clientHidden) {
3727 wtoken.clientHidden = ttoken.clientHidden;
3728 wtoken.sendAppVisibilityToClients();
3729 }
3730 if (ttoken.animation != null) {
3731 wtoken.animation = ttoken.animation;
3732 wtoken.animating = ttoken.animating;
3733 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3734 ttoken.animation = null;
3735 ttoken.animLayerAdjustment = 0;
3736 wtoken.updateLayers();
3737 ttoken.updateLayers();
3738 }
Romain Guy06882f82009-06-10 13:36:04 -07003739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003740 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003741 mLayoutNeeded = true;
3742 performLayoutAndPlaceSurfacesLocked();
3743 Binder.restoreCallingIdentity(origId);
3744 return;
3745 } else if (ttoken.startingData != null) {
3746 // The previous app was getting ready to show a
3747 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003748 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003749 "Moving pending starting from " + ttoken
3750 + " to " + wtoken);
3751 wtoken.startingData = ttoken.startingData;
3752 ttoken.startingData = null;
3753 ttoken.startingMoved = true;
3754 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3755 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3756 // want to process the message ASAP, before any other queued
3757 // messages.
3758 mH.sendMessageAtFrontOfQueue(m);
3759 return;
3760 }
3761 }
3762 }
3763
3764 // There is no existing starting window, and the caller doesn't
3765 // want us to create one, so that's it!
3766 if (!createIfNeeded) {
3767 return;
3768 }
Romain Guy06882f82009-06-10 13:36:04 -07003769
Dianne Hackborn284ac932009-08-28 10:34:25 -07003770 // If this is a translucent or wallpaper window, then don't
3771 // show a starting window -- the current effect (a full-screen
3772 // opaque starting window that fades away to the real contents
3773 // when it is ready) does not work for this.
3774 if (theme != 0) {
3775 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3776 com.android.internal.R.styleable.Window);
3777 if (ent.array.getBoolean(
3778 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3779 return;
3780 }
3781 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003782 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3783 return;
3784 }
3785 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003786 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3787 return;
3788 }
3789 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003791 mStartingIconInTransition = true;
3792 wtoken.startingData = new StartingData(
3793 pkg, theme, nonLocalizedLabel,
3794 labelRes, icon);
3795 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3796 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3797 // want to process the message ASAP, before any other queued
3798 // messages.
3799 mH.sendMessageAtFrontOfQueue(m);
3800 }
3801 }
3802
3803 public void setAppWillBeHidden(IBinder token) {
3804 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3805 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003806 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003807 }
3808
3809 AppWindowToken wtoken;
3810
3811 synchronized(mWindowMap) {
3812 wtoken = findAppWindowToken(token);
3813 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003814 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 -08003815 return;
3816 }
3817 wtoken.willBeHidden = true;
3818 }
3819 }
Romain Guy06882f82009-06-10 13:36:04 -07003820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003821 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3822 boolean visible, int transit, boolean performLayout) {
3823 boolean delayed = false;
3824
3825 if (wtoken.clientHidden == visible) {
3826 wtoken.clientHidden = !visible;
3827 wtoken.sendAppVisibilityToClients();
3828 }
Romain Guy06882f82009-06-10 13:36:04 -07003829
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003830 wtoken.willBeHidden = false;
3831 if (wtoken.hidden == visible) {
3832 final int N = wtoken.allAppWindows.size();
3833 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003834 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003835 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3836 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003838 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003839
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003840 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003841 if (wtoken.animation == sDummyAnimation) {
3842 wtoken.animation = null;
3843 }
3844 applyAnimationLocked(wtoken, lp, transit, visible);
3845 changed = true;
3846 if (wtoken.animation != null) {
3847 delayed = runningAppAnimation = true;
3848 }
3849 }
Romain Guy06882f82009-06-10 13:36:04 -07003850
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003851 for (int i=0; i<N; i++) {
3852 WindowState win = wtoken.allAppWindows.get(i);
3853 if (win == wtoken.startingWindow) {
3854 continue;
3855 }
3856
3857 if (win.isAnimating()) {
3858 delayed = true;
3859 }
Romain Guy06882f82009-06-10 13:36:04 -07003860
Joe Onorato8a9b2202010-02-26 18:56:32 -08003861 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003862 //win.dump(" ");
3863 if (visible) {
3864 if (!win.isVisibleNow()) {
3865 if (!runningAppAnimation) {
3866 applyAnimationLocked(win,
3867 WindowManagerPolicy.TRANSIT_ENTER, true);
3868 }
3869 changed = true;
3870 }
3871 } else if (win.isVisibleNow()) {
3872 if (!runningAppAnimation) {
3873 applyAnimationLocked(win,
3874 WindowManagerPolicy.TRANSIT_EXIT, false);
3875 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003876 changed = true;
3877 }
3878 }
3879
3880 wtoken.hidden = wtoken.hiddenRequested = !visible;
3881 if (!visible) {
3882 unsetAppFreezingScreenLocked(wtoken, true, true);
3883 } else {
3884 // If we are being set visible, and the starting window is
3885 // not yet displayed, then make sure it doesn't get displayed.
3886 WindowState swin = wtoken.startingWindow;
3887 if (swin != null && (swin.mDrawPending
3888 || swin.mCommitDrawPending)) {
3889 swin.mPolicyVisibility = false;
3890 swin.mPolicyVisibilityAfterAnim = false;
3891 }
3892 }
Romain Guy06882f82009-06-10 13:36:04 -07003893
Joe Onorato8a9b2202010-02-26 18:56:32 -08003894 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003895 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3896 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003897
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003898 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003899 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003900 if (performLayout) {
3901 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3902 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003903 } else {
3904 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003905 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003906 }
3907 }
3908
3909 if (wtoken.animation != null) {
3910 delayed = true;
3911 }
Romain Guy06882f82009-06-10 13:36:04 -07003912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003913 return delayed;
3914 }
3915
3916 public void setAppVisibility(IBinder token, boolean visible) {
3917 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3918 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003919 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003920 }
3921
3922 AppWindowToken wtoken;
3923
3924 synchronized(mWindowMap) {
3925 wtoken = findAppWindowToken(token);
3926 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003927 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003928 return;
3929 }
3930
3931 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003932 RuntimeException e = null;
3933 if (!HIDE_STACK_CRAWLS) {
3934 e = new RuntimeException();
3935 e.fillInStackTrace();
3936 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003937 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003938 + "): mNextAppTransition=" + mNextAppTransition
3939 + " hidden=" + wtoken.hidden
3940 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3941 }
Romain Guy06882f82009-06-10 13:36:04 -07003942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003943 // If we are preparing an app transition, then delay changing
3944 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003945 if (!mDisplayFrozen && mPolicy.isScreenOn()
3946 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003947 // Already in requested state, don't do anything more.
3948 if (wtoken.hiddenRequested != visible) {
3949 return;
3950 }
3951 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003952
Joe Onorato8a9b2202010-02-26 18:56:32 -08003953 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003954 TAG, "Setting dummy animation on: " + wtoken);
3955 wtoken.setDummyAnimation();
3956 mOpeningApps.remove(wtoken);
3957 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003958 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003959 wtoken.inPendingTransaction = true;
3960 if (visible) {
3961 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003962 wtoken.startingDisplayed = false;
3963 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003964
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003965 // If the token is currently hidden (should be the
3966 // common case), then we need to set up to wait for
3967 // its windows to be ready.
3968 if (wtoken.hidden) {
3969 wtoken.allDrawn = false;
3970 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003971
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003972 if (wtoken.clientHidden) {
3973 // In the case where we are making an app visible
3974 // but holding off for a transition, we still need
3975 // to tell the client to make its windows visible so
3976 // they get drawn. Otherwise, we will wait on
3977 // performing the transition until all windows have
3978 // been drawn, they never will be, and we are sad.
3979 wtoken.clientHidden = false;
3980 wtoken.sendAppVisibilityToClients();
3981 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003982 }
3983 } else {
3984 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003985
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003986 // If the token is currently visible (should be the
3987 // common case), then set up to wait for it to be hidden.
3988 if (!wtoken.hidden) {
3989 wtoken.waitingToHide = true;
3990 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003991 }
3992 return;
3993 }
Romain Guy06882f82009-06-10 13:36:04 -07003994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003995 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003996 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003997 wtoken.updateReportedVisibilityLocked();
3998 Binder.restoreCallingIdentity(origId);
3999 }
4000 }
4001
4002 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4003 boolean unfreezeSurfaceNow, boolean force) {
4004 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004005 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004006 + " force=" + force);
4007 final int N = wtoken.allAppWindows.size();
4008 boolean unfrozeWindows = false;
4009 for (int i=0; i<N; i++) {
4010 WindowState w = wtoken.allAppWindows.get(i);
4011 if (w.mAppFreezing) {
4012 w.mAppFreezing = false;
4013 if (w.mSurface != null && !w.mOrientationChanging) {
4014 w.mOrientationChanging = true;
4015 }
4016 unfrozeWindows = true;
4017 }
4018 }
4019 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004020 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004021 wtoken.freezingScreen = false;
4022 mAppsFreezingScreen--;
4023 }
4024 if (unfreezeSurfaceNow) {
4025 if (unfrozeWindows) {
4026 mLayoutNeeded = true;
4027 performLayoutAndPlaceSurfacesLocked();
4028 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004029 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004030 }
4031 }
4032 }
Romain Guy06882f82009-06-10 13:36:04 -07004033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004034 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4035 int configChanges) {
4036 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004037 RuntimeException e = null;
4038 if (!HIDE_STACK_CRAWLS) {
4039 e = new RuntimeException();
4040 e.fillInStackTrace();
4041 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004042 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004043 + ": hidden=" + wtoken.hidden + " freezing="
4044 + wtoken.freezingScreen, e);
4045 }
4046 if (!wtoken.hiddenRequested) {
4047 if (!wtoken.freezingScreen) {
4048 wtoken.freezingScreen = true;
4049 mAppsFreezingScreen++;
4050 if (mAppsFreezingScreen == 1) {
4051 startFreezingDisplayLocked();
4052 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4053 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4054 5000);
4055 }
4056 }
4057 final int N = wtoken.allAppWindows.size();
4058 for (int i=0; i<N; i++) {
4059 WindowState w = wtoken.allAppWindows.get(i);
4060 w.mAppFreezing = true;
4061 }
4062 }
4063 }
Romain Guy06882f82009-06-10 13:36:04 -07004064
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004065 public void startAppFreezingScreen(IBinder token, int configChanges) {
4066 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4067 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004068 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004069 }
4070
4071 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004072 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004073 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004074 return;
4075 }
Romain Guy06882f82009-06-10 13:36:04 -07004076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004077 AppWindowToken wtoken = findAppWindowToken(token);
4078 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004079 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004080 return;
4081 }
4082 final long origId = Binder.clearCallingIdentity();
4083 startAppFreezingScreenLocked(wtoken, configChanges);
4084 Binder.restoreCallingIdentity(origId);
4085 }
4086 }
Romain Guy06882f82009-06-10 13:36:04 -07004087
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004088 public void stopAppFreezingScreen(IBinder token, boolean force) {
4089 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4090 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004091 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004092 }
4093
4094 synchronized(mWindowMap) {
4095 AppWindowToken wtoken = findAppWindowToken(token);
4096 if (wtoken == null || wtoken.appToken == null) {
4097 return;
4098 }
4099 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004100 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004101 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4102 unsetAppFreezingScreenLocked(wtoken, true, force);
4103 Binder.restoreCallingIdentity(origId);
4104 }
4105 }
Romain Guy06882f82009-06-10 13:36:04 -07004106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004107 public void removeAppToken(IBinder token) {
4108 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4109 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004110 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004111 }
4112
4113 AppWindowToken wtoken = null;
4114 AppWindowToken startingToken = null;
4115 boolean delayed = false;
4116
4117 final long origId = Binder.clearCallingIdentity();
4118 synchronized(mWindowMap) {
4119 WindowToken basewtoken = mTokenMap.remove(token);
4120 mTokenList.remove(basewtoken);
4121 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004122 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004123 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004124 wtoken.inPendingTransaction = false;
4125 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004126 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004127 if (mClosingApps.contains(wtoken)) {
4128 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004129 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004130 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004131 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004132 delayed = true;
4133 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004134 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004135 TAG, "Removing app " + wtoken + " delayed=" + delayed
4136 + " animation=" + wtoken.animation
4137 + " animating=" + wtoken.animating);
4138 if (delayed) {
4139 // set the token aside because it has an active animation to be finished
4140 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004141 } else {
4142 // Make sure there is no animation running on this token,
4143 // so any windows associated with it will be removed as
4144 // soon as their animations are complete
4145 wtoken.animation = null;
4146 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004147 }
4148 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07004149 if (mLastEnterAnimToken == wtoken) {
4150 mLastEnterAnimToken = null;
4151 mLastEnterAnimParams = null;
4152 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004153 wtoken.removed = true;
4154 if (wtoken.startingData != null) {
4155 startingToken = wtoken;
4156 }
4157 unsetAppFreezingScreenLocked(wtoken, true, true);
4158 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004159 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004160 mFocusedApp = null;
4161 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004162 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004163 }
4164 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004165 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004166 }
Romain Guy06882f82009-06-10 13:36:04 -07004167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004168 if (!delayed && wtoken != null) {
4169 wtoken.updateReportedVisibilityLocked();
4170 }
4171 }
4172 Binder.restoreCallingIdentity(origId);
4173
4174 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004175 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004176 + startingToken + ": app token removed");
4177 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4178 mH.sendMessage(m);
4179 }
4180 }
4181
4182 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4183 final int NW = token.windows.size();
4184 for (int i=0; i<NW; i++) {
4185 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004186 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004187 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004188 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004189 int j = win.mChildWindows.size();
4190 while (j > 0) {
4191 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004192 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004193 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004194 "Tmp removing child window " + cwin);
4195 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004196 }
4197 }
4198 return NW > 0;
4199 }
4200
4201 void dumpAppTokensLocked() {
4202 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004203 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004204 }
4205 }
Romain Guy06882f82009-06-10 13:36:04 -07004206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004207 void dumpWindowsLocked() {
4208 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004209 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004210 }
4211 }
Romain Guy06882f82009-06-10 13:36:04 -07004212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004213 private int findWindowOffsetLocked(int tokenPos) {
4214 final int NW = mWindows.size();
4215
4216 if (tokenPos >= mAppTokens.size()) {
4217 int i = NW;
4218 while (i > 0) {
4219 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004220 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004221 if (win.getAppToken() != null) {
4222 return i+1;
4223 }
4224 }
4225 }
4226
4227 while (tokenPos > 0) {
4228 // Find the first app token below the new position that has
4229 // a window displayed.
4230 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004231 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004232 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004233 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004234 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004235 "Skipping token -- currently sending to bottom");
4236 tokenPos--;
4237 continue;
4238 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004239 int i = wtoken.windows.size();
4240 while (i > 0) {
4241 i--;
4242 WindowState win = wtoken.windows.get(i);
4243 int j = win.mChildWindows.size();
4244 while (j > 0) {
4245 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004246 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004247 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004248 for (int pos=NW-1; pos>=0; pos--) {
4249 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004250 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004251 "Found child win @" + (pos+1));
4252 return pos+1;
4253 }
4254 }
4255 }
4256 }
4257 for (int pos=NW-1; pos>=0; pos--) {
4258 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004259 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004260 return pos+1;
4261 }
4262 }
4263 }
4264 tokenPos--;
4265 }
4266
4267 return 0;
4268 }
4269
4270 private final int reAddWindowLocked(int index, WindowState win) {
4271 final int NCW = win.mChildWindows.size();
4272 boolean added = false;
4273 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004274 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004275 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004276 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004277 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004278 mWindows.add(index, win);
4279 index++;
4280 added = true;
4281 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004282 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004283 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004284 mWindows.add(index, cwin);
4285 index++;
4286 }
4287 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004288 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004289 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004290 mWindows.add(index, win);
4291 index++;
4292 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004293 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004294 return index;
4295 }
Romain Guy06882f82009-06-10 13:36:04 -07004296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004297 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4298 final int NW = token.windows.size();
4299 for (int i=0; i<NW; i++) {
4300 index = reAddWindowLocked(index, token.windows.get(i));
4301 }
4302 return index;
4303 }
4304
4305 public void moveAppToken(int index, IBinder token) {
4306 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4307 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004308 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004309 }
4310
4311 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004312 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004313 if (DEBUG_REORDER) dumpAppTokensLocked();
4314 final AppWindowToken wtoken = findAppWindowToken(token);
4315 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004316 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004317 + token + " (" + wtoken + ")");
4318 return;
4319 }
4320 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004321 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004322 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004324 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004325 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004326 if (DEBUG_REORDER) dumpWindowsLocked();
4327 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004328 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004329 if (DEBUG_REORDER) dumpWindowsLocked();
4330 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004331 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004332 if (DEBUG_REORDER) dumpWindowsLocked();
4333 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004334 mLayoutNeeded = true;
4335 performLayoutAndPlaceSurfacesLocked();
4336 }
4337 Binder.restoreCallingIdentity(origId);
4338 }
4339 }
4340
4341 private void removeAppTokensLocked(List<IBinder> tokens) {
4342 // XXX This should be done more efficiently!
4343 // (take advantage of the fact that both lists should be
4344 // ordered in the same way.)
4345 int N = tokens.size();
4346 for (int i=0; i<N; i++) {
4347 IBinder token = tokens.get(i);
4348 final AppWindowToken wtoken = findAppWindowToken(token);
4349 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004350 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004351 + token + " (" + wtoken + ")");
4352 i--;
4353 N--;
4354 }
4355 }
4356 }
4357
Dianne Hackborna8f60182009-09-01 19:01:50 -07004358 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4359 boolean updateFocusAndLayout) {
4360 // First remove all of the windows from the list.
4361 tmpRemoveAppWindowsLocked(wtoken);
4362
4363 // Where to start adding?
4364 int pos = findWindowOffsetLocked(tokenPos);
4365
4366 // And now add them back at the correct place.
4367 pos = reAddAppWindowsLocked(pos, wtoken);
4368
4369 if (updateFocusAndLayout) {
4370 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4371 assignLayersLocked();
4372 }
4373 mLayoutNeeded = true;
4374 performLayoutAndPlaceSurfacesLocked();
4375 }
4376 }
4377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004378 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4379 // First remove all of the windows from the list.
4380 final int N = tokens.size();
4381 int i;
4382 for (i=0; i<N; i++) {
4383 WindowToken token = mTokenMap.get(tokens.get(i));
4384 if (token != null) {
4385 tmpRemoveAppWindowsLocked(token);
4386 }
4387 }
4388
4389 // Where to start adding?
4390 int pos = findWindowOffsetLocked(tokenPos);
4391
4392 // And now add them back at the correct place.
4393 for (i=0; i<N; i++) {
4394 WindowToken token = mTokenMap.get(tokens.get(i));
4395 if (token != null) {
4396 pos = reAddAppWindowsLocked(pos, token);
4397 }
4398 }
4399
Dianne Hackborna8f60182009-09-01 19:01:50 -07004400 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4401 assignLayersLocked();
4402 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004403 mLayoutNeeded = true;
4404 performLayoutAndPlaceSurfacesLocked();
4405
4406 //dump();
4407 }
4408
4409 public void moveAppTokensToTop(List<IBinder> tokens) {
4410 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4411 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004412 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004413 }
4414
4415 final long origId = Binder.clearCallingIdentity();
4416 synchronized(mWindowMap) {
4417 removeAppTokensLocked(tokens);
4418 final int N = tokens.size();
4419 for (int i=0; i<N; i++) {
4420 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4421 if (wt != null) {
4422 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004423 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004424 mToTopApps.remove(wt);
4425 mToBottomApps.remove(wt);
4426 mToTopApps.add(wt);
4427 wt.sendingToBottom = false;
4428 wt.sendingToTop = true;
4429 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004430 }
4431 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004432
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004433 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004434 moveAppWindowsLocked(tokens, mAppTokens.size());
4435 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004436 }
4437 Binder.restoreCallingIdentity(origId);
4438 }
4439
4440 public void moveAppTokensToBottom(List<IBinder> tokens) {
4441 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4442 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004443 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004444 }
4445
4446 final long origId = Binder.clearCallingIdentity();
4447 synchronized(mWindowMap) {
4448 removeAppTokensLocked(tokens);
4449 final int N = tokens.size();
4450 int pos = 0;
4451 for (int i=0; i<N; i++) {
4452 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4453 if (wt != null) {
4454 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004455 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004456 mToTopApps.remove(wt);
4457 mToBottomApps.remove(wt);
4458 mToBottomApps.add(i, wt);
4459 wt.sendingToTop = false;
4460 wt.sendingToBottom = true;
4461 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004462 pos++;
4463 }
4464 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004465
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004466 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004467 moveAppWindowsLocked(tokens, 0);
4468 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004469 }
4470 Binder.restoreCallingIdentity(origId);
4471 }
4472
4473 // -------------------------------------------------------------
4474 // Misc IWindowSession methods
4475 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004476
Jim Miller284b62e2010-06-08 14:27:42 -07004477 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004478 {
Jim Miller284b62e2010-06-08 14:27:42 -07004479 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4480 // called before DevicePolicyManagerService has started.
4481 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4482 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4483 Context.DEVICE_POLICY_SERVICE);
4484 if (dpm != null) {
4485 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4486 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4487 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4488 }
Jim Millerd6b57052010-06-07 17:52:42 -07004489 }
Jim Miller284b62e2010-06-08 14:27:42 -07004490 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004491 }
4492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004493 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004494 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004495 != PackageManager.PERMISSION_GRANTED) {
4496 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4497 }
Jim Millerd6b57052010-06-07 17:52:42 -07004498
Jim Miller284b62e2010-06-08 14:27:42 -07004499 synchronized (mKeyguardTokenWatcher) {
4500 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004501 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004502 }
4503
4504 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004505 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004506 != PackageManager.PERMISSION_GRANTED) {
4507 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4508 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004509
Jim Miller284b62e2010-06-08 14:27:42 -07004510 synchronized (mKeyguardTokenWatcher) {
4511 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004512
Jim Miller284b62e2010-06-08 14:27:42 -07004513 if (!mKeyguardTokenWatcher.isAcquired()) {
4514 // If we are the last one to reenable the keyguard wait until
4515 // we have actually finished reenabling until returning.
4516 // It is possible that reenableKeyguard() can be called before
4517 // the previous disableKeyguard() is handled, in which case
4518 // neither mKeyguardTokenWatcher.acquired() or released() would
4519 // be called. In that case mKeyguardDisabled will be false here
4520 // and we have nothing to wait for.
4521 while (mKeyguardDisabled) {
4522 try {
4523 mKeyguardTokenWatcher.wait();
4524 } catch (InterruptedException e) {
4525 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004526 }
4527 }
4528 }
4529 }
4530 }
4531
4532 /**
4533 * @see android.app.KeyguardManager#exitKeyguardSecurely
4534 */
4535 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004536 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004537 != PackageManager.PERMISSION_GRANTED) {
4538 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4539 }
4540 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4541 public void onKeyguardExitResult(boolean success) {
4542 try {
4543 callback.onKeyguardExitResult(success);
4544 } catch (RemoteException e) {
4545 // Client has died, we don't care.
4546 }
4547 }
4548 });
4549 }
4550
4551 public boolean inKeyguardRestrictedInputMode() {
4552 return mPolicy.inKeyguardRestrictedKeyInputMode();
4553 }
Romain Guy06882f82009-06-10 13:36:04 -07004554
Dianne Hackbornffa42482009-09-23 22:20:11 -07004555 public void closeSystemDialogs(String reason) {
4556 synchronized(mWindowMap) {
4557 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004558 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004559 if (w.mSurface != null) {
4560 try {
4561 w.mClient.closeSystemDialogs(reason);
4562 } catch (RemoteException e) {
4563 }
4564 }
4565 }
4566 }
4567 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004569 static float fixScale(float scale) {
4570 if (scale < 0) scale = 0;
4571 else if (scale > 20) scale = 20;
4572 return Math.abs(scale);
4573 }
Romain Guy06882f82009-06-10 13:36:04 -07004574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004575 public void setAnimationScale(int which, float scale) {
4576 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4577 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004578 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004579 }
4580
4581 if (scale < 0) scale = 0;
4582 else if (scale > 20) scale = 20;
4583 scale = Math.abs(scale);
4584 switch (which) {
4585 case 0: mWindowAnimationScale = fixScale(scale); break;
4586 case 1: mTransitionAnimationScale = fixScale(scale); break;
4587 }
Romain Guy06882f82009-06-10 13:36:04 -07004588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004589 // Persist setting
4590 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4591 }
Romain Guy06882f82009-06-10 13:36:04 -07004592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004593 public void setAnimationScales(float[] scales) {
4594 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4595 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004596 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004597 }
4598
4599 if (scales != null) {
4600 if (scales.length >= 1) {
4601 mWindowAnimationScale = fixScale(scales[0]);
4602 }
4603 if (scales.length >= 2) {
4604 mTransitionAnimationScale = fixScale(scales[1]);
4605 }
4606 }
Romain Guy06882f82009-06-10 13:36:04 -07004607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004608 // Persist setting
4609 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4610 }
Romain Guy06882f82009-06-10 13:36:04 -07004611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004612 public float getAnimationScale(int which) {
4613 switch (which) {
4614 case 0: return mWindowAnimationScale;
4615 case 1: return mTransitionAnimationScale;
4616 }
4617 return 0;
4618 }
Romain Guy06882f82009-06-10 13:36:04 -07004619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004620 public float[] getAnimationScales() {
4621 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4622 }
Romain Guy06882f82009-06-10 13:36:04 -07004623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004624 public int getSwitchState(int sw) {
4625 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4626 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004627 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004628 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004629 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004630 }
Romain Guy06882f82009-06-10 13:36:04 -07004631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004632 public int getSwitchStateForDevice(int devid, int sw) {
4633 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4634 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004635 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004636 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004637 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004638 }
Romain Guy06882f82009-06-10 13:36:04 -07004639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004640 public int getScancodeState(int sw) {
4641 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4642 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004643 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004644 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004645 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004646 }
Romain Guy06882f82009-06-10 13:36:04 -07004647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004648 public int getScancodeStateForDevice(int devid, int sw) {
4649 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4650 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004651 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004652 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004653 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004654 }
Romain Guy06882f82009-06-10 13:36:04 -07004655
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004656 public int getTrackballScancodeState(int sw) {
4657 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4658 "getTrackballScancodeState()")) {
4659 throw new SecurityException("Requires READ_INPUT_STATE permission");
4660 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004661 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004662 }
4663
4664 public int getDPadScancodeState(int sw) {
4665 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4666 "getDPadScancodeState()")) {
4667 throw new SecurityException("Requires READ_INPUT_STATE permission");
4668 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004669 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004670 }
4671
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004672 public int getKeycodeState(int sw) {
4673 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4674 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004675 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004676 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004677 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004678 }
Romain Guy06882f82009-06-10 13:36:04 -07004679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004680 public int getKeycodeStateForDevice(int devid, int sw) {
4681 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4682 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004683 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004684 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004685 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004686 }
Romain Guy06882f82009-06-10 13:36:04 -07004687
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004688 public int getTrackballKeycodeState(int sw) {
4689 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4690 "getTrackballKeycodeState()")) {
4691 throw new SecurityException("Requires READ_INPUT_STATE permission");
4692 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004693 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004694 }
4695
4696 public int getDPadKeycodeState(int sw) {
4697 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4698 "getDPadKeycodeState()")) {
4699 throw new SecurityException("Requires READ_INPUT_STATE permission");
4700 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004701 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004702 }
Jeff Browna41ca772010-08-11 14:46:32 -07004703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004704 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004705 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004706 }
Romain Guy06882f82009-06-10 13:36:04 -07004707
Jeff Browna41ca772010-08-11 14:46:32 -07004708 public InputChannel monitorInput(String inputChannelName) {
4709 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4710 "monitorInput()")) {
4711 throw new SecurityException("Requires READ_INPUT_STATE permission");
4712 }
4713 return mInputManager.monitorInput(inputChannelName);
4714 }
4715
Jeff Brown8d608662010-08-30 03:02:23 -07004716 public InputDevice getInputDevice(int deviceId) {
4717 return mInputManager.getInputDevice(deviceId);
4718 }
4719
4720 public int[] getInputDeviceIds() {
4721 return mInputManager.getInputDeviceIds();
4722 }
4723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004724 public void enableScreenAfterBoot() {
4725 synchronized(mWindowMap) {
4726 if (mSystemBooted) {
4727 return;
4728 }
4729 mSystemBooted = true;
4730 }
Romain Guy06882f82009-06-10 13:36:04 -07004731
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004732 performEnableScreen();
4733 }
Romain Guy06882f82009-06-10 13:36:04 -07004734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004735 public void enableScreenIfNeededLocked() {
4736 if (mDisplayEnabled) {
4737 return;
4738 }
4739 if (!mSystemBooted) {
4740 return;
4741 }
4742 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4743 }
Romain Guy06882f82009-06-10 13:36:04 -07004744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004745 public void performEnableScreen() {
4746 synchronized(mWindowMap) {
4747 if (mDisplayEnabled) {
4748 return;
4749 }
4750 if (!mSystemBooted) {
4751 return;
4752 }
Romain Guy06882f82009-06-10 13:36:04 -07004753
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004754 // Don't enable the screen until all existing windows
4755 // have been drawn.
4756 final int N = mWindows.size();
4757 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004758 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004759 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004760 return;
4761 }
4762 }
Romain Guy06882f82009-06-10 13:36:04 -07004763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004764 mDisplayEnabled = true;
4765 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004766 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004767 StringWriter sw = new StringWriter();
4768 PrintWriter pw = new PrintWriter(sw);
4769 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004770 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004771 }
4772 try {
4773 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4774 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004775 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004776 Parcel data = Parcel.obtain();
4777 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4778 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4779 data, null, 0);
4780 data.recycle();
4781 }
4782 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004783 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004784 }
4785 }
Romain Guy06882f82009-06-10 13:36:04 -07004786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004787 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004789 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004790 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4791 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004792 }
Romain Guy06882f82009-06-10 13:36:04 -07004793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004794 public void setInTouchMode(boolean mode) {
4795 synchronized(mWindowMap) {
4796 mInTouchMode = mode;
4797 }
4798 }
4799
Romain Guy06882f82009-06-10 13:36:04 -07004800 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004801 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004802 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004803 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004804 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004805 }
4806
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004807 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004808 }
Romain Guy06882f82009-06-10 13:36:04 -07004809
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004810 public void setRotationUnchecked(int rotation,
4811 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004812 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004813 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004814
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004815 long origId = Binder.clearCallingIdentity();
4816 boolean changed;
4817 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004818 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004819 }
Romain Guy06882f82009-06-10 13:36:04 -07004820
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004821 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004822 sendNewConfiguration();
4823 }
Romain Guy06882f82009-06-10 13:36:04 -07004824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004825 Binder.restoreCallingIdentity(origId);
4826 }
Romain Guy06882f82009-06-10 13:36:04 -07004827
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004828 /**
4829 * Apply a new rotation to the screen, respecting the requests of
4830 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4831 * re-evaluate the desired rotation.
4832 *
4833 * Returns null if the rotation has been changed. In this case YOU
4834 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4835 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004836 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004837 boolean changed;
4838 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4839 rotation = mRequestedRotation;
4840 } else {
4841 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004842 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004843 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004844 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004845 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004846 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004847 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004848 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004849
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004850 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004851 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004852 "Rotation changed to " + rotation
4853 + " from " + mRotation
4854 + " (forceApp=" + mForcedAppOrientation
4855 + ", req=" + mRequestedRotation + ")");
4856 mRotation = rotation;
4857 mWindowsFreezingScreen = true;
4858 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4859 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4860 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004861 mWaitingForConfig = true;
4862 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004863 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004864 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004865 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004866 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004867 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004868 }
4869 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004870 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004871 if (w.mSurface != null) {
4872 w.mOrientationChanging = true;
4873 }
4874 }
4875 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4876 try {
4877 mRotationWatchers.get(i).onRotationChanged(rotation);
4878 } catch (RemoteException e) {
4879 }
4880 }
4881 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004883 return changed;
4884 }
Romain Guy06882f82009-06-10 13:36:04 -07004885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004886 public int getRotation() {
4887 return mRotation;
4888 }
4889
4890 public int watchRotation(IRotationWatcher watcher) {
4891 final IBinder watcherBinder = watcher.asBinder();
4892 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4893 public void binderDied() {
4894 synchronized (mWindowMap) {
4895 for (int i=0; i<mRotationWatchers.size(); i++) {
4896 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004897 IRotationWatcher removed = mRotationWatchers.remove(i);
4898 if (removed != null) {
4899 removed.asBinder().unlinkToDeath(this, 0);
4900 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004901 i--;
4902 }
4903 }
4904 }
4905 }
4906 };
Romain Guy06882f82009-06-10 13:36:04 -07004907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004908 synchronized (mWindowMap) {
4909 try {
4910 watcher.asBinder().linkToDeath(dr, 0);
4911 mRotationWatchers.add(watcher);
4912 } catch (RemoteException e) {
4913 // Client died, no cleanup needed.
4914 }
Romain Guy06882f82009-06-10 13:36:04 -07004915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004916 return mRotation;
4917 }
4918 }
4919
4920 /**
4921 * Starts the view server on the specified port.
4922 *
4923 * @param port The port to listener to.
4924 *
4925 * @return True if the server was successfully started, false otherwise.
4926 *
4927 * @see com.android.server.ViewServer
4928 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4929 */
4930 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004931 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004932 return false;
4933 }
4934
4935 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4936 return false;
4937 }
4938
4939 if (port < 1024) {
4940 return false;
4941 }
4942
4943 if (mViewServer != null) {
4944 if (!mViewServer.isRunning()) {
4945 try {
4946 return mViewServer.start();
4947 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004948 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004949 }
4950 }
4951 return false;
4952 }
4953
4954 try {
4955 mViewServer = new ViewServer(this, port);
4956 return mViewServer.start();
4957 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004958 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004959 }
4960 return false;
4961 }
4962
Romain Guy06882f82009-06-10 13:36:04 -07004963 private boolean isSystemSecure() {
4964 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4965 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4966 }
4967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004968 /**
4969 * Stops the view server if it exists.
4970 *
4971 * @return True if the server stopped, false if it wasn't started or
4972 * couldn't be stopped.
4973 *
4974 * @see com.android.server.ViewServer
4975 */
4976 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004977 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004978 return false;
4979 }
4980
4981 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4982 return false;
4983 }
4984
4985 if (mViewServer != null) {
4986 return mViewServer.stop();
4987 }
4988 return false;
4989 }
4990
4991 /**
4992 * Indicates whether the view server is running.
4993 *
4994 * @return True if the server is running, false otherwise.
4995 *
4996 * @see com.android.server.ViewServer
4997 */
4998 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004999 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005000 return false;
5001 }
5002
5003 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5004 return false;
5005 }
5006
5007 return mViewServer != null && mViewServer.isRunning();
5008 }
5009
5010 /**
5011 * Lists all availble windows in the system. The listing is written in the
5012 * specified Socket's output stream with the following syntax:
5013 * windowHashCodeInHexadecimal windowName
5014 * Each line of the ouput represents a different window.
5015 *
5016 * @param client The remote client to send the listing to.
5017 * @return False if an error occured, true otherwise.
5018 */
5019 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005020 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005021 return false;
5022 }
5023
5024 boolean result = true;
5025
Jeff Browne33348b2010-07-15 23:54:05 -07005026 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005027 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005028 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005029 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005030 }
5031
5032 BufferedWriter out = null;
5033
5034 // Any uncaught exception will crash the system process
5035 try {
5036 OutputStream clientStream = client.getOutputStream();
5037 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5038
5039 final int count = windows.length;
5040 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005041 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005042 out.write(Integer.toHexString(System.identityHashCode(w)));
5043 out.write(' ');
5044 out.append(w.mAttrs.getTitle());
5045 out.write('\n');
5046 }
5047
5048 out.write("DONE.\n");
5049 out.flush();
5050 } catch (Exception e) {
5051 result = false;
5052 } finally {
5053 if (out != null) {
5054 try {
5055 out.close();
5056 } catch (IOException e) {
5057 result = false;
5058 }
5059 }
5060 }
5061
5062 return result;
5063 }
5064
5065 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005066 * Returns the focused window in the following format:
5067 * windowHashCodeInHexadecimal windowName
5068 *
5069 * @param client The remote client to send the listing to.
5070 * @return False if an error occurred, true otherwise.
5071 */
5072 boolean viewServerGetFocusedWindow(Socket client) {
5073 if (isSystemSecure()) {
5074 return false;
5075 }
5076
5077 boolean result = true;
5078
5079 WindowState focusedWindow = getFocusedWindow();
5080
5081 BufferedWriter out = null;
5082
5083 // Any uncaught exception will crash the system process
5084 try {
5085 OutputStream clientStream = client.getOutputStream();
5086 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5087
5088 if(focusedWindow != null) {
5089 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5090 out.write(' ');
5091 out.append(focusedWindow.mAttrs.getTitle());
5092 }
5093 out.write('\n');
5094 out.flush();
5095 } catch (Exception e) {
5096 result = false;
5097 } finally {
5098 if (out != null) {
5099 try {
5100 out.close();
5101 } catch (IOException e) {
5102 result = false;
5103 }
5104 }
5105 }
5106
5107 return result;
5108 }
5109
5110 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005111 * Sends a command to a target window. The result of the command, if any, will be
5112 * written in the output stream of the specified socket.
5113 *
5114 * The parameters must follow this syntax:
5115 * windowHashcode extra
5116 *
5117 * Where XX is the length in characeters of the windowTitle.
5118 *
5119 * The first parameter is the target window. The window with the specified hashcode
5120 * will be the target. If no target can be found, nothing happens. The extra parameters
5121 * will be delivered to the target window and as parameters to the command itself.
5122 *
5123 * @param client The remote client to sent the result, if any, to.
5124 * @param command The command to execute.
5125 * @param parameters The command parameters.
5126 *
5127 * @return True if the command was successfully delivered, false otherwise. This does
5128 * not indicate whether the command itself was successful.
5129 */
5130 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005131 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005132 return false;
5133 }
5134
5135 boolean success = true;
5136 Parcel data = null;
5137 Parcel reply = null;
5138
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005139 BufferedWriter out = null;
5140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005141 // Any uncaught exception will crash the system process
5142 try {
5143 // Find the hashcode of the window
5144 int index = parameters.indexOf(' ');
5145 if (index == -1) {
5146 index = parameters.length();
5147 }
5148 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005149 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005150
5151 // Extract the command's parameter after the window description
5152 if (index < parameters.length()) {
5153 parameters = parameters.substring(index + 1);
5154 } else {
5155 parameters = "";
5156 }
5157
5158 final WindowManagerService.WindowState window = findWindow(hashCode);
5159 if (window == null) {
5160 return false;
5161 }
5162
5163 data = Parcel.obtain();
5164 data.writeInterfaceToken("android.view.IWindow");
5165 data.writeString(command);
5166 data.writeString(parameters);
5167 data.writeInt(1);
5168 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5169
5170 reply = Parcel.obtain();
5171
5172 final IBinder binder = window.mClient.asBinder();
5173 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5174 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5175
5176 reply.readException();
5177
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005178 if (!client.isOutputShutdown()) {
5179 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5180 out.write("DONE\n");
5181 out.flush();
5182 }
5183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005184 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005185 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005186 success = false;
5187 } finally {
5188 if (data != null) {
5189 data.recycle();
5190 }
5191 if (reply != null) {
5192 reply.recycle();
5193 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005194 if (out != null) {
5195 try {
5196 out.close();
5197 } catch (IOException e) {
5198
5199 }
5200 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005201 }
5202
5203 return success;
5204 }
5205
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005206 public void addWindowChangeListener(WindowChangeListener listener) {
5207 synchronized(mWindowMap) {
5208 mWindowChangeListeners.add(listener);
5209 }
5210 }
5211
5212 public void removeWindowChangeListener(WindowChangeListener listener) {
5213 synchronized(mWindowMap) {
5214 mWindowChangeListeners.remove(listener);
5215 }
5216 }
5217
5218 private void notifyWindowsChanged() {
5219 WindowChangeListener[] windowChangeListeners;
5220 synchronized(mWindowMap) {
5221 if(mWindowChangeListeners.isEmpty()) {
5222 return;
5223 }
5224 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5225 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5226 }
5227 int N = windowChangeListeners.length;
5228 for(int i = 0; i < N; i++) {
5229 windowChangeListeners[i].windowsChanged();
5230 }
5231 }
5232
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005233 private void notifyFocusChanged() {
5234 WindowChangeListener[] windowChangeListeners;
5235 synchronized(mWindowMap) {
5236 if(mWindowChangeListeners.isEmpty()) {
5237 return;
5238 }
5239 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5240 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5241 }
5242 int N = windowChangeListeners.length;
5243 for(int i = 0; i < N; i++) {
5244 windowChangeListeners[i].focusChanged();
5245 }
5246 }
5247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005248 private WindowState findWindow(int hashCode) {
5249 if (hashCode == -1) {
5250 return getFocusedWindow();
5251 }
5252
5253 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005254 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005255 final int count = windows.size();
5256
5257 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005258 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005259 if (System.identityHashCode(w) == hashCode) {
5260 return w;
5261 }
5262 }
5263 }
5264
5265 return null;
5266 }
5267
5268 /*
5269 * Instruct the Activity Manager to fetch the current configuration and broadcast
5270 * that to config-changed listeners if appropriate.
5271 */
5272 void sendNewConfiguration() {
5273 try {
5274 mActivityManager.updateConfiguration(null);
5275 } catch (RemoteException e) {
5276 }
5277 }
Romain Guy06882f82009-06-10 13:36:04 -07005278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005279 public Configuration computeNewConfiguration() {
5280 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07005281 return computeNewConfigurationLocked();
5282 }
5283 }
Romain Guy06882f82009-06-10 13:36:04 -07005284
Dianne Hackbornc485a602009-03-24 22:39:49 -07005285 Configuration computeNewConfigurationLocked() {
5286 Configuration config = new Configuration();
5287 if (!computeNewConfigurationLocked(config)) {
5288 return null;
5289 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005290 return config;
5291 }
Romain Guy06882f82009-06-10 13:36:04 -07005292
Dianne Hackbornc485a602009-03-24 22:39:49 -07005293 boolean computeNewConfigurationLocked(Configuration config) {
5294 if (mDisplay == null) {
5295 return false;
5296 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005297
5298 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005299
5300 // Use the effective "visual" dimensions based on current rotation
5301 final boolean rotated = (mRotation == Surface.ROTATION_90
5302 || mRotation == Surface.ROTATION_270);
5303 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5304 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5305
Dianne Hackbornc485a602009-03-24 22:39:49 -07005306 int orientation = Configuration.ORIENTATION_SQUARE;
5307 if (dw < dh) {
5308 orientation = Configuration.ORIENTATION_PORTRAIT;
5309 } else if (dw > dh) {
5310 orientation = Configuration.ORIENTATION_LANDSCAPE;
5311 }
5312 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005313
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005314 DisplayMetrics dm = new DisplayMetrics();
5315 mDisplay.getMetrics(dm);
5316 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5317
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005318 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005319 // Note we only do this once because at this point we don't
5320 // expect the screen to change in this way at runtime, and want
5321 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005322 int longSize = dw;
5323 int shortSize = dh;
5324 if (longSize < shortSize) {
5325 int tmp = longSize;
5326 longSize = shortSize;
5327 shortSize = tmp;
5328 }
5329 longSize = (int)(longSize/dm.density);
5330 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005331
Dianne Hackborn723738c2009-06-25 19:48:04 -07005332 // These semi-magic numbers define our compatibility modes for
5333 // applications with different screens. Don't change unless you
5334 // make sure to test lots and lots of apps!
5335 if (longSize < 470) {
5336 // This is shorter than an HVGA normal density screen (which
5337 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005338 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5339 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005340 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005341 // What size is this screen screen?
5342 if (longSize >= 800 && shortSize >= 600) {
5343 // SVGA or larger screens at medium density are the point
5344 // at which we consider it to be an extra large screen.
5345 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
5346 } else if (longSize >= 640 && shortSize >= 480) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005347 // VGA or larger screens at medium density are the point
5348 // at which we consider it to be a large screen.
5349 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5350 } else {
5351 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005352
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005353 // If this screen is wider than normal HVGA, or taller
5354 // than FWVGA, then for old apps we want to run in size
5355 // compatibility mode.
5356 if (shortSize > 321 || longSize > 570) {
5357 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5358 }
5359 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005360
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005361 // Is this a long screen?
5362 if (((longSize*3)/5) >= (shortSize-1)) {
5363 // Anything wider than WVGA (5:3) is considering to be long.
5364 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5365 } else {
5366 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5367 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005368 }
5369 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005370 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005371
Dianne Hackbornc485a602009-03-24 22:39:49 -07005372 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5373 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5374 mPolicy.adjustConfigurationLw(config);
5375 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005376 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005377
5378 // -------------------------------------------------------------
5379 // Drag and drop
5380 // -------------------------------------------------------------
5381
5382 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
5383 boolean localOnly, int width, int height, Surface outSurface) {
5384 if (DEBUG_DRAG) {
5385 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
5386 + " local=" + localOnly + " win=" + window
5387 + " asbinder=" + window.asBinder());
5388 }
5389
5390 final int callerPid = Binder.getCallingPid();
5391 final long origId = Binder.clearCallingIdentity();
5392 IBinder token = null;
5393
5394 try {
5395 synchronized (mWindowMap) {
5396 try {
5397 // !!! TODO: fail if the given window does not currently have touch focus?
5398
5399 if (mDragState == null) {
5400 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5401 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5402 outSurface.copyFrom(surface);
5403 token = new Binder();
5404 mDragState = new DragState(token, surface, localOnly);
5405 mDragState.mSurface = surface;
5406 mDragState.mLocalOnly = localOnly;
5407 token = mDragState.mToken = new Binder();
5408
5409 // 5 second timeout for this window to actually begin the drag
5410 mH.removeMessages(H.DRAG_START_TIMEOUT, window);
5411 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, window.asBinder());
5412 mH.sendMessageDelayed(msg, 5000);
5413 } else {
5414 Slog.w(TAG, "Drag already in progress");
5415 }
5416 } catch (Surface.OutOfResourcesException e) {
5417 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5418 if (mDragState != null) {
5419 mDragState.reset();
5420 mDragState = null;
5421 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005422 }
5423 }
5424 } finally {
5425 Binder.restoreCallingIdentity(origId);
5426 }
5427
5428 return token;
5429 }
5430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005431 // -------------------------------------------------------------
5432 // Input Events and Focus Management
5433 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005434
Jeff Brown349703e2010-06-22 01:27:15 -07005435 InputMonitor mInputMonitor = new InputMonitor();
5436
5437 /* Tracks the progress of input dispatch and ensures that input dispatch state
5438 * is kept in sync with changes in window focus, visibility, registration, and
5439 * other relevant Window Manager state transitions. */
5440 final class InputMonitor {
5441 // Current window with input focus for keys and other non-touch events. May be null.
5442 private WindowState mInputFocus;
5443
5444 // When true, prevents input dispatch from proceeding until set to false again.
5445 private boolean mInputDispatchFrozen;
5446
5447 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5448 private boolean mInputDispatchEnabled = true;
5449
5450 // Temporary list of windows information to provide to the input dispatcher.
5451 private InputWindowList mTempInputWindows = new InputWindowList();
5452
5453 // Temporary input application object to provide to the input dispatcher.
5454 private InputApplication mTempInputApplication = new InputApplication();
5455
5456 /* Notifies the window manager about a broken input channel.
5457 *
5458 * Called by the InputManager.
5459 */
5460 public void notifyInputChannelBroken(InputChannel inputChannel) {
5461 synchronized (mWindowMap) {
5462 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5463 if (windowState == null) {
5464 return; // irrelevant
5465 }
5466
5467 Slog.i(TAG, "WINDOW DIED " + windowState);
5468 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005469 }
5470 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005471
Jeff Brown519e0242010-09-15 15:18:56 -07005472 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005473 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005474 *
5475 * Called by the InputManager.
5476 */
Jeff Brown519e0242010-09-15 15:18:56 -07005477 public long notifyANR(Object token, InputChannel inputChannel) {
5478 AppWindowToken appWindowToken = null;
5479 if (inputChannel != null) {
5480 synchronized (mWindowMap) {
5481 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5482 if (windowState != null) {
5483 Slog.i(TAG, "Input event dispatching timed out sending to "
5484 + windowState.mAttrs.getTitle());
5485 appWindowToken = windowState.mAppToken;
5486 }
Jeff Brown349703e2010-06-22 01:27:15 -07005487 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005488 }
5489
Jeff Brown519e0242010-09-15 15:18:56 -07005490 if (appWindowToken == null && token != null) {
5491 appWindowToken = (AppWindowToken) token;
5492 Slog.i(TAG, "Input event dispatching timed out sending to application "
5493 + appWindowToken.stringName);
5494 }
Jeff Brown349703e2010-06-22 01:27:15 -07005495
Jeff Brown519e0242010-09-15 15:18:56 -07005496 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005497 try {
5498 // Notify the activity manager about the timeout and let it decide whether
5499 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005500 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005501 if (! abort) {
5502 // The activity manager declined to abort dispatching.
5503 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005504 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005505 }
Jeff Brown349703e2010-06-22 01:27:15 -07005506 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005507 }
5508 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005509 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005510 }
5511
Jeff Brown349703e2010-06-22 01:27:15 -07005512 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5513 synchronized (mWindowMap) {
5514 return getWindowStateForInputChannelLocked(inputChannel);
5515 }
5516 }
5517
5518 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5519 int windowCount = mWindows.size();
5520 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005521 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005522 if (windowState.mInputChannel == inputChannel) {
5523 return windowState;
5524 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005525 }
5526
Jeff Brown349703e2010-06-22 01:27:15 -07005527 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005528 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005529
5530 private void addDragInputWindow(InputWindowList windowList) {
5531 final InputWindow inputWindow = windowList.add();
5532 inputWindow.inputChannel = mDragState.mServerChannel;
5533 inputWindow.name = "drag";
5534 inputWindow.layoutParamsFlags = 0;
5535 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5536 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5537 inputWindow.visible = true;
5538 inputWindow.canReceiveKeys = false;
5539 inputWindow.hasFocus = true;
5540 inputWindow.hasWallpaper = false;
5541 inputWindow.paused = false;
5542 inputWindow.layer = mPolicy.windowTypeToLayerLw(inputWindow.layoutParamsType)
5543 * TYPE_LAYER_MULTIPLIER
5544 + TYPE_LAYER_OFFSET;
5545 inputWindow.ownerPid = Process.myPid();
5546 inputWindow.ownerUid = Process.myUid();
5547
5548 // The drag window covers the entire display
5549 inputWindow.frameLeft = 0;
5550 inputWindow.frameTop = 0;
5551 inputWindow.frameRight = mDisplay.getWidth();
5552 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005553
Christopher Tatea53146c2010-09-07 11:57:52 -07005554 inputWindow.visibleFrameLeft = inputWindow.frameLeft;
5555 inputWindow.visibleFrameTop = inputWindow.frameTop;
5556 inputWindow.visibleFrameRight = inputWindow.frameRight;
5557 inputWindow.visibleFrameBottom = inputWindow.frameBottom;
5558
5559 inputWindow.touchableAreaLeft = inputWindow.frameLeft;
5560 inputWindow.touchableAreaTop = inputWindow.frameTop;
5561 inputWindow.touchableAreaRight = inputWindow.frameRight;
5562 inputWindow.touchableAreaBottom = inputWindow.frameBottom;
5563 }
5564
Jeff Brown349703e2010-06-22 01:27:15 -07005565 /* Updates the cached window information provided to the input dispatcher. */
5566 public void updateInputWindowsLw() {
5567 // Populate the input window list with information about all of the windows that
5568 // could potentially receive input.
5569 // As an optimization, we could try to prune the list of windows but this turns
5570 // out to be difficult because only the native code knows for sure which window
5571 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005572 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005573
5574 // If there's a drag in flight, provide a pseudowindow to catch drag input
5575 final boolean inDrag = (mDragState != null);
5576 if (inDrag) {
5577 if (DEBUG_DRAG) {
5578 Log.d(TAG, "Inserting drag window");
5579 }
5580 addDragInputWindow(mTempInputWindows);
5581 }
5582
Jeff Brown7fbdc842010-06-17 20:52:56 -07005583 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005584 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005585 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005586 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005587 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005588 continue;
5589 }
5590
Jeff Brown349703e2010-06-22 01:27:15 -07005591 final int flags = child.mAttrs.flags;
5592 final int type = child.mAttrs.type;
5593
5594 final boolean hasFocus = (child == mInputFocus);
5595 final boolean isVisible = child.isVisibleLw();
5596 final boolean hasWallpaper = (child == mWallpaperTarget)
5597 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005598
5599 // If there's a drag in progress and 'child' is a potential drop target,
5600 // make sure it's been told about the drag
5601 if (inDrag && isVisible) {
5602 mDragState.sendDragStartedIfNeededLw(child);
5603 }
5604
Jeff Brown349703e2010-06-22 01:27:15 -07005605 // Add a window to our list of input windows.
5606 final InputWindow inputWindow = mTempInputWindows.add();
5607 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005608 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005609 inputWindow.layoutParamsFlags = flags;
5610 inputWindow.layoutParamsType = type;
5611 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5612 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005613 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005614 inputWindow.hasFocus = hasFocus;
5615 inputWindow.hasWallpaper = hasWallpaper;
5616 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005617 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005618 inputWindow.ownerPid = child.mSession.mPid;
5619 inputWindow.ownerUid = child.mSession.mUid;
5620
5621 final Rect frame = child.mFrame;
5622 inputWindow.frameLeft = frame.left;
5623 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005624 inputWindow.frameRight = frame.right;
5625 inputWindow.frameBottom = frame.bottom;
5626
5627 final Rect visibleFrame = child.mVisibleFrame;
5628 inputWindow.visibleFrameLeft = visibleFrame.left;
5629 inputWindow.visibleFrameTop = visibleFrame.top;
5630 inputWindow.visibleFrameRight = visibleFrame.right;
5631 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005632
5633 switch (child.mTouchableInsets) {
5634 default:
5635 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5636 inputWindow.touchableAreaLeft = frame.left;
5637 inputWindow.touchableAreaTop = frame.top;
5638 inputWindow.touchableAreaRight = frame.right;
5639 inputWindow.touchableAreaBottom = frame.bottom;
5640 break;
5641
5642 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5643 Rect inset = child.mGivenContentInsets;
5644 inputWindow.touchableAreaLeft = frame.left + inset.left;
5645 inputWindow.touchableAreaTop = frame.top + inset.top;
5646 inputWindow.touchableAreaRight = frame.right - inset.right;
5647 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5648 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005649 }
Jeff Brown349703e2010-06-22 01:27:15 -07005650
5651 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5652 Rect inset = child.mGivenVisibleInsets;
5653 inputWindow.touchableAreaLeft = frame.left + inset.left;
5654 inputWindow.touchableAreaTop = frame.top + inset.top;
5655 inputWindow.touchableAreaRight = frame.right - inset.right;
5656 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005657 break;
5658 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005659 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005660 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005661
Jeff Brown349703e2010-06-22 01:27:15 -07005662 // Send windows to native code.
5663 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005664
Jeff Brown349703e2010-06-22 01:27:15 -07005665 // Clear the list in preparation for the next round.
5666 // Also avoids keeping InputChannel objects referenced unnecessarily.
5667 mTempInputWindows.clear();
5668 }
5669
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005670 /* Provides feedback for a virtual key down. */
5671 public void virtualKeyDownFeedback() {
5672 synchronized (mWindowMap) {
5673 mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5674 }
5675 }
5676
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005677 /* Notifies that the lid switch changed state. */
5678 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5679 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5680 }
5681
Jeff Brown349703e2010-06-22 01:27:15 -07005682 /* Provides an opportunity for the window manager policy to intercept early key
5683 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005684 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5685 int policyFlags, boolean isScreenOn) {
5686 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5687 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005688 }
5689
5690 /* Provides an opportunity for the window manager policy to process a key before
5691 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005692 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5693 int action, int flags, int keyCode, int metaState, int repeatCount,
5694 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005695 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005696 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5697 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005698 }
5699
5700 /* Called when the current input focus changes.
5701 * Layer assignment is assumed to be complete by the time this is called.
5702 */
5703 public void setInputFocusLw(WindowState newWindow) {
5704 if (DEBUG_INPUT) {
5705 Slog.d(TAG, "Input focus has changed to " + newWindow);
5706 }
5707
5708 if (newWindow != mInputFocus) {
5709 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005710 // Displaying a window implicitly causes dispatching to be unpaused.
5711 // This is to protect against bugs if someone pauses dispatching but
5712 // forgets to resume.
5713 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005714 }
Jeff Brown349703e2010-06-22 01:27:15 -07005715
5716 mInputFocus = newWindow;
5717 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005718 }
5719 }
5720
Jeff Brown349703e2010-06-22 01:27:15 -07005721 public void setFocusedAppLw(AppWindowToken newApp) {
5722 // Focused app has changed.
5723 if (newApp == null) {
5724 mInputManager.setFocusedApplication(null);
5725 } else {
5726 mTempInputApplication.name = newApp.toString();
5727 mTempInputApplication.dispatchingTimeoutNanos =
5728 newApp.inputDispatchingTimeoutNanos;
5729 mTempInputApplication.token = newApp;
5730
5731 mInputManager.setFocusedApplication(mTempInputApplication);
5732 }
5733 }
5734
Jeff Brown349703e2010-06-22 01:27:15 -07005735 public void pauseDispatchingLw(WindowToken window) {
5736 if (! window.paused) {
5737 if (DEBUG_INPUT) {
5738 Slog.v(TAG, "Pausing WindowToken " + window);
5739 }
5740
5741 window.paused = true;
5742 updateInputWindowsLw();
5743 }
5744 }
5745
5746 public void resumeDispatchingLw(WindowToken window) {
5747 if (window.paused) {
5748 if (DEBUG_INPUT) {
5749 Slog.v(TAG, "Resuming WindowToken " + window);
5750 }
5751
5752 window.paused = false;
5753 updateInputWindowsLw();
5754 }
5755 }
5756
5757 public void freezeInputDispatchingLw() {
5758 if (! mInputDispatchFrozen) {
5759 if (DEBUG_INPUT) {
5760 Slog.v(TAG, "Freezing input dispatching");
5761 }
5762
5763 mInputDispatchFrozen = true;
5764 updateInputDispatchModeLw();
5765 }
5766 }
5767
5768 public void thawInputDispatchingLw() {
5769 if (mInputDispatchFrozen) {
5770 if (DEBUG_INPUT) {
5771 Slog.v(TAG, "Thawing input dispatching");
5772 }
5773
5774 mInputDispatchFrozen = false;
5775 updateInputDispatchModeLw();
5776 }
5777 }
5778
5779 public void setEventDispatchingLw(boolean enabled) {
5780 if (mInputDispatchEnabled != enabled) {
5781 if (DEBUG_INPUT) {
5782 Slog.v(TAG, "Setting event dispatching to " + enabled);
5783 }
5784
5785 mInputDispatchEnabled = enabled;
5786 updateInputDispatchModeLw();
5787 }
5788 }
5789
5790 private void updateInputDispatchModeLw() {
5791 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5792 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005793 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005795 public void pauseKeyDispatching(IBinder _token) {
5796 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5797 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005798 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005799 }
5800
5801 synchronized (mWindowMap) {
5802 WindowToken token = mTokenMap.get(_token);
5803 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005804 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005805 }
5806 }
5807 }
5808
5809 public void resumeKeyDispatching(IBinder _token) {
5810 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5811 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005812 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005813 }
5814
5815 synchronized (mWindowMap) {
5816 WindowToken token = mTokenMap.get(_token);
5817 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005818 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005819 }
5820 }
5821 }
5822
5823 public void setEventDispatching(boolean enabled) {
5824 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5825 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005826 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005827 }
5828
5829 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005830 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005831 }
5832 }
Romain Guy06882f82009-06-10 13:36:04 -07005833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005834 /**
5835 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005836 * Even when sync is false, this method may block while waiting for current
5837 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005838 *
5839 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005840 * {@link SystemClock#uptimeMillis()} as the timebase.)
5841 * @param sync If true, wait for the event to be completed before returning to the caller.
5842 * @return Returns true if event was dispatched, false if it was dropped for any reason
5843 */
5844 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5845 long downTime = ev.getDownTime();
5846 long eventTime = ev.getEventTime();
5847
5848 int action = ev.getAction();
5849 int code = ev.getKeyCode();
5850 int repeatCount = ev.getRepeatCount();
5851 int metaState = ev.getMetaState();
5852 int deviceId = ev.getDeviceId();
5853 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005854 int source = ev.getSource();
5855
5856 if (source == InputDevice.SOURCE_UNKNOWN) {
5857 source = InputDevice.SOURCE_KEYBOARD;
5858 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005859
5860 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5861 if (downTime == 0) downTime = eventTime;
5862
5863 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005864 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005865
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005866 final int pid = Binder.getCallingPid();
5867 final int uid = Binder.getCallingUid();
5868 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005869
Jeff Brownbbda99d2010-07-28 15:48:59 -07005870 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5871 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5872 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5873 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005874
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005875 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005876 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005877 }
5878
5879 /**
5880 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005881 * Even when sync is false, this method may block while waiting for current
5882 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005883 *
5884 * @param ev A motion event describing the pointer (touch) action. (As noted in
5885 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005886 * {@link SystemClock#uptimeMillis()} as the timebase.)
5887 * @param sync If true, wait for the event to be completed before returning to the caller.
5888 * @return Returns true if event was dispatched, false if it was dropped for any reason
5889 */
5890 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005891 final int pid = Binder.getCallingPid();
5892 final int uid = Binder.getCallingUid();
5893 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005894
Jeff Brownc5ed5912010-07-14 18:48:53 -07005895 MotionEvent newEvent = MotionEvent.obtain(ev);
5896 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5897 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5898 }
5899
Jeff Brownbbda99d2010-07-28 15:48:59 -07005900 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5901 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5902 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5903 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005904
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005905 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005906 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005907 }
Romain Guy06882f82009-06-10 13:36:04 -07005908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005909 /**
5910 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005911 * Even when sync is false, this method may block while waiting for current
5912 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005913 *
5914 * @param ev A motion event describing the trackball action. (As noted in
5915 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005916 * {@link SystemClock#uptimeMillis()} as the timebase.)
5917 * @param sync If true, wait for the event to be completed before returning to the caller.
5918 * @return Returns true if event was dispatched, false if it was dropped for any reason
5919 */
5920 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005921 final int pid = Binder.getCallingPid();
5922 final int uid = Binder.getCallingUid();
5923 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005924
Jeff Brownc5ed5912010-07-14 18:48:53 -07005925 MotionEvent newEvent = MotionEvent.obtain(ev);
5926 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5927 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5928 }
5929
Jeff Brownbbda99d2010-07-28 15:48:59 -07005930 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5931 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5932 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5933 INJECTION_TIMEOUT_MILLIS);
5934
5935 Binder.restoreCallingIdentity(ident);
5936 return reportInjectionResult(result);
5937 }
5938
5939 /**
5940 * Inject an input event into the UI without waiting for dispatch to commence.
5941 * This variant is useful for fire-and-forget input event injection. It does not
5942 * block any longer than it takes to enqueue the input event.
5943 *
5944 * @param ev An input event. (Be sure to set the input source correctly.)
5945 * @return Returns true if event was dispatched, false if it was dropped for any reason
5946 */
5947 public boolean injectInputEventNoWait(InputEvent ev) {
5948 final int pid = Binder.getCallingPid();
5949 final int uid = Binder.getCallingUid();
5950 final long ident = Binder.clearCallingIdentity();
5951
5952 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5953 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5954 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005955
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005956 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005957 return reportInjectionResult(result);
5958 }
5959
5960 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005961 switch (result) {
5962 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5963 Slog.w(TAG, "Input event injection permission denied.");
5964 throw new SecurityException(
5965 "Injecting to another application requires INJECT_EVENTS permission");
5966 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07005967 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005968 return true;
5969 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5970 Slog.w(TAG, "Input event injection timed out.");
5971 return false;
5972 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5973 default:
5974 Slog.w(TAG, "Input event injection failed.");
5975 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005976 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005977 }
Romain Guy06882f82009-06-10 13:36:04 -07005978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005979 private WindowState getFocusedWindow() {
5980 synchronized (mWindowMap) {
5981 return getFocusedWindowLocked();
5982 }
5983 }
5984
5985 private WindowState getFocusedWindowLocked() {
5986 return mCurrentFocus;
5987 }
Romain Guy06882f82009-06-10 13:36:04 -07005988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005989 public boolean detectSafeMode() {
5990 mSafeMode = mPolicy.detectSafeMode();
5991 return mSafeMode;
5992 }
Romain Guy06882f82009-06-10 13:36:04 -07005993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005994 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07005995 synchronized(mWindowMap) {
5996 if (mDisplay != null) {
5997 throw new IllegalStateException("Display already initialized");
5998 }
5999 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6000 mDisplay = wm.getDefaultDisplay();
6001 mInitialDisplayWidth = mDisplay.getWidth();
6002 mInitialDisplayHeight = mDisplay.getHeight();
6003 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
6004 }
6005
6006 try {
6007 mActivityManager.updateConfiguration(null);
6008 } catch (RemoteException e) {
6009 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006010
6011 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006012 }
6013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006014 // -------------------------------------------------------------
6015 // Client Session State
6016 // -------------------------------------------------------------
6017
6018 private final class Session extends IWindowSession.Stub
6019 implements IBinder.DeathRecipient {
6020 final IInputMethodClient mClient;
6021 final IInputContext mInputContext;
6022 final int mUid;
6023 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006024 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006025 SurfaceSession mSurfaceSession;
6026 int mNumWindow = 0;
6027 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006029 public Session(IInputMethodClient client, IInputContext inputContext) {
6030 mClient = client;
6031 mInputContext = inputContext;
6032 mUid = Binder.getCallingUid();
6033 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006034 StringBuilder sb = new StringBuilder();
6035 sb.append("Session{");
6036 sb.append(Integer.toHexString(System.identityHashCode(this)));
6037 sb.append(" uid ");
6038 sb.append(mUid);
6039 sb.append("}");
6040 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006042 synchronized (mWindowMap) {
6043 if (mInputMethodManager == null && mHaveInputMethods) {
6044 IBinder b = ServiceManager.getService(
6045 Context.INPUT_METHOD_SERVICE);
6046 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6047 }
6048 }
6049 long ident = Binder.clearCallingIdentity();
6050 try {
6051 // Note: it is safe to call in to the input method manager
6052 // here because we are not holding our lock.
6053 if (mInputMethodManager != null) {
6054 mInputMethodManager.addClient(client, inputContext,
6055 mUid, mPid);
6056 } else {
6057 client.setUsingInputMethod(false);
6058 }
6059 client.asBinder().linkToDeath(this, 0);
6060 } catch (RemoteException e) {
6061 // The caller has died, so we can just forget about this.
6062 try {
6063 if (mInputMethodManager != null) {
6064 mInputMethodManager.removeClient(client);
6065 }
6066 } catch (RemoteException ee) {
6067 }
6068 } finally {
6069 Binder.restoreCallingIdentity(ident);
6070 }
6071 }
Romain Guy06882f82009-06-10 13:36:04 -07006072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006073 @Override
6074 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6075 throws RemoteException {
6076 try {
6077 return super.onTransact(code, data, reply, flags);
6078 } catch (RuntimeException e) {
6079 // Log all 'real' exceptions thrown to the caller
6080 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006081 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006082 }
6083 throw e;
6084 }
6085 }
6086
6087 public void binderDied() {
6088 // Note: it is safe to call in to the input method manager
6089 // here because we are not holding our lock.
6090 try {
6091 if (mInputMethodManager != null) {
6092 mInputMethodManager.removeClient(mClient);
6093 }
6094 } catch (RemoteException e) {
6095 }
6096 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006097 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006098 mClientDead = true;
6099 killSessionLocked();
6100 }
6101 }
6102
6103 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006104 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6105 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6106 outInputChannel);
6107 }
6108
6109 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006110 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006111 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006112 }
Romain Guy06882f82009-06-10 13:36:04 -07006113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006114 public void remove(IWindow window) {
6115 removeWindow(this, window);
6116 }
Romain Guy06882f82009-06-10 13:36:04 -07006117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006118 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6119 int requestedWidth, int requestedHeight, int viewFlags,
6120 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006121 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006122 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6123 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006124 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006125 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006126 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6127 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006128 }
Romain Guy06882f82009-06-10 13:36:04 -07006129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006130 public void setTransparentRegion(IWindow window, Region region) {
6131 setTransparentRegionWindow(this, window, region);
6132 }
Romain Guy06882f82009-06-10 13:36:04 -07006133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006134 public void setInsets(IWindow window, int touchableInsets,
6135 Rect contentInsets, Rect visibleInsets) {
6136 setInsetsWindow(this, window, touchableInsets, contentInsets,
6137 visibleInsets);
6138 }
Romain Guy06882f82009-06-10 13:36:04 -07006139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006140 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6141 getWindowDisplayFrame(this, window, outDisplayFrame);
6142 }
Romain Guy06882f82009-06-10 13:36:04 -07006143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006144 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006145 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006146 TAG, "IWindow finishDrawing called for " + window);
6147 finishDrawingWindow(this, window);
6148 }
6149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006150 public void setInTouchMode(boolean mode) {
6151 synchronized(mWindowMap) {
6152 mInTouchMode = mode;
6153 }
6154 }
6155
6156 public boolean getInTouchMode() {
6157 synchronized(mWindowMap) {
6158 return mInTouchMode;
6159 }
6160 }
6161
6162 public boolean performHapticFeedback(IWindow window, int effectId,
6163 boolean always) {
6164 synchronized(mWindowMap) {
6165 long ident = Binder.clearCallingIdentity();
6166 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006167 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006168 windowForClientLocked(this, window, true),
6169 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006170 } finally {
6171 Binder.restoreCallingIdentity(ident);
6172 }
6173 }
6174 }
Romain Guy06882f82009-06-10 13:36:04 -07006175
Christopher Tatea53146c2010-09-07 11:57:52 -07006176 /* Drag/drop */
6177 public IBinder prepareDrag(IWindow window, boolean localOnly,
6178 int width, int height, Surface outSurface) {
6179 return prepareDragSurface(window, mSurfaceSession, localOnly,
6180 width, height, outSurface);
6181 }
6182
6183 public boolean performDrag(IWindow window, IBinder dragToken,
6184 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6185 ClipData data) {
6186 if (DEBUG_DRAG) {
6187 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6188 }
6189
6190 synchronized (mWindowMap) {
6191 if (mDragState == null) {
6192 Slog.w(TAG, "No drag prepared");
6193 throw new IllegalStateException("performDrag() without prepareDrag()");
6194 }
6195
6196 if (dragToken != mDragState.mToken) {
6197 Slog.w(TAG, "Performing mismatched drag");
6198 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6199 }
6200
6201 WindowState callingWin = windowForClientLocked(null, window, false);
6202 if (callingWin == null) {
6203 Slog.w(TAG, "Bad requesting window " + window);
6204 return false; // !!! TODO: throw here?
6205 }
6206
6207 // !!! TODO: if input is not still focused on the initiating window, fail
6208 // the drag initiation (e.g. an alarm window popped up just as the application
6209 // called performDrag()
6210
6211 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6212
Christopher Tate2c095f32010-10-04 14:13:40 -07006213 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6214 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006215
6216 mDragState.register();
6217 mInputMonitor.updateInputWindowsLw();
6218 mInputManager.transferTouchFocus(callingWin.mInputChannel,
6219 mDragState.mServerChannel);
6220
6221 mDragState.mData = data;
6222 mDragState.broadcastDragStartedLw();
6223
6224 // remember the thumb offsets for later
6225 mDragState.mThumbOffsetX = thumbCenterX;
6226 mDragState.mThumbOffsetY = thumbCenterY;
6227
6228 // Make the surface visible at the proper location
6229 final Surface surface = mDragState.mSurface;
6230 surface.openTransaction();
6231 try {
6232 surface.setPosition((int)(touchX - thumbCenterX),
6233 (int)(touchY - thumbCenterY));
6234 surface.setAlpha(.5f);
6235 surface.show();
6236 } finally {
6237 surface.closeTransaction();
6238 }
6239 }
6240
6241 return true; // success!
6242 }
6243
6244 public void dragRecipientEntered(IWindow window) {
6245 if (DEBUG_DRAG) {
6246 Slog.d(TAG, "Drag into new candidate view @ " + window);
6247 }
6248 }
6249
6250 public void dragRecipientExited(IWindow window) {
6251 if (DEBUG_DRAG) {
6252 Slog.d(TAG, "Drag from old candidate view @ " + window);
6253 }
6254 }
6255
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006256 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006257 synchronized(mWindowMap) {
6258 long ident = Binder.clearCallingIdentity();
6259 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006260 setWindowWallpaperPositionLocked(
6261 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006262 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006263 } finally {
6264 Binder.restoreCallingIdentity(ident);
6265 }
6266 }
6267 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006268
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006269 public void wallpaperOffsetsComplete(IBinder window) {
6270 WindowManagerService.this.wallpaperOffsetsComplete(window);
6271 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006272
Dianne Hackborn75804932009-10-20 20:15:20 -07006273 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6274 int z, Bundle extras, boolean sync) {
6275 synchronized(mWindowMap) {
6276 long ident = Binder.clearCallingIdentity();
6277 try {
6278 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006279 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006280 action, x, y, z, extras, sync);
6281 } finally {
6282 Binder.restoreCallingIdentity(ident);
6283 }
6284 }
6285 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006286
Dianne Hackborn75804932009-10-20 20:15:20 -07006287 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6288 WindowManagerService.this.wallpaperCommandComplete(window, result);
6289 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006291 void windowAddedLocked() {
6292 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006293 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006294 TAG, "First window added to " + this + ", creating SurfaceSession");
6295 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006296 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006297 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006298 mSessions.add(this);
6299 }
6300 mNumWindow++;
6301 }
6302
6303 void windowRemovedLocked() {
6304 mNumWindow--;
6305 killSessionLocked();
6306 }
Romain Guy06882f82009-06-10 13:36:04 -07006307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006308 void killSessionLocked() {
6309 if (mNumWindow <= 0 && mClientDead) {
6310 mSessions.remove(this);
6311 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006312 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006313 TAG, "Last window removed from " + this
6314 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006315 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006316 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006317 try {
6318 mSurfaceSession.kill();
6319 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006320 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006321 + mSurfaceSession + " in session " + this
6322 + ": " + e.toString());
6323 }
6324 mSurfaceSession = null;
6325 }
6326 }
6327 }
Romain Guy06882f82009-06-10 13:36:04 -07006328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006329 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006330 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6331 pw.print(" mClientDead="); pw.print(mClientDead);
6332 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006333 }
6334
6335 @Override
6336 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006337 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006338 }
6339 }
6340
6341 // -------------------------------------------------------------
6342 // Client Window State
6343 // -------------------------------------------------------------
6344
6345 private final class WindowState implements WindowManagerPolicy.WindowState {
6346 final Session mSession;
6347 final IWindow mClient;
6348 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006349 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006350 AppWindowToken mAppToken;
6351 AppWindowToken mTargetAppToken;
6352 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6353 final DeathRecipient mDeathRecipient;
6354 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006355 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006356 final int mBaseLayer;
6357 final int mSubLayer;
6358 final boolean mLayoutAttached;
6359 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006360 final boolean mIsWallpaper;
6361 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006362 int mViewVisibility;
6363 boolean mPolicyVisibility = true;
6364 boolean mPolicyVisibilityAfterAnim = true;
6365 boolean mAppFreezing;
6366 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006367 boolean mReportDestroySurface;
6368 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006369 boolean mAttachedHidden; // is our parent window hidden?
6370 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006371 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006372 int mRequestedWidth;
6373 int mRequestedHeight;
6374 int mLastRequestedWidth;
6375 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006376 int mLayer;
6377 int mAnimLayer;
6378 int mLastLayer;
6379 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006380 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006381 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006382
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006383 int mLayoutSeq = -1;
6384
6385 Configuration mConfiguration = null;
6386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006387 // Actual frame shown on-screen (may be modified by animation)
6388 final Rect mShownFrame = new Rect();
6389 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006391 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006392 * Set when we have changed the size of the surface, to know that
6393 * we must tell them application to resize (and thus redraw itself).
6394 */
6395 boolean mSurfaceResized;
6396
6397 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006398 * Insets that determine the actually visible area
6399 */
6400 final Rect mVisibleInsets = new Rect();
6401 final Rect mLastVisibleInsets = new Rect();
6402 boolean mVisibleInsetsChanged;
6403
6404 /**
6405 * Insets that are covered by system windows
6406 */
6407 final Rect mContentInsets = new Rect();
6408 final Rect mLastContentInsets = new Rect();
6409 boolean mContentInsetsChanged;
6410
6411 /**
6412 * Set to true if we are waiting for this window to receive its
6413 * given internal insets before laying out other windows based on it.
6414 */
6415 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006417 /**
6418 * These are the content insets that were given during layout for
6419 * this window, to be applied to windows behind it.
6420 */
6421 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006423 /**
6424 * These are the visible insets that were given during layout for
6425 * this window, to be applied to windows behind it.
6426 */
6427 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006429 /**
6430 * Flag indicating whether the touchable region should be adjusted by
6431 * the visible insets; if false the area outside the visible insets is
6432 * NOT touchable, so we must use those to adjust the frame during hit
6433 * tests.
6434 */
6435 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006437 // Current transformation being applied.
6438 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6439 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6440 float mHScale=1, mVScale=1;
6441 float mLastHScale=1, mLastVScale=1;
6442 final Matrix mTmpMatrix = new Matrix();
6443
6444 // "Real" frame that the application sees.
6445 final Rect mFrame = new Rect();
6446 final Rect mLastFrame = new Rect();
6447
6448 final Rect mContainingFrame = new Rect();
6449 final Rect mDisplayFrame = new Rect();
6450 final Rect mContentFrame = new Rect();
6451 final Rect mVisibleFrame = new Rect();
6452
6453 float mShownAlpha = 1;
6454 float mAlpha = 1;
6455 float mLastAlpha = 1;
6456
6457 // Set to true if, when the window gets displayed, it should perform
6458 // an enter animation.
6459 boolean mEnterAnimationPending;
6460
6461 // Currently running animation.
6462 boolean mAnimating;
6463 boolean mLocalAnimating;
6464 Animation mAnimation;
6465 boolean mAnimationIsEntrance;
6466 boolean mHasTransformation;
6467 boolean mHasLocalTransformation;
6468 final Transformation mTransformation = new Transformation();
6469
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006470 // If a window showing a wallpaper: the requested offset for the
6471 // wallpaper; if a wallpaper window: the currently applied offset.
6472 float mWallpaperX = -1;
6473 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006474
6475 // If a window showing a wallpaper: what fraction of the offset
6476 // range corresponds to a full virtual screen.
6477 float mWallpaperXStep = -1;
6478 float mWallpaperYStep = -1;
6479
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006480 // Wallpaper windows: pixels offset based on above variables.
6481 int mXOffset;
6482 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006484 // This is set after IWindowSession.relayout() has been called at
6485 // least once for the window. It allows us to detect the situation
6486 // where we don't yet have a surface, but should have one soon, so
6487 // we can give the window focus before waiting for the relayout.
6488 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006490 // This is set after the Surface has been created but before the
6491 // window has been drawn. During this time the surface is hidden.
6492 boolean mDrawPending;
6493
6494 // This is set after the window has finished drawing for the first
6495 // time but before its surface is shown. The surface will be
6496 // displayed when the next layout is run.
6497 boolean mCommitDrawPending;
6498
6499 // This is set during the time after the window's drawing has been
6500 // committed, and before its surface is actually shown. It is used
6501 // to delay showing the surface until all windows in a token are ready
6502 // to be shown.
6503 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006505 // Set when the window has been shown in the screen the first time.
6506 boolean mHasDrawn;
6507
6508 // Currently running an exit animation?
6509 boolean mExiting;
6510
6511 // Currently on the mDestroySurface list?
6512 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006514 // Completely remove from window manager after exit animation?
6515 boolean mRemoveOnExit;
6516
6517 // Set when the orientation is changing and this window has not yet
6518 // been updated for the new orientation.
6519 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006521 // Is this window now (or just being) removed?
6522 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006523
Dianne Hackborn16064f92010-03-25 00:47:24 -07006524 // For debugging, this is the last information given to the surface flinger.
6525 boolean mSurfaceShown;
6526 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6527 int mSurfaceLayer;
6528 float mSurfaceAlpha;
6529
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006530 // Input channel
6531 InputChannel mInputChannel;
6532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006533 WindowState(Session s, IWindow c, WindowToken token,
6534 WindowState attachedWindow, WindowManager.LayoutParams a,
6535 int viewVisibility) {
6536 mSession = s;
6537 mClient = c;
6538 mToken = token;
6539 mAttrs.copyFrom(a);
6540 mViewVisibility = viewVisibility;
6541 DeathRecipient deathRecipient = new DeathRecipient();
6542 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006543 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006544 TAG, "Window " + this + " client=" + c.asBinder()
6545 + " token=" + token + " (" + mAttrs.token + ")");
6546 try {
6547 c.asBinder().linkToDeath(deathRecipient, 0);
6548 } catch (RemoteException e) {
6549 mDeathRecipient = null;
6550 mAttachedWindow = null;
6551 mLayoutAttached = false;
6552 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006553 mIsWallpaper = false;
6554 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006555 mBaseLayer = 0;
6556 mSubLayer = 0;
6557 return;
6558 }
6559 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006561 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6562 mAttrs.type <= LAST_SUB_WINDOW)) {
6563 // The multiplier here is to reserve space for multiple
6564 // windows in the same type layer.
6565 mBaseLayer = mPolicy.windowTypeToLayerLw(
6566 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6567 + TYPE_LAYER_OFFSET;
6568 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6569 mAttachedWindow = attachedWindow;
6570 mAttachedWindow.mChildWindows.add(this);
6571 mLayoutAttached = mAttrs.type !=
6572 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6573 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6574 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006575 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6576 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006577 } else {
6578 // The multiplier here is to reserve space for multiple
6579 // windows in the same type layer.
6580 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6581 * TYPE_LAYER_MULTIPLIER
6582 + TYPE_LAYER_OFFSET;
6583 mSubLayer = 0;
6584 mAttachedWindow = null;
6585 mLayoutAttached = false;
6586 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6587 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006588 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6589 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006590 }
6591
6592 WindowState appWin = this;
6593 while (appWin.mAttachedWindow != null) {
6594 appWin = mAttachedWindow;
6595 }
6596 WindowToken appToken = appWin.mToken;
6597 while (appToken.appWindowToken == null) {
6598 WindowToken parent = mTokenMap.get(appToken.token);
6599 if (parent == null || appToken == parent) {
6600 break;
6601 }
6602 appToken = parent;
6603 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006604 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006605 mAppToken = appToken.appWindowToken;
6606
6607 mSurface = null;
6608 mRequestedWidth = 0;
6609 mRequestedHeight = 0;
6610 mLastRequestedWidth = 0;
6611 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006612 mXOffset = 0;
6613 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006614 mLayer = 0;
6615 mAnimLayer = 0;
6616 mLastLayer = 0;
6617 }
6618
6619 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006620 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006621 TAG, "Attaching " + this + " token=" + mToken
6622 + ", list=" + mToken.windows);
6623 mSession.windowAddedLocked();
6624 }
6625
6626 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6627 mHaveFrame = true;
6628
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006629 final Rect container = mContainingFrame;
6630 container.set(pf);
6631
6632 final Rect display = mDisplayFrame;
6633 display.set(df);
6634
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006635 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006636 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006637 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6638 display.intersect(mCompatibleScreenFrame);
6639 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006640 }
6641
6642 final int pw = container.right - container.left;
6643 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006644
6645 int w,h;
6646 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6647 w = mAttrs.width < 0 ? pw : mAttrs.width;
6648 h = mAttrs.height< 0 ? ph : mAttrs.height;
6649 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006650 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6651 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006652 }
Romain Guy06882f82009-06-10 13:36:04 -07006653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006654 final Rect content = mContentFrame;
6655 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006657 final Rect visible = mVisibleFrame;
6658 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006660 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006661 final int fw = frame.width();
6662 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006664 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6665 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6666
6667 Gravity.apply(mAttrs.gravity, w, h, container,
6668 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6669 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6670
6671 //System.out.println("Out: " + mFrame);
6672
6673 // Now make sure the window fits in the overall display.
6674 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006675
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006676 // Make sure the content and visible frames are inside of the
6677 // final window frame.
6678 if (content.left < frame.left) content.left = frame.left;
6679 if (content.top < frame.top) content.top = frame.top;
6680 if (content.right > frame.right) content.right = frame.right;
6681 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6682 if (visible.left < frame.left) visible.left = frame.left;
6683 if (visible.top < frame.top) visible.top = frame.top;
6684 if (visible.right > frame.right) visible.right = frame.right;
6685 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006687 final Rect contentInsets = mContentInsets;
6688 contentInsets.left = content.left-frame.left;
6689 contentInsets.top = content.top-frame.top;
6690 contentInsets.right = frame.right-content.right;
6691 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006693 final Rect visibleInsets = mVisibleInsets;
6694 visibleInsets.left = visible.left-frame.left;
6695 visibleInsets.top = visible.top-frame.top;
6696 visibleInsets.right = frame.right-visible.right;
6697 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006698
Dianne Hackborn284ac932009-08-28 10:34:25 -07006699 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6700 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006701 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006702 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006704 if (localLOGV) {
6705 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6706 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006707 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006708 + mRequestedWidth + ", mRequestedheight="
6709 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6710 + "): frame=" + mFrame.toShortString()
6711 + " ci=" + contentInsets.toShortString()
6712 + " vi=" + visibleInsets.toShortString());
6713 //}
6714 }
6715 }
Romain Guy06882f82009-06-10 13:36:04 -07006716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006717 public Rect getFrameLw() {
6718 return mFrame;
6719 }
6720
6721 public Rect getShownFrameLw() {
6722 return mShownFrame;
6723 }
6724
6725 public Rect getDisplayFrameLw() {
6726 return mDisplayFrame;
6727 }
6728
6729 public Rect getContentFrameLw() {
6730 return mContentFrame;
6731 }
6732
6733 public Rect getVisibleFrameLw() {
6734 return mVisibleFrame;
6735 }
6736
6737 public boolean getGivenInsetsPendingLw() {
6738 return mGivenInsetsPending;
6739 }
6740
6741 public Rect getGivenContentInsetsLw() {
6742 return mGivenContentInsets;
6743 }
Romain Guy06882f82009-06-10 13:36:04 -07006744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006745 public Rect getGivenVisibleInsetsLw() {
6746 return mGivenVisibleInsets;
6747 }
Romain Guy06882f82009-06-10 13:36:04 -07006748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006749 public WindowManager.LayoutParams getAttrs() {
6750 return mAttrs;
6751 }
6752
6753 public int getSurfaceLayer() {
6754 return mLayer;
6755 }
Romain Guy06882f82009-06-10 13:36:04 -07006756
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006757 public IApplicationToken getAppToken() {
6758 return mAppToken != null ? mAppToken.appToken : null;
6759 }
Jeff Brown349703e2010-06-22 01:27:15 -07006760
6761 public long getInputDispatchingTimeoutNanos() {
6762 return mAppToken != null
6763 ? mAppToken.inputDispatchingTimeoutNanos
6764 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6765 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006766
6767 public boolean hasAppShownWindows() {
6768 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6769 }
6770
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006771 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006772 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006773 TAG, "Setting animation in " + this + ": " + anim);
6774 mAnimating = false;
6775 mLocalAnimating = false;
6776 mAnimation = anim;
6777 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6778 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6779 }
6780
6781 public void clearAnimation() {
6782 if (mAnimation != null) {
6783 mAnimating = true;
6784 mLocalAnimating = false;
6785 mAnimation = null;
6786 }
6787 }
Romain Guy06882f82009-06-10 13:36:04 -07006788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006789 Surface createSurfaceLocked() {
6790 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006791 mReportDestroySurface = false;
6792 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006793 mDrawPending = true;
6794 mCommitDrawPending = false;
6795 mReadyToShow = false;
6796 if (mAppToken != null) {
6797 mAppToken.allDrawn = false;
6798 }
6799
6800 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006801 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006802 flags |= Surface.PUSH_BUFFERS;
6803 }
6804
6805 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6806 flags |= Surface.SECURE;
6807 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006808 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006809 TAG, "Creating surface in session "
6810 + mSession.mSurfaceSession + " window " + this
6811 + " w=" + mFrame.width()
6812 + " h=" + mFrame.height() + " format="
6813 + mAttrs.format + " flags=" + flags);
6814
6815 int w = mFrame.width();
6816 int h = mFrame.height();
6817 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6818 // for a scaled surface, we always want the requested
6819 // size.
6820 w = mRequestedWidth;
6821 h = mRequestedHeight;
6822 }
6823
Romain Guy9825ec62009-10-01 00:58:09 -07006824 // Something is wrong and SurfaceFlinger will not like this,
6825 // try to revert to sane values
6826 if (w <= 0) w = 1;
6827 if (h <= 0) h = 1;
6828
Dianne Hackborn16064f92010-03-25 00:47:24 -07006829 mSurfaceShown = false;
6830 mSurfaceLayer = 0;
6831 mSurfaceAlpha = 1;
6832 mSurfaceX = 0;
6833 mSurfaceY = 0;
6834 mSurfaceW = w;
6835 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006836 try {
6837 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006838 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006839 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006840 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006841 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006842 + mSurface + " IN SESSION "
6843 + mSession.mSurfaceSession
6844 + ": pid=" + mSession.mPid + " format="
6845 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006846 + Integer.toHexString(flags)
6847 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006848 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006849 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006850 reclaimSomeSurfaceMemoryLocked(this, "create");
6851 return null;
6852 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006853 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006854 return null;
6855 }
Romain Guy06882f82009-06-10 13:36:04 -07006856
Joe Onorato8a9b2202010-02-26 18:56:32 -08006857 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006858 TAG, "Got surface: " + mSurface
6859 + ", set left=" + mFrame.left + " top=" + mFrame.top
6860 + ", animLayer=" + mAnimLayer);
6861 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006862 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006863 if (SHOW_TRANSACTIONS) logSurface(this,
6864 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6865 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6866 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006867 }
6868 Surface.openTransaction();
6869 try {
6870 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006871 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006872 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006873 mSurface.setPosition(mSurfaceX, mSurfaceY);
6874 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006875 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006876 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006877 mSurface.hide();
6878 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006879 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006880 mSurface.setFlags(Surface.SURFACE_DITHER,
6881 Surface.SURFACE_DITHER);
6882 }
6883 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006884 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006885 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6886 }
6887 mLastHidden = true;
6888 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006889 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006890 Surface.closeTransaction();
6891 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006892 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006893 TAG, "Created surface " + this);
6894 }
6895 return mSurface;
6896 }
Romain Guy06882f82009-06-10 13:36:04 -07006897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006898 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006899 if (mAppToken != null && this == mAppToken.startingWindow) {
6900 mAppToken.startingDisplayed = false;
6901 }
Romain Guy06882f82009-06-10 13:36:04 -07006902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006903 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006904 mDrawPending = false;
6905 mCommitDrawPending = false;
6906 mReadyToShow = false;
6907
6908 int i = mChildWindows.size();
6909 while (i > 0) {
6910 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006911 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006912 c.mAttachedHidden = true;
6913 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006914
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006915 if (mReportDestroySurface) {
6916 mReportDestroySurface = false;
6917 mSurfacePendingDestroy = true;
6918 try {
6919 mClient.dispatchGetNewSurface();
6920 // We'll really destroy on the next time around.
6921 return;
6922 } catch (RemoteException e) {
6923 }
6924 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006926 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006927 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006928 RuntimeException e = null;
6929 if (!HIDE_STACK_CRAWLS) {
6930 e = new RuntimeException();
6931 e.fillInStackTrace();
6932 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006933 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006934 + mSurface + ", session " + mSession, e);
6935 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006936 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006937 RuntimeException e = null;
6938 if (!HIDE_STACK_CRAWLS) {
6939 e = new RuntimeException();
6940 e.fillInStackTrace();
6941 }
6942 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006943 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006944 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006945 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006946 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006947 + " surface " + mSurface + " session " + mSession
6948 + ": " + e.toString());
6949 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006950
Dianne Hackborn16064f92010-03-25 00:47:24 -07006951 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006952 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006953 }
6954 }
6955
6956 boolean finishDrawingLocked() {
6957 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006958 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006959 TAG, "finishDrawingLocked: " + mSurface);
6960 mCommitDrawPending = true;
6961 mDrawPending = false;
6962 return true;
6963 }
6964 return false;
6965 }
6966
6967 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006968 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006969 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006970 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006971 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006972 }
6973 mCommitDrawPending = false;
6974 mReadyToShow = true;
6975 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6976 final AppWindowToken atoken = mAppToken;
6977 if (atoken == null || atoken.allDrawn || starting) {
6978 performShowLocked();
6979 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006980 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006981 }
6982
6983 // This must be called while inside a transaction.
6984 boolean performShowLocked() {
6985 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006986 RuntimeException e = null;
6987 if (!HIDE_STACK_CRAWLS) {
6988 e = new RuntimeException();
6989 e.fillInStackTrace();
6990 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006991 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006992 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
6993 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
6994 }
6995 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006996 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
6997 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006998 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006999 + " during animation: policyVis=" + mPolicyVisibility
7000 + " attHidden=" + mAttachedHidden
7001 + " tok.hiddenRequested="
7002 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007003 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007004 + (mAppToken != null ? mAppToken.hidden : false)
7005 + " animating=" + mAnimating
7006 + " tok animating="
7007 + (mAppToken != null ? mAppToken.animating : false));
7008 if (!showSurfaceRobustlyLocked(this)) {
7009 return false;
7010 }
7011 mLastAlpha = -1;
7012 mHasDrawn = true;
7013 mLastHidden = false;
7014 mReadyToShow = false;
7015 enableScreenIfNeededLocked();
7016
7017 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007018
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007019 int i = mChildWindows.size();
7020 while (i > 0) {
7021 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007022 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007023 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007024 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007025 if (c.mSurface != null) {
7026 c.performShowLocked();
7027 // It hadn't been shown, which means layout not
7028 // performed on it, so now we want to make sure to
7029 // do a layout. If called from within the transaction
7030 // loop, this will cause it to restart with a new
7031 // layout.
7032 mLayoutNeeded = true;
7033 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007034 }
7035 }
Romain Guy06882f82009-06-10 13:36:04 -07007036
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007037 if (mAttrs.type != TYPE_APPLICATION_STARTING
7038 && mAppToken != null) {
7039 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007040
Dianne Hackborn248b1882009-09-16 16:46:44 -07007041 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007042 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007043 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007044 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007045 // If this initial window is animating, stop it -- we
7046 // will do an animation to reveal it from behind the
7047 // starting window, so there is no need for it to also
7048 // be doing its own stuff.
7049 if (mAnimation != null) {
7050 mAnimation = null;
7051 // Make sure we clean up the animation.
7052 mAnimating = true;
7053 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007054 mFinishedStarting.add(mAppToken);
7055 mH.sendEmptyMessage(H.FINISHED_STARTING);
7056 }
7057 mAppToken.updateReportedVisibilityLocked();
7058 }
7059 }
7060 return true;
7061 }
Romain Guy06882f82009-06-10 13:36:04 -07007062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007063 // This must be called while inside a transaction. Returns true if
7064 // there is more animation to run.
7065 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007066 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007067 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007069 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7070 mHasTransformation = true;
7071 mHasLocalTransformation = true;
7072 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007073 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007074 TAG, "Starting animation in " + this +
7075 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7076 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7077 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7078 mAnimation.setStartTime(currentTime);
7079 mLocalAnimating = true;
7080 mAnimating = true;
7081 }
7082 mTransformation.clear();
7083 final boolean more = mAnimation.getTransformation(
7084 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007085 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007086 TAG, "Stepped animation in " + this +
7087 ": more=" + more + ", xform=" + mTransformation);
7088 if (more) {
7089 // we're not done!
7090 return true;
7091 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007092 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007093 TAG, "Finished animation in " + this +
7094 " @ " + currentTime);
7095 mAnimation = null;
7096 //WindowManagerService.this.dump();
7097 }
7098 mHasLocalTransformation = false;
7099 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007100 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007101 // When our app token is animating, we kind-of pretend like
7102 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7103 // part of this check means that we will only do this if
7104 // our window is not currently exiting, or it is not
7105 // locally animating itself. The idea being that one that
7106 // is exiting and doing a local animation should be removed
7107 // once that animation is done.
7108 mAnimating = true;
7109 mHasTransformation = true;
7110 mTransformation.clear();
7111 return false;
7112 } else if (mHasTransformation) {
7113 // Little trick to get through the path below to act like
7114 // we have finished an animation.
7115 mAnimating = true;
7116 } else if (isAnimating()) {
7117 mAnimating = true;
7118 }
7119 } else if (mAnimation != null) {
7120 // If the display is frozen, and there is a pending animation,
7121 // clear it and make sure we run the cleanup code.
7122 mAnimating = true;
7123 mLocalAnimating = true;
7124 mAnimation = null;
7125 }
Romain Guy06882f82009-06-10 13:36:04 -07007126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007127 if (!mAnimating && !mLocalAnimating) {
7128 return false;
7129 }
7130
Joe Onorato8a9b2202010-02-26 18:56:32 -08007131 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007132 TAG, "Animation done in " + this + ": exiting=" + mExiting
7133 + ", reportedVisible="
7134 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007136 mAnimating = false;
7137 mLocalAnimating = false;
7138 mAnimation = null;
7139 mAnimLayer = mLayer;
7140 if (mIsImWindow) {
7141 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007142 } else if (mIsWallpaper) {
7143 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007144 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007145 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007146 + " anim layer: " + mAnimLayer);
7147 mHasTransformation = false;
7148 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007149 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7150 if (DEBUG_VISIBILITY) {
7151 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7152 + mPolicyVisibilityAfterAnim);
7153 }
7154 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7155 if (!mPolicyVisibility) {
7156 if (mCurrentFocus == this) {
7157 mFocusMayChange = true;
7158 }
7159 // Window is no longer visible -- make sure if we were waiting
7160 // for it to be displayed before enabling the display, that
7161 // we allow the display to be enabled now.
7162 enableScreenIfNeededLocked();
7163 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007164 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007165 mTransformation.clear();
7166 if (mHasDrawn
7167 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7168 && mAppToken != null
7169 && mAppToken.firstWindowDrawn
7170 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007171 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007172 + mToken + ": first real window done animating");
7173 mFinishedStarting.add(mAppToken);
7174 mH.sendEmptyMessage(H.FINISHED_STARTING);
7175 }
Romain Guy06882f82009-06-10 13:36:04 -07007176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007177 finishExit();
7178
7179 if (mAppToken != null) {
7180 mAppToken.updateReportedVisibilityLocked();
7181 }
7182
7183 return false;
7184 }
7185
7186 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007187 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007188 TAG, "finishExit in " + this
7189 + ": exiting=" + mExiting
7190 + " remove=" + mRemoveOnExit
7191 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007193 final int N = mChildWindows.size();
7194 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007195 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007196 }
Romain Guy06882f82009-06-10 13:36:04 -07007197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007198 if (!mExiting) {
7199 return;
7200 }
Romain Guy06882f82009-06-10 13:36:04 -07007201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007202 if (isWindowAnimating()) {
7203 return;
7204 }
7205
Joe Onorato8a9b2202010-02-26 18:56:32 -08007206 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007207 TAG, "Exit animation finished in " + this
7208 + ": remove=" + mRemoveOnExit);
7209 if (mSurface != null) {
7210 mDestroySurface.add(this);
7211 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007212 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007213 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007214 try {
7215 mSurface.hide();
7216 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007217 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007218 }
7219 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007220 }
7221 mExiting = false;
7222 if (mRemoveOnExit) {
7223 mPendingRemove.add(this);
7224 mRemoveOnExit = false;
7225 }
7226 }
Romain Guy06882f82009-06-10 13:36:04 -07007227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007228 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7229 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7230 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7231 if (dtdx < -.000001f || dtdx > .000001f) return false;
7232 if (dsdy < -.000001f || dsdy > .000001f) return false;
7233 return true;
7234 }
Romain Guy06882f82009-06-10 13:36:04 -07007235
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007236 void computeShownFrameLocked() {
7237 final boolean selfTransformation = mHasLocalTransformation;
7238 Transformation attachedTransformation =
7239 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7240 ? mAttachedWindow.mTransformation : null;
7241 Transformation appTransformation =
7242 (mAppToken != null && mAppToken.hasTransformation)
7243 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007244
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007245 // Wallpapers are animated based on the "real" window they
7246 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007247 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007248 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007249 if (mWallpaperTarget.mHasLocalTransformation &&
7250 mWallpaperTarget.mAnimation != null &&
7251 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007252 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007253 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007254 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007255 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007256 }
7257 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007258 mWallpaperTarget.mAppToken.hasTransformation &&
7259 mWallpaperTarget.mAppToken.animation != null &&
7260 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007261 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007262 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007263 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007264 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007265 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007266 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007268 if (selfTransformation || attachedTransformation != null
7269 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007270 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007271 final Rect frame = mFrame;
7272 final float tmpFloats[] = mTmpFloats;
7273 final Matrix tmpMatrix = mTmpMatrix;
7274
7275 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007276 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007277 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007278 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007279 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007280 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007281 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007282 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007283 }
7284 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007285 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007286 }
7287
7288 // "convert" it into SurfaceFlinger's format
7289 // (a 2x2 matrix + an offset)
7290 // Here we must not transform the position of the surface
7291 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007292 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007294 tmpMatrix.getValues(tmpFloats);
7295 mDsDx = tmpFloats[Matrix.MSCALE_X];
7296 mDtDx = tmpFloats[Matrix.MSKEW_X];
7297 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7298 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007299 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7300 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007301 int w = frame.width();
7302 int h = frame.height();
7303 mShownFrame.set(x, y, x+w, y+h);
7304
7305 // Now set the alpha... but because our current hardware
7306 // can't do alpha transformation on a non-opaque surface,
7307 // turn it off if we are running an animation that is also
7308 // transforming since it is more important to have that
7309 // animation be smooth.
7310 mShownAlpha = mAlpha;
7311 if (!mLimitedAlphaCompositing
7312 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7313 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7314 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007315 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007316 if (selfTransformation) {
7317 mShownAlpha *= mTransformation.getAlpha();
7318 }
7319 if (attachedTransformation != null) {
7320 mShownAlpha *= attachedTransformation.getAlpha();
7321 }
7322 if (appTransformation != null) {
7323 mShownAlpha *= appTransformation.getAlpha();
7324 }
7325 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007326 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007327 }
Romain Guy06882f82009-06-10 13:36:04 -07007328
Joe Onorato8a9b2202010-02-26 18:56:32 -08007329 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007330 TAG, "Continuing animation in " + this +
7331 ": " + mShownFrame +
7332 ", alpha=" + mTransformation.getAlpha());
7333 return;
7334 }
Romain Guy06882f82009-06-10 13:36:04 -07007335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007336 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007337 if (mXOffset != 0 || mYOffset != 0) {
7338 mShownFrame.offset(mXOffset, mYOffset);
7339 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007340 mShownAlpha = mAlpha;
7341 mDsDx = 1;
7342 mDtDx = 0;
7343 mDsDy = 0;
7344 mDtDy = 1;
7345 }
Romain Guy06882f82009-06-10 13:36:04 -07007346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007347 /**
7348 * Is this window visible? It is not visible if there is no
7349 * surface, or we are in the process of running an exit animation
7350 * that will remove the surface, or its app token has been hidden.
7351 */
7352 public boolean isVisibleLw() {
7353 final AppWindowToken atoken = mAppToken;
7354 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7355 && (atoken == null || !atoken.hiddenRequested)
7356 && !mExiting && !mDestroying;
7357 }
7358
7359 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007360 * Like {@link #isVisibleLw}, but also counts a window that is currently
7361 * "hidden" behind the keyguard as visible. This allows us to apply
7362 * things like window flags that impact the keyguard.
7363 * XXX I am starting to think we need to have ANOTHER visibility flag
7364 * for this "hidden behind keyguard" state rather than overloading
7365 * mPolicyVisibility. Ungh.
7366 */
7367 public boolean isVisibleOrBehindKeyguardLw() {
7368 final AppWindowToken atoken = mAppToken;
7369 return mSurface != null && !mAttachedHidden
7370 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007371 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007372 && !mExiting && !mDestroying;
7373 }
7374
7375 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007376 * Is this window visible, ignoring its app token? It is not visible
7377 * if there is no surface, or we are in the process of running an exit animation
7378 * that will remove the surface.
7379 */
7380 public boolean isWinVisibleLw() {
7381 final AppWindowToken atoken = mAppToken;
7382 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7383 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7384 && !mExiting && !mDestroying;
7385 }
7386
7387 /**
7388 * The same as isVisible(), but follows the current hidden state of
7389 * the associated app token, not the pending requested hidden state.
7390 */
7391 boolean isVisibleNow() {
7392 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007393 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007394 }
7395
7396 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007397 * Can this window possibly be a drag/drop target? The test here is
7398 * a combination of the above "visible now" with the check that the
7399 * Input Manager uses when discarding windows from input consideration.
7400 */
7401 boolean isPotentialDragTarget() {
7402 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7403 }
7404
7405 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007406 * Same as isVisible(), but we also count it as visible between the
7407 * call to IWindowSession.add() and the first relayout().
7408 */
7409 boolean isVisibleOrAdding() {
7410 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007411 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007412 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7413 && mPolicyVisibility && !mAttachedHidden
7414 && (atoken == null || !atoken.hiddenRequested)
7415 && !mExiting && !mDestroying;
7416 }
7417
7418 /**
7419 * Is this window currently on-screen? It is on-screen either if it
7420 * is visible or it is currently running an animation before no longer
7421 * being visible.
7422 */
7423 boolean isOnScreen() {
7424 final AppWindowToken atoken = mAppToken;
7425 if (atoken != null) {
7426 return mSurface != null && mPolicyVisibility && !mDestroying
7427 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007428 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007429 } else {
7430 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007431 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007432 }
7433 }
Romain Guy06882f82009-06-10 13:36:04 -07007434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007435 /**
7436 * Like isOnScreen(), but we don't return true if the window is part
7437 * of a transition that has not yet been started.
7438 */
7439 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007440 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007441 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007442 return false;
7443 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007444 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007445 final boolean animating = atoken != null
7446 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007447 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007448 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7449 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007450 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007451 }
7452
7453 /** Is the window or its container currently animating? */
7454 boolean isAnimating() {
7455 final WindowState attached = mAttachedWindow;
7456 final AppWindowToken atoken = mAppToken;
7457 return mAnimation != null
7458 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007459 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007460 (atoken.animation != null
7461 || atoken.inPendingTransaction));
7462 }
7463
7464 /** Is this window currently animating? */
7465 boolean isWindowAnimating() {
7466 return mAnimation != null;
7467 }
7468
7469 /**
7470 * Like isOnScreen, but returns false if the surface hasn't yet
7471 * been drawn.
7472 */
7473 public boolean isDisplayedLw() {
7474 final AppWindowToken atoken = mAppToken;
7475 return mSurface != null && mPolicyVisibility && !mDestroying
7476 && !mDrawPending && !mCommitDrawPending
7477 && ((!mAttachedHidden &&
7478 (atoken == null || !atoken.hiddenRequested))
7479 || mAnimating);
7480 }
7481
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007482 /**
7483 * Returns true if the window has a surface that it has drawn a
7484 * complete UI in to.
7485 */
7486 public boolean isDrawnLw() {
7487 final AppWindowToken atoken = mAppToken;
7488 return mSurface != null && !mDestroying
7489 && !mDrawPending && !mCommitDrawPending;
7490 }
7491
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007492 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007493 * Return true if the window is opaque and fully drawn. This indicates
7494 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007495 */
7496 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007497 return (mAttrs.format == PixelFormat.OPAQUE
7498 || mAttrs.type == TYPE_WALLPAPER)
7499 && mSurface != null && mAnimation == null
7500 && (mAppToken == null || mAppToken.animation == null)
7501 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007502 }
7503
7504 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7505 return
7506 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007507 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7508 // only if it's visible
7509 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007510 // and only if the application fills the compatible screen
7511 mFrame.left <= mCompatibleScreenFrame.left &&
7512 mFrame.top <= mCompatibleScreenFrame.top &&
7513 mFrame.right >= mCompatibleScreenFrame.right &&
7514 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007515 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007516 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007517 }
7518
7519 boolean isFullscreen(int screenWidth, int screenHeight) {
7520 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007521 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007522 }
7523
7524 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007525 disposeInputChannel();
7526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007527 if (mAttachedWindow != null) {
7528 mAttachedWindow.mChildWindows.remove(this);
7529 }
7530 destroySurfaceLocked();
7531 mSession.windowRemovedLocked();
7532 try {
7533 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7534 } catch (RuntimeException e) {
7535 // Ignore if it has already been removed (usually because
7536 // we are doing this as part of processing a death note.)
7537 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007538 }
7539
7540 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007541 if (mInputChannel != null) {
7542 mInputManager.unregisterInputChannel(mInputChannel);
7543
7544 mInputChannel.dispose();
7545 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007546 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007547 }
7548
7549 private class DeathRecipient implements IBinder.DeathRecipient {
7550 public void binderDied() {
7551 try {
7552 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007553 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007554 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007555 if (win != null) {
7556 removeWindowLocked(mSession, win);
7557 }
7558 }
7559 } catch (IllegalArgumentException ex) {
7560 // This will happen if the window has already been
7561 // removed.
7562 }
7563 }
7564 }
7565
7566 /** Returns true if this window desires key events. */
7567 public final boolean canReceiveKeys() {
7568 return isVisibleOrAdding()
7569 && (mViewVisibility == View.VISIBLE)
7570 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7571 }
7572
7573 public boolean hasDrawnLw() {
7574 return mHasDrawn;
7575 }
7576
7577 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007578 return showLw(doAnimation, true);
7579 }
7580
7581 boolean showLw(boolean doAnimation, boolean requestAnim) {
7582 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7583 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007584 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007585 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007586 if (doAnimation) {
7587 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7588 + mPolicyVisibility + " mAnimation=" + mAnimation);
7589 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7590 doAnimation = false;
7591 } else if (mPolicyVisibility && mAnimation == null) {
7592 // Check for the case where we are currently visible and
7593 // not animating; we do not want to do animation at such a
7594 // point to become visible when we already are.
7595 doAnimation = false;
7596 }
7597 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007598 mPolicyVisibility = true;
7599 mPolicyVisibilityAfterAnim = true;
7600 if (doAnimation) {
7601 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7602 }
7603 if (requestAnim) {
7604 requestAnimationLocked(0);
7605 }
7606 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007607 }
7608
7609 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007610 return hideLw(doAnimation, true);
7611 }
7612
7613 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007614 if (doAnimation) {
7615 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7616 doAnimation = false;
7617 }
7618 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007619 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7620 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007621 if (!current) {
7622 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007623 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007624 if (doAnimation) {
7625 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7626 if (mAnimation == null) {
7627 doAnimation = false;
7628 }
7629 }
7630 if (doAnimation) {
7631 mPolicyVisibilityAfterAnim = false;
7632 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007633 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007634 mPolicyVisibilityAfterAnim = false;
7635 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007636 // Window is no longer visible -- make sure if we were waiting
7637 // for it to be displayed before enabling the display, that
7638 // we allow the display to be enabled now.
7639 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007640 if (mCurrentFocus == this) {
7641 mFocusMayChange = true;
7642 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007643 }
7644 if (requestAnim) {
7645 requestAnimationLocked(0);
7646 }
7647 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007648 }
7649
7650 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007651 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7652 pw.print(" mClient="); pw.println(mClient.asBinder());
7653 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7654 if (mAttachedWindow != null || mLayoutAttached) {
7655 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7656 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7657 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007658 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7659 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7660 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007661 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7662 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007663 }
7664 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7665 pw.print(" mSubLayer="); pw.print(mSubLayer);
7666 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7667 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7668 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7669 pw.print("="); pw.print(mAnimLayer);
7670 pw.print(" mLastLayer="); pw.println(mLastLayer);
7671 if (mSurface != null) {
7672 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007673 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7674 pw.print(" layer="); pw.print(mSurfaceLayer);
7675 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7676 pw.print(" rect=("); pw.print(mSurfaceX);
7677 pw.print(","); pw.print(mSurfaceY);
7678 pw.print(") "); pw.print(mSurfaceW);
7679 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007680 }
7681 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7682 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7683 if (mAppToken != null) {
7684 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7685 }
7686 if (mTargetAppToken != null) {
7687 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7688 }
7689 pw.print(prefix); pw.print("mViewVisibility=0x");
7690 pw.print(Integer.toHexString(mViewVisibility));
7691 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007692 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7693 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007694 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7695 pw.print(prefix); pw.print("mPolicyVisibility=");
7696 pw.print(mPolicyVisibility);
7697 pw.print(" mPolicyVisibilityAfterAnim=");
7698 pw.print(mPolicyVisibilityAfterAnim);
7699 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7700 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007701 if (!mRelayoutCalled) {
7702 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7703 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007704 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007705 pw.print(" h="); pw.print(mRequestedHeight);
7706 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007707 if (mXOffset != 0 || mYOffset != 0) {
7708 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7709 pw.print(" y="); pw.println(mYOffset);
7710 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007711 pw.print(prefix); pw.print("mGivenContentInsets=");
7712 mGivenContentInsets.printShortString(pw);
7713 pw.print(" mGivenVisibleInsets=");
7714 mGivenVisibleInsets.printShortString(pw);
7715 pw.println();
7716 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7717 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7718 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7719 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007720 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007721 pw.print(prefix); pw.print("mShownFrame=");
7722 mShownFrame.printShortString(pw);
7723 pw.print(" last="); mLastShownFrame.printShortString(pw);
7724 pw.println();
7725 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7726 pw.print(" last="); mLastFrame.printShortString(pw);
7727 pw.println();
7728 pw.print(prefix); pw.print("mContainingFrame=");
7729 mContainingFrame.printShortString(pw);
7730 pw.print(" mDisplayFrame=");
7731 mDisplayFrame.printShortString(pw);
7732 pw.println();
7733 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7734 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7735 pw.println();
7736 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7737 pw.print(" last="); mLastContentInsets.printShortString(pw);
7738 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7739 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7740 pw.println();
7741 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7742 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7743 pw.print(" mAlpha="); pw.print(mAlpha);
7744 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7745 }
7746 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7747 || mAnimation != null) {
7748 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7749 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7750 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7751 pw.print(" mAnimation="); pw.println(mAnimation);
7752 }
7753 if (mHasTransformation || mHasLocalTransformation) {
7754 pw.print(prefix); pw.print("XForm: has=");
7755 pw.print(mHasTransformation);
7756 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7757 pw.print(" "); mTransformation.printShortString(pw);
7758 pw.println();
7759 }
7760 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7761 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7762 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7763 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7764 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7765 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7766 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7767 pw.print(" mDestroying="); pw.print(mDestroying);
7768 pw.print(" mRemoved="); pw.println(mRemoved);
7769 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007770 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007771 pw.print(prefix); pw.print("mOrientationChanging=");
7772 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007773 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7774 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007775 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007776 if (mHScale != 1 || mVScale != 1) {
7777 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7778 pw.print(" mVScale="); pw.println(mVScale);
7779 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007780 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007781 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7782 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7783 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007784 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7785 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7786 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7787 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007788 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007789
7790 String makeInputChannelName() {
7791 return Integer.toHexString(System.identityHashCode(this))
7792 + " " + mAttrs.getTitle();
7793 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007794
7795 @Override
7796 public String toString() {
7797 return "Window{"
7798 + Integer.toHexString(System.identityHashCode(this))
7799 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7800 }
7801 }
Romain Guy06882f82009-06-10 13:36:04 -07007802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007803 // -------------------------------------------------------------
7804 // Window Token State
7805 // -------------------------------------------------------------
7806
7807 class WindowToken {
7808 // The actual token.
7809 final IBinder token;
7810
7811 // The type of window this token is for, as per WindowManager.LayoutParams.
7812 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007814 // Set if this token was explicitly added by a client, so should
7815 // not be removed when all windows are removed.
7816 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007817
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007818 // For printing.
7819 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007821 // If this is an AppWindowToken, this is non-null.
7822 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007824 // All of the windows associated with this token.
7825 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7826
7827 // Is key dispatching paused for this token?
7828 boolean paused = false;
7829
7830 // Should this token's windows be hidden?
7831 boolean hidden;
7832
7833 // Temporary for finding which tokens no longer have visible windows.
7834 boolean hasVisible;
7835
Dianne Hackborna8f60182009-09-01 19:01:50 -07007836 // Set to true when this token is in a pending transaction where it
7837 // will be shown.
7838 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007839
Dianne Hackborna8f60182009-09-01 19:01:50 -07007840 // Set to true when this token is in a pending transaction where it
7841 // will be hidden.
7842 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007843
Dianne Hackborna8f60182009-09-01 19:01:50 -07007844 // Set to true when this token is in a pending transaction where its
7845 // windows will be put to the bottom of the list.
7846 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007847
Dianne Hackborna8f60182009-09-01 19:01:50 -07007848 // Set to true when this token is in a pending transaction where its
7849 // windows will be put to the top of the list.
7850 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007851
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007852 WindowToken(IBinder _token, int type, boolean _explicit) {
7853 token = _token;
7854 windowType = type;
7855 explicit = _explicit;
7856 }
7857
7858 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007859 pw.print(prefix); pw.print("token="); pw.println(token);
7860 pw.print(prefix); pw.print("windows="); pw.println(windows);
7861 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7862 pw.print(" hidden="); pw.print(hidden);
7863 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007864 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7865 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7866 pw.print(" waitingToHide="); pw.print(waitingToHide);
7867 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7868 pw.print(" sendingToTop="); pw.println(sendingToTop);
7869 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007870 }
7871
7872 @Override
7873 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007874 if (stringName == null) {
7875 StringBuilder sb = new StringBuilder();
7876 sb.append("WindowToken{");
7877 sb.append(Integer.toHexString(System.identityHashCode(this)));
7878 sb.append(" token="); sb.append(token); sb.append('}');
7879 stringName = sb.toString();
7880 }
7881 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007882 }
7883 };
7884
7885 class AppWindowToken extends WindowToken {
7886 // Non-null only for application tokens.
7887 final IApplicationToken appToken;
7888
7889 // All of the windows and child windows that are included in this
7890 // application token. Note this list is NOT sorted!
7891 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7892
7893 int groupId = -1;
7894 boolean appFullscreen;
7895 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007896
7897 // The input dispatching timeout for this application token in nanoseconds.
7898 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007900 // These are used for determining when all windows associated with
7901 // an activity have been drawn, so they can be made visible together
7902 // at the same time.
7903 int lastTransactionSequence = mTransactionSequence-1;
7904 int numInterestingWindows;
7905 int numDrawnWindows;
7906 boolean inPendingTransaction;
7907 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007909 // Is this token going to be hidden in a little while? If so, it
7910 // won't be taken into account for setting the screen orientation.
7911 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007913 // Is this window's surface needed? This is almost like hidden, except
7914 // it will sometimes be true a little earlier: when the token has
7915 // been shown, but is still waiting for its app transition to execute
7916 // before making its windows shown.
7917 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007919 // Have we told the window clients to hide themselves?
7920 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007922 // Last visibility state we reported to the app token.
7923 boolean reportedVisible;
7924
7925 // Set to true when the token has been removed from the window mgr.
7926 boolean removed;
7927
7928 // Have we been asked to have this token keep the screen frozen?
7929 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007931 boolean animating;
7932 Animation animation;
7933 boolean hasTransformation;
7934 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007936 // Offset to the window of all layers in the token, for use by
7937 // AppWindowToken animations.
7938 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007940 // Information about an application starting window if displayed.
7941 StartingData startingData;
7942 WindowState startingWindow;
7943 View startingView;
7944 boolean startingDisplayed;
7945 boolean startingMoved;
7946 boolean firstWindowDrawn;
7947
7948 AppWindowToken(IApplicationToken _token) {
7949 super(_token.asBinder(),
7950 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7951 appWindowToken = this;
7952 appToken = _token;
7953 }
Romain Guy06882f82009-06-10 13:36:04 -07007954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007955 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007956 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007957 TAG, "Setting animation in " + this + ": " + anim);
7958 animation = anim;
7959 animating = false;
7960 anim.restrictDuration(MAX_ANIMATION_DURATION);
7961 anim.scaleCurrentDuration(mTransitionAnimationScale);
7962 int zorder = anim.getZAdjustment();
7963 int adj = 0;
7964 if (zorder == Animation.ZORDER_TOP) {
7965 adj = TYPE_LAYER_OFFSET;
7966 } else if (zorder == Animation.ZORDER_BOTTOM) {
7967 adj = -TYPE_LAYER_OFFSET;
7968 }
Romain Guy06882f82009-06-10 13:36:04 -07007969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007970 if (animLayerAdjustment != adj) {
7971 animLayerAdjustment = adj;
7972 updateLayers();
7973 }
7974 }
Romain Guy06882f82009-06-10 13:36:04 -07007975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007976 public void setDummyAnimation() {
7977 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007978 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007979 TAG, "Setting dummy animation in " + this);
7980 animation = sDummyAnimation;
7981 }
7982 }
7983
7984 public void clearAnimation() {
7985 if (animation != null) {
7986 animation = null;
7987 animating = true;
7988 }
7989 }
Romain Guy06882f82009-06-10 13:36:04 -07007990
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007991 void updateLayers() {
7992 final int N = allAppWindows.size();
7993 final int adj = animLayerAdjustment;
7994 for (int i=0; i<N; i++) {
7995 WindowState w = allAppWindows.get(i);
7996 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007997 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007998 + w.mAnimLayer);
7999 if (w == mInputMethodTarget) {
8000 setInputMethodAnimLayerAdjustment(adj);
8001 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008002 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008003 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008004 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008005 }
8006 }
Romain Guy06882f82009-06-10 13:36:04 -07008007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008008 void sendAppVisibilityToClients() {
8009 final int N = allAppWindows.size();
8010 for (int i=0; i<N; i++) {
8011 WindowState win = allAppWindows.get(i);
8012 if (win == startingWindow && clientHidden) {
8013 // Don't hide the starting window.
8014 continue;
8015 }
8016 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008017 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008018 "Setting visibility of " + win + ": " + (!clientHidden));
8019 win.mClient.dispatchAppVisibility(!clientHidden);
8020 } catch (RemoteException e) {
8021 }
8022 }
8023 }
Romain Guy06882f82009-06-10 13:36:04 -07008024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008025 void showAllWindowsLocked() {
8026 final int NW = allAppWindows.size();
8027 for (int i=0; i<NW; i++) {
8028 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008029 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008030 "performing show on: " + w);
8031 w.performShowLocked();
8032 }
8033 }
Romain Guy06882f82009-06-10 13:36:04 -07008034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008035 // This must be called while inside a transaction.
8036 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008037 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008038 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008040 if (animation == sDummyAnimation) {
8041 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008042 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008043 // when it is really time to animate, this will be set to
8044 // a real animation and the next call will execute normally.
8045 return false;
8046 }
Romain Guy06882f82009-06-10 13:36:04 -07008047
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008048 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8049 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008050 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008051 TAG, "Starting animation in " + this +
8052 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8053 + " scale=" + mTransitionAnimationScale
8054 + " allDrawn=" + allDrawn + " animating=" + animating);
8055 animation.initialize(dw, dh, dw, dh);
8056 animation.setStartTime(currentTime);
8057 animating = true;
8058 }
8059 transformation.clear();
8060 final boolean more = animation.getTransformation(
8061 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008062 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008063 TAG, "Stepped animation in " + this +
8064 ": more=" + more + ", xform=" + transformation);
8065 if (more) {
8066 // we're done!
8067 hasTransformation = true;
8068 return true;
8069 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008070 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008071 TAG, "Finished animation in " + this +
8072 " @ " + currentTime);
8073 animation = null;
8074 }
8075 } else if (animation != null) {
8076 // If the display is frozen, and there is a pending animation,
8077 // clear it and make sure we run the cleanup code.
8078 animating = true;
8079 animation = null;
8080 }
8081
8082 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008084 if (!animating) {
8085 return false;
8086 }
8087
8088 clearAnimation();
8089 animating = false;
8090 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8091 moveInputMethodWindowsIfNeededLocked(true);
8092 }
Romain Guy06882f82009-06-10 13:36:04 -07008093
Joe Onorato8a9b2202010-02-26 18:56:32 -08008094 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008095 TAG, "Animation done in " + this
8096 + ": reportedVisible=" + reportedVisible);
8097
8098 transformation.clear();
8099 if (animLayerAdjustment != 0) {
8100 animLayerAdjustment = 0;
8101 updateLayers();
8102 }
Romain Guy06882f82009-06-10 13:36:04 -07008103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008104 final int N = windows.size();
8105 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008106 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008107 }
8108 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008110 return false;
8111 }
8112
8113 void updateReportedVisibilityLocked() {
8114 if (appToken == null) {
8115 return;
8116 }
Romain Guy06882f82009-06-10 13:36:04 -07008117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008118 int numInteresting = 0;
8119 int numVisible = 0;
8120 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008121
Joe Onorato8a9b2202010-02-26 18:56:32 -08008122 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008123 final int N = allAppWindows.size();
8124 for (int i=0; i<N; i++) {
8125 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008126 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008127 || win.mViewVisibility != View.VISIBLE
8128 || win.mAttrs.type == TYPE_APPLICATION_STARTING) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008129 continue;
8130 }
8131 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008132 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008133 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008134 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008135 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008136 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008137 + " pv=" + win.mPolicyVisibility
8138 + " dp=" + win.mDrawPending
8139 + " cdp=" + win.mCommitDrawPending
8140 + " ah=" + win.mAttachedHidden
8141 + " th="
8142 + (win.mAppToken != null
8143 ? win.mAppToken.hiddenRequested : false)
8144 + " a=" + win.mAnimating);
8145 }
8146 }
8147 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008148 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008149 if (!win.isAnimating()) {
8150 numVisible++;
8151 }
8152 nowGone = false;
8153 } else if (win.isAnimating()) {
8154 nowGone = false;
8155 }
8156 }
Romain Guy06882f82009-06-10 13:36:04 -07008157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008158 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008159 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008160 + numInteresting + " visible=" + numVisible);
8161 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008162 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008163 TAG, "Visibility changed in " + this
8164 + ": vis=" + nowVisible);
8165 reportedVisible = nowVisible;
8166 Message m = mH.obtainMessage(
8167 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8168 nowVisible ? 1 : 0,
8169 nowGone ? 1 : 0,
8170 this);
8171 mH.sendMessage(m);
8172 }
8173 }
Romain Guy06882f82009-06-10 13:36:04 -07008174
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008175 WindowState findMainWindow() {
8176 int j = windows.size();
8177 while (j > 0) {
8178 j--;
8179 WindowState win = windows.get(j);
8180 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8181 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8182 return win;
8183 }
8184 }
8185 return null;
8186 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008188 void dump(PrintWriter pw, String prefix) {
8189 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008190 if (appToken != null) {
8191 pw.print(prefix); pw.println("app=true");
8192 }
8193 if (allAppWindows.size() > 0) {
8194 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8195 }
8196 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008197 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008198 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8199 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8200 pw.print(" clientHidden="); pw.print(clientHidden);
8201 pw.print(" willBeHidden="); pw.print(willBeHidden);
8202 pw.print(" reportedVisible="); pw.println(reportedVisible);
8203 if (paused || freezingScreen) {
8204 pw.print(prefix); pw.print("paused="); pw.print(paused);
8205 pw.print(" freezingScreen="); pw.println(freezingScreen);
8206 }
8207 if (numInterestingWindows != 0 || numDrawnWindows != 0
8208 || inPendingTransaction || allDrawn) {
8209 pw.print(prefix); pw.print("numInterestingWindows=");
8210 pw.print(numInterestingWindows);
8211 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8212 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8213 pw.print(" allDrawn="); pw.println(allDrawn);
8214 }
8215 if (animating || animation != null) {
8216 pw.print(prefix); pw.print("animating="); pw.print(animating);
8217 pw.print(" animation="); pw.println(animation);
8218 }
8219 if (animLayerAdjustment != 0) {
8220 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8221 }
8222 if (hasTransformation) {
8223 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8224 pw.print(" transformation="); transformation.printShortString(pw);
8225 pw.println();
8226 }
8227 if (startingData != null || removed || firstWindowDrawn) {
8228 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8229 pw.print(" removed="); pw.print(removed);
8230 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8231 }
8232 if (startingWindow != null || startingView != null
8233 || startingDisplayed || startingMoved) {
8234 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8235 pw.print(" startingView="); pw.print(startingView);
8236 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8237 pw.print(" startingMoved"); pw.println(startingMoved);
8238 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008239 }
8240
8241 @Override
8242 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008243 if (stringName == null) {
8244 StringBuilder sb = new StringBuilder();
8245 sb.append("AppWindowToken{");
8246 sb.append(Integer.toHexString(System.identityHashCode(this)));
8247 sb.append(" token="); sb.append(token); sb.append('}');
8248 stringName = sb.toString();
8249 }
8250 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008251 }
8252 }
Romain Guy06882f82009-06-10 13:36:04 -07008253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008254 // -------------------------------------------------------------
8255 // DummyAnimation
8256 // -------------------------------------------------------------
8257
8258 // This is an animation that does nothing: it just immediately finishes
8259 // itself every time it is called. It is used as a stub animation in cases
8260 // where we want to synchronize multiple things that may be animating.
8261 static final class DummyAnimation extends Animation {
8262 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8263 return false;
8264 }
8265 }
8266 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008268 // -------------------------------------------------------------
8269 // Async Handler
8270 // -------------------------------------------------------------
8271
8272 static final class StartingData {
8273 final String pkg;
8274 final int theme;
8275 final CharSequence nonLocalizedLabel;
8276 final int labelRes;
8277 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008279 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8280 int _labelRes, int _icon) {
8281 pkg = _pkg;
8282 theme = _theme;
8283 nonLocalizedLabel = _nonLocalizedLabel;
8284 labelRes = _labelRes;
8285 icon = _icon;
8286 }
8287 }
8288
8289 private final class H extends Handler {
8290 public static final int REPORT_FOCUS_CHANGE = 2;
8291 public static final int REPORT_LOSING_FOCUS = 3;
8292 public static final int ANIMATE = 4;
8293 public static final int ADD_STARTING = 5;
8294 public static final int REMOVE_STARTING = 6;
8295 public static final int FINISHED_STARTING = 7;
8296 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008297 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8298 public static final int HOLD_SCREEN_CHANGED = 12;
8299 public static final int APP_TRANSITION_TIMEOUT = 13;
8300 public static final int PERSIST_ANIMATION_SCALE = 14;
8301 public static final int FORCE_GC = 15;
8302 public static final int ENABLE_SCREEN = 16;
8303 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008304 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008305 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008306 public static final int DRAG_START_TIMEOUT = 20;
Romain Guy06882f82009-06-10 13:36:04 -07008307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008308 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008310 public H() {
8311 }
Romain Guy06882f82009-06-10 13:36:04 -07008312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008313 @Override
8314 public void handleMessage(Message msg) {
8315 switch (msg.what) {
8316 case REPORT_FOCUS_CHANGE: {
8317 WindowState lastFocus;
8318 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008320 synchronized(mWindowMap) {
8321 lastFocus = mLastFocus;
8322 newFocus = mCurrentFocus;
8323 if (lastFocus == newFocus) {
8324 // Focus is not changing, so nothing to do.
8325 return;
8326 }
8327 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008328 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008329 // + " to " + newFocus);
8330 if (newFocus != null && lastFocus != null
8331 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008332 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008333 mLosingFocus.add(lastFocus);
8334 lastFocus = null;
8335 }
8336 }
8337
8338 if (lastFocus != newFocus) {
8339 //System.out.println("Changing focus from " + lastFocus
8340 // + " to " + newFocus);
8341 if (newFocus != null) {
8342 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008343 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008344 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8345 } catch (RemoteException e) {
8346 // Ignore if process has died.
8347 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008348 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008349 }
8350
8351 if (lastFocus != null) {
8352 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008353 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008354 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8355 } catch (RemoteException e) {
8356 // Ignore if process has died.
8357 }
8358 }
8359 }
8360 } break;
8361
8362 case REPORT_LOSING_FOCUS: {
8363 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008365 synchronized(mWindowMap) {
8366 losers = mLosingFocus;
8367 mLosingFocus = new ArrayList<WindowState>();
8368 }
8369
8370 final int N = losers.size();
8371 for (int i=0; i<N; i++) {
8372 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008373 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008374 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8375 } catch (RemoteException e) {
8376 // Ignore if process has died.
8377 }
8378 }
8379 } break;
8380
8381 case ANIMATE: {
8382 synchronized(mWindowMap) {
8383 mAnimationPending = false;
8384 performLayoutAndPlaceSurfacesLocked();
8385 }
8386 } break;
8387
8388 case ADD_STARTING: {
8389 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8390 final StartingData sd = wtoken.startingData;
8391
8392 if (sd == null) {
8393 // Animation has been canceled... do nothing.
8394 return;
8395 }
Romain Guy06882f82009-06-10 13:36:04 -07008396
Joe Onorato8a9b2202010-02-26 18:56:32 -08008397 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008398 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008400 View view = null;
8401 try {
8402 view = mPolicy.addStartingWindow(
8403 wtoken.token, sd.pkg,
8404 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8405 sd.icon);
8406 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008407 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008408 }
8409
8410 if (view != null) {
8411 boolean abort = false;
8412
8413 synchronized(mWindowMap) {
8414 if (wtoken.removed || wtoken.startingData == null) {
8415 // If the window was successfully added, then
8416 // we need to remove it.
8417 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008418 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008419 "Aborted starting " + wtoken
8420 + ": removed=" + wtoken.removed
8421 + " startingData=" + wtoken.startingData);
8422 wtoken.startingWindow = null;
8423 wtoken.startingData = null;
8424 abort = true;
8425 }
8426 } else {
8427 wtoken.startingView = view;
8428 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008429 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008430 "Added starting " + wtoken
8431 + ": startingWindow="
8432 + wtoken.startingWindow + " startingView="
8433 + wtoken.startingView);
8434 }
8435
8436 if (abort) {
8437 try {
8438 mPolicy.removeStartingWindow(wtoken.token, view);
8439 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008440 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008441 }
8442 }
8443 }
8444 } break;
8445
8446 case REMOVE_STARTING: {
8447 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8448 IBinder token = null;
8449 View view = null;
8450 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008451 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008452 + wtoken + ": startingWindow="
8453 + wtoken.startingWindow + " startingView="
8454 + wtoken.startingView);
8455 if (wtoken.startingWindow != null) {
8456 view = wtoken.startingView;
8457 token = wtoken.token;
8458 wtoken.startingData = null;
8459 wtoken.startingView = null;
8460 wtoken.startingWindow = null;
8461 }
8462 }
8463 if (view != null) {
8464 try {
8465 mPolicy.removeStartingWindow(token, view);
8466 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008467 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008468 }
8469 }
8470 } break;
8471
8472 case FINISHED_STARTING: {
8473 IBinder token = null;
8474 View view = null;
8475 while (true) {
8476 synchronized (mWindowMap) {
8477 final int N = mFinishedStarting.size();
8478 if (N <= 0) {
8479 break;
8480 }
8481 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8482
Joe Onorato8a9b2202010-02-26 18:56:32 -08008483 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008484 "Finished starting " + wtoken
8485 + ": startingWindow=" + wtoken.startingWindow
8486 + " startingView=" + wtoken.startingView);
8487
8488 if (wtoken.startingWindow == null) {
8489 continue;
8490 }
8491
8492 view = wtoken.startingView;
8493 token = wtoken.token;
8494 wtoken.startingData = null;
8495 wtoken.startingView = null;
8496 wtoken.startingWindow = null;
8497 }
8498
8499 try {
8500 mPolicy.removeStartingWindow(token, view);
8501 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008502 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008503 }
8504 }
8505 } break;
8506
8507 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8508 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8509
8510 boolean nowVisible = msg.arg1 != 0;
8511 boolean nowGone = msg.arg2 != 0;
8512
8513 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008514 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008515 TAG, "Reporting visible in " + wtoken
8516 + " visible=" + nowVisible
8517 + " gone=" + nowGone);
8518 if (nowVisible) {
8519 wtoken.appToken.windowsVisible();
8520 } else {
8521 wtoken.appToken.windowsGone();
8522 }
8523 } catch (RemoteException ex) {
8524 }
8525 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008527 case WINDOW_FREEZE_TIMEOUT: {
8528 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008529 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008530 int i = mWindows.size();
8531 while (i > 0) {
8532 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008533 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008534 if (w.mOrientationChanging) {
8535 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008536 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008537 }
8538 }
8539 performLayoutAndPlaceSurfacesLocked();
8540 }
8541 break;
8542 }
Romain Guy06882f82009-06-10 13:36:04 -07008543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008544 case HOLD_SCREEN_CHANGED: {
8545 Session oldHold;
8546 Session newHold;
8547 synchronized (mWindowMap) {
8548 oldHold = mLastReportedHold;
8549 newHold = (Session)msg.obj;
8550 mLastReportedHold = newHold;
8551 }
Romain Guy06882f82009-06-10 13:36:04 -07008552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008553 if (oldHold != newHold) {
8554 try {
8555 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008556 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008557 "window",
8558 BatteryStats.WAKE_TYPE_WINDOW);
8559 }
8560 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008561 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008562 "window",
8563 BatteryStats.WAKE_TYPE_WINDOW);
8564 }
8565 } catch (RemoteException e) {
8566 }
8567 }
8568 break;
8569 }
Romain Guy06882f82009-06-10 13:36:04 -07008570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008571 case APP_TRANSITION_TIMEOUT: {
8572 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008573 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008574 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008575 "*** APP TRANSITION TIMEOUT");
8576 mAppTransitionReady = true;
8577 mAppTransitionTimeout = true;
8578 performLayoutAndPlaceSurfacesLocked();
8579 }
8580 }
8581 break;
8582 }
Romain Guy06882f82009-06-10 13:36:04 -07008583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008584 case PERSIST_ANIMATION_SCALE: {
8585 Settings.System.putFloat(mContext.getContentResolver(),
8586 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8587 Settings.System.putFloat(mContext.getContentResolver(),
8588 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8589 break;
8590 }
Romain Guy06882f82009-06-10 13:36:04 -07008591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008592 case FORCE_GC: {
8593 synchronized(mWindowMap) {
8594 if (mAnimationPending) {
8595 // If we are animating, don't do the gc now but
8596 // delay a bit so we don't interrupt the animation.
8597 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8598 2000);
8599 return;
8600 }
8601 // If we are currently rotating the display, it will
8602 // schedule a new message when done.
8603 if (mDisplayFrozen) {
8604 return;
8605 }
8606 mFreezeGcPending = 0;
8607 }
8608 Runtime.getRuntime().gc();
8609 break;
8610 }
Romain Guy06882f82009-06-10 13:36:04 -07008611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008612 case ENABLE_SCREEN: {
8613 performEnableScreen();
8614 break;
8615 }
Romain Guy06882f82009-06-10 13:36:04 -07008616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008617 case APP_FREEZE_TIMEOUT: {
8618 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008619 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008620 int i = mAppTokens.size();
8621 while (i > 0) {
8622 i--;
8623 AppWindowToken tok = mAppTokens.get(i);
8624 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008625 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008626 unsetAppFreezingScreenLocked(tok, true, true);
8627 }
8628 }
8629 }
8630 break;
8631 }
Romain Guy06882f82009-06-10 13:36:04 -07008632
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008633 case SEND_NEW_CONFIGURATION: {
8634 removeMessages(SEND_NEW_CONFIGURATION);
8635 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008636 break;
8637 }
Romain Guy06882f82009-06-10 13:36:04 -07008638
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008639 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008640 if (mWindowsChanged) {
8641 synchronized (mWindowMap) {
8642 mWindowsChanged = false;
8643 }
8644 notifyWindowsChanged();
8645 }
8646 break;
8647 }
8648
Christopher Tatea53146c2010-09-07 11:57:52 -07008649 case DRAG_START_TIMEOUT: {
8650 IBinder win = (IBinder)msg.obj;
8651 if (DEBUG_DRAG) {
8652 Slog.w(TAG, "Timeout starting drag by win " + win);
8653 }
8654 synchronized (mWindowMap) {
8655 // !!! TODO: ANR the app that has failed to start the drag in time
8656 if (mDragState != null) {
8657 mDragState.reset();
8658 mDragState = null;
8659 }
8660 }
8661 }
8662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008663 }
8664 }
8665 }
8666
8667 // -------------------------------------------------------------
8668 // IWindowManager API
8669 // -------------------------------------------------------------
8670
8671 public IWindowSession openSession(IInputMethodClient client,
8672 IInputContext inputContext) {
8673 if (client == null) throw new IllegalArgumentException("null client");
8674 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008675 Session session = new Session(client, inputContext);
8676 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008677 }
8678
8679 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8680 synchronized (mWindowMap) {
8681 // The focus for the client is the window immediately below
8682 // where we would place the input method window.
8683 int idx = findDesiredInputMethodWindowIndexLocked(false);
8684 WindowState imFocus;
8685 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008686 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008687 if (imFocus != null) {
8688 if (imFocus.mSession.mClient != null &&
8689 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8690 return true;
8691 }
8692 }
8693 }
8694 }
8695 return false;
8696 }
Romain Guy06882f82009-06-10 13:36:04 -07008697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008698 // -------------------------------------------------------------
8699 // Internals
8700 // -------------------------------------------------------------
8701
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008702 final WindowState windowForClientLocked(Session session, IWindow client,
8703 boolean throwOnError) {
8704 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008705 }
Romain Guy06882f82009-06-10 13:36:04 -07008706
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008707 final WindowState windowForClientLocked(Session session, IBinder client,
8708 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008709 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008710 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008711 TAG, "Looking up client " + client + ": " + win);
8712 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008713 RuntimeException ex = new IllegalArgumentException(
8714 "Requested window " + client + " does not exist");
8715 if (throwOnError) {
8716 throw ex;
8717 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008718 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008719 return null;
8720 }
8721 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008722 RuntimeException ex = new IllegalArgumentException(
8723 "Requested window " + client + " is in session " +
8724 win.mSession + ", not " + session);
8725 if (throwOnError) {
8726 throw ex;
8727 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008728 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008729 return null;
8730 }
8731
8732 return win;
8733 }
8734
Dianne Hackborna8f60182009-09-01 19:01:50 -07008735 final void rebuildAppWindowListLocked() {
8736 int NW = mWindows.size();
8737 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008738 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008739 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008740
Dianne Hackborna8f60182009-09-01 19:01:50 -07008741 // First remove all existing app windows.
8742 i=0;
8743 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008744 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008745 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008746 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008747 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008748 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008749 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008750 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008751 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008752 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008753 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8754 && lastWallpaper == i-1) {
8755 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008756 }
8757 i++;
8758 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008759
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008760 // The wallpaper window(s) typically live at the bottom of the stack,
8761 // so skip them before adding app tokens.
8762 lastWallpaper++;
8763 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008764
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008765 // First add all of the exiting app tokens... these are no longer
8766 // in the main app list, but still have windows shown. We put them
8767 // in the back because now that the animation is over we no longer
8768 // will care about them.
8769 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008770 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008771 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8772 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008773
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008774 // And add in the still active app tokens in Z order.
8775 NT = mAppTokens.size();
8776 for (int j=0; j<NT; j++) {
8777 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008778 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008779
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008780 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008781 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008782 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008783 + " windows but added " + i);
8784 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008785 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008787 private final void assignLayersLocked() {
8788 int N = mWindows.size();
8789 int curBaseLayer = 0;
8790 int curLayer = 0;
8791 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008793 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008794 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008795 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8796 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008797 curLayer += WINDOW_LAYER_MULTIPLIER;
8798 w.mLayer = curLayer;
8799 } else {
8800 curBaseLayer = curLayer = w.mBaseLayer;
8801 w.mLayer = curLayer;
8802 }
8803 if (w.mTargetAppToken != null) {
8804 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8805 } else if (w.mAppToken != null) {
8806 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8807 } else {
8808 w.mAnimLayer = w.mLayer;
8809 }
8810 if (w.mIsImWindow) {
8811 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008812 } else if (w.mIsWallpaper) {
8813 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008814 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008815 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008816 + w.mAnimLayer);
8817 //System.out.println(
8818 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8819 }
8820 }
8821
8822 private boolean mInLayout = false;
8823 private final void performLayoutAndPlaceSurfacesLocked() {
8824 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008825 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008826 throw new RuntimeException("Recursive call!");
8827 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008828 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008829 return;
8830 }
8831
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008832 if (mWaitingForConfig) {
8833 // Our configuration has changed (most likely rotation), but we
8834 // don't yet have the complete configuration to report to
8835 // applications. Don't do any window layout until we have it.
8836 return;
8837 }
8838
Dianne Hackbornce2ef762010-09-20 11:39:14 -07008839 if (mDisplay == null) {
8840 // Not yet initialized, nothing to do.
8841 return;
8842 }
8843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008844 boolean recoveringMemory = false;
8845 if (mForceRemoves != null) {
8846 recoveringMemory = true;
8847 // Wait a little it for things to settle down, and off we go.
8848 for (int i=0; i<mForceRemoves.size(); i++) {
8849 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008850 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008851 removeWindowInnerLocked(ws.mSession, ws);
8852 }
8853 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008854 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008855 Object tmp = new Object();
8856 synchronized (tmp) {
8857 try {
8858 tmp.wait(250);
8859 } catch (InterruptedException e) {
8860 }
8861 }
8862 }
Romain Guy06882f82009-06-10 13:36:04 -07008863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008864 mInLayout = true;
8865 try {
8866 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008867
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008868 int i = mPendingRemove.size()-1;
8869 if (i >= 0) {
8870 while (i >= 0) {
8871 WindowState w = mPendingRemove.get(i);
8872 removeWindowInnerLocked(w.mSession, w);
8873 i--;
8874 }
8875 mPendingRemove.clear();
8876
8877 mInLayout = false;
8878 assignLayersLocked();
8879 mLayoutNeeded = true;
8880 performLayoutAndPlaceSurfacesLocked();
8881
8882 } else {
8883 mInLayout = false;
8884 if (mLayoutNeeded) {
8885 requestAnimationLocked(0);
8886 }
8887 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008888 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008889 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8890 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008891 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008892 } catch (RuntimeException e) {
8893 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008894 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008895 }
8896 }
8897
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008898 private final int performLayoutLockedInner() {
8899 if (!mLayoutNeeded) {
8900 return 0;
8901 }
8902
8903 mLayoutNeeded = false;
8904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008905 final int dw = mDisplay.getWidth();
8906 final int dh = mDisplay.getHeight();
8907
8908 final int N = mWindows.size();
8909 int i;
8910
Joe Onorato8a9b2202010-02-26 18:56:32 -08008911 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008912 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8913
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008914 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008915
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008916 int seq = mLayoutSeq+1;
8917 if (seq < 0) seq = 0;
8918 mLayoutSeq = seq;
8919
8920 // First perform layout of any root windows (not attached
8921 // to another window).
8922 int topAttached = -1;
8923 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008924 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008925
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008926 // Don't do layout of a window if it is not visible, or
8927 // soon won't be visible, to avoid wasting time and funky
8928 // changes while a window is animating away.
8929 final AppWindowToken atoken = win.mAppToken;
8930 final boolean gone = win.mViewVisibility == View.GONE
8931 || !win.mRelayoutCalled
8932 || win.mRootToken.hidden
8933 || (atoken != null && atoken.hiddenRequested)
8934 || win.mAttachedHidden
8935 || win.mExiting || win.mDestroying;
8936
8937 if (!win.mLayoutAttached) {
8938 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
8939 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
8940 + " mLayoutAttached=" + win.mLayoutAttached);
8941 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
8942 + win.mViewVisibility + " mRelayoutCalled="
8943 + win.mRelayoutCalled + " hidden="
8944 + win.mRootToken.hidden + " hiddenRequested="
8945 + (atoken != null && atoken.hiddenRequested)
8946 + " mAttachedHidden=" + win.mAttachedHidden);
8947 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008948
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008949 // If this view is GONE, then skip it -- keep the current
8950 // frame, and let the caller know so they can ignore it
8951 // if they want. (We do the normal layout for INVISIBLE
8952 // windows, since that means "perform layout as normal,
8953 // just don't display").
8954 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008955 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008956 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8957 win.mLayoutSeq = seq;
8958 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8959 + win.mFrame + " mContainingFrame="
8960 + win.mContainingFrame + " mDisplayFrame="
8961 + win.mDisplayFrame);
8962 } else {
8963 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008964 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008965 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008966 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008967
8968 // Now perform layout of attached windows, which usually
8969 // depend on the position of the window they are attached to.
8970 // XXX does not deal with windows that are attached to windows
8971 // that are themselves attached.
8972 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008973 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008974
8975 // If this view is GONE, then skip it -- keep the current
8976 // frame, and let the caller know so they can ignore it
8977 // if they want. (We do the normal layout for INVISIBLE
8978 // windows, since that means "perform layout as normal,
8979 // just don't display").
8980 if (win.mLayoutAttached) {
8981 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
8982 + " mHaveFrame=" + win.mHaveFrame
8983 + " mViewVisibility=" + win.mViewVisibility
8984 + " mRelayoutCalled=" + win.mRelayoutCalled);
8985 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
8986 || !win.mHaveFrame) {
8987 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
8988 win.mLayoutSeq = seq;
8989 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8990 + win.mFrame + " mContainingFrame="
8991 + win.mContainingFrame + " mDisplayFrame="
8992 + win.mDisplayFrame);
8993 }
8994 }
8995 }
Jeff Brown349703e2010-06-22 01:27:15 -07008996
8997 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008998 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008999
9000 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009001 }
Romain Guy06882f82009-06-10 13:36:04 -07009002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009003 private final void performLayoutAndPlaceSurfacesLockedInner(
9004 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009005 if (mDisplay == null) {
9006 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9007 return;
9008 }
9009
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009010 final long currentTime = SystemClock.uptimeMillis();
9011 final int dw = mDisplay.getWidth();
9012 final int dh = mDisplay.getHeight();
9013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009014 int i;
9015
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009016 if (mFocusMayChange) {
9017 mFocusMayChange = false;
9018 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9019 }
9020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009021 // Initialize state of exiting tokens.
9022 for (i=mExitingTokens.size()-1; i>=0; i--) {
9023 mExitingTokens.get(i).hasVisible = false;
9024 }
9025
9026 // Initialize state of exiting applications.
9027 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9028 mExitingAppTokens.get(i).hasVisible = false;
9029 }
9030
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009031 boolean orientationChangeComplete = true;
9032 Session holdScreen = null;
9033 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009034 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009035 boolean focusDisplayed = false;
9036 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009037 boolean createWatermark = false;
9038
9039 if (mFxSession == null) {
9040 mFxSession = new SurfaceSession();
9041 createWatermark = true;
9042 }
9043
9044 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009045
9046 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009047
9048 if (createWatermark) {
9049 createWatermark();
9050 }
9051 if (mWatermark != null) {
9052 mWatermark.positionSurface(dw, dh);
9053 }
9054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009055 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009056 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009057 int repeats = 0;
9058 int changes = 0;
9059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009060 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009061 repeats++;
9062 if (repeats > 6) {
9063 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9064 mLayoutNeeded = false;
9065 break;
9066 }
9067
9068 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9069 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9070 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9071 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9072 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9073 assignLayersLocked();
9074 mLayoutNeeded = true;
9075 }
9076 }
9077 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9078 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9079 if (updateOrientationFromAppTokensLocked()) {
9080 mLayoutNeeded = true;
9081 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9082 }
9083 }
9084 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9085 mLayoutNeeded = true;
9086 }
9087 }
9088
9089 // FIRST LOOP: Perform a layout, if needed.
9090 if (repeats < 4) {
9091 changes = performLayoutLockedInner();
9092 if (changes != 0) {
9093 continue;
9094 }
9095 } else {
9096 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9097 changes = 0;
9098 }
9099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009100 final int transactionSequence = ++mTransactionSequence;
9101
9102 // Update animations of all applications, including those
9103 // associated with exiting/removed apps
9104 boolean tokensAnimating = false;
9105 final int NAT = mAppTokens.size();
9106 for (i=0; i<NAT; i++) {
9107 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9108 tokensAnimating = true;
9109 }
9110 }
9111 final int NEAT = mExitingAppTokens.size();
9112 for (i=0; i<NEAT; i++) {
9113 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9114 tokensAnimating = true;
9115 }
9116 }
9117
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009118 // SECOND LOOP: Execute animations and update visibility of windows.
9119
Joe Onorato8a9b2202010-02-26 18:56:32 -08009120 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009121 + transactionSequence + " tokensAnimating="
9122 + tokensAnimating);
9123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009124 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009125
9126 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009127 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009128 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009129
9130 mPolicy.beginAnimationLw(dw, dh);
9131
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009132 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009134 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009135 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009136
9137 final WindowManager.LayoutParams attrs = w.mAttrs;
9138
9139 if (w.mSurface != null) {
9140 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009141 if (w.commitFinishDrawingLocked(currentTime)) {
9142 if ((w.mAttrs.flags
9143 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009144 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009145 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009146 wallpaperMayChange = true;
9147 }
9148 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009149
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009150 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009151 if (w.stepAnimationLocked(currentTime, dw, dh)) {
9152 animating = true;
9153 //w.dump(" ");
9154 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009155 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9156 wallpaperMayChange = true;
9157 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009158
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009159 if (mPolicy.doesForceHide(w, attrs)) {
9160 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009161 if (DEBUG_VISIBILITY) Slog.v(TAG,
9162 "Animation done that could impact force hide: "
9163 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009164 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009165 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009166 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9167 forceHiding = true;
9168 }
9169 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9170 boolean changed;
9171 if (forceHiding) {
9172 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009173 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9174 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009175 } else {
9176 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009177 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9178 "Now policy shown: " + w);
9179 if (changed) {
9180 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009181 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009182 // Assume we will need to animate. If
9183 // we don't (because the wallpaper will
9184 // stay with the lock screen), then we will
9185 // clean up later.
9186 Animation a = mPolicy.createForceHideEnterAnimation();
9187 if (a != null) {
9188 w.setAnimation(a);
9189 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009190 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009191 if (mCurrentFocus == null ||
9192 mCurrentFocus.mLayer < w.mLayer) {
9193 // We are showing on to of the current
9194 // focus, so re-evaluate focus to make
9195 // sure it is correct.
9196 mFocusMayChange = true;
9197 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009198 }
9199 }
9200 if (changed && (attrs.flags
9201 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9202 wallpaperMayChange = true;
9203 }
9204 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009206 mPolicy.animatingWindowLw(w, attrs);
9207 }
9208
9209 final AppWindowToken atoken = w.mAppToken;
9210 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9211 if (atoken.lastTransactionSequence != transactionSequence) {
9212 atoken.lastTransactionSequence = transactionSequence;
9213 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9214 atoken.startingDisplayed = false;
9215 }
9216 if ((w.isOnScreen() || w.mAttrs.type
9217 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9218 && !w.mExiting && !w.mDestroying) {
9219 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009220 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009221 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009222 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009223 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009224 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009225 + " pv=" + w.mPolicyVisibility
9226 + " dp=" + w.mDrawPending
9227 + " cdp=" + w.mCommitDrawPending
9228 + " ah=" + w.mAttachedHidden
9229 + " th=" + atoken.hiddenRequested
9230 + " a=" + w.mAnimating);
9231 }
9232 }
9233 if (w != atoken.startingWindow) {
9234 if (!atoken.freezingScreen || !w.mAppFreezing) {
9235 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009236 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009237 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009238 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009239 "tokenMayBeDrawn: " + atoken
9240 + " freezingScreen=" + atoken.freezingScreen
9241 + " mAppFreezing=" + w.mAppFreezing);
9242 tokenMayBeDrawn = true;
9243 }
9244 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009245 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009246 atoken.startingDisplayed = true;
9247 }
9248 }
9249 } else if (w.mReadyToShow) {
9250 w.performShowLocked();
9251 }
9252 }
9253
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009254 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009255
9256 if (tokenMayBeDrawn) {
9257 // See if any windows have been drawn, so they (and others
9258 // associated with them) can now be shown.
9259 final int NT = mTokenList.size();
9260 for (i=0; i<NT; i++) {
9261 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9262 if (wtoken == null) {
9263 continue;
9264 }
9265 if (wtoken.freezingScreen) {
9266 int numInteresting = wtoken.numInterestingWindows;
9267 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009268 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009269 "allDrawn: " + wtoken
9270 + " interesting=" + numInteresting
9271 + " drawn=" + wtoken.numDrawnWindows);
9272 wtoken.showAllWindowsLocked();
9273 unsetAppFreezingScreenLocked(wtoken, false, true);
9274 orientationChangeComplete = true;
9275 }
9276 } else if (!wtoken.allDrawn) {
9277 int numInteresting = wtoken.numInterestingWindows;
9278 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009279 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009280 "allDrawn: " + wtoken
9281 + " interesting=" + numInteresting
9282 + " drawn=" + wtoken.numDrawnWindows);
9283 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009284 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009285
9286 // We can now show all of the drawn windows!
9287 if (!mOpeningApps.contains(wtoken)) {
9288 wtoken.showAllWindowsLocked();
9289 }
9290 }
9291 }
9292 }
9293 }
9294
9295 // If we are ready to perform an app transition, check through
9296 // all of the app tokens to be shown and see if they are ready
9297 // to go.
9298 if (mAppTransitionReady) {
9299 int NN = mOpeningApps.size();
9300 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009301 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009302 "Checking " + NN + " opening apps (frozen="
9303 + mDisplayFrozen + " timeout="
9304 + mAppTransitionTimeout + ")...");
9305 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9306 // If the display isn't frozen, wait to do anything until
9307 // all of the apps are ready. Otherwise just go because
9308 // we'll unfreeze the display when everyone is ready.
9309 for (i=0; i<NN && goodToGo; i++) {
9310 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009311 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009312 "Check opening app" + wtoken + ": allDrawn="
9313 + wtoken.allDrawn + " startingDisplayed="
9314 + wtoken.startingDisplayed);
9315 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9316 && !wtoken.startingMoved) {
9317 goodToGo = false;
9318 }
9319 }
9320 }
9321 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009322 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009323 int transit = mNextAppTransition;
9324 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009325 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009326 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009327 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009328 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009329 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009330 mAppTransitionTimeout = false;
9331 mStartingIconInTransition = false;
9332 mSkipAppTransitionAnimation = false;
9333
9334 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9335
Dianne Hackborna8f60182009-09-01 19:01:50 -07009336 // If there are applications waiting to come to the
9337 // top of the stack, now is the time to move their windows.
9338 // (Note that we don't do apps going to the bottom
9339 // here -- we want to keep their windows in the old
9340 // Z-order until the animation completes.)
9341 if (mToTopApps.size() > 0) {
9342 NN = mAppTokens.size();
9343 for (i=0; i<NN; i++) {
9344 AppWindowToken wtoken = mAppTokens.get(i);
9345 if (wtoken.sendingToTop) {
9346 wtoken.sendingToTop = false;
9347 moveAppWindowsLocked(wtoken, NN, false);
9348 }
9349 }
9350 mToTopApps.clear();
9351 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009352
Dianne Hackborn25994b42009-09-04 14:21:19 -07009353 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009354
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009355 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009356 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009357
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009358 // The top-most window will supply the layout params,
9359 // and we will determine it below.
9360 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009361 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009362 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009363
Joe Onorato8a9b2202010-02-26 18:56:32 -08009364 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009365 "New wallpaper target=" + mWallpaperTarget
9366 + ", lower target=" + mLowerWallpaperTarget
9367 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009368 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009369 // Do a first pass through the tokens for two
9370 // things:
9371 // (1) Determine if both the closing and opening
9372 // app token sets are wallpaper targets, in which
9373 // case special animations are needed
9374 // (since the wallpaper needs to stay static
9375 // behind them).
9376 // (2) Find the layout params of the top-most
9377 // application window in the tokens, which is
9378 // what will control the animation theme.
9379 final int NC = mClosingApps.size();
9380 NN = NC + mOpeningApps.size();
9381 for (i=0; i<NN; i++) {
9382 AppWindowToken wtoken;
9383 int mode;
9384 if (i < NC) {
9385 wtoken = mClosingApps.get(i);
9386 mode = 1;
9387 } else {
9388 wtoken = mOpeningApps.get(i-NC);
9389 mode = 2;
9390 }
9391 if (mLowerWallpaperTarget != null) {
9392 if (mLowerWallpaperTarget.mAppToken == wtoken
9393 || mUpperWallpaperTarget.mAppToken == wtoken) {
9394 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009395 }
9396 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009397 if (wtoken.appFullscreen) {
9398 WindowState ws = wtoken.findMainWindow();
9399 if (ws != null) {
9400 // If this is a compatibility mode
9401 // window, we will always use its anim.
9402 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9403 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009404 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009405 bestAnimLayer = Integer.MAX_VALUE;
9406 } else if (ws.mLayer > bestAnimLayer) {
9407 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009408 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009409 bestAnimLayer = ws.mLayer;
9410 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009411 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009412 }
9413 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009414
Dianne Hackborn25994b42009-09-04 14:21:19 -07009415 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009416 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009417 "Wallpaper animation!");
9418 switch (transit) {
9419 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9420 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9421 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9422 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9423 break;
9424 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9425 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9426 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9427 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9428 break;
9429 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009430 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009431 "New transit: " + transit);
9432 } else if (oldWallpaper != null) {
9433 // We are transitioning from an activity with
9434 // a wallpaper to one without.
9435 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009436 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009437 "New transit away from wallpaper: " + transit);
9438 } else if (mWallpaperTarget != null) {
9439 // We are transitioning from an activity without
9440 // a wallpaper to now showing the wallpaper
9441 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009442 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009443 "New transit into wallpaper: " + transit);
9444 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009445
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009446 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9447 mLastEnterAnimToken = animToken;
9448 mLastEnterAnimParams = animLp;
9449 } else if (mLastEnterAnimParams != null) {
9450 animLp = mLastEnterAnimParams;
9451 mLastEnterAnimToken = null;
9452 mLastEnterAnimParams = null;
9453 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009454
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009455 // If all closing windows are obscured, then there is
9456 // no need to do an animation. This is the case, for
9457 // example, when this transition is being done behind
9458 // the lock screen.
9459 if (!mPolicy.allowAppAnimationsLw()) {
9460 animLp = null;
9461 }
9462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009463 NN = mOpeningApps.size();
9464 for (i=0; i<NN; i++) {
9465 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009466 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009467 "Now opening app" + wtoken);
9468 wtoken.reportedVisible = false;
9469 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009470 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009471 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009472 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009473 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009474 wtoken.showAllWindowsLocked();
9475 }
9476 NN = mClosingApps.size();
9477 for (i=0; i<NN; i++) {
9478 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009479 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009480 "Now closing app" + wtoken);
9481 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009482 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009483 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009484 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009485 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009486 // Force the allDrawn flag, because we want to start
9487 // this guy's animations regardless of whether it's
9488 // gotten drawn.
9489 wtoken.allDrawn = true;
9490 }
9491
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009492 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009494 mOpeningApps.clear();
9495 mClosingApps.clear();
9496
9497 // This has changed the visibility of windows, so perform
9498 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009499 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009500 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009501 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9502 assignLayersLocked();
9503 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009504 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009505 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009506 }
9507 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009508
Dianne Hackborn16064f92010-03-25 00:47:24 -07009509 int adjResult = 0;
9510
Dianne Hackborna8f60182009-09-01 19:01:50 -07009511 if (!animating && mAppTransitionRunning) {
9512 // We have finished the animation of an app transition. To do
9513 // this, we have delayed a lot of operations like showing and
9514 // hiding apps, moving apps in Z-order, etc. The app token list
9515 // reflects the correct Z-order, but the window list may now
9516 // be out of sync with it. So here we will just rebuild the
9517 // entire app window list. Fun!
9518 mAppTransitionRunning = false;
9519 // Clear information about apps that were moving.
9520 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009521
Dianne Hackborna8f60182009-09-01 19:01:50 -07009522 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009523 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009524 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009525 moveInputMethodWindowsIfNeededLocked(false);
9526 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009527 // Since the window list has been rebuilt, focus might
9528 // have to be recomputed since the actual order of windows
9529 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009530 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009531 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009532
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009533 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009534 // At this point, there was a window with a wallpaper that
9535 // was force hiding other windows behind it, but now it
9536 // is going away. This may be simple -- just animate
9537 // away the wallpaper and its window -- or it may be
9538 // hard -- the wallpaper now needs to be shown behind
9539 // something that was hidden.
9540 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009541 if (mLowerWallpaperTarget != null
9542 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009543 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009544 "wallpaperForceHiding changed with lower="
9545 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009546 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009547 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9548 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9549 if (mLowerWallpaperTarget.mAppToken.hidden) {
9550 // The lower target has become hidden before we
9551 // actually started the animation... let's completely
9552 // re-evaluate everything.
9553 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009554 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009555 }
9556 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009557 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009558 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009559 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009560 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009561 + " NEW: " + mWallpaperTarget
9562 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009563 if (mLowerWallpaperTarget == null) {
9564 // Whoops, we don't need a special wallpaper animation.
9565 // Clear them out.
9566 forceHiding = false;
9567 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009568 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009569 if (w.mSurface != null) {
9570 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009571 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009572 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009573 forceHiding = true;
9574 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9575 if (!w.mAnimating) {
9576 // We set the animation above so it
9577 // is not yet running.
9578 w.clearAnimation();
9579 }
9580 }
9581 }
9582 }
9583 }
9584 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009585
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009586 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009587 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009588 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009589 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009590 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009591
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009592 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009593 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009594 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009595 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009596 assignLayersLocked();
9597 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009598 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009599 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009600 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009601 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009602
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009603 if (mFocusMayChange) {
9604 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009605 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009606 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009607 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009608 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009609 }
9610
9611 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009612 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009613 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009614
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009615 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9616 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009617
Jeff Browne33348b2010-07-15 23:54:05 -07009618 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009619 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009620
9621 // THIRD LOOP: Update the surfaces of all windows.
9622
9623 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9624
9625 boolean obscured = false;
9626 boolean blurring = false;
9627 boolean dimming = false;
9628 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009629 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009630 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009631
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009632 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009634 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009635 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009636
9637 boolean displayed = false;
9638 final WindowManager.LayoutParams attrs = w.mAttrs;
9639 final int attrFlags = attrs.flags;
9640
9641 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009642 // XXX NOTE: The logic here could be improved. We have
9643 // the decision about whether to resize a window separated
9644 // from whether to hide the surface. This can cause us to
9645 // resize a surface even if we are going to hide it. You
9646 // can see this by (1) holding device in landscape mode on
9647 // home screen; (2) tapping browser icon (device will rotate
9648 // to landscape; (3) tap home. The wallpaper will be resized
9649 // in step 2 but then immediately hidden, causing us to
9650 // have to resize and then redraw it again in step 3. It
9651 // would be nice to figure out how to avoid this, but it is
9652 // difficult because we do need to resize surfaces in some
9653 // cases while they are hidden such as when first showing a
9654 // window.
9655
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009656 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009657 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009658 TAG, "Placing surface #" + i + " " + w.mSurface
9659 + ": new=" + w.mShownFrame + ", old="
9660 + w.mLastShownFrame);
9661
9662 boolean resize;
9663 int width, height;
9664 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9665 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9666 w.mLastRequestedHeight != w.mRequestedHeight;
9667 // for a scaled surface, we just want to use
9668 // the requested size.
9669 width = w.mRequestedWidth;
9670 height = w.mRequestedHeight;
9671 w.mLastRequestedWidth = width;
9672 w.mLastRequestedHeight = height;
9673 w.mLastShownFrame.set(w.mShownFrame);
9674 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009675 if (SHOW_TRANSACTIONS) logSurface(w,
9676 "POS " + w.mShownFrame.left
9677 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009678 w.mSurfaceX = w.mShownFrame.left;
9679 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009680 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9681 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009682 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009683 if (!recoveringMemory) {
9684 reclaimSomeSurfaceMemoryLocked(w, "position");
9685 }
9686 }
9687 } else {
9688 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9689 width = w.mShownFrame.width();
9690 height = w.mShownFrame.height();
9691 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009692 }
9693
9694 if (resize) {
9695 if (width < 1) width = 1;
9696 if (height < 1) height = 1;
9697 if (w.mSurface != null) {
9698 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009699 if (SHOW_TRANSACTIONS) logSurface(w,
9700 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009701 + w.mShownFrame.top + " SIZE "
9702 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009703 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009704 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009705 w.mSurfaceW = width;
9706 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009707 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009708 w.mSurfaceX = w.mShownFrame.left;
9709 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009710 w.mSurface.setPosition(w.mShownFrame.left,
9711 w.mShownFrame.top);
9712 } catch (RuntimeException e) {
9713 // If something goes wrong with the surface (such
9714 // as running out of memory), don't take down the
9715 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009716 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009717 + "size=(" + width + "x" + height
9718 + "), pos=(" + w.mShownFrame.left
9719 + "," + w.mShownFrame.top + ")", e);
9720 if (!recoveringMemory) {
9721 reclaimSomeSurfaceMemoryLocked(w, "size");
9722 }
9723 }
9724 }
9725 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009726 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009727 w.mContentInsetsChanged =
9728 !w.mLastContentInsets.equals(w.mContentInsets);
9729 w.mVisibleInsetsChanged =
9730 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009731 boolean configChanged =
9732 w.mConfiguration != mCurConfiguration
9733 && (w.mConfiguration == null
9734 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009735 if (DEBUG_CONFIGURATION && configChanged) {
9736 Slog.v(TAG, "Win " + w + " config changed: "
9737 + mCurConfiguration);
9738 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009739 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009740 + ": configChanged=" + configChanged
9741 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009742 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009743 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009744 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009745 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009746 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009747 w.mLastFrame.set(w.mFrame);
9748 w.mLastContentInsets.set(w.mContentInsets);
9749 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009750 // If the screen is currently frozen, then keep
9751 // it frozen until this window draws at its new
9752 // orientation.
9753 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009754 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009755 "Resizing while display frozen: " + w);
9756 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009757 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009758 mWindowsFreezingScreen = true;
9759 // XXX should probably keep timeout from
9760 // when we first froze the display.
9761 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9762 mH.sendMessageDelayed(mH.obtainMessage(
9763 H.WINDOW_FREEZE_TIMEOUT), 2000);
9764 }
9765 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009766 // If the orientation is changing, then we need to
9767 // hold off on unfreezing the display until this
9768 // window has been redrawn; to do that, we need
9769 // to go through the process of getting informed
9770 // by the application when it has finished drawing.
9771 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009772 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009773 "Orientation start waiting for draw in "
9774 + w + ", surface " + w.mSurface);
9775 w.mDrawPending = true;
9776 w.mCommitDrawPending = false;
9777 w.mReadyToShow = false;
9778 if (w.mAppToken != null) {
9779 w.mAppToken.allDrawn = false;
9780 }
9781 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009782 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009783 "Resizing window " + w + " to " + w.mFrame);
9784 mResizingWindows.add(w);
9785 } else if (w.mOrientationChanging) {
9786 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009787 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009788 "Orientation not waiting for draw in "
9789 + w + ", surface " + w.mSurface);
9790 w.mOrientationChanging = false;
9791 }
9792 }
9793 }
9794
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009795 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009796 if (!w.mLastHidden) {
9797 //dump();
9798 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009799 if (SHOW_TRANSACTIONS) logSurface(w,
9800 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009801 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009802 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009803 try {
9804 w.mSurface.hide();
9805 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009806 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009807 }
9808 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009809 }
9810 // If we are waiting for this window to handle an
9811 // orientation change, well, it is hidden, so
9812 // doesn't really matter. Note that this does
9813 // introduce a potential glitch if the window
9814 // becomes unhidden before it has drawn for the
9815 // new orientation.
9816 if (w.mOrientationChanging) {
9817 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009818 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009819 "Orientation change skips hidden " + w);
9820 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009821 } else if (w.mLastLayer != w.mAnimLayer
9822 || w.mLastAlpha != w.mShownAlpha
9823 || w.mLastDsDx != w.mDsDx
9824 || w.mLastDtDx != w.mDtDx
9825 || w.mLastDsDy != w.mDsDy
9826 || w.mLastDtDy != w.mDtDy
9827 || w.mLastHScale != w.mHScale
9828 || w.mLastVScale != w.mVScale
9829 || w.mLastHidden) {
9830 displayed = true;
9831 w.mLastAlpha = w.mShownAlpha;
9832 w.mLastLayer = w.mAnimLayer;
9833 w.mLastDsDx = w.mDsDx;
9834 w.mLastDtDx = w.mDtDx;
9835 w.mLastDsDy = w.mDsDy;
9836 w.mLastDtDy = w.mDtDy;
9837 w.mLastHScale = w.mHScale;
9838 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009839 if (SHOW_TRANSACTIONS) logSurface(w,
9840 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009841 + " matrix=[" + (w.mDsDx*w.mHScale)
9842 + "," + (w.mDtDx*w.mVScale)
9843 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009844 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009845 if (w.mSurface != null) {
9846 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009847 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009848 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009849 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009850 w.mSurface.setLayer(w.mAnimLayer);
9851 w.mSurface.setMatrix(
9852 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9853 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9854 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009855 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009856 if (!recoveringMemory) {
9857 reclaimSomeSurfaceMemoryLocked(w, "update");
9858 }
9859 }
9860 }
9861
9862 if (w.mLastHidden && !w.mDrawPending
9863 && !w.mCommitDrawPending
9864 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009865 if (SHOW_TRANSACTIONS) logSurface(w,
9866 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009867 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009868 + " during relayout");
9869 if (showSurfaceRobustlyLocked(w)) {
9870 w.mHasDrawn = true;
9871 w.mLastHidden = false;
9872 } else {
9873 w.mOrientationChanging = false;
9874 }
9875 }
9876 if (w.mSurface != null) {
9877 w.mToken.hasVisible = true;
9878 }
9879 } else {
9880 displayed = true;
9881 }
9882
9883 if (displayed) {
9884 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009885 if (attrs.width == LayoutParams.MATCH_PARENT
9886 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009887 covered = true;
9888 }
9889 }
9890 if (w.mOrientationChanging) {
9891 if (w.mDrawPending || w.mCommitDrawPending) {
9892 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009893 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009894 "Orientation continue waiting for draw in " + w);
9895 } else {
9896 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009897 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009898 "Orientation change complete in " + w);
9899 }
9900 }
9901 w.mToken.hasVisible = true;
9902 }
9903 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009904 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009905 "Orientation change skips hidden " + w);
9906 w.mOrientationChanging = false;
9907 }
9908
9909 final boolean canBeSeen = w.isDisplayedLw();
9910
9911 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9912 focusDisplayed = true;
9913 }
9914
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009915 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009917 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009918 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009919 if (w.mSurface != null) {
9920 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9921 holdScreen = w.mSession;
9922 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009923 if (!syswin && w.mAttrs.screenBrightness >= 0
9924 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009925 screenBrightness = w.mAttrs.screenBrightness;
9926 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009927 if (!syswin && w.mAttrs.buttonBrightness >= 0
9928 && buttonBrightness < 0) {
9929 buttonBrightness = w.mAttrs.buttonBrightness;
9930 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05009931 if (canBeSeen
9932 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9933 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9934 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009935 syswin = true;
9936 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009937 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009938
Dianne Hackborn25994b42009-09-04 14:21:19 -07009939 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
9940 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009941 // This window completely covers everything behind it,
9942 // so we want to leave all of them as unblurred (for
9943 // performance reasons).
9944 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009945 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009946 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009947 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009948 obscured = true;
9949 if (mBackgroundFillerSurface == null) {
9950 try {
9951 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009952 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009953 0, dw, dh,
9954 PixelFormat.OPAQUE,
9955 Surface.FX_SURFACE_NORMAL);
9956 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009957 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009958 }
9959 }
9960 try {
9961 mBackgroundFillerSurface.setPosition(0, 0);
9962 mBackgroundFillerSurface.setSize(dw, dh);
9963 // Using the same layer as Dim because they will never be shown at the
9964 // same time.
9965 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9966 mBackgroundFillerSurface.show();
9967 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009968 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009969 }
9970 backgroundFillerShown = true;
9971 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009972 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009973 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009974 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009975 + ": blurring=" + blurring
9976 + " obscured=" + obscured
9977 + " displayed=" + displayed);
9978 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9979 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009980 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009981 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009982 if (mDimAnimator == null) {
9983 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009984 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009985 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009986 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009987 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009988 }
9989 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
9990 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009991 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009992 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009993 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009994 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009995 + mBlurSurface + ": CREATE");
9996 try {
Romain Guy06882f82009-06-10 13:36:04 -07009997 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009998 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009999 -1, 16, 16,
10000 PixelFormat.OPAQUE,
10001 Surface.FX_SURFACE_BLUR);
10002 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010003 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010004 }
10005 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010006 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010007 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10008 + mBlurSurface + ": pos=(0,0) (" +
10009 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010010 mBlurSurface.setPosition(0, 0);
10011 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010012 mBlurSurface.setLayer(w.mAnimLayer-2);
10013 if (!mBlurShown) {
10014 try {
10015 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10016 + mBlurSurface + ": SHOW");
10017 mBlurSurface.show();
10018 } catch (RuntimeException e) {
10019 Slog.w(TAG, "Failure showing blur surface", e);
10020 }
10021 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010022 }
10023 }
10024 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010025 }
10026 }
10027 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010028
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010029 if (obscuredChanged && mWallpaperTarget == w) {
10030 // This is the wallpaper target and its obscured state
10031 // changed... make sure the current wallaper's visibility
10032 // has been updated accordingly.
10033 updateWallpaperVisibilityLocked();
10034 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010035 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010036
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010037 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10038 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010039 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010040 try {
10041 mBackgroundFillerSurface.hide();
10042 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010043 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010044 }
10045 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010046
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010047 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010048 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10049 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010050 }
Romain Guy06882f82009-06-10 13:36:04 -070010051
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010052 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010053 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010054 + ": HIDE");
10055 try {
10056 mBlurSurface.hide();
10057 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010058 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010059 }
10060 mBlurShown = false;
10061 }
10062
Joe Onorato8a9b2202010-02-26 18:56:32 -080010063 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010064 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010065 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010066 }
10067
Jeff Browne33348b2010-07-15 23:54:05 -070010068 mInputMonitor.updateInputWindowsLw();
10069
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010070 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010071
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010072 if (mWatermark != null) {
10073 mWatermark.drawIfNeeded();
10074 }
10075
Joe Onorato8a9b2202010-02-26 18:56:32 -080010076 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010077 "With display frozen, orientationChangeComplete="
10078 + orientationChangeComplete);
10079 if (orientationChangeComplete) {
10080 if (mWindowsFreezingScreen) {
10081 mWindowsFreezingScreen = false;
10082 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10083 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010084 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010085 }
Romain Guy06882f82009-06-10 13:36:04 -070010086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010087 i = mResizingWindows.size();
10088 if (i > 0) {
10089 do {
10090 i--;
10091 WindowState win = mResizingWindows.get(i);
10092 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010093 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10094 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010095 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010096 boolean configChanged =
10097 win.mConfiguration != mCurConfiguration
10098 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010099 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10100 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10101 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010102 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010103 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010104 + " / " + mCurConfiguration + " / 0x"
10105 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010106 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010107 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010108 win.mClient.resized(win.mFrame.width(),
10109 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010110 win.mLastVisibleInsets, win.mDrawPending,
10111 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010112 win.mContentInsetsChanged = false;
10113 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010114 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010115 } catch (RemoteException e) {
10116 win.mOrientationChanging = false;
10117 }
10118 } while (i > 0);
10119 mResizingWindows.clear();
10120 }
Romain Guy06882f82009-06-10 13:36:04 -070010121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010122 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010123 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010124 i = mDestroySurface.size();
10125 if (i > 0) {
10126 do {
10127 i--;
10128 WindowState win = mDestroySurface.get(i);
10129 win.mDestroying = false;
10130 if (mInputMethodWindow == win) {
10131 mInputMethodWindow = null;
10132 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010133 if (win == mWallpaperTarget) {
10134 wallpaperDestroyed = true;
10135 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010136 win.destroySurfaceLocked();
10137 } while (i > 0);
10138 mDestroySurface.clear();
10139 }
10140
10141 // Time to remove any exiting tokens?
10142 for (i=mExitingTokens.size()-1; i>=0; i--) {
10143 WindowToken token = mExitingTokens.get(i);
10144 if (!token.hasVisible) {
10145 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010146 if (token.windowType == TYPE_WALLPAPER) {
10147 mWallpaperTokens.remove(token);
10148 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010149 }
10150 }
10151
10152 // Time to remove any exiting applications?
10153 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10154 AppWindowToken token = mExitingAppTokens.get(i);
10155 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010156 // Make sure there is no animation running on this token,
10157 // so any windows associated with it will be removed as
10158 // soon as their animations are complete
10159 token.animation = null;
10160 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010161 mAppTokens.remove(token);
10162 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010163 if (mLastEnterAnimToken == token) {
10164 mLastEnterAnimToken = null;
10165 mLastEnterAnimParams = null;
10166 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010167 }
10168 }
10169
Dianne Hackborna8f60182009-09-01 19:01:50 -070010170 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010171
Dianne Hackborna8f60182009-09-01 19:01:50 -070010172 if (!animating && mAppTransitionRunning) {
10173 // We have finished the animation of an app transition. To do
10174 // this, we have delayed a lot of operations like showing and
10175 // hiding apps, moving apps in Z-order, etc. The app token list
10176 // reflects the correct Z-order, but the window list may now
10177 // be out of sync with it. So here we will just rebuild the
10178 // entire app window list. Fun!
10179 mAppTransitionRunning = false;
10180 needRelayout = true;
10181 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010182 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010183 // Clear information about apps that were moving.
10184 mToBottomApps.clear();
10185 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010187 if (focusDisplayed) {
10188 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10189 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010190 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010191 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010192 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010193 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010194 requestAnimationLocked(0);
10195 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010196 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10197 }
Jeff Browneb857f12010-07-16 10:06:33 -070010198
Jeff Browne33348b2010-07-15 23:54:05 -070010199 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010200
Jeff Brown8e03b752010-06-13 19:16:55 -070010201 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010202 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10203 mPowerManager.setScreenBrightnessOverride(-1);
10204 } else {
10205 mPowerManager.setScreenBrightnessOverride((int)
10206 (screenBrightness * Power.BRIGHTNESS_ON));
10207 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010208 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10209 mPowerManager.setButtonBrightnessOverride(-1);
10210 } else {
10211 mPowerManager.setButtonBrightnessOverride((int)
10212 (buttonBrightness * Power.BRIGHTNESS_ON));
10213 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010214 if (holdScreen != mHoldingScreenOn) {
10215 mHoldingScreenOn = holdScreen;
10216 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10217 mH.sendMessage(m);
10218 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010219
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010220 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010221 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010222 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10223 LocalPowerManager.BUTTON_EVENT, true);
10224 mTurnOnScreen = false;
10225 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010226
10227 // Check to see if we are now in a state where the screen should
10228 // be enabled, because the window obscured flags have changed.
10229 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010230 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070010231
10232 /**
10233 * Must be called with the main window manager lock held.
10234 */
10235 void setHoldScreenLocked(boolean holding) {
10236 boolean state = mHoldingScreenWakeLock.isHeld();
10237 if (holding != state) {
10238 if (holding) {
10239 mHoldingScreenWakeLock.acquire();
10240 } else {
10241 mPolicy.screenOnStoppedLw();
10242 mHoldingScreenWakeLock.release();
10243 }
10244 }
10245 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010246
10247 void requestAnimationLocked(long delay) {
10248 if (!mAnimationPending) {
10249 mAnimationPending = true;
10250 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10251 }
10252 }
Romain Guy06882f82009-06-10 13:36:04 -070010253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010254 /**
10255 * Have the surface flinger show a surface, robustly dealing with
10256 * error conditions. In particular, if there is not enough memory
10257 * to show the surface, then we will try to get rid of other surfaces
10258 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010259 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010260 * @return Returns true if the surface was successfully shown.
10261 */
10262 boolean showSurfaceRobustlyLocked(WindowState win) {
10263 try {
10264 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010265 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010266 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010267 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010268 if (DEBUG_VISIBILITY) Slog.v(TAG,
10269 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010270 win.mTurnOnScreen = false;
10271 mTurnOnScreen = true;
10272 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010273 }
10274 return true;
10275 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010276 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010277 }
Romain Guy06882f82009-06-10 13:36:04 -070010278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010279 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010281 return false;
10282 }
Romain Guy06882f82009-06-10 13:36:04 -070010283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010284 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10285 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010286
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010287 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010288 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010290 if (mForceRemoves == null) {
10291 mForceRemoves = new ArrayList<WindowState>();
10292 }
Romain Guy06882f82009-06-10 13:36:04 -070010293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010294 long callingIdentity = Binder.clearCallingIdentity();
10295 try {
10296 // There was some problem... first, do a sanity check of the
10297 // window list to make sure we haven't left any dangling surfaces
10298 // around.
10299 int N = mWindows.size();
10300 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010301 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010302 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010303 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010304 if (ws.mSurface != null) {
10305 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010306 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010307 + ws + " surface=" + ws.mSurface
10308 + " token=" + win.mToken
10309 + " pid=" + ws.mSession.mPid
10310 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010311 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010312 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010313 ws.mSurface = null;
10314 mForceRemoves.add(ws);
10315 i--;
10316 N--;
10317 leakedSurface = true;
10318 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010319 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010320 + ws + " surface=" + ws.mSurface
10321 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010322 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010323 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010324 ws.mSurface = null;
10325 leakedSurface = true;
10326 }
10327 }
10328 }
Romain Guy06882f82009-06-10 13:36:04 -070010329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010330 boolean killedApps = false;
10331 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010332 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010333 SparseIntArray pidCandidates = new SparseIntArray();
10334 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010335 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010336 if (ws.mSurface != null) {
10337 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10338 }
10339 }
10340 if (pidCandidates.size() > 0) {
10341 int[] pids = new int[pidCandidates.size()];
10342 for (int i=0; i<pids.length; i++) {
10343 pids[i] = pidCandidates.keyAt(i);
10344 }
10345 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010346 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010347 killedApps = true;
10348 }
10349 } catch (RemoteException e) {
10350 }
10351 }
10352 }
Romain Guy06882f82009-06-10 13:36:04 -070010353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010354 if (leakedSurface || killedApps) {
10355 // We managed to reclaim some memory, so get rid of the trouble
10356 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010357 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010358 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010359 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010360 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010361 win.mSurface = null;
10362 }
Romain Guy06882f82009-06-10 13:36:04 -070010363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010364 try {
10365 win.mClient.dispatchGetNewSurface();
10366 } catch (RemoteException e) {
10367 }
10368 }
10369 } finally {
10370 Binder.restoreCallingIdentity(callingIdentity);
10371 }
10372 }
Romain Guy06882f82009-06-10 13:36:04 -070010373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010374 private boolean updateFocusedWindowLocked(int mode) {
10375 WindowState newFocus = computeFocusedWindowLocked();
10376 if (mCurrentFocus != newFocus) {
10377 // This check makes sure that we don't already have the focus
10378 // change message pending.
10379 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10380 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010381 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010382 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10383 final WindowState oldFocus = mCurrentFocus;
10384 mCurrentFocus = newFocus;
10385 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010387 final WindowState imWindow = mInputMethodWindow;
10388 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010389 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010390 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010391 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10392 mLayoutNeeded = true;
10393 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010394 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
10395 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010396 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10397 // Client will do the layout, but we need to assign layers
10398 // for handleNewWindowLocked() below.
10399 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010400 }
10401 }
Jeff Brown349703e2010-06-22 01:27:15 -070010402
10403 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10404 // If we defer assigning layers, then the caller is responsible for
10405 // doing this part.
10406 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010407 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010408 return true;
10409 }
10410 return false;
10411 }
Jeff Brown349703e2010-06-22 01:27:15 -070010412
10413 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010414 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070010415 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010416
10417 private WindowState computeFocusedWindowLocked() {
10418 WindowState result = null;
10419 WindowState win;
10420
10421 int i = mWindows.size() - 1;
10422 int nextAppIndex = mAppTokens.size()-1;
10423 WindowToken nextApp = nextAppIndex >= 0
10424 ? mAppTokens.get(nextAppIndex) : null;
10425
10426 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070010427 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010428
Joe Onorato8a9b2202010-02-26 18:56:32 -080010429 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010430 TAG, "Looking for focus: " + i
10431 + " = " + win
10432 + ", flags=" + win.mAttrs.flags
10433 + ", canReceive=" + win.canReceiveKeys());
10434
10435 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010437 // If this window's application has been removed, just skip it.
10438 if (thisApp != null && thisApp.removed) {
10439 i--;
10440 continue;
10441 }
Romain Guy06882f82009-06-10 13:36:04 -070010442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010443 // If there is a focused app, don't allow focus to go to any
10444 // windows below it. If this is an application window, step
10445 // through the app tokens until we find its app.
10446 if (thisApp != null && nextApp != null && thisApp != nextApp
10447 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10448 int origAppIndex = nextAppIndex;
10449 while (nextAppIndex > 0) {
10450 if (nextApp == mFocusedApp) {
10451 // Whoops, we are below the focused app... no focus
10452 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010453 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010454 TAG, "Reached focused app: " + mFocusedApp);
10455 return null;
10456 }
10457 nextAppIndex--;
10458 nextApp = mAppTokens.get(nextAppIndex);
10459 if (nextApp == thisApp) {
10460 break;
10461 }
10462 }
10463 if (thisApp != nextApp) {
10464 // Uh oh, the app token doesn't exist! This shouldn't
10465 // happen, but if it does we can get totally hosed...
10466 // so restart at the original app.
10467 nextAppIndex = origAppIndex;
10468 nextApp = mAppTokens.get(nextAppIndex);
10469 }
10470 }
10471
10472 // Dispatch to this window if it is wants key events.
10473 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010474 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010475 TAG, "Found focus @ " + i + " = " + win);
10476 result = win;
10477 break;
10478 }
10479
10480 i--;
10481 }
10482
10483 return result;
10484 }
10485
10486 private void startFreezingDisplayLocked() {
10487 if (mDisplayFrozen) {
10488 return;
10489 }
Romain Guy06882f82009-06-10 13:36:04 -070010490
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010491 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010493 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010494 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010495 if (mFreezeGcPending != 0) {
10496 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010497 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010498 mH.removeMessages(H.FORCE_GC);
10499 Runtime.getRuntime().gc();
10500 mFreezeGcPending = now;
10501 }
10502 } else {
10503 mFreezeGcPending = now;
10504 }
Romain Guy06882f82009-06-10 13:36:04 -070010505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010506 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010507
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010508 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010509
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010510 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10511 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010512 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010513 mAppTransitionReady = true;
10514 }
Romain Guy06882f82009-06-10 13:36:04 -070010515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010516 if (PROFILE_ORIENTATION) {
10517 File file = new File("/data/system/frozen");
10518 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10519 }
10520 Surface.freezeDisplay(0);
10521 }
Romain Guy06882f82009-06-10 13:36:04 -070010522
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010523 private void stopFreezingDisplayLocked() {
10524 if (!mDisplayFrozen) {
10525 return;
10526 }
Romain Guy06882f82009-06-10 13:36:04 -070010527
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010528 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10529 return;
10530 }
10531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010532 mDisplayFrozen = false;
10533 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10534 if (PROFILE_ORIENTATION) {
10535 Debug.stopMethodTracing();
10536 }
10537 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010538
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010539 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010540
Christopher Tateb696aee2010-04-02 19:08:30 -070010541 // While the display is frozen we don't re-compute the orientation
10542 // to avoid inconsistent states. However, something interesting
10543 // could have actually changed during that time so re-evaluate it
10544 // now to catch that.
10545 if (updateOrientationFromAppTokensLocked()) {
10546 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10547 }
10548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010549 // A little kludge: a lot could have happened while the
10550 // display was frozen, so now that we are coming back we
10551 // do a gc so that any remote references the system
10552 // processes holds on others can be released if they are
10553 // no longer needed.
10554 mH.removeMessages(H.FORCE_GC);
10555 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10556 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010558 mScreenFrozenLock.release();
10559 }
Romain Guy06882f82009-06-10 13:36:04 -070010560
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010561 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10562 DisplayMetrics dm) {
10563 if (index < tokens.length) {
10564 String str = tokens[index];
10565 if (str != null && str.length() > 0) {
10566 try {
10567 int val = Integer.parseInt(str);
10568 return val;
10569 } catch (Exception e) {
10570 }
10571 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010572 }
10573 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10574 return defDps;
10575 }
10576 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10577 return val;
10578 }
10579
10580 class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010581 final String[] mTokens;
10582 final String mText;
10583 final Paint mTextPaint;
10584 final int mTextWidth;
10585 final int mTextHeight;
10586 final int mTextAscent;
10587 final int mTextDescent;
10588 final int mDeltaX;
10589 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010590
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010591 Surface mSurface;
10592 int mLastDW;
10593 int mLastDH;
10594 boolean mDrawNeeded;
10595
10596 Watermark(SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010597 final DisplayMetrics dm = new DisplayMetrics();
10598 mDisplay.getMetrics(dm);
10599
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010600 if (false) {
10601 Log.i(TAG, "*********************** WATERMARK");
10602 for (int i=0; i<tokens.length; i++) {
10603 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10604 }
10605 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010606
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010607 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010608
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010609 StringBuilder builder = new StringBuilder(32);
10610 int len = mTokens[0].length();
10611 len = len & ~1;
10612 for (int i=0; i<len; i+=2) {
10613 int c1 = mTokens[0].charAt(i);
10614 int c2 = mTokens[0].charAt(i+1);
10615 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10616 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10617 else c1 -= '0';
10618 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10619 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10620 else c2 -= '0';
10621 builder.append((char)(255-((c1*16)+c2)));
10622 }
10623 mText = builder.toString();
10624 if (false) {
10625 Log.i(TAG, "Final text: " + mText);
10626 }
10627
10628 int fontSize = getPropertyInt(tokens, 1,
10629 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10630
10631 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10632 mTextPaint.setTextSize(fontSize);
10633 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10634
10635 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
10636 mTextWidth = (int)mTextPaint.measureText(mText);
10637 mTextAscent = fm.ascent;
10638 mTextDescent = fm.descent;
10639 mTextHeight = fm.descent - fm.ascent;
10640
10641 mDeltaX = getPropertyInt(tokens, 2,
10642 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
10643 mDeltaY = getPropertyInt(tokens, 3,
10644 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
10645 int shadowColor = getPropertyInt(tokens, 4,
10646 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
10647 int color = getPropertyInt(tokens, 5,
10648 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
10649 int shadowRadius = getPropertyInt(tokens, 6,
10650 TypedValue.COMPLEX_UNIT_PX, 7, dm);
10651 int shadowDx = getPropertyInt(tokens, 8,
10652 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10653 int shadowDy = getPropertyInt(tokens, 9,
10654 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10655
10656 mTextPaint.setColor(color);
10657 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010658
10659 try {
10660 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010661 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010662 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010663 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010664 mSurface.show();
10665 } catch (OutOfResourcesException e) {
10666 }
10667 }
10668
10669 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010670 if (mLastDW != dw || mLastDH != dh) {
10671 mLastDW = dw;
10672 mLastDH = dh;
10673 mSurface.setSize(dw, dh);
10674 mDrawNeeded = true;
10675 }
10676 }
10677
10678 void drawIfNeeded() {
10679 if (mDrawNeeded) {
10680 final int dw = mLastDW;
10681 final int dh = mLastDH;
10682
10683 mDrawNeeded = false;
10684 Rect dirty = new Rect(0, 0, dw, dh);
10685 Canvas c = null;
10686 try {
10687 c = mSurface.lockCanvas(dirty);
10688 } catch (IllegalArgumentException e) {
10689 } catch (OutOfResourcesException e) {
10690 }
10691 if (c != null) {
10692 int deltaX = mDeltaX;
10693 int deltaY = mDeltaY;
10694
10695 // deltaX shouldn't be close to a round fraction of our
10696 // x step, or else things will line up too much.
10697 int div = (dw+mTextWidth)/deltaX;
10698 int rem = (dw+mTextWidth) - (div*deltaX);
10699 int qdelta = deltaX/4;
10700 if (rem < qdelta || rem > (deltaX-qdelta)) {
10701 deltaX += deltaX/3;
10702 }
10703
10704 int y = -mTextHeight;
10705 int x = -mTextWidth;
10706 while (y < (dh+mTextHeight)) {
10707 c.drawText(mText, x, y, mTextPaint);
10708 x += deltaX;
10709 if (x >= dw) {
10710 x -= (dw+mTextWidth);
10711 y += deltaY;
10712 }
10713 }
10714 mSurface.unlockCanvasAndPost(c);
10715 }
10716 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010717 }
10718 }
10719
10720 void createWatermark() {
10721 if (mWatermark != null) {
10722 return;
10723 }
10724
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010725 File file = new File("/system/etc/setup.conf");
10726 FileInputStream in = null;
10727 try {
10728 in = new FileInputStream(file);
10729 DataInputStream ind = new DataInputStream(in);
10730 String line = ind.readLine();
10731 if (line != null) {
10732 String[] toks = line.split("%");
10733 if (toks != null && toks.length > 0) {
10734 mWatermark = new Watermark(mFxSession, toks);
10735 }
10736 }
10737 } catch (FileNotFoundException e) {
10738 } catch (IOException e) {
10739 } finally {
10740 if (in != null) {
10741 try {
10742 in.close();
10743 } catch (IOException e) {
10744 }
10745 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010746 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010747 }
10748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010749 @Override
10750 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10751 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10752 != PackageManager.PERMISSION_GRANTED) {
10753 pw.println("Permission Denial: can't dump WindowManager from from pid="
10754 + Binder.getCallingPid()
10755 + ", uid=" + Binder.getCallingUid());
10756 return;
10757 }
Romain Guy06882f82009-06-10 13:36:04 -070010758
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010759 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010760 pw.println(" ");
10761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010762 synchronized(mWindowMap) {
10763 pw.println("Current Window Manager state:");
10764 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010765 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010766 pw.print(" Window #"); pw.print(i); pw.print(' ');
10767 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010768 w.dump(pw, " ");
10769 }
10770 if (mInputMethodDialogs.size() > 0) {
10771 pw.println(" ");
10772 pw.println(" Input method dialogs:");
10773 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10774 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010775 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010776 }
10777 }
10778 if (mPendingRemove.size() > 0) {
10779 pw.println(" ");
10780 pw.println(" Remove pending for:");
10781 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10782 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010783 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10784 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010785 w.dump(pw, " ");
10786 }
10787 }
10788 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10789 pw.println(" ");
10790 pw.println(" Windows force removing:");
10791 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10792 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010793 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10794 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010795 w.dump(pw, " ");
10796 }
10797 }
10798 if (mDestroySurface.size() > 0) {
10799 pw.println(" ");
10800 pw.println(" Windows waiting to destroy their surface:");
10801 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10802 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010803 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10804 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010805 w.dump(pw, " ");
10806 }
10807 }
10808 if (mLosingFocus.size() > 0) {
10809 pw.println(" ");
10810 pw.println(" Windows losing focus:");
10811 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10812 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010813 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10814 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010815 w.dump(pw, " ");
10816 }
10817 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010818 if (mResizingWindows.size() > 0) {
10819 pw.println(" ");
10820 pw.println(" Windows waiting to resize:");
10821 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10822 WindowState w = mResizingWindows.get(i);
10823 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10824 pw.print(w); pw.println(":");
10825 w.dump(pw, " ");
10826 }
10827 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010828 if (mSessions.size() > 0) {
10829 pw.println(" ");
10830 pw.println(" All active sessions:");
10831 Iterator<Session> it = mSessions.iterator();
10832 while (it.hasNext()) {
10833 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010834 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010835 s.dump(pw, " ");
10836 }
10837 }
10838 if (mTokenMap.size() > 0) {
10839 pw.println(" ");
10840 pw.println(" All tokens:");
10841 Iterator<WindowToken> it = mTokenMap.values().iterator();
10842 while (it.hasNext()) {
10843 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010844 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010845 token.dump(pw, " ");
10846 }
10847 }
10848 if (mTokenList.size() > 0) {
10849 pw.println(" ");
10850 pw.println(" Window token list:");
10851 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010852 pw.print(" #"); pw.print(i); pw.print(": ");
10853 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010854 }
10855 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010856 if (mWallpaperTokens.size() > 0) {
10857 pw.println(" ");
10858 pw.println(" Wallpaper tokens:");
10859 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10860 WindowToken token = mWallpaperTokens.get(i);
10861 pw.print(" Wallpaper #"); pw.print(i);
10862 pw.print(' '); pw.print(token); pw.println(':');
10863 token.dump(pw, " ");
10864 }
10865 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010866 if (mAppTokens.size() > 0) {
10867 pw.println(" ");
10868 pw.println(" Application tokens in Z order:");
10869 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010870 pw.print(" App #"); pw.print(i); pw.print(": ");
10871 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010872 }
10873 }
10874 if (mFinishedStarting.size() > 0) {
10875 pw.println(" ");
10876 pw.println(" Finishing start of application tokens:");
10877 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10878 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010879 pw.print(" Finished Starting #"); pw.print(i);
10880 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010881 token.dump(pw, " ");
10882 }
10883 }
10884 if (mExitingTokens.size() > 0) {
10885 pw.println(" ");
10886 pw.println(" Exiting tokens:");
10887 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10888 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010889 pw.print(" Exiting #"); pw.print(i);
10890 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010891 token.dump(pw, " ");
10892 }
10893 }
10894 if (mExitingAppTokens.size() > 0) {
10895 pw.println(" ");
10896 pw.println(" Exiting application tokens:");
10897 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10898 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010899 pw.print(" Exiting App #"); pw.print(i);
10900 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010901 token.dump(pw, " ");
10902 }
10903 }
10904 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010905 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10906 pw.print(" mLastFocus="); pw.println(mLastFocus);
10907 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10908 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10909 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010910 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010911 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10912 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10913 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10914 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010915 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10916 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10917 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010918 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10919 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10920 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10921 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010922 if (mDimAnimator != null) {
10923 mDimAnimator.printTo(pw);
10924 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080010925 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010926 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010927 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010928 pw.print(mInputMethodAnimLayerAdjustment);
10929 pw.print(" mWallpaperAnimLayerAdjustment=");
10930 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010931 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10932 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010933 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10934 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010935 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
10936 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010937 pw.print(" mRotation="); pw.print(mRotation);
10938 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10939 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10940 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10941 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10942 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10943 pw.print(" mNextAppTransition=0x");
10944 pw.print(Integer.toHexString(mNextAppTransition));
10945 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010946 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010947 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010948 if (mNextAppTransitionPackage != null) {
10949 pw.print(" mNextAppTransitionPackage=");
10950 pw.print(mNextAppTransitionPackage);
10951 pw.print(", mNextAppTransitionEnter=0x");
10952 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10953 pw.print(", mNextAppTransitionExit=0x");
10954 pw.print(Integer.toHexString(mNextAppTransitionExit));
10955 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010956 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10957 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010958 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10959 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10960 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10961 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010962 if (mOpeningApps.size() > 0) {
10963 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10964 }
10965 if (mClosingApps.size() > 0) {
10966 pw.print(" mClosingApps="); pw.println(mClosingApps);
10967 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010968 if (mToTopApps.size() > 0) {
10969 pw.print(" mToTopApps="); pw.println(mToTopApps);
10970 }
10971 if (mToBottomApps.size() > 0) {
10972 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10973 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010974 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10975 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010976 }
10977 }
10978
Jeff Brown349703e2010-06-22 01:27:15 -070010979 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010980 public void monitor() {
10981 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010982 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070010983 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010984
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010985 /**
10986 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010987 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010988 */
10989 private static class DimAnimator {
10990 Surface mDimSurface;
10991 boolean mDimShown = false;
10992 float mDimCurrentAlpha;
10993 float mDimTargetAlpha;
10994 float mDimDeltaPerMs;
10995 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010996
10997 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010998
10999 DimAnimator (SurfaceSession session) {
11000 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011001 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011002 + mDimSurface + ": CREATE");
11003 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011004 mDimSurface = new Surface(session, 0,
11005 "DimSurface",
11006 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011007 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011008 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011009 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011010 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011011 }
11012 }
11013 }
11014
11015 /**
11016 * Show the dim surface.
11017 */
11018 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011019 if (!mDimShown) {
11020 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11021 dw + "x" + dh + ")");
11022 mDimShown = true;
11023 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011024 mLastDimWidth = dw;
11025 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011026 mDimSurface.setPosition(0, 0);
11027 mDimSurface.setSize(dw, dh);
11028 mDimSurface.show();
11029 } catch (RuntimeException e) {
11030 Slog.w(TAG, "Failure showing dim surface", e);
11031 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011032 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11033 mLastDimWidth = dw;
11034 mLastDimHeight = dh;
11035 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011036 }
11037 }
11038
11039 /**
11040 * Set's the dim surface's layer and update dim parameters that will be used in
11041 * {@link updateSurface} after all windows are examined.
11042 */
11043 void updateParameters(WindowState w, long currentTime) {
11044 mDimSurface.setLayer(w.mAnimLayer-1);
11045
11046 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011047 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011048 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011049 if (mDimTargetAlpha != target) {
11050 // If the desired dim level has changed, then
11051 // start an animation to it.
11052 mLastDimAnimTime = currentTime;
11053 long duration = (w.mAnimating && w.mAnimation != null)
11054 ? w.mAnimation.computeDurationHint()
11055 : DEFAULT_DIM_DURATION;
11056 if (target > mDimTargetAlpha) {
11057 // This is happening behind the activity UI,
11058 // so we can make it run a little longer to
11059 // give a stronger impression without disrupting
11060 // the user.
11061 duration *= DIM_DURATION_MULTIPLIER;
11062 }
11063 if (duration < 1) {
11064 // Don't divide by zero
11065 duration = 1;
11066 }
11067 mDimTargetAlpha = target;
11068 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11069 }
11070 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011071
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011072 /**
11073 * Updating the surface's alpha. Returns true if the animation continues, or returns
11074 * false when the animation is finished and the dim surface is hidden.
11075 */
11076 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11077 if (!dimming) {
11078 if (mDimTargetAlpha != 0) {
11079 mLastDimAnimTime = currentTime;
11080 mDimTargetAlpha = 0;
11081 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11082 }
11083 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011084
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011085 boolean animating = false;
11086 if (mLastDimAnimTime != 0) {
11087 mDimCurrentAlpha += mDimDeltaPerMs
11088 * (currentTime-mLastDimAnimTime);
11089 boolean more = true;
11090 if (displayFrozen) {
11091 // If the display is frozen, there is no reason to animate.
11092 more = false;
11093 } else if (mDimDeltaPerMs > 0) {
11094 if (mDimCurrentAlpha > mDimTargetAlpha) {
11095 more = false;
11096 }
11097 } else if (mDimDeltaPerMs < 0) {
11098 if (mDimCurrentAlpha < mDimTargetAlpha) {
11099 more = false;
11100 }
11101 } else {
11102 more = false;
11103 }
11104
11105 // Do we need to continue animating?
11106 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011107 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011108 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11109 mLastDimAnimTime = currentTime;
11110 mDimSurface.setAlpha(mDimCurrentAlpha);
11111 animating = true;
11112 } else {
11113 mDimCurrentAlpha = mDimTargetAlpha;
11114 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011115 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011116 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11117 mDimSurface.setAlpha(mDimCurrentAlpha);
11118 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011119 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011120 + ": HIDE");
11121 try {
11122 mDimSurface.hide();
11123 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011124 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011125 }
11126 mDimShown = false;
11127 }
11128 }
11129 }
11130 return animating;
11131 }
11132
11133 public void printTo(PrintWriter pw) {
11134 pw.print(" mDimShown="); pw.print(mDimShown);
11135 pw.print(" current="); pw.print(mDimCurrentAlpha);
11136 pw.print(" target="); pw.print(mDimTargetAlpha);
11137 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11138 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11139 }
11140 }
11141
11142 /**
11143 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11144 * This is used for opening/closing transition for apps in compatible mode.
11145 */
11146 private static class FadeInOutAnimation extends Animation {
11147 int mWidth;
11148 boolean mFadeIn;
11149
11150 public FadeInOutAnimation(boolean fadeIn) {
11151 setInterpolator(new AccelerateInterpolator());
11152 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11153 mFadeIn = fadeIn;
11154 }
11155
11156 @Override
11157 protected void applyTransformation(float interpolatedTime, Transformation t) {
11158 float x = interpolatedTime;
11159 if (!mFadeIn) {
11160 x = 1.0f - x; // reverse the interpolation for fade out
11161 }
11162 if (x < 0.5) {
11163 // move the window out of the screen.
11164 t.getMatrix().setTranslate(mWidth, 0);
11165 } else {
11166 t.getMatrix().setTranslate(0, 0);// show
11167 t.setAlpha((x - 0.5f) * 2);
11168 }
11169 }
11170
11171 @Override
11172 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11173 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11174 mWidth = width;
11175 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011176
11177 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011178 public int getZAdjustment() {
11179 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011180 }
11181 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011182}