blob: 60bd19b09845d2dac9bef96f44cab874b71c72eb [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
20import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
21import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070022import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
24import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070025import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
Joe Onorato93056472010-09-10 10:30:46 -040026import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR;
28import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
29import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070030import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
32import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS;
34import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
35import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
36import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
37import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070038import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039
40import com.android.internal.app.IBatteryStats;
41import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080042import com.android.internal.policy.impl.PhoneWindowManager;
Christopher Tatea53146c2010-09-07 11:57:52 -070043import com.android.internal.view.BaseInputHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import com.android.internal.view.IInputContext;
45import com.android.internal.view.IInputMethodClient;
46import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080047import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import com.android.server.am.BatteryStatsService;
49
50import android.Manifest;
51import android.app.ActivityManagerNative;
52import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070053import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070054import android.content.BroadcastReceiver;
Christopher Tatea53146c2010-09-07 11:57:52 -070055import android.content.ClipData;
56import android.content.ClipDescription;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070058import android.content.Intent;
59import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.content.pm.ActivityInfo;
61import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070062import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import android.content.res.Configuration;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070064import android.graphics.Canvas;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065import android.graphics.Matrix;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070066import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import android.graphics.PixelFormat;
68import android.graphics.Rect;
69import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070070import android.graphics.Typeface;
71import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072import android.os.BatteryStats;
73import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070074import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075import android.os.Debug;
76import android.os.Handler;
77import android.os.IBinder;
78import android.os.LocalPowerManager;
79import android.os.Looper;
80import android.os.Message;
81import android.os.Parcel;
82import android.os.ParcelFileDescriptor;
83import android.os.Power;
84import android.os.PowerManager;
85import android.os.Process;
86import android.os.RemoteException;
87import android.os.ServiceManager;
88import android.os.SystemClock;
89import android.os.SystemProperties;
90import android.os.TokenWatcher;
91import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070092import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070094import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080095import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070097import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098import android.view.Display;
Christopher Tatea53146c2010-09-07 11:57:52 -070099import android.view.DragEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100import android.view.Gravity;
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700101import android.view.HapticFeedbackConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102import android.view.IApplicationToken;
103import android.view.IOnKeyguardExitResult;
104import android.view.IRotationWatcher;
105import android.view.IWindow;
106import android.view.IWindowManager;
107import android.view.IWindowSession;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700108import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700109import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700110import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700111import android.view.InputHandler;
112import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113import android.view.KeyEvent;
114import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115import android.view.Surface;
116import android.view.SurfaceSession;
117import android.view.View;
118import android.view.ViewTreeObserver;
119import android.view.WindowManager;
120import android.view.WindowManagerImpl;
121import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700122import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700124import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125import android.view.animation.Animation;
126import android.view.animation.AnimationUtils;
127import android.view.animation.Transformation;
128
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700129import java.io.BufferedReader;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700131import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132import java.io.File;
133import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700134import java.io.FileInputStream;
135import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136import java.io.IOException;
137import java.io.OutputStream;
138import java.io.OutputStreamWriter;
139import java.io.PrintWriter;
140import java.io.StringWriter;
141import java.net.Socket;
142import java.util.ArrayList;
143import java.util.HashMap;
144import java.util.HashSet;
145import java.util.Iterator;
146import java.util.List;
147
148/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700149public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700150 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 static final String TAG = "WindowManager";
152 static final boolean DEBUG = false;
153 static final boolean DEBUG_FOCUS = false;
154 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800155 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800156 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 static final boolean DEBUG_LAYERS = false;
158 static final boolean DEBUG_INPUT = false;
159 static final boolean DEBUG_INPUT_METHOD = false;
160 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700161 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700163 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 static final boolean DEBUG_APP_TRANSITIONS = false;
165 static final boolean DEBUG_STARTING_WINDOW = false;
166 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700167 static final boolean DEBUG_WALLPAPER = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700168 static final boolean DEBUG_DRAG = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700170 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172 static final boolean PROFILE_ORIENTATION = false;
173 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700174 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 /** How much to multiply the policy's type layer, to reserve room
177 * for multiple windows of the same type and Z-ordering adjustment
178 * with TYPE_LAYER_OFFSET. */
179 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
182 * or below others in the same layer. */
183 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 /** How much to increment the layer for each window, to reserve room
186 * for effect surfaces between them.
187 */
188 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 /** The maximum length we will accept for a loaded animation duration:
191 * this is 10 seconds.
192 */
193 static final int MAX_ANIMATION_DURATION = 10*1000;
194
195 /** Amount of time (in milliseconds) to animate the dim surface from one
196 * value to another, when no window animation is driving it.
197 */
198 static final int DEFAULT_DIM_DURATION = 200;
199
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700200 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
201 * compatible windows.
202 */
203 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 /** Adjustment to time to perform a dim, to make it more dramatic.
206 */
207 static final int DIM_DURATION_MULTIPLIER = 6;
Jeff Brown7fbdc842010-06-17 20:52:56 -0700208
209 // Maximum number of milliseconds to wait for input event injection.
210 // FIXME is this value reasonable?
211 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700212
213 // Default input dispatching timeout in nanoseconds.
214 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 static final int UPDATE_FOCUS_NORMAL = 0;
217 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
218 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
219 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700222 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223
224 /**
225 * Condition waited on by {@link #reenableKeyguard} to know the call to
226 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500227 * This is set to true only if mKeyguardTokenWatcher.acquired() has
228 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500230 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231
Jim Miller284b62e2010-06-08 14:27:42 -0700232 private static final int ALLOW_DISABLE_YES = 1;
233 private static final int ALLOW_DISABLE_NO = 0;
234 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
235 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
236
Mike Lockwood983ee092009-11-22 01:42:24 -0500237 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
238 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700240 if (shouldAllowDisableKeyguard()) {
241 mPolicy.enableKeyguard(false);
242 mKeyguardDisabled = true;
243 } else {
244 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
245 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 }
247 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700248 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500249 synchronized (mKeyguardTokenWatcher) {
250 mKeyguardDisabled = false;
251 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252 }
253 }
254 };
255
Jim Miller284b62e2010-06-08 14:27:42 -0700256 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
257 @Override
258 public void onReceive(Context context, Intent intent) {
259 mPolicy.enableKeyguard(true);
260 synchronized(mKeyguardTokenWatcher) {
261 // lazily evaluate this next time we're asked to disable keyguard
262 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
263 mKeyguardDisabled = false;
264 }
265 }
266 };
267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 final Context mContext;
269
270 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
275
276 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280 /**
281 * All currently active sessions with clients.
282 */
283 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 /**
286 * Mapping from an IWindow IBinder to the server's Window object.
287 * This is also used as the lock for all of our state.
288 */
289 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
290
291 /**
292 * Mapping from a token IBinder to a WindowToken object.
293 */
294 final HashMap<IBinder, WindowToken> mTokenMap =
295 new HashMap<IBinder, WindowToken>();
296
297 /**
298 * The same tokens as mTokenMap, stored in a list for efficient iteration
299 * over them.
300 */
301 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800303 /**
304 * Window tokens that are in the process of exiting, but still
305 * on screen for animations.
306 */
307 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
308
309 /**
310 * Z-ordered (bottom-most first) list of all application tokens, for
311 * controlling the ordering of windows in different applications. This
312 * contains WindowToken objects.
313 */
314 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
315
316 /**
317 * Application tokens that are in the process of exiting, but still
318 * on screen for animations.
319 */
320 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
321
322 /**
323 * List of window tokens that have finished starting their application,
324 * and now need to have the policy remove their windows.
325 */
326 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
327
328 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700329 * This was the app token that was used to retrieve the last enter
330 * animation. It will be used for the next exit animation.
331 */
332 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800333
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700334 /**
335 * These were the layout params used to retrieve the last enter animation.
336 * They will be used for the next exit animation.
337 */
338 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800339
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700340 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 * Z-ordered (bottom-most first) list of all Window objects.
342 */
Jeff Browne33348b2010-07-15 23:54:05 -0700343 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344
345 /**
346 * Windows that are being resized. Used so we can tell the client about
347 * the resize after closing the transaction in which we resized the
348 * underlying surface.
349 */
350 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
351
352 /**
353 * Windows whose animations have ended and now must be removed.
354 */
355 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
356
357 /**
358 * Windows whose surface should be destroyed.
359 */
360 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
361
362 /**
363 * Windows that have lost input focus and are waiting for the new
364 * focus window to be displayed before they are told about this.
365 */
366 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
367
368 /**
369 * This is set when we have run out of memory, and will either be an empty
370 * list or contain windows that need to be force removed.
371 */
372 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700377 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 Surface mBlurSurface;
379 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700380 Watermark mWatermark;
Romain Guy06882f82009-06-10 13:36:04 -0700381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 final float[] mTmpFloats = new float[9];
385
386 boolean mSafeMode;
387 boolean mDisplayEnabled = false;
388 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700389 int mInitialDisplayWidth = 0;
390 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 int mRotation = 0;
392 int mRequestedRotation = 0;
393 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700394 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 ArrayList<IRotationWatcher> mRotationWatchers
396 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800398 boolean mLayoutNeeded = true;
399 boolean mAnimationPending = false;
400 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800401 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 boolean mWindowsFreezingScreen = false;
403 long mFreezeGcPending = 0;
404 int mAppsFreezingScreen = 0;
405
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800406 int mLayoutSeq = 0;
407
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800408 // State while inside of layoutAndPlaceSurfacesLocked().
409 boolean mFocusMayChange;
410
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800411 Configuration mCurConfiguration = new Configuration();
412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 // This is held as long as we have the screen frozen, to give us time to
414 // perform a rotation animation when turning off shows the lock screen which
415 // changes the orientation.
416 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418 // State management of app transitions. When we are preparing for a
419 // transition, mNextAppTransition will be the kind of transition to
420 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
421 // mOpeningApps and mClosingApps are the lists of tokens that will be
422 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700423 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700424 String mNextAppTransitionPackage;
425 int mNextAppTransitionEnter;
426 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700428 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 boolean mAppTransitionTimeout = false;
430 boolean mStartingIconInTransition = false;
431 boolean mSkipAppTransitionAnimation = false;
432 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
433 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700434 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
435 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 H mH = new H();
440
441 WindowState mCurrentFocus = null;
442 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 // This just indicates the window the input method is on top of, not
445 // necessarily the window its input is going to.
446 WindowState mInputMethodTarget = null;
447 WindowState mUpcomingInputMethodTarget = null;
448 boolean mInputMethodTargetWaitingAnim;
449 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 WindowState mInputMethodWindow = null;
452 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
453
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700454 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800455
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700456 // If non-null, this is the currently visible window that is associated
457 // with the wallpaper.
458 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700459 // If non-null, we are in the middle of animating from one wallpaper target
460 // to another, and this is the lower one in Z-order.
461 WindowState mLowerWallpaperTarget = null;
462 // If non-null, we are in the middle of animating from one wallpaper target
463 // to another, and this is the higher one in Z-order.
464 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700465 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700466 float mLastWallpaperX = -1;
467 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800468 float mLastWallpaperXStep = -1;
469 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700470 // This is set when we are waiting for a wallpaper to tell us it is done
471 // changing its scroll position.
472 WindowState mWaitingOnWallpaper;
473 // The last time we had a timeout when waiting for a wallpaper.
474 long mLastWallpaperTimeoutTime;
475 // We give a wallpaper up to 150ms to finish scrolling.
476 static final long WALLPAPER_TIMEOUT = 150;
477 // Time we wait after a timeout before trying to wait again.
478 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800480 AppWindowToken mFocusedApp = null;
481
482 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800484 float mWindowAnimationScale = 1.0f;
485 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700486
Jeff Brown46b9ac02010-04-22 18:58:52 -0700487 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488
489 // Who is holding the screen on.
490 Session mHoldingScreenOn;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700491 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700492
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700493 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700496 * Drag/drop state
497 */
498 class DragState {
499 IBinder mToken;
500 Surface mSurface;
501 boolean mLocalOnly;
502 ClipData mData;
503 ClipDescription mDataDescription;
Chris Tated4533f12010-10-19 15:15:08 -0700504 boolean mDragResult;
Chris Tateb478f462010-10-15 16:02:26 -0700505 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700506 float mThumbOffsetX, mThumbOffsetY;
507 InputChannel mServerChannel, mClientChannel;
508 WindowState mTargetWindow;
509 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700510 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700511
512 private final Rect tmpRect = new Rect();
513
514 DragState(IBinder token, Surface surface, boolean localOnly) {
515 mToken = token;
516 mSurface = surface;
517 mLocalOnly = localOnly;
518 mNotifiedWindows = new ArrayList<WindowState>();
519 }
520
521 void reset() {
522 if (mSurface != null) {
523 mSurface.destroy();
524 }
525 mSurface = null;
526 mLocalOnly = false;
527 mToken = null;
528 mData = null;
529 mThumbOffsetX = mThumbOffsetY = 0;
530 mNotifiedWindows = null;
531 }
532
533 void register() {
534 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
535 if (mClientChannel != null) {
536 Slog.e(TAG, "Duplicate register of drag input channel");
537 } else {
538 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
539 mServerChannel = channels[0];
540 mClientChannel = channels[1];
541 mInputManager.registerInputChannel(mServerChannel);
542 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
543 mH.getLooper().getQueue());
544 }
545 }
546
547 void unregister() {
548 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
549 if (mClientChannel == null) {
550 Slog.e(TAG, "Unregister of nonexistent drag input channel");
551 } else {
552 mInputManager.unregisterInputChannel(mServerChannel);
553 InputQueue.unregisterInputChannel(mClientChannel);
554 mClientChannel.dispose();
555 mClientChannel = null;
556 mServerChannel = null;
557 }
558 }
559
Chris Tatea32dcf72010-10-14 12:13:50 -0700560 int getDragLayerLw() {
561 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
562 * TYPE_LAYER_MULTIPLIER
563 + TYPE_LAYER_OFFSET;
564 }
565
Christopher Tatea53146c2010-09-07 11:57:52 -0700566 /* call out to each visible window/session informing it about the drag
567 */
Chris Tateb8203e92010-10-12 14:23:21 -0700568 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700569 // Cache a base-class instance of the clip metadata so that parceling
570 // works correctly in calling out to the apps.
571 mDataDescription = new ClipDescription(mData);
572 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700573 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700574
575 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700576 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
Christopher Tatea53146c2010-09-07 11:57:52 -0700577 }
578
Christopher Tate2c095f32010-10-04 14:13:40 -0700579 final int N = mWindows.size();
580 for (int i = 0; i < N; i++) {
Chris Tateb478f462010-10-15 16:02:26 -0700581 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700582 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700583 }
584
585 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
586 * designated window is potentially a drop recipient. There are race situations
587 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
588 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700589 *
590 * This method clones the 'event' parameter if it's being delivered to the same
591 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700592 */
Chris Tateb478f462010-10-15 16:02:26 -0700593 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
594 ClipDescription desc) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700595 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700596 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
597 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
Chris Tated4533f12010-10-19 15:15:08 -0700598 desc, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700599 try {
600 newWin.mClient.dispatchDragEvent(event);
601 // track each window that we've notified that the drag is starting
602 mNotifiedWindows.add(newWin);
603 } catch (RemoteException e) {
604 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700605 } finally {
606 // if the callee was local, the dispatch has already recycled the event
607 if (Process.myPid() != newWin.mSession.mPid) {
608 event.recycle();
609 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700610 }
611 }
612 }
613
614 /* helper - construct and send a DRAG_STARTED event only if the window has not
615 * previously been notified, i.e. it became visible after the drag operation
616 * was begun. This is a rare case.
617 */
618 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700619 if (mDragInProgress) {
620 // If we have sent the drag-started, we needn't do so again
621 for (WindowState ws : mNotifiedWindows) {
622 if (ws == newWin) {
623 return;
624 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700625 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700626 if (DEBUG_DRAG) {
627 Slog.d(TAG, "sending DRAG_STARTED to new window " + newWin);
628 }
Chris Tateb478f462010-10-15 16:02:26 -0700629 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700630 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700631 }
632
Chris Tated4533f12010-10-19 15:15:08 -0700633 void broadcastDragEndedLw() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700634 if (DEBUG_DRAG) {
635 Slog.d(TAG, "broadcasting DRAG_ENDED");
636 }
Chris Tated4533f12010-10-19 15:15:08 -0700637 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
638 0, 0, null, null, mDragResult);
639 for (WindowState ws: mNotifiedWindows) {
640 try {
641 ws.mClient.dispatchDragEvent(evt);
642 } catch (RemoteException e) {
643 Slog.w(TAG, "Unable to drag-end window " + ws);
Christopher Tatea53146c2010-09-07 11:57:52 -0700644 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700645 }
Chris Tated4533f12010-10-19 15:15:08 -0700646 mNotifiedWindows.clear();
647 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700648 evt.recycle();
649 }
650
Chris Tated4533f12010-10-19 15:15:08 -0700651 void endDragLw() {
652 mDragState.broadcastDragEndedLw();
653
654 // stop intercepting input
655 mDragState.unregister();
656 mInputMonitor.updateInputWindowsLw();
657
658 // free our resources and drop all the object references
659 mDragState.reset();
660 mDragState = null;
661 }
662
Christopher Tatea53146c2010-09-07 11:57:52 -0700663 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700664 final int myPid = Process.myPid();
665
666 // Move the surface to the given touch
667 mSurface.openTransaction();
668 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
669 mSurface.closeTransaction();
670
671 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700672 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
673 try {
674 // have we dragged over a new window?
675 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
676 if (DEBUG_DRAG) {
677 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
678 }
679 // force DRAG_EXITED_EVENT if appropriate
680 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700681 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
Chris Tated4533f12010-10-19 15:15:08 -0700682 null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700683 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700684 if (myPid != mTargetWindow.mSession.mPid) {
685 evt.recycle();
686 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700687 }
688 if (touchedWin != null) {
689 if (DEBUG_DRAG) {
690 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
691 }
692 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700693 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Chris Tated4533f12010-10-19 15:15:08 -0700694 null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700695 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700696 if (myPid != touchedWin.mSession.mPid) {
697 evt.recycle();
698 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700699 }
700 } catch (RemoteException e) {
701 Slog.w(TAG, "can't send drag notification to windows");
702 }
703 mTargetWindow = touchedWin;
704 }
705
Chris Tated4533f12010-10-19 15:15:08 -0700706 // Tell the drop target about the data. Returns 'true' if we can immediately
707 // dispatch the global drag-ended message, 'false' if we need to wait for a
708 // result from the recipient.
709 boolean notifyDropLw(float x, float y) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700710 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tated4533f12010-10-19 15:15:08 -0700711 if (touchedWin == null) {
712 // "drop" outside a valid window -- no recipient to apply a
713 // timeout to, and we can send the drag-ended message immediately.
714 mDragResult = false;
715 return true;
716 }
717
718 if (DEBUG_DRAG) {
719 Slog.d(TAG, "sending DROP to " + touchedWin);
720 }
721 final int myPid = Process.myPid();
722 final IBinder token = touchedWin.mClient.asBinder();
723 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
724 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
725 null, mData, false);
726 try {
727 touchedWin.mClient.dispatchDragEvent(evt);
728
729 // 5 second timeout for this window to respond to the drop
730 mH.removeMessages(H.DRAG_END_TIMEOUT, token);
731 Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
732 mH.sendMessageDelayed(msg, 5000);
733 } catch (RemoteException e) {
734 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
735 return true;
736 } finally {
Christopher Tate2c095f32010-10-04 14:13:40 -0700737 if (myPid != touchedWin.mSession.mPid) {
738 evt.recycle();
739 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700740 }
Chris Tated4533f12010-10-19 15:15:08 -0700741 mToken = token;
742 return false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700743 }
744
745 // Find the visible, touch-deliverable window under the given point
746 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
747 WindowState touchedWin = null;
748 final int x = (int) xf;
749 final int y = (int) yf;
750 final ArrayList<WindowState> windows = mWindows;
751 final int N = windows.size();
752 for (int i = N - 1; i >= 0; i--) {
753 WindowState child = windows.get(i);
754 final int flags = child.mAttrs.flags;
755 if (!child.isVisibleLw()) {
756 // not visible == don't tell about drags
757 continue;
758 }
759 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
760 // not touchable == don't tell about drags
761 continue;
762 }
763 // account for the window's decor etc
764 tmpRect.set(child.mFrame);
765 if (child.mTouchableInsets == ViewTreeObserver
766 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
767 // The point is inside of the window if it is
768 // inside the frame, AND the content part of that
769 // frame that was given by the application.
770 tmpRect.left += child.mGivenContentInsets.left;
771 tmpRect.top += child.mGivenContentInsets.top;
772 tmpRect.right -= child.mGivenContentInsets.right;
773 tmpRect.bottom -= child.mGivenContentInsets.bottom;
774 } else if (child.mTouchableInsets == ViewTreeObserver
775 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
776 // The point is inside of the window if it is
777 // inside the frame, AND the visible part of that
778 // frame that was given by the application.
779 tmpRect.left += child.mGivenVisibleInsets.left;
780 tmpRect.top += child.mGivenVisibleInsets.top;
781 tmpRect.right -= child.mGivenVisibleInsets.right;
782 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
783 }
784 final int touchFlags = flags &
785 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
786 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
787 if (tmpRect.contains(x, y) || touchFlags == 0) {
788 // Found it
789 touchedWin = child;
790 break;
791 }
792 }
793
794 return touchedWin;
795 }
796 }
797
798 DragState mDragState = null;
799 private final InputHandler mDragInputHandler = new BaseInputHandler() {
800 @Override
801 public void handleMotion(MotionEvent event, Runnable finishedCallback) {
802 boolean endDrag = false;
803 final float newX = event.getRawX();
804 final float newY = event.getRawY();
805
806 try {
807 if (mDragState != null) {
808 switch (event.getAction()) {
809 case MotionEvent.ACTION_DOWN: {
810 if (DEBUG_DRAG) {
811 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
812 }
813 } break;
814
815 case MotionEvent.ACTION_MOVE: {
816 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700817 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700818 mDragState.notifyMoveLw(newX, newY);
819 }
820 } break;
821
822 case MotionEvent.ACTION_UP: {
823 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
824 + newX + "," + newY);
825 synchronized (mWindowMap) {
Chris Tated4533f12010-10-19 15:15:08 -0700826 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700827 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700828 } break;
829
830 case MotionEvent.ACTION_CANCEL: {
831 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
832 endDrag = true;
833 } break;
834 }
835
836 if (endDrag) {
837 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
838 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700839 synchronized (mWindowMap) {
Chris Tated4533f12010-10-19 15:15:08 -0700840 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700841 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700842 }
843 }
844 } catch (Exception e) {
845 Slog.e(TAG, "Exception caught by drag handleMotion", e);
846 } finally {
847 finishedCallback.run();
848 }
849 }
850 };
851
852 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800853 * Whether the UI is currently running in touch mode (not showing
854 * navigational focus because the user is directly pressing the screen).
855 */
856 boolean mInTouchMode = false;
857
858 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700859 private ArrayList<WindowChangeListener> mWindowChangeListeners =
860 new ArrayList<WindowChangeListener>();
861 private boolean mWindowsChanged = false;
862
863 public interface WindowChangeListener {
864 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700865 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700866 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800867
Dianne Hackbornc485a602009-03-24 22:39:49 -0700868 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700869 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700870
871 // The frame use to limit the size of the app running in compatibility mode.
872 Rect mCompatibleScreenFrame = new Rect();
873 // The surface used to fill the outer rim of the app running in compatibility mode.
874 Surface mBackgroundFillerSurface = null;
875 boolean mBackgroundFillerShown = false;
876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800877 public static WindowManagerService main(Context context,
878 PowerManagerService pm, boolean haveInputMethods) {
879 WMThread thr = new WMThread(context, pm, haveInputMethods);
880 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800882 synchronized (thr) {
883 while (thr.mService == null) {
884 try {
885 thr.wait();
886 } catch (InterruptedException e) {
887 }
888 }
889 }
Romain Guy06882f82009-06-10 13:36:04 -0700890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800891 return thr.mService;
892 }
Romain Guy06882f82009-06-10 13:36:04 -0700893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800894 static class WMThread extends Thread {
895 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800897 private final Context mContext;
898 private final PowerManagerService mPM;
899 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800901 public WMThread(Context context, PowerManagerService pm,
902 boolean haveInputMethods) {
903 super("WindowManager");
904 mContext = context;
905 mPM = pm;
906 mHaveInputMethods = haveInputMethods;
907 }
Romain Guy06882f82009-06-10 13:36:04 -0700908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800909 public void run() {
910 Looper.prepare();
911 WindowManagerService s = new WindowManagerService(mContext, mPM,
912 mHaveInputMethods);
913 android.os.Process.setThreadPriority(
914 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700915 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800917 synchronized (this) {
918 mService = s;
919 notifyAll();
920 }
Romain Guy06882f82009-06-10 13:36:04 -0700921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800922 Looper.loop();
923 }
924 }
925
926 static class PolicyThread extends Thread {
927 private final WindowManagerPolicy mPolicy;
928 private final WindowManagerService mService;
929 private final Context mContext;
930 private final PowerManagerService mPM;
931 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 public PolicyThread(WindowManagerPolicy policy,
934 WindowManagerService service, Context context,
935 PowerManagerService pm) {
936 super("WindowManagerPolicy");
937 mPolicy = policy;
938 mService = service;
939 mContext = context;
940 mPM = pm;
941 }
Romain Guy06882f82009-06-10 13:36:04 -0700942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800943 public void run() {
944 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800945 WindowManagerPolicyThread.set(this, Looper.myLooper());
946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800947 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800948 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800949 android.os.Process.setThreadPriority(
950 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700951 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800952 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800954 synchronized (this) {
955 mRunning = true;
956 notifyAll();
957 }
Romain Guy06882f82009-06-10 13:36:04 -0700958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800959 Looper.loop();
960 }
961 }
962
963 private WindowManagerService(Context context, PowerManagerService pm,
964 boolean haveInputMethods) {
965 mContext = context;
966 mHaveInputMethods = haveInputMethods;
967 mLimitedAlphaCompositing = context.getResources().getBoolean(
968 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800970 mPowerManager = pm;
971 mPowerManager.setPolicy(mPolicy);
972 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
973 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
974 "SCREEN_FROZEN");
975 mScreenFrozenLock.setReferenceCounted(false);
976
977 mActivityManager = ActivityManagerNative.getDefault();
978 mBatteryStats = BatteryStatsService.getService();
979
980 // Get persisted window scale setting
981 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
982 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
983 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
984 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700985
Jim Miller284b62e2010-06-08 14:27:42 -0700986 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
987 IntentFilter filter = new IntentFilter();
988 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
989 mContext.registerReceiver(mBroadcastReceiver, filter);
990
Jeff Brown46b9ac02010-04-22 18:58:52 -0700991 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
992 "KEEP_SCREEN_ON_FLAG");
993 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800994
Jeff Browne33348b2010-07-15 23:54:05 -0700995 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -0700996
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800997 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
998 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001000 synchronized (thr) {
1001 while (!thr.mRunning) {
1002 try {
1003 thr.wait();
1004 } catch (InterruptedException e) {
1005 }
1006 }
1007 }
Romain Guy06882f82009-06-10 13:36:04 -07001008
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001009 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001010
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001011 // Add ourself to the Watchdog monitors.
1012 Watchdog.getInstance().addMonitor(this);
1013 }
1014
1015 @Override
1016 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1017 throws RemoteException {
1018 try {
1019 return super.onTransact(code, data, reply, flags);
1020 } catch (RuntimeException e) {
1021 // The window manager only throws security exceptions, so let's
1022 // log all others.
1023 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001024 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001025 }
1026 throw e;
1027 }
1028 }
1029
Jeff Browne33348b2010-07-15 23:54:05 -07001030 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001031 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001032 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001033 TAG, "Adding window " + window + " at "
1034 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1035 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001036 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001037 }
1038
Jeff Browne33348b2010-07-15 23:54:05 -07001039 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001040 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001041 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001042 TAG, "Adding window " + window + " at "
1043 + i + " of " + mWindows.size() + " (before " + pos + ")");
1044 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001045 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001046 }
1047
1048 //This method finds out the index of a window that has the same app token as
1049 //win. used for z ordering the windows in mWindows
1050 private int findIdxBasedOnAppTokens(WindowState win) {
1051 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001052 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001053 int jmax = localmWindows.size();
1054 if(jmax == 0) {
1055 return -1;
1056 }
1057 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001058 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001059 if(wentry.mAppToken == win.mAppToken) {
1060 return j;
1061 }
1062 }
1063 return -1;
1064 }
Romain Guy06882f82009-06-10 13:36:04 -07001065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1067 final IWindow client = win.mClient;
1068 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001069 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001071 final int N = localmWindows.size();
1072 final WindowState attached = win.mAttachedWindow;
1073 int i;
1074 if (attached == null) {
1075 int tokenWindowsPos = token.windows.size();
1076 if (token.appWindowToken != null) {
1077 int index = tokenWindowsPos-1;
1078 if (index >= 0) {
1079 // If this application has existing windows, we
1080 // simply place the new window on top of them... but
1081 // keep the starting window on top.
1082 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1083 // Base windows go behind everything else.
1084 placeWindowBefore(token.windows.get(0), win);
1085 tokenWindowsPos = 0;
1086 } else {
1087 AppWindowToken atoken = win.mAppToken;
1088 if (atoken != null &&
1089 token.windows.get(index) == atoken.startingWindow) {
1090 placeWindowBefore(token.windows.get(index), win);
1091 tokenWindowsPos--;
1092 } else {
1093 int newIdx = findIdxBasedOnAppTokens(win);
1094 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001095 //there is a window above this one associated with the same
1096 //apptoken note that the window could be a floating window
1097 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001098 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001099 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001100 TAG, "Adding window " + win + " at "
1101 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001102 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001103 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001104 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 }
1106 }
1107 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001108 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001109 TAG, "Figuring out where to add app window "
1110 + client.asBinder() + " (token=" + token + ")");
1111 // Figure out where the window should go, based on the
1112 // order of applications.
1113 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001114 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 for (i=NA-1; i>=0; i--) {
1116 AppWindowToken t = mAppTokens.get(i);
1117 if (t == token) {
1118 i--;
1119 break;
1120 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001121
Dianne Hackborna8f60182009-09-01 19:01:50 -07001122 // We haven't reached the token yet; if this token
1123 // is not going to the bottom and has windows, we can
1124 // use it as an anchor for when we do reach the token.
1125 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001126 pos = t.windows.get(0);
1127 }
1128 }
1129 // We now know the index into the apps. If we found
1130 // an app window above, that gives us the position; else
1131 // we need to look some more.
1132 if (pos != null) {
1133 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001134 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 if (atoken != null) {
1136 final int NC = atoken.windows.size();
1137 if (NC > 0) {
1138 WindowState bottom = atoken.windows.get(0);
1139 if (bottom.mSubLayer < 0) {
1140 pos = bottom;
1141 }
1142 }
1143 }
1144 placeWindowBefore(pos, win);
1145 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001146 // Continue looking down until we find the first
1147 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 while (i >= 0) {
1149 AppWindowToken t = mAppTokens.get(i);
1150 final int NW = t.windows.size();
1151 if (NW > 0) {
1152 pos = t.windows.get(NW-1);
1153 break;
1154 }
1155 i--;
1156 }
1157 if (pos != null) {
1158 // Move in front of any windows attached to this
1159 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001160 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001161 if (atoken != null) {
1162 final int NC = atoken.windows.size();
1163 if (NC > 0) {
1164 WindowState top = atoken.windows.get(NC-1);
1165 if (top.mSubLayer >= 0) {
1166 pos = top;
1167 }
1168 }
1169 }
1170 placeWindowAfter(pos, win);
1171 } else {
1172 // Just search for the start of this layer.
1173 final int myLayer = win.mBaseLayer;
1174 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001175 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001176 if (w.mBaseLayer > myLayer) {
1177 break;
1178 }
1179 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001180 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001181 TAG, "Adding window " + win + " at "
1182 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001183 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001184 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001185 }
1186 }
1187 }
1188 } else {
1189 // Figure out where window should go, based on layer.
1190 final int myLayer = win.mBaseLayer;
1191 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001192 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001193 i++;
1194 break;
1195 }
1196 }
1197 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001198 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001199 TAG, "Adding window " + win + " at "
1200 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001201 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001202 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001203 }
1204 if (addToToken) {
1205 token.windows.add(tokenWindowsPos, win);
1206 }
1207
1208 } else {
1209 // Figure out this window's ordering relative to the window
1210 // it is attached to.
1211 final int NA = token.windows.size();
1212 final int sublayer = win.mSubLayer;
1213 int largestSublayer = Integer.MIN_VALUE;
1214 WindowState windowWithLargestSublayer = null;
1215 for (i=0; i<NA; i++) {
1216 WindowState w = token.windows.get(i);
1217 final int wSublayer = w.mSubLayer;
1218 if (wSublayer >= largestSublayer) {
1219 largestSublayer = wSublayer;
1220 windowWithLargestSublayer = w;
1221 }
1222 if (sublayer < 0) {
1223 // For negative sublayers, we go below all windows
1224 // in the same sublayer.
1225 if (wSublayer >= sublayer) {
1226 if (addToToken) {
1227 token.windows.add(i, win);
1228 }
1229 placeWindowBefore(
1230 wSublayer >= 0 ? attached : w, win);
1231 break;
1232 }
1233 } else {
1234 // For positive sublayers, we go above all windows
1235 // in the same sublayer.
1236 if (wSublayer > sublayer) {
1237 if (addToToken) {
1238 token.windows.add(i, win);
1239 }
1240 placeWindowBefore(w, win);
1241 break;
1242 }
1243 }
1244 }
1245 if (i >= NA) {
1246 if (addToToken) {
1247 token.windows.add(win);
1248 }
1249 if (sublayer < 0) {
1250 placeWindowBefore(attached, win);
1251 } else {
1252 placeWindowAfter(largestSublayer >= 0
1253 ? windowWithLargestSublayer
1254 : attached,
1255 win);
1256 }
1257 }
1258 }
Romain Guy06882f82009-06-10 13:36:04 -07001259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001260 if (win.mAppToken != null && addToToken) {
1261 win.mAppToken.allAppWindows.add(win);
1262 }
1263 }
Romain Guy06882f82009-06-10 13:36:04 -07001264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 static boolean canBeImeTarget(WindowState w) {
1266 final int fl = w.mAttrs.flags
1267 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1268 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1269 return w.isVisibleOrAdding();
1270 }
1271 return false;
1272 }
Romain Guy06882f82009-06-10 13:36:04 -07001273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001274 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001275 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001276 final int N = localmWindows.size();
1277 WindowState w = null;
1278 int i = N;
1279 while (i > 0) {
1280 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001281 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001282
Joe Onorato8a9b2202010-02-26 18:56:32 -08001283 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001284 // + Integer.toHexString(w.mAttrs.flags));
1285 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001286 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001288 // Yet more tricksyness! If this window is a "starting"
1289 // window, we do actually want to be on top of it, but
1290 // it is not -really- where input will go. So if the caller
1291 // is not actually looking to move the IME, look down below
1292 // for a real window to target...
1293 if (!willMove
1294 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1295 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001296 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001297 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1298 i--;
1299 w = wb;
1300 }
1301 }
1302 break;
1303 }
1304 }
Romain Guy06882f82009-06-10 13:36:04 -07001305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001306 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -07001307
Joe Onorato8a9b2202010-02-26 18:56:32 -08001308 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001309 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001311 if (willMove && w != null) {
1312 final WindowState curTarget = mInputMethodTarget;
1313 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001315 // Now some fun for dealing with window animations that
1316 // modify the Z order. We need to look at all windows below
1317 // the current target that are in this app, finding the highest
1318 // visible one in layering.
1319 AppWindowToken token = curTarget.mAppToken;
1320 WindowState highestTarget = null;
1321 int highestPos = 0;
1322 if (token.animating || token.animation != null) {
1323 int pos = 0;
1324 pos = localmWindows.indexOf(curTarget);
1325 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001326 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001327 if (win.mAppToken != token) {
1328 break;
1329 }
1330 if (!win.mRemoved) {
1331 if (highestTarget == null || win.mAnimLayer >
1332 highestTarget.mAnimLayer) {
1333 highestTarget = win;
1334 highestPos = pos;
1335 }
1336 }
1337 pos--;
1338 }
1339 }
Romain Guy06882f82009-06-10 13:36:04 -07001340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001341 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001342 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001343 + mNextAppTransition + " " + highestTarget
1344 + " animating=" + highestTarget.isAnimating()
1345 + " layer=" + highestTarget.mAnimLayer
1346 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001347
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001348 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001349 // If we are currently setting up for an animation,
1350 // hold everything until we can find out what will happen.
1351 mInputMethodTargetWaitingAnim = true;
1352 mInputMethodTarget = highestTarget;
1353 return highestPos + 1;
1354 } else if (highestTarget.isAnimating() &&
1355 highestTarget.mAnimLayer > w.mAnimLayer) {
1356 // If the window we are currently targeting is involved
1357 // with an animation, and it is on top of the next target
1358 // we will be over, then hold off on moving until
1359 // that is done.
1360 mInputMethodTarget = highestTarget;
1361 return highestPos + 1;
1362 }
1363 }
1364 }
1365 }
Romain Guy06882f82009-06-10 13:36:04 -07001366
Joe Onorato8a9b2202010-02-26 18:56:32 -08001367 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001368 if (w != null) {
1369 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001370 if (DEBUG_INPUT_METHOD) {
1371 RuntimeException e = null;
1372 if (!HIDE_STACK_CRAWLS) {
1373 e = new RuntimeException();
1374 e.fillInStackTrace();
1375 }
1376 Slog.w(TAG, "Moving IM target from "
1377 + mInputMethodTarget + " to " + w, e);
1378 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001379 mInputMethodTarget = w;
1380 if (w.mAppToken != null) {
1381 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1382 } else {
1383 setInputMethodAnimLayerAdjustment(0);
1384 }
1385 }
1386 return i+1;
1387 }
1388 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001389 if (DEBUG_INPUT_METHOD) {
1390 RuntimeException e = null;
1391 if (!HIDE_STACK_CRAWLS) {
1392 e = new RuntimeException();
1393 e.fillInStackTrace();
1394 }
1395 Slog.w(TAG, "Moving IM target from "
1396 + mInputMethodTarget + " to null", e);
1397 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001398 mInputMethodTarget = null;
1399 setInputMethodAnimLayerAdjustment(0);
1400 }
1401 return -1;
1402 }
Romain Guy06882f82009-06-10 13:36:04 -07001403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001404 void addInputMethodWindowToListLocked(WindowState win) {
1405 int pos = findDesiredInputMethodWindowIndexLocked(true);
1406 if (pos >= 0) {
1407 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001408 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001409 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001410 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001411 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001412 moveInputMethodDialogsLocked(pos+1);
1413 return;
1414 }
1415 win.mTargetAppToken = null;
1416 addWindowToListInOrderLocked(win, true);
1417 moveInputMethodDialogsLocked(pos);
1418 }
Romain Guy06882f82009-06-10 13:36:04 -07001419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001420 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001421 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001422 mInputMethodAnimLayerAdjustment = adj;
1423 WindowState imw = mInputMethodWindow;
1424 if (imw != null) {
1425 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001426 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001427 + " anim layer: " + imw.mAnimLayer);
1428 int wi = imw.mChildWindows.size();
1429 while (wi > 0) {
1430 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001431 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001432 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001433 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001434 + " anim layer: " + cw.mAnimLayer);
1435 }
1436 }
1437 int di = mInputMethodDialogs.size();
1438 while (di > 0) {
1439 di --;
1440 imw = mInputMethodDialogs.get(di);
1441 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001442 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001443 + " anim layer: " + imw.mAnimLayer);
1444 }
1445 }
Romain Guy06882f82009-06-10 13:36:04 -07001446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001447 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1448 int wpos = mWindows.indexOf(win);
1449 if (wpos >= 0) {
1450 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001451 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001452 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001453 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001454 int NC = win.mChildWindows.size();
1455 while (NC > 0) {
1456 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001457 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001458 int cpos = mWindows.indexOf(cw);
1459 if (cpos >= 0) {
1460 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001461 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001462 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463 mWindows.remove(cpos);
1464 }
1465 }
1466 }
1467 return interestingPos;
1468 }
Romain Guy06882f82009-06-10 13:36:04 -07001469
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001470 private void reAddWindowToListInOrderLocked(WindowState win) {
1471 addWindowToListInOrderLocked(win, false);
1472 // This is a hack to get all of the child windows added as well
1473 // at the right position. Child windows should be rare and
1474 // this case should be rare, so it shouldn't be that big a deal.
1475 int wpos = mWindows.indexOf(win);
1476 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001477 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001478 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001479 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001480 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001481 reAddWindowLocked(wpos, win);
1482 }
1483 }
Romain Guy06882f82009-06-10 13:36:04 -07001484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001485 void logWindowList(String prefix) {
1486 int N = mWindows.size();
1487 while (N > 0) {
1488 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001489 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001490 }
1491 }
Romain Guy06882f82009-06-10 13:36:04 -07001492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001493 void moveInputMethodDialogsLocked(int pos) {
1494 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001496 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001497 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001498 for (int i=0; i<N; i++) {
1499 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1500 }
1501 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001502 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001503 logWindowList(" ");
1504 }
Romain Guy06882f82009-06-10 13:36:04 -07001505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001506 if (pos >= 0) {
1507 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1508 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001509 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001510 if (wp == mInputMethodWindow) {
1511 pos++;
1512 }
1513 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001514 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001515 for (int i=0; i<N; i++) {
1516 WindowState win = dialogs.get(i);
1517 win.mTargetAppToken = targetAppToken;
1518 pos = reAddWindowLocked(pos, win);
1519 }
1520 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001521 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001522 logWindowList(" ");
1523 }
1524 return;
1525 }
1526 for (int i=0; i<N; i++) {
1527 WindowState win = dialogs.get(i);
1528 win.mTargetAppToken = null;
1529 reAddWindowToListInOrderLocked(win);
1530 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001531 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001532 logWindowList(" ");
1533 }
1534 }
1535 }
Romain Guy06882f82009-06-10 13:36:04 -07001536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001537 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1538 final WindowState imWin = mInputMethodWindow;
1539 final int DN = mInputMethodDialogs.size();
1540 if (imWin == null && DN == 0) {
1541 return false;
1542 }
Romain Guy06882f82009-06-10 13:36:04 -07001543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1545 if (imPos >= 0) {
1546 // In this case, the input method windows are to be placed
1547 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001549 // First check to see if the input method windows are already
1550 // located here, and contiguous.
1551 final int N = mWindows.size();
1552 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001553 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001555 // Figure out the actual input method window that should be
1556 // at the bottom of their stack.
1557 WindowState baseImWin = imWin != null
1558 ? imWin : mInputMethodDialogs.get(0);
1559 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001560 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001561 if (cw.mSubLayer < 0) baseImWin = cw;
1562 }
Romain Guy06882f82009-06-10 13:36:04 -07001563
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001564 if (firstImWin == baseImWin) {
1565 // The windows haven't moved... but are they still contiguous?
1566 // First find the top IM window.
1567 int pos = imPos+1;
1568 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001569 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001570 break;
1571 }
1572 pos++;
1573 }
1574 pos++;
1575 // Now there should be no more input method windows above.
1576 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001577 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001578 break;
1579 }
1580 pos++;
1581 }
1582 if (pos >= N) {
1583 // All is good!
1584 return false;
1585 }
1586 }
Romain Guy06882f82009-06-10 13:36:04 -07001587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001588 if (imWin != null) {
1589 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001590 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001591 logWindowList(" ");
1592 }
1593 imPos = tmpRemoveWindowLocked(imPos, imWin);
1594 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001595 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001596 logWindowList(" ");
1597 }
1598 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1599 reAddWindowLocked(imPos, imWin);
1600 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001601 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001602 logWindowList(" ");
1603 }
1604 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1605 } else {
1606 moveInputMethodDialogsLocked(imPos);
1607 }
Romain Guy06882f82009-06-10 13:36:04 -07001608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001609 } else {
1610 // In this case, the input method windows go in a fixed layer,
1611 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001613 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001614 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001615 tmpRemoveWindowLocked(0, imWin);
1616 imWin.mTargetAppToken = null;
1617 reAddWindowToListInOrderLocked(imWin);
1618 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001619 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001620 logWindowList(" ");
1621 }
1622 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1623 } else {
1624 moveInputMethodDialogsLocked(-1);;
1625 }
Romain Guy06882f82009-06-10 13:36:04 -07001626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001627 }
Romain Guy06882f82009-06-10 13:36:04 -07001628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001629 if (needAssignLayers) {
1630 assignLayersLocked();
1631 }
Romain Guy06882f82009-06-10 13:36:04 -07001632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001633 return true;
1634 }
Romain Guy06882f82009-06-10 13:36:04 -07001635
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001636 void adjustInputMethodDialogsLocked() {
1637 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1638 }
Romain Guy06882f82009-06-10 13:36:04 -07001639
Dianne Hackborn25994b42009-09-04 14:21:19 -07001640 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001641 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001642 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1643 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1644 ? wallpaperTarget.mAppToken.animation : null)
1645 + " upper=" + mUpperWallpaperTarget
1646 + " lower=" + mLowerWallpaperTarget);
1647 return (wallpaperTarget != null
1648 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1649 && wallpaperTarget.mAppToken.animation != null)))
1650 || mUpperWallpaperTarget != null
1651 || mLowerWallpaperTarget != null;
1652 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001653
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001654 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1655 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001656
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001657 int adjustWallpaperWindowsLocked() {
1658 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001659
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001660 final int dw = mDisplay.getWidth();
1661 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001662
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001663 // First find top-most window that has asked to be on top of the
1664 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001665 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001666 int N = localmWindows.size();
1667 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001668 WindowState foundW = null;
1669 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001670 WindowState topCurW = null;
1671 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001672 int i = N;
1673 while (i > 0) {
1674 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001675 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001676 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1677 if (topCurW == null) {
1678 topCurW = w;
1679 topCurI = i;
1680 }
1681 continue;
1682 }
1683 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001684 if (w.mAppToken != null) {
1685 // If this window's app token is hidden and not animating,
1686 // it is of no interest to us.
1687 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001688 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001689 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001690 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001691 continue;
1692 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001693 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001694 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001695 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1696 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001697 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001698 && (mWallpaperTarget == w
1699 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001700 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001701 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001702 foundW = w;
1703 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001704 if (w == mWallpaperTarget && ((w.mAppToken != null
1705 && w.mAppToken.animation != null)
1706 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001707 // The current wallpaper target is animating, so we'll
1708 // look behind it for another possible target and figure
1709 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001710 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001711 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001712 continue;
1713 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001714 break;
1715 }
1716 }
1717
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001718 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001719 // If we are currently waiting for an app transition, and either
1720 // the current target or the next target are involved with it,
1721 // then hold off on doing anything with the wallpaper.
1722 // Note that we are checking here for just whether the target
1723 // is part of an app token... which is potentially overly aggressive
1724 // (the app token may not be involved in the transition), but good
1725 // enough (we'll just wait until whatever transition is pending
1726 // executes).
1727 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001728 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001729 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001730 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001731 }
1732 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001733 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001734 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001735 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001736 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001737 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001738
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001739 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001740 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001741 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001742 + " oldTarget: " + mWallpaperTarget);
1743 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001744
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001745 mLowerWallpaperTarget = null;
1746 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001747
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001748 WindowState oldW = mWallpaperTarget;
1749 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001750
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001751 // Now what is happening... if the current and new targets are
1752 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001753 if (foundW != null && oldW != null) {
1754 boolean oldAnim = oldW.mAnimation != null
1755 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1756 boolean foundAnim = foundW.mAnimation != null
1757 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001758 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001759 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001760 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001761 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001762 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001763 int oldI = localmWindows.indexOf(oldW);
1764 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001765 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001766 }
1767 if (oldI >= 0) {
1768 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001769 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001770 + "=" + oldW + "; new#" + foundI
1771 + "=" + foundW);
1772 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001773
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001774 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001775 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001776 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001777 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001778 }
1779 mWallpaperTarget = oldW;
1780 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001781
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001782 // Now set the upper and lower wallpaper targets
1783 // correctly, and make sure that we are positioning
1784 // the wallpaper below the lower.
1785 if (foundI > oldI) {
1786 // The new target is on top of the old one.
1787 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001788 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001789 }
1790 mUpperWallpaperTarget = foundW;
1791 mLowerWallpaperTarget = oldW;
1792 foundW = oldW;
1793 foundI = oldI;
1794 } else {
1795 // The new target is below the old one.
1796 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001797 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001798 }
1799 mUpperWallpaperTarget = oldW;
1800 mLowerWallpaperTarget = foundW;
1801 }
1802 }
1803 }
1804 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001805
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001806 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001807 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001808 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1809 || (mLowerWallpaperTarget.mAppToken != null
1810 && mLowerWallpaperTarget.mAppToken.animation != null);
1811 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1812 || (mUpperWallpaperTarget.mAppToken != null
1813 && mUpperWallpaperTarget.mAppToken.animation != null);
1814 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001815 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001816 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001817 }
1818 mLowerWallpaperTarget = null;
1819 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001820 }
1821 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001822
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001823 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001824 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001825 // The window is visible to the compositor... but is it visible
1826 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001827 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001828 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001829
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001830 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001831 // its layer adjustment. Only do this if we are not transfering
1832 // between two wallpaper targets.
1833 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001834 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001835 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001836
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001837 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1838 * TYPE_LAYER_MULTIPLIER
1839 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001840
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001841 // Now w is the window we are supposed to be behind... but we
1842 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001843 // AND any starting window associated with it, AND below the
1844 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001845 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001846 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001847 if (wb.mBaseLayer < maxLayer &&
1848 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001849 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001850 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001851 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001852 // This window is not related to the previous one in any
1853 // interesting way, so stop here.
1854 break;
1855 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001856 foundW = wb;
1857 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001858 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001859 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001860 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001861 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001862
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001863 if (foundW == null && topCurW != null) {
1864 // There is no wallpaper target, so it goes at the bottom.
1865 // We will assume it is the same place as last time, if known.
1866 foundW = topCurW;
1867 foundI = topCurI+1;
1868 } else {
1869 // Okay i is the position immediately above the wallpaper. Look at
1870 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001871 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001872 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001873
Dianne Hackborn284ac932009-08-28 10:34:25 -07001874 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001875 if (mWallpaperTarget.mWallpaperX >= 0) {
1876 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001877 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001878 }
1879 if (mWallpaperTarget.mWallpaperY >= 0) {
1880 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001881 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001882 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001883 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001884
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001885 // Start stepping backwards from here, ensuring that our wallpaper windows
1886 // are correctly placed.
1887 int curTokenIndex = mWallpaperTokens.size();
1888 while (curTokenIndex > 0) {
1889 curTokenIndex--;
1890 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001891 if (token.hidden == visible) {
1892 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1893 token.hidden = !visible;
1894 // Need to do a layout to ensure the wallpaper now has the
1895 // correct size.
1896 mLayoutNeeded = true;
1897 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001898
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001899 int curWallpaperIndex = token.windows.size();
1900 while (curWallpaperIndex > 0) {
1901 curWallpaperIndex--;
1902 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001903
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001904 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001905 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001906 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001907
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001908 // First, make sure the client has the current visibility
1909 // state.
1910 if (wallpaper.mWallpaperVisible != visible) {
1911 wallpaper.mWallpaperVisible = visible;
1912 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001913 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001914 "Setting visibility of wallpaper " + wallpaper
1915 + ": " + visible);
1916 wallpaper.mClient.dispatchAppVisibility(visible);
1917 } catch (RemoteException e) {
1918 }
1919 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001920
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001921 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001922 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001923 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001924
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001925 // First, if this window is at the current index, then all
1926 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001927 if (wallpaper == foundW) {
1928 foundI--;
1929 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001930 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001931 continue;
1932 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001933
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001934 // The window didn't match... the current wallpaper window,
1935 // wherever it is, is in the wrong place, so make sure it is
1936 // not in the list.
1937 int oldIndex = localmWindows.indexOf(wallpaper);
1938 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001939 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001940 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001941 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001942 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001943 if (oldIndex < foundI) {
1944 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001945 }
1946 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001947
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001948 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001949 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001950 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001951 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001952
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001953 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001954 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001955 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001956 }
1957 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001958
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001959 return changed;
1960 }
1961
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001962 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001963 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001964 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001965 mWallpaperAnimLayerAdjustment = adj;
1966 int curTokenIndex = mWallpaperTokens.size();
1967 while (curTokenIndex > 0) {
1968 curTokenIndex--;
1969 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1970 int curWallpaperIndex = token.windows.size();
1971 while (curWallpaperIndex > 0) {
1972 curWallpaperIndex--;
1973 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1974 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001975 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001976 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001977 }
1978 }
1979 }
1980
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001981 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1982 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001983 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001984 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001985 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001986 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001987 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1988 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1989 changed = wallpaperWin.mXOffset != offset;
1990 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001991 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001992 + wallpaperWin + " x: " + offset);
1993 wallpaperWin.mXOffset = offset;
1994 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001995 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001996 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001997 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001998 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001999 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002000
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002001 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002002 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002003 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2004 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2005 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002006 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002007 + wallpaperWin + " y: " + offset);
2008 changed = true;
2009 wallpaperWin.mYOffset = offset;
2010 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002011 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002012 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002013 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002014 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002015 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002016
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002017 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002018 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002019 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002020 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2021 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002022 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002023 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002024 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002025 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002026 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2027 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002028 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002029 if (mWaitingOnWallpaper != null) {
2030 long start = SystemClock.uptimeMillis();
2031 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2032 < start) {
2033 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002034 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002035 "Waiting for offset complete...");
2036 mWindowMap.wait(WALLPAPER_TIMEOUT);
2037 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002038 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002039 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002040 if ((start+WALLPAPER_TIMEOUT)
2041 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002042 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002043 + wallpaperWin);
2044 mLastWallpaperTimeoutTime = start;
2045 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002046 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002047 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002048 }
2049 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002050 } catch (RemoteException e) {
2051 }
2052 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002053
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002054 return changed;
2055 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002056
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002057 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002058 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002059 if (mWaitingOnWallpaper != null &&
2060 mWaitingOnWallpaper.mClient.asBinder() == window) {
2061 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002062 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002063 }
2064 }
2065 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002066
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002067 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002068 final int dw = mDisplay.getWidth();
2069 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002070
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002071 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002072
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002073 WindowState target = mWallpaperTarget;
2074 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002075 if (target.mWallpaperX >= 0) {
2076 mLastWallpaperX = target.mWallpaperX;
2077 } else if (changingTarget.mWallpaperX >= 0) {
2078 mLastWallpaperX = changingTarget.mWallpaperX;
2079 }
2080 if (target.mWallpaperY >= 0) {
2081 mLastWallpaperY = target.mWallpaperY;
2082 } else if (changingTarget.mWallpaperY >= 0) {
2083 mLastWallpaperY = changingTarget.mWallpaperY;
2084 }
2085 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002086
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002087 int curTokenIndex = mWallpaperTokens.size();
2088 while (curTokenIndex > 0) {
2089 curTokenIndex--;
2090 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2091 int curWallpaperIndex = token.windows.size();
2092 while (curWallpaperIndex > 0) {
2093 curWallpaperIndex--;
2094 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2095 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2096 wallpaper.computeShownFrameLocked();
2097 changed = true;
2098 // We only want to be synchronous with one wallpaper.
2099 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002100 }
2101 }
2102 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002103
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002104 return changed;
2105 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002106
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002107 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002108 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002109 final int dw = mDisplay.getWidth();
2110 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002111
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002112 int curTokenIndex = mWallpaperTokens.size();
2113 while (curTokenIndex > 0) {
2114 curTokenIndex--;
2115 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002116 if (token.hidden == visible) {
2117 token.hidden = !visible;
2118 // Need to do a layout to ensure the wallpaper now has the
2119 // correct size.
2120 mLayoutNeeded = true;
2121 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002122
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002123 int curWallpaperIndex = token.windows.size();
2124 while (curWallpaperIndex > 0) {
2125 curWallpaperIndex--;
2126 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2127 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002128 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002129 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002130
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002131 if (wallpaper.mWallpaperVisible != visible) {
2132 wallpaper.mWallpaperVisible = visible;
2133 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002134 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002135 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002136 + ": " + visible);
2137 wallpaper.mClient.dispatchAppVisibility(visible);
2138 } catch (RemoteException e) {
2139 }
2140 }
2141 }
2142 }
2143 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002145 public int addWindow(Session session, IWindow client,
2146 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac02010-04-22 18:58:52 -07002147 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002148 int res = mPolicy.checkAddPermission(attrs);
2149 if (res != WindowManagerImpl.ADD_OKAY) {
2150 return res;
2151 }
Romain Guy06882f82009-06-10 13:36:04 -07002152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002153 boolean reportNewConfig = false;
2154 WindowState attachedWindow = null;
2155 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002156 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002158 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002159 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002160 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002161 }
Romain Guy06882f82009-06-10 13:36:04 -07002162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002163 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002164 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002165 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2166 }
2167
2168 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002169 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002170 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002171 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002172 + attrs.token + ". Aborting.");
2173 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2174 }
2175 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2176 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002177 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002178 + attrs.token + ". Aborting.");
2179 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2180 }
2181 }
2182
2183 boolean addToken = false;
2184 WindowToken token = mTokenMap.get(attrs.token);
2185 if (token == null) {
2186 if (attrs.type >= FIRST_APPLICATION_WINDOW
2187 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002188 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002189 + attrs.token + ". Aborting.");
2190 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2191 }
2192 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002193 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002194 + attrs.token + ". Aborting.");
2195 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2196 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002197 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002198 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002199 + attrs.token + ". Aborting.");
2200 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2201 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002202 token = new WindowToken(attrs.token, -1, false);
2203 addToken = true;
2204 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2205 && attrs.type <= LAST_APPLICATION_WINDOW) {
2206 AppWindowToken atoken = token.appWindowToken;
2207 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002208 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002209 + token + ". Aborting.");
2210 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2211 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002212 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002213 + token + ". Aborting.");
2214 return WindowManagerImpl.ADD_APP_EXITING;
2215 }
2216 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2217 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002218 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002219 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2220 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2221 }
2222 } else if (attrs.type == TYPE_INPUT_METHOD) {
2223 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002224 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002225 + attrs.token + ". Aborting.");
2226 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2227 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002228 } else if (attrs.type == TYPE_WALLPAPER) {
2229 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002230 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002231 + attrs.token + ". Aborting.");
2232 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2233 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002234 }
2235
2236 win = new WindowState(session, client, token,
2237 attachedWindow, attrs, viewVisibility);
2238 if (win.mDeathRecipient == null) {
2239 // Client has apparently died, so there is no reason to
2240 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002241 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002242 + " that is dead, aborting.");
2243 return WindowManagerImpl.ADD_APP_EXITING;
2244 }
2245
2246 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002248 res = mPolicy.prepareAddWindowLw(win, attrs);
2249 if (res != WindowManagerImpl.ADD_OKAY) {
2250 return res;
2251 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07002252
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002253 if (outInputChannel != null) {
2254 String name = win.makeInputChannelName();
2255 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2256 win.mInputChannel = inputChannels[0];
2257 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2258
2259 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -07002260 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002261
2262 // From now on, no exceptions or errors allowed!
2263
2264 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002265
Dianne Hackborn5132b372010-07-29 12:51:35 -07002266 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002268 if (addToken) {
2269 mTokenMap.put(attrs.token, token);
2270 mTokenList.add(token);
2271 }
2272 win.attach();
2273 mWindowMap.put(client.asBinder(), win);
2274
2275 if (attrs.type == TYPE_APPLICATION_STARTING &&
2276 token.appWindowToken != null) {
2277 token.appWindowToken.startingWindow = win;
2278 }
2279
2280 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002282 if (attrs.type == TYPE_INPUT_METHOD) {
2283 mInputMethodWindow = win;
2284 addInputMethodWindowToListLocked(win);
2285 imMayMove = false;
2286 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2287 mInputMethodDialogs.add(win);
2288 addWindowToListInOrderLocked(win, true);
2289 adjustInputMethodDialogsLocked();
2290 imMayMove = false;
2291 } else {
2292 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002293 if (attrs.type == TYPE_WALLPAPER) {
2294 mLastWallpaperTimeoutTime = 0;
2295 adjustWallpaperWindowsLocked();
2296 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002297 adjustWallpaperWindowsLocked();
2298 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002299 }
Romain Guy06882f82009-06-10 13:36:04 -07002300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002301 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002303 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002305 if (mInTouchMode) {
2306 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2307 }
2308 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2309 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2310 }
Romain Guy06882f82009-06-10 13:36:04 -07002311
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002312 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002313 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07002314 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
2315 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002316 imMayMove = false;
2317 }
2318 }
Romain Guy06882f82009-06-10 13:36:04 -07002319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002320 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002321 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002322 }
Romain Guy06882f82009-06-10 13:36:04 -07002323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002324 assignLayersLocked();
2325 // Don't do layout here, the window must call
2326 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002328 //dump();
2329
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002330 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07002331 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002332 }
Jeff Brown349703e2010-06-22 01:27:15 -07002333
Joe Onorato8a9b2202010-02-26 18:56:32 -08002334 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002335 TAG, "New client " + client.asBinder()
2336 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002337
2338 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2339 reportNewConfig = true;
2340 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002341 }
2342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002343 if (reportNewConfig) {
2344 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002345 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002347 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002348
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002349 return res;
2350 }
Romain Guy06882f82009-06-10 13:36:04 -07002351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002352 public void removeWindow(Session session, IWindow client) {
2353 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002354 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002355 if (win == null) {
2356 return;
2357 }
2358 removeWindowLocked(session, win);
2359 }
2360 }
Romain Guy06882f82009-06-10 13:36:04 -07002361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002362 public void removeWindowLocked(Session session, WindowState win) {
2363
Joe Onorato8a9b2202010-02-26 18:56:32 -08002364 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002365 TAG, "Remove " + win + " client="
2366 + Integer.toHexString(System.identityHashCode(
2367 win.mClient.asBinder()))
2368 + ", surface=" + win.mSurface);
2369
2370 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002371
2372 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002373
Joe Onorato8a9b2202010-02-26 18:56:32 -08002374 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002375 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2376 + " mExiting=" + win.mExiting
2377 + " isAnimating=" + win.isAnimating()
2378 + " app-animation="
2379 + (win.mAppToken != null ? win.mAppToken.animation : null)
2380 + " inPendingTransaction="
2381 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2382 + " mDisplayFrozen=" + mDisplayFrozen);
2383 // Visibility of the removed window. Will be used later to update orientation later on.
2384 boolean wasVisible = false;
2385 // First, see if we need to run an animation. If we do, we have
2386 // to hold off on removing the window until the animation is done.
2387 // If the display is frozen, just remove immediately, since the
2388 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002389 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002390 // If we are not currently running the exit animation, we
2391 // need to see about starting one.
2392 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002394 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2395 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2396 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2397 }
2398 // Try starting an animation.
2399 if (applyAnimationLocked(win, transit, false)) {
2400 win.mExiting = true;
2401 }
2402 }
2403 if (win.mExiting || win.isAnimating()) {
2404 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002405 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002406 win.mExiting = true;
2407 win.mRemoveOnExit = true;
2408 mLayoutNeeded = true;
2409 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2410 performLayoutAndPlaceSurfacesLocked();
2411 if (win.mAppToken != null) {
2412 win.mAppToken.updateReportedVisibilityLocked();
2413 }
2414 //dump();
2415 Binder.restoreCallingIdentity(origId);
2416 return;
2417 }
2418 }
2419
2420 removeWindowInnerLocked(session, win);
2421 // Removing a visible window will effect the computed orientation
2422 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002423 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002424 != mForcedAppOrientation
2425 && updateOrientationFromAppTokensLocked()) {
2426 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002427 }
2428 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2429 Binder.restoreCallingIdentity(origId);
2430 }
Romain Guy06882f82009-06-10 13:36:04 -07002431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002432 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002433 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002435 if (mInputMethodTarget == win) {
2436 moveInputMethodWindowsIfNeededLocked(false);
2437 }
Romain Guy06882f82009-06-10 13:36:04 -07002438
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002439 if (false) {
2440 RuntimeException e = new RuntimeException("here");
2441 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002442 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002443 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002445 mPolicy.removeWindowLw(win);
2446 win.removeLocked();
2447
2448 mWindowMap.remove(win.mClient.asBinder());
2449 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002450 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002451 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002452
2453 if (mInputMethodWindow == win) {
2454 mInputMethodWindow = null;
2455 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2456 mInputMethodDialogs.remove(win);
2457 }
Romain Guy06882f82009-06-10 13:36:04 -07002458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002459 final WindowToken token = win.mToken;
2460 final AppWindowToken atoken = win.mAppToken;
2461 token.windows.remove(win);
2462 if (atoken != null) {
2463 atoken.allAppWindows.remove(win);
2464 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002465 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002466 TAG, "**** Removing window " + win + ": count="
2467 + token.windows.size());
2468 if (token.windows.size() == 0) {
2469 if (!token.explicit) {
2470 mTokenMap.remove(token.token);
2471 mTokenList.remove(token);
2472 } else if (atoken != null) {
2473 atoken.firstWindowDrawn = false;
2474 }
2475 }
2476
2477 if (atoken != null) {
2478 if (atoken.startingWindow == win) {
2479 atoken.startingWindow = null;
2480 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2481 // If this is the last window and we had requested a starting
2482 // transition window, well there is no point now.
2483 atoken.startingData = null;
2484 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2485 // If this is the last window except for a starting transition
2486 // window, we need to get rid of the starting transition.
2487 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002488 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002489 + ": no more real windows");
2490 }
2491 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2492 mH.sendMessage(m);
2493 }
2494 }
Romain Guy06882f82009-06-10 13:36:04 -07002495
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002496 if (win.mAttrs.type == TYPE_WALLPAPER) {
2497 mLastWallpaperTimeoutTime = 0;
2498 adjustWallpaperWindowsLocked();
2499 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002500 adjustWallpaperWindowsLocked();
2501 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002503 if (!mInLayout) {
2504 assignLayersLocked();
2505 mLayoutNeeded = true;
2506 performLayoutAndPlaceSurfacesLocked();
2507 if (win.mAppToken != null) {
2508 win.mAppToken.updateReportedVisibilityLocked();
2509 }
2510 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002511
2512 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002513 }
2514
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002515 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2516 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2517 + ": " + msg + " / " + w.mAttrs.getTitle();
2518 if (where != null) {
2519 Slog.i(TAG, str, where);
2520 } else {
2521 Slog.i(TAG, str);
2522 }
2523 }
2524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002525 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2526 long origId = Binder.clearCallingIdentity();
2527 try {
2528 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002529 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002530 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002531 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002532 Surface.openTransaction();
2533 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002534 if (SHOW_TRANSACTIONS) logSurface(w,
2535 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002536 w.mSurface.setTransparentRegionHint(region);
2537 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002538 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002539 Surface.closeTransaction();
2540 }
2541 }
2542 }
2543 } finally {
2544 Binder.restoreCallingIdentity(origId);
2545 }
2546 }
2547
2548 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002549 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002550 Rect visibleInsets) {
2551 long origId = Binder.clearCallingIdentity();
2552 try {
2553 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002554 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002555 if (w != null) {
2556 w.mGivenInsetsPending = false;
2557 w.mGivenContentInsets.set(contentInsets);
2558 w.mGivenVisibleInsets.set(visibleInsets);
2559 w.mTouchableInsets = touchableInsets;
2560 mLayoutNeeded = true;
2561 performLayoutAndPlaceSurfacesLocked();
2562 }
2563 }
2564 } finally {
2565 Binder.restoreCallingIdentity(origId);
2566 }
2567 }
Romain Guy06882f82009-06-10 13:36:04 -07002568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002569 public void getWindowDisplayFrame(Session session, IWindow client,
2570 Rect outDisplayFrame) {
2571 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002572 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002573 if (win == null) {
2574 outDisplayFrame.setEmpty();
2575 return;
2576 }
2577 outDisplayFrame.set(win.mDisplayFrame);
2578 }
2579 }
2580
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002581 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2582 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002583 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2584 window.mWallpaperX = x;
2585 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002586 window.mWallpaperXStep = xStep;
2587 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002588 if (updateWallpaperOffsetLocked(window, true)) {
2589 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002590 }
2591 }
2592 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002593
Dianne Hackborn75804932009-10-20 20:15:20 -07002594 void wallpaperCommandComplete(IBinder window, Bundle result) {
2595 synchronized (mWindowMap) {
2596 if (mWaitingOnWallpaper != null &&
2597 mWaitingOnWallpaper.mClient.asBinder() == window) {
2598 mWaitingOnWallpaper = null;
2599 mWindowMap.notifyAll();
2600 }
2601 }
2602 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002603
Dianne Hackborn75804932009-10-20 20:15:20 -07002604 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2605 String action, int x, int y, int z, Bundle extras, boolean sync) {
2606 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2607 || window == mUpperWallpaperTarget) {
2608 boolean doWait = sync;
2609 int curTokenIndex = mWallpaperTokens.size();
2610 while (curTokenIndex > 0) {
2611 curTokenIndex--;
2612 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2613 int curWallpaperIndex = token.windows.size();
2614 while (curWallpaperIndex > 0) {
2615 curWallpaperIndex--;
2616 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2617 try {
2618 wallpaper.mClient.dispatchWallpaperCommand(action,
2619 x, y, z, extras, sync);
2620 // We only want to be synchronous with one wallpaper.
2621 sync = false;
2622 } catch (RemoteException e) {
2623 }
2624 }
2625 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002626
Dianne Hackborn75804932009-10-20 20:15:20 -07002627 if (doWait) {
2628 // XXX Need to wait for result.
2629 }
2630 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002631
Dianne Hackborn75804932009-10-20 20:15:20 -07002632 return null;
2633 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002635 public int relayoutWindow(Session session, IWindow client,
2636 WindowManager.LayoutParams attrs, int requestedWidth,
2637 int requestedHeight, int viewVisibility, boolean insetsPending,
2638 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002639 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002640 boolean displayed = false;
2641 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002642 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002643 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002645 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002646 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002647 if (win == null) {
2648 return 0;
2649 }
2650 win.mRequestedWidth = requestedWidth;
2651 win.mRequestedHeight = requestedHeight;
2652
2653 if (attrs != null) {
2654 mPolicy.adjustWindowParamsLw(attrs);
2655 }
Romain Guy06882f82009-06-10 13:36:04 -07002656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002657 int attrChanges = 0;
2658 int flagChanges = 0;
2659 if (attrs != null) {
2660 flagChanges = win.mAttrs.flags ^= attrs.flags;
2661 attrChanges = win.mAttrs.copyFrom(attrs);
2662 }
2663
Joe Onorato8a9b2202010-02-26 18:56:32 -08002664 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002665
2666 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2667 win.mAlpha = attrs.alpha;
2668 }
2669
2670 final boolean scaledWindow =
2671 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2672
2673 if (scaledWindow) {
2674 // requested{Width|Height} Surface's physical size
2675 // attrs.{width|height} Size on screen
2676 win.mHScale = (attrs.width != requestedWidth) ?
2677 (attrs.width / (float)requestedWidth) : 1.0f;
2678 win.mVScale = (attrs.height != requestedHeight) ?
2679 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002680 } else {
2681 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002682 }
2683
2684 boolean imMayMove = (flagChanges&(
2685 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2686 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002688 boolean focusMayChange = win.mViewVisibility != viewVisibility
2689 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2690 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002691
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002692 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2693 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002695 win.mRelayoutCalled = true;
2696 final int oldVisibility = win.mViewVisibility;
2697 win.mViewVisibility = viewVisibility;
2698 if (viewVisibility == View.VISIBLE &&
2699 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2700 displayed = !win.isVisibleLw();
2701 if (win.mExiting) {
2702 win.mExiting = false;
2703 win.mAnimation = null;
2704 }
2705 if (win.mDestroying) {
2706 win.mDestroying = false;
2707 mDestroySurface.remove(win);
2708 }
2709 if (oldVisibility == View.GONE) {
2710 win.mEnterAnimationPending = true;
2711 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002712 if (displayed) {
2713 if (win.mSurface != null && !win.mDrawPending
2714 && !win.mCommitDrawPending && !mDisplayFrozen
2715 && mPolicy.isScreenOn()) {
2716 applyEnterAnimationLocked(win);
2717 }
2718 if ((win.mAttrs.flags
2719 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2720 if (DEBUG_VISIBILITY) Slog.v(TAG,
2721 "Relayout window turning screen on: " + win);
2722 win.mTurnOnScreen = true;
2723 }
2724 int diff = 0;
2725 if (win.mConfiguration != mCurConfiguration
2726 && (win.mConfiguration == null
2727 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2728 win.mConfiguration = mCurConfiguration;
2729 if (DEBUG_CONFIGURATION) {
2730 Slog.i(TAG, "Window " + win + " visible with new config: "
2731 + win.mConfiguration + " / 0x"
2732 + Integer.toHexString(diff));
2733 }
2734 outConfig.setTo(mCurConfiguration);
2735 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002736 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002737 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2738 // To change the format, we need to re-build the surface.
2739 win.destroySurfaceLocked();
2740 displayed = true;
2741 }
2742 try {
2743 Surface surface = win.createSurfaceLocked();
2744 if (surface != null) {
2745 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002746 win.mReportDestroySurface = false;
2747 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002748 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002749 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002750 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002751 // For some reason there isn't a surface. Clear the
2752 // caller's object so they see the same state.
2753 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002754 }
2755 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002756 mInputMonitor.updateInputWindowsLw();
2757
Joe Onorato8a9b2202010-02-26 18:56:32 -08002758 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002759 + client + " (" + win.mAttrs.getTitle() + ")",
2760 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002761 Binder.restoreCallingIdentity(origId);
2762 return 0;
2763 }
2764 if (displayed) {
2765 focusMayChange = true;
2766 }
2767 if (win.mAttrs.type == TYPE_INPUT_METHOD
2768 && mInputMethodWindow == null) {
2769 mInputMethodWindow = win;
2770 imMayMove = true;
2771 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002772 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2773 && win.mAppToken != null
2774 && win.mAppToken.startingWindow != null) {
2775 // Special handling of starting window over the base
2776 // window of the app: propagate lock screen flags to it,
2777 // to provide the correct semantics while starting.
2778 final int mask =
2779 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002780 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2781 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002782 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2783 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2784 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002785 } else {
2786 win.mEnterAnimationPending = false;
2787 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002788 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002789 + ": mExiting=" + win.mExiting
2790 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002791 // If we are not currently running the exit animation, we
2792 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002793 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002794 // Try starting an animation; if there isn't one, we
2795 // can destroy the surface right away.
2796 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2797 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2798 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2799 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002800 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002801 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002802 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002803 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002804 } else if (win.isAnimating()) {
2805 // Currently in a hide animation... turn this into
2806 // an exit.
2807 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002808 } else if (win == mWallpaperTarget) {
2809 // If the wallpaper is currently behind this
2810 // window, we need to change both of them inside
2811 // of a transaction to avoid artifacts.
2812 win.mExiting = true;
2813 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002814 } else {
2815 if (mInputMethodWindow == win) {
2816 mInputMethodWindow = null;
2817 }
2818 win.destroySurfaceLocked();
2819 }
2820 }
2821 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002822
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002823 if (win.mSurface == null || (win.getAttrs().flags
2824 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2825 || win.mSurfacePendingDestroy) {
2826 // We are being called from a local process, which
2827 // means outSurface holds its current surface. Ensure the
2828 // surface object is cleared, but we don't want it actually
2829 // destroyed at this point.
2830 win.mSurfacePendingDestroy = false;
2831 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002832 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002833 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002834 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002835 "Keeping surface, will report destroy: " + win);
2836 win.mReportDestroySurface = true;
2837 outSurface.copyFrom(win.mSurface);
2838 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002839 }
2840
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002841 if (focusMayChange) {
2842 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2843 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002844 imMayMove = false;
2845 }
2846 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2847 }
Romain Guy06882f82009-06-10 13:36:04 -07002848
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002849 // updateFocusedWindowLocked() already assigned layers so we only need to
2850 // reassign them at this point if the IM window state gets shuffled
2851 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002853 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002854 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2855 // Little hack here -- we -should- be able to rely on the
2856 // function to return true if the IME has moved and needs
2857 // its layer recomputed. However, if the IME was hidden
2858 // and isn't actually moved in the list, its layer may be
2859 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002860 assignLayers = true;
2861 }
2862 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002863 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002864 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002865 assignLayers = true;
2866 }
2867 }
Romain Guy06882f82009-06-10 13:36:04 -07002868
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002869 mLayoutNeeded = true;
2870 win.mGivenInsetsPending = insetsPending;
2871 if (assignLayers) {
2872 assignLayersLocked();
2873 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002874 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002875 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002876 if (displayed && win.mIsWallpaper) {
2877 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002878 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002879 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002880 if (win.mAppToken != null) {
2881 win.mAppToken.updateReportedVisibilityLocked();
2882 }
2883 outFrame.set(win.mFrame);
2884 outContentInsets.set(win.mContentInsets);
2885 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002886 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002887 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002888 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002889 + ", requestedHeight=" + requestedHeight
2890 + ", viewVisibility=" + viewVisibility
2891 + "\nRelayout returning frame=" + outFrame
2892 + ", surface=" + outSurface);
2893
Joe Onorato8a9b2202010-02-26 18:56:32 -08002894 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002895 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2896
2897 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002898
2899 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002900 }
2901
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002902 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002903 sendNewConfiguration();
2904 }
Romain Guy06882f82009-06-10 13:36:04 -07002905
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002906 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002908 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2909 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2910 }
2911
2912 public void finishDrawingWindow(Session session, IWindow client) {
2913 final long origId = Binder.clearCallingIdentity();
2914 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002915 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002916 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002917 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2918 adjustWallpaperWindowsLocked();
2919 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002920 mLayoutNeeded = true;
2921 performLayoutAndPlaceSurfacesLocked();
2922 }
2923 }
2924 Binder.restoreCallingIdentity(origId);
2925 }
2926
2927 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002928 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002929 + (lp != null ? lp.packageName : null)
2930 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2931 if (lp != null && lp.windowAnimations != 0) {
2932 // If this is a system resource, don't try to load it from the
2933 // application resources. It is nice to avoid loading application
2934 // resources if we can.
2935 String packageName = lp.packageName != null ? lp.packageName : "android";
2936 int resId = lp.windowAnimations;
2937 if ((resId&0xFF000000) == 0x01000000) {
2938 packageName = "android";
2939 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002940 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002941 + packageName);
2942 return AttributeCache.instance().get(packageName, resId,
2943 com.android.internal.R.styleable.WindowAnimation);
2944 }
2945 return null;
2946 }
Romain Guy06882f82009-06-10 13:36:04 -07002947
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002948 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002949 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002950 + packageName + " resId=0x" + Integer.toHexString(resId));
2951 if (packageName != null) {
2952 if ((resId&0xFF000000) == 0x01000000) {
2953 packageName = "android";
2954 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002955 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002956 + packageName);
2957 return AttributeCache.instance().get(packageName, resId,
2958 com.android.internal.R.styleable.WindowAnimation);
2959 }
2960 return null;
2961 }
2962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002963 private void applyEnterAnimationLocked(WindowState win) {
2964 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2965 if (win.mEnterAnimationPending) {
2966 win.mEnterAnimationPending = false;
2967 transit = WindowManagerPolicy.TRANSIT_ENTER;
2968 }
2969
2970 applyAnimationLocked(win, transit, true);
2971 }
2972
2973 private boolean applyAnimationLocked(WindowState win,
2974 int transit, boolean isEntrance) {
2975 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2976 // If we are trying to apply an animation, but already running
2977 // an animation of the same type, then just leave that one alone.
2978 return true;
2979 }
Romain Guy06882f82009-06-10 13:36:04 -07002980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002981 // Only apply an animation if the display isn't frozen. If it is
2982 // frozen, there is no reason to animate and it can cause strange
2983 // artifacts when we unfreeze the display if some different animation
2984 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002985 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002986 int anim = mPolicy.selectAnimationLw(win, transit);
2987 int attr = -1;
2988 Animation a = null;
2989 if (anim != 0) {
2990 a = AnimationUtils.loadAnimation(mContext, anim);
2991 } else {
2992 switch (transit) {
2993 case WindowManagerPolicy.TRANSIT_ENTER:
2994 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2995 break;
2996 case WindowManagerPolicy.TRANSIT_EXIT:
2997 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2998 break;
2999 case WindowManagerPolicy.TRANSIT_SHOW:
3000 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3001 break;
3002 case WindowManagerPolicy.TRANSIT_HIDE:
3003 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3004 break;
3005 }
3006 if (attr >= 0) {
3007 a = loadAnimation(win.mAttrs, attr);
3008 }
3009 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003010 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003011 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3012 + " mAnimation=" + win.mAnimation
3013 + " isEntrance=" + isEntrance);
3014 if (a != null) {
3015 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003016 RuntimeException e = null;
3017 if (!HIDE_STACK_CRAWLS) {
3018 e = new RuntimeException();
3019 e.fillInStackTrace();
3020 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003021 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003022 }
3023 win.setAnimation(a);
3024 win.mAnimationIsEntrance = isEntrance;
3025 }
3026 } else {
3027 win.clearAnimation();
3028 }
3029
3030 return win.mAnimation != null;
3031 }
3032
3033 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3034 int anim = 0;
3035 Context context = mContext;
3036 if (animAttr >= 0) {
3037 AttributeCache.Entry ent = getCachedAnimations(lp);
3038 if (ent != null) {
3039 context = ent.context;
3040 anim = ent.array.getResourceId(animAttr, 0);
3041 }
3042 }
3043 if (anim != 0) {
3044 return AnimationUtils.loadAnimation(context, anim);
3045 }
3046 return null;
3047 }
Romain Guy06882f82009-06-10 13:36:04 -07003048
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003049 private Animation loadAnimation(String packageName, int resId) {
3050 int anim = 0;
3051 Context context = mContext;
3052 if (resId >= 0) {
3053 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3054 if (ent != null) {
3055 context = ent.context;
3056 anim = resId;
3057 }
3058 }
3059 if (anim != 0) {
3060 return AnimationUtils.loadAnimation(context, anim);
3061 }
3062 return null;
3063 }
3064
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003065 private boolean applyAnimationLocked(AppWindowToken wtoken,
3066 WindowManager.LayoutParams lp, int transit, boolean enter) {
3067 // Only apply an animation if the display isn't frozen. If it is
3068 // frozen, there is no reason to animate and it can cause strange
3069 // artifacts when we unfreeze the display if some different animation
3070 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003071 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003072 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003073 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003074 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003075 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003076 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003077 } else if (mNextAppTransitionPackage != null) {
3078 a = loadAnimation(mNextAppTransitionPackage, enter ?
3079 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003080 } else {
3081 int animAttr = 0;
3082 switch (transit) {
3083 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3084 animAttr = enter
3085 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3086 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3087 break;
3088 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3089 animAttr = enter
3090 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3091 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3092 break;
3093 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3094 animAttr = enter
3095 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3096 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3097 break;
3098 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3099 animAttr = enter
3100 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3101 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3102 break;
3103 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3104 animAttr = enter
3105 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3106 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3107 break;
3108 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3109 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003110 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003111 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3112 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003113 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003114 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003115 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3116 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003117 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003118 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003119 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003120 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3121 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3122 break;
3123 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3124 animAttr = enter
3125 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3126 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3127 break;
3128 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3129 animAttr = enter
3130 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3131 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003132 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003133 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003134 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003135 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003136 + " anim=" + a
3137 + " animAttr=0x" + Integer.toHexString(animAttr)
3138 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003139 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003140 if (a != null) {
3141 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003142 RuntimeException e = null;
3143 if (!HIDE_STACK_CRAWLS) {
3144 e = new RuntimeException();
3145 e.fillInStackTrace();
3146 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003147 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003148 }
3149 wtoken.setAnimation(a);
3150 }
3151 } else {
3152 wtoken.clearAnimation();
3153 }
3154
3155 return wtoken.animation != null;
3156 }
3157
3158 // -------------------------------------------------------------
3159 // Application Window Tokens
3160 // -------------------------------------------------------------
3161
3162 public void validateAppTokens(List tokens) {
3163 int v = tokens.size()-1;
3164 int m = mAppTokens.size()-1;
3165 while (v >= 0 && m >= 0) {
3166 AppWindowToken wtoken = mAppTokens.get(m);
3167 if (wtoken.removed) {
3168 m--;
3169 continue;
3170 }
3171 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003172 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003173 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3174 }
3175 v--;
3176 m--;
3177 }
3178 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003179 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003180 v--;
3181 }
3182 while (m >= 0) {
3183 AppWindowToken wtoken = mAppTokens.get(m);
3184 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003185 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003186 }
3187 m--;
3188 }
3189 }
3190
3191 boolean checkCallingPermission(String permission, String func) {
3192 // Quick check: if the calling permission is me, it's all okay.
3193 if (Binder.getCallingPid() == Process.myPid()) {
3194 return true;
3195 }
Romain Guy06882f82009-06-10 13:36:04 -07003196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003197 if (mContext.checkCallingPermission(permission)
3198 == PackageManager.PERMISSION_GRANTED) {
3199 return true;
3200 }
3201 String msg = "Permission Denial: " + func + " from pid="
3202 + Binder.getCallingPid()
3203 + ", uid=" + Binder.getCallingUid()
3204 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003205 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003206 return false;
3207 }
Romain Guy06882f82009-06-10 13:36:04 -07003208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003209 AppWindowToken findAppWindowToken(IBinder token) {
3210 WindowToken wtoken = mTokenMap.get(token);
3211 if (wtoken == null) {
3212 return null;
3213 }
3214 return wtoken.appWindowToken;
3215 }
Romain Guy06882f82009-06-10 13:36:04 -07003216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003217 public void addWindowToken(IBinder token, int type) {
3218 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3219 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003220 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003221 }
Romain Guy06882f82009-06-10 13:36:04 -07003222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003223 synchronized(mWindowMap) {
3224 WindowToken wtoken = mTokenMap.get(token);
3225 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003226 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003227 return;
3228 }
3229 wtoken = new WindowToken(token, type, true);
3230 mTokenMap.put(token, wtoken);
3231 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003232 if (type == TYPE_WALLPAPER) {
3233 mWallpaperTokens.add(wtoken);
3234 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003235 }
3236 }
Romain Guy06882f82009-06-10 13:36:04 -07003237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003238 public void removeWindowToken(IBinder token) {
3239 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3240 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003241 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003242 }
3243
3244 final long origId = Binder.clearCallingIdentity();
3245 synchronized(mWindowMap) {
3246 WindowToken wtoken = mTokenMap.remove(token);
3247 mTokenList.remove(wtoken);
3248 if (wtoken != null) {
3249 boolean delayed = false;
3250 if (!wtoken.hidden) {
3251 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003253 final int N = wtoken.windows.size();
3254 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003256 for (int i=0; i<N; i++) {
3257 WindowState win = wtoken.windows.get(i);
3258
3259 if (win.isAnimating()) {
3260 delayed = true;
3261 }
Romain Guy06882f82009-06-10 13:36:04 -07003262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003263 if (win.isVisibleNow()) {
3264 applyAnimationLocked(win,
3265 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003266 changed = true;
3267 }
3268 }
3269
3270 if (changed) {
3271 mLayoutNeeded = true;
3272 performLayoutAndPlaceSurfacesLocked();
3273 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3274 }
Romain Guy06882f82009-06-10 13:36:04 -07003275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003276 if (delayed) {
3277 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003278 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3279 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003280 }
3281 }
Romain Guy06882f82009-06-10 13:36:04 -07003282
Jeff Brownc5ed5912010-07-14 18:48:53 -07003283 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003284 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003285 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003286 }
3287 }
3288 Binder.restoreCallingIdentity(origId);
3289 }
3290
3291 public void addAppToken(int addPos, IApplicationToken token,
3292 int groupId, int requestedOrientation, boolean fullscreen) {
3293 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3294 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003295 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003296 }
Jeff Brown349703e2010-06-22 01:27:15 -07003297
3298 // Get the dispatching timeout here while we are not holding any locks so that it
3299 // can be cached by the AppWindowToken. The timeout value is used later by the
3300 // input dispatcher in code that does hold locks. If we did not cache the value
3301 // here we would run the chance of introducing a deadlock between the window manager
3302 // (which holds locks while updating the input dispatcher state) and the activity manager
3303 // (which holds locks while querying the application token).
3304 long inputDispatchingTimeoutNanos;
3305 try {
3306 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3307 } catch (RemoteException ex) {
3308 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3309 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3310 }
Romain Guy06882f82009-06-10 13:36:04 -07003311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003312 synchronized(mWindowMap) {
3313 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3314 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003315 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003316 return;
3317 }
3318 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003319 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003320 wtoken.groupId = groupId;
3321 wtoken.appFullscreen = fullscreen;
3322 wtoken.requestedOrientation = requestedOrientation;
3323 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003324 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003325 mTokenMap.put(token.asBinder(), wtoken);
3326 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003328 // Application tokens start out hidden.
3329 wtoken.hidden = true;
3330 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003332 //dump();
3333 }
3334 }
Romain Guy06882f82009-06-10 13:36:04 -07003335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003336 public void setAppGroupId(IBinder token, int groupId) {
3337 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3338 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003339 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003340 }
3341
3342 synchronized(mWindowMap) {
3343 AppWindowToken wtoken = findAppWindowToken(token);
3344 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003345 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003346 return;
3347 }
3348 wtoken.groupId = groupId;
3349 }
3350 }
Romain Guy06882f82009-06-10 13:36:04 -07003351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003352 public int getOrientationFromWindowsLocked() {
3353 int pos = mWindows.size() - 1;
3354 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003355 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003356 pos--;
3357 if (wtoken.mAppToken != null) {
3358 // We hit an application window. so the orientation will be determined by the
3359 // app window. No point in continuing further.
3360 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3361 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003362 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003363 continue;
3364 }
3365 int req = wtoken.mAttrs.screenOrientation;
3366 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3367 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3368 continue;
3369 } else {
3370 return req;
3371 }
3372 }
3373 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3374 }
Romain Guy06882f82009-06-10 13:36:04 -07003375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003376 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003377 int pos = mAppTokens.size() - 1;
3378 int curGroup = 0;
3379 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3380 boolean findingBehind = false;
3381 boolean haveGroup = false;
3382 boolean lastFullscreen = false;
3383 while (pos >= 0) {
3384 AppWindowToken wtoken = mAppTokens.get(pos);
3385 pos--;
3386 // if we're about to tear down this window and not seek for
3387 // the behind activity, don't use it for orientation
3388 if (!findingBehind
3389 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3390 continue;
3391 }
3392
3393 if (!haveGroup) {
3394 // We ignore any hidden applications on the top.
3395 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003396 continue;
3397 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003398 haveGroup = true;
3399 curGroup = wtoken.groupId;
3400 lastOrientation = wtoken.requestedOrientation;
3401 } else if (curGroup != wtoken.groupId) {
3402 // If we have hit a new application group, and the bottom
3403 // of the previous group didn't explicitly say to use
3404 // the orientation behind it, and the last app was
3405 // full screen, then we'll stick with the
3406 // user's orientation.
3407 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3408 && lastFullscreen) {
3409 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003410 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003411 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003412 int or = wtoken.requestedOrientation;
3413 // If this application is fullscreen, and didn't explicitly say
3414 // to use the orientation behind it, then just take whatever
3415 // orientation it has and ignores whatever is under it.
3416 lastFullscreen = wtoken.appFullscreen;
3417 if (lastFullscreen
3418 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3419 return or;
3420 }
3421 // If this application has requested an explicit orientation,
3422 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003423 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3424 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003425 return or;
3426 }
3427 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3428 }
3429 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003430 }
Romain Guy06882f82009-06-10 13:36:04 -07003431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003432 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003433 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003434 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3435 "updateOrientationFromAppTokens()")) {
3436 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3437 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003438
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003439 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003440 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003441
3442 synchronized(mWindowMap) {
3443 if (updateOrientationFromAppTokensLocked()) {
3444 if (freezeThisOneIfNeeded != null) {
3445 AppWindowToken wtoken = findAppWindowToken(
3446 freezeThisOneIfNeeded);
3447 if (wtoken != null) {
3448 startAppFreezingScreenLocked(wtoken,
3449 ActivityInfo.CONFIG_ORIENTATION);
3450 }
3451 }
3452 config = computeNewConfigurationLocked();
3453
3454 } else if (currentConfig != null) {
3455 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003456 // state mismatches the activity manager's, update it,
3457 // disregarding font scale, which should remain set to
3458 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003459 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003460 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003461 if (computeNewConfigurationLocked(mTempConfiguration)) {
3462 if (currentConfig.diff(mTempConfiguration) != 0) {
3463 mWaitingForConfig = true;
3464 mLayoutNeeded = true;
3465 startFreezingDisplayLocked();
3466 config = new Configuration(mTempConfiguration);
3467 }
3468 }
3469 }
3470 }
3471
Dianne Hackborncfaef692009-06-15 14:24:44 -07003472 Binder.restoreCallingIdentity(ident);
3473 return config;
3474 }
3475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003476 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003477 * Determine the new desired orientation of the display, returning
3478 * a non-null new Configuration if it has changed from the current
3479 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3480 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3481 * SCREEN. This will typically be done for you if you call
3482 * sendNewConfiguration().
3483 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003484 * The orientation is computed from non-application windows first. If none of
3485 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003486 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003487 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3488 * android.os.IBinder)
3489 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003490 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003491 if (mDisplayFrozen) {
3492 // If the display is frozen, some activities may be in the middle
3493 // of restarting, and thus have removed their old window. If the
3494 // window has the flag to hide the lock screen, then the lock screen
3495 // can re-appear and inflict its own orientation on us. Keep the
3496 // orientation stable until this all settles down.
3497 return false;
3498 }
3499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003500 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003501 long ident = Binder.clearCallingIdentity();
3502 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003503 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003505 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003506 mForcedAppOrientation = req;
3507 //send a message to Policy indicating orientation change to take
3508 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003509 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003510 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3511 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3512 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003513 }
3514 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003515
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003516 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003517 } finally {
3518 Binder.restoreCallingIdentity(ident);
3519 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003520 }
Romain Guy06882f82009-06-10 13:36:04 -07003521
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003522 int computeForcedAppOrientationLocked() {
3523 int req = getOrientationFromWindowsLocked();
3524 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3525 req = getOrientationFromAppTokensLocked();
3526 }
3527 return req;
3528 }
Romain Guy06882f82009-06-10 13:36:04 -07003529
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003530 public void setNewConfiguration(Configuration config) {
3531 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3532 "setNewConfiguration()")) {
3533 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3534 }
3535
3536 synchronized(mWindowMap) {
3537 mCurConfiguration = new Configuration(config);
3538 mWaitingForConfig = false;
3539 performLayoutAndPlaceSurfacesLocked();
3540 }
3541 }
3542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003543 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3544 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3545 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003546 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003547 }
Romain Guy06882f82009-06-10 13:36:04 -07003548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003549 synchronized(mWindowMap) {
3550 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3551 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003552 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003553 return;
3554 }
Romain Guy06882f82009-06-10 13:36:04 -07003555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003556 wtoken.requestedOrientation = requestedOrientation;
3557 }
3558 }
Romain Guy06882f82009-06-10 13:36:04 -07003559
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003560 public int getAppOrientation(IApplicationToken token) {
3561 synchronized(mWindowMap) {
3562 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3563 if (wtoken == null) {
3564 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3565 }
Romain Guy06882f82009-06-10 13:36:04 -07003566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003567 return wtoken.requestedOrientation;
3568 }
3569 }
Romain Guy06882f82009-06-10 13:36:04 -07003570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003571 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3572 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3573 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003574 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003575 }
3576
3577 synchronized(mWindowMap) {
3578 boolean changed = false;
3579 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003580 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003581 changed = mFocusedApp != null;
3582 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003583 if (changed) {
3584 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003585 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003586 } else {
3587 AppWindowToken newFocus = findAppWindowToken(token);
3588 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003589 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003590 return;
3591 }
3592 changed = mFocusedApp != newFocus;
3593 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003594 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003595 if (changed) {
3596 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003597 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003598 }
3599
3600 if (moveFocusNow && changed) {
3601 final long origId = Binder.clearCallingIdentity();
3602 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3603 Binder.restoreCallingIdentity(origId);
3604 }
3605 }
3606 }
3607
3608 public void prepareAppTransition(int transit) {
3609 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3610 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003611 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003612 }
Romain Guy06882f82009-06-10 13:36:04 -07003613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003614 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003615 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003616 TAG, "Prepare app transition: transit=" + transit
3617 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003618 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003619 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3620 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003621 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003622 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3623 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3624 // Opening a new task always supersedes a close for the anim.
3625 mNextAppTransition = transit;
3626 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3627 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3628 // Opening a new activity always supersedes a close for the anim.
3629 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003630 }
3631 mAppTransitionReady = false;
3632 mAppTransitionTimeout = false;
3633 mStartingIconInTransition = false;
3634 mSkipAppTransitionAnimation = false;
3635 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3636 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3637 5000);
3638 }
3639 }
3640 }
3641
3642 public int getPendingAppTransition() {
3643 return mNextAppTransition;
3644 }
Romain Guy06882f82009-06-10 13:36:04 -07003645
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003646 public void overridePendingAppTransition(String packageName,
3647 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003648 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003649 mNextAppTransitionPackage = packageName;
3650 mNextAppTransitionEnter = enterAnim;
3651 mNextAppTransitionExit = exitAnim;
3652 }
3653 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003655 public void executeAppTransition() {
3656 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3657 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003658 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003659 }
Romain Guy06882f82009-06-10 13:36:04 -07003660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003661 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003662 if (DEBUG_APP_TRANSITIONS) {
3663 RuntimeException e = new RuntimeException("here");
3664 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003665 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003666 + mNextAppTransition, e);
3667 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003668 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003669 mAppTransitionReady = true;
3670 final long origId = Binder.clearCallingIdentity();
3671 performLayoutAndPlaceSurfacesLocked();
3672 Binder.restoreCallingIdentity(origId);
3673 }
3674 }
3675 }
3676
3677 public void setAppStartingWindow(IBinder token, String pkg,
3678 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3679 IBinder transferFrom, boolean createIfNeeded) {
3680 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3681 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003682 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003683 }
3684
3685 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003686 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003687 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3688 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003690 AppWindowToken wtoken = findAppWindowToken(token);
3691 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003692 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003693 return;
3694 }
3695
3696 // If the display is frozen, we won't do anything until the
3697 // actual window is displayed so there is no reason to put in
3698 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003699 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003700 return;
3701 }
Romain Guy06882f82009-06-10 13:36:04 -07003702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003703 if (wtoken.startingData != null) {
3704 return;
3705 }
Romain Guy06882f82009-06-10 13:36:04 -07003706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003707 if (transferFrom != null) {
3708 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3709 if (ttoken != null) {
3710 WindowState startingWindow = ttoken.startingWindow;
3711 if (startingWindow != null) {
3712 if (mStartingIconInTransition) {
3713 // In this case, the starting icon has already
3714 // been displayed, so start letting windows get
3715 // shown immediately without any more transitions.
3716 mSkipAppTransitionAnimation = true;
3717 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003718 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003719 "Moving existing starting from " + ttoken
3720 + " to " + wtoken);
3721 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003722
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003723 // Transfer the starting window over to the new
3724 // token.
3725 wtoken.startingData = ttoken.startingData;
3726 wtoken.startingView = ttoken.startingView;
3727 wtoken.startingWindow = startingWindow;
3728 ttoken.startingData = null;
3729 ttoken.startingView = null;
3730 ttoken.startingWindow = null;
3731 ttoken.startingMoved = true;
3732 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003733 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003734 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003735 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003736 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003737 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003738 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003739 ttoken.windows.remove(startingWindow);
3740 ttoken.allAppWindows.remove(startingWindow);
3741 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003742
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003743 // Propagate other interesting state between the
3744 // tokens. If the old token is displayed, we should
3745 // immediately force the new one to be displayed. If
3746 // it is animating, we need to move that animation to
3747 // the new one.
3748 if (ttoken.allDrawn) {
3749 wtoken.allDrawn = true;
3750 }
3751 if (ttoken.firstWindowDrawn) {
3752 wtoken.firstWindowDrawn = true;
3753 }
3754 if (!ttoken.hidden) {
3755 wtoken.hidden = false;
3756 wtoken.hiddenRequested = false;
3757 wtoken.willBeHidden = false;
3758 }
3759 if (wtoken.clientHidden != ttoken.clientHidden) {
3760 wtoken.clientHidden = ttoken.clientHidden;
3761 wtoken.sendAppVisibilityToClients();
3762 }
3763 if (ttoken.animation != null) {
3764 wtoken.animation = ttoken.animation;
3765 wtoken.animating = ttoken.animating;
3766 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3767 ttoken.animation = null;
3768 ttoken.animLayerAdjustment = 0;
3769 wtoken.updateLayers();
3770 ttoken.updateLayers();
3771 }
Romain Guy06882f82009-06-10 13:36:04 -07003772
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003773 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003774 mLayoutNeeded = true;
3775 performLayoutAndPlaceSurfacesLocked();
3776 Binder.restoreCallingIdentity(origId);
3777 return;
3778 } else if (ttoken.startingData != null) {
3779 // The previous app was getting ready to show a
3780 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003781 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003782 "Moving pending starting from " + ttoken
3783 + " to " + wtoken);
3784 wtoken.startingData = ttoken.startingData;
3785 ttoken.startingData = null;
3786 ttoken.startingMoved = true;
3787 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3788 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3789 // want to process the message ASAP, before any other queued
3790 // messages.
3791 mH.sendMessageAtFrontOfQueue(m);
3792 return;
3793 }
3794 }
3795 }
3796
3797 // There is no existing starting window, and the caller doesn't
3798 // want us to create one, so that's it!
3799 if (!createIfNeeded) {
3800 return;
3801 }
Romain Guy06882f82009-06-10 13:36:04 -07003802
Dianne Hackborn284ac932009-08-28 10:34:25 -07003803 // If this is a translucent or wallpaper window, then don't
3804 // show a starting window -- the current effect (a full-screen
3805 // opaque starting window that fades away to the real contents
3806 // when it is ready) does not work for this.
3807 if (theme != 0) {
3808 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3809 com.android.internal.R.styleable.Window);
3810 if (ent.array.getBoolean(
3811 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3812 return;
3813 }
3814 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003815 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3816 return;
3817 }
3818 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003819 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3820 return;
3821 }
3822 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003824 mStartingIconInTransition = true;
3825 wtoken.startingData = new StartingData(
3826 pkg, theme, nonLocalizedLabel,
3827 labelRes, icon);
3828 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3829 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3830 // want to process the message ASAP, before any other queued
3831 // messages.
3832 mH.sendMessageAtFrontOfQueue(m);
3833 }
3834 }
3835
3836 public void setAppWillBeHidden(IBinder token) {
3837 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3838 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003839 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003840 }
3841
3842 AppWindowToken wtoken;
3843
3844 synchronized(mWindowMap) {
3845 wtoken = findAppWindowToken(token);
3846 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003847 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 -08003848 return;
3849 }
3850 wtoken.willBeHidden = true;
3851 }
3852 }
Romain Guy06882f82009-06-10 13:36:04 -07003853
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003854 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3855 boolean visible, int transit, boolean performLayout) {
3856 boolean delayed = false;
3857
3858 if (wtoken.clientHidden == visible) {
3859 wtoken.clientHidden = !visible;
3860 wtoken.sendAppVisibilityToClients();
3861 }
Romain Guy06882f82009-06-10 13:36:04 -07003862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003863 wtoken.willBeHidden = false;
3864 if (wtoken.hidden == visible) {
3865 final int N = wtoken.allAppWindows.size();
3866 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003867 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003868 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3869 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003870
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003871 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003872
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003873 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003874 if (wtoken.animation == sDummyAnimation) {
3875 wtoken.animation = null;
3876 }
3877 applyAnimationLocked(wtoken, lp, transit, visible);
3878 changed = true;
3879 if (wtoken.animation != null) {
3880 delayed = runningAppAnimation = true;
3881 }
3882 }
Romain Guy06882f82009-06-10 13:36:04 -07003883
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003884 for (int i=0; i<N; i++) {
3885 WindowState win = wtoken.allAppWindows.get(i);
3886 if (win == wtoken.startingWindow) {
3887 continue;
3888 }
3889
3890 if (win.isAnimating()) {
3891 delayed = true;
3892 }
Romain Guy06882f82009-06-10 13:36:04 -07003893
Joe Onorato8a9b2202010-02-26 18:56:32 -08003894 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003895 //win.dump(" ");
3896 if (visible) {
3897 if (!win.isVisibleNow()) {
3898 if (!runningAppAnimation) {
3899 applyAnimationLocked(win,
3900 WindowManagerPolicy.TRANSIT_ENTER, true);
3901 }
3902 changed = true;
3903 }
3904 } else if (win.isVisibleNow()) {
3905 if (!runningAppAnimation) {
3906 applyAnimationLocked(win,
3907 WindowManagerPolicy.TRANSIT_EXIT, false);
3908 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003909 changed = true;
3910 }
3911 }
3912
3913 wtoken.hidden = wtoken.hiddenRequested = !visible;
3914 if (!visible) {
3915 unsetAppFreezingScreenLocked(wtoken, true, true);
3916 } else {
3917 // If we are being set visible, and the starting window is
3918 // not yet displayed, then make sure it doesn't get displayed.
3919 WindowState swin = wtoken.startingWindow;
3920 if (swin != null && (swin.mDrawPending
3921 || swin.mCommitDrawPending)) {
3922 swin.mPolicyVisibility = false;
3923 swin.mPolicyVisibilityAfterAnim = false;
3924 }
3925 }
Romain Guy06882f82009-06-10 13:36:04 -07003926
Joe Onorato8a9b2202010-02-26 18:56:32 -08003927 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003928 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3929 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003930
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003931 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003932 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003933 if (performLayout) {
3934 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3935 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003936 } else {
3937 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003938 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003939 }
3940 }
3941
3942 if (wtoken.animation != null) {
3943 delayed = true;
3944 }
Romain Guy06882f82009-06-10 13:36:04 -07003945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003946 return delayed;
3947 }
3948
3949 public void setAppVisibility(IBinder token, boolean visible) {
3950 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3951 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003952 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003953 }
3954
3955 AppWindowToken wtoken;
3956
3957 synchronized(mWindowMap) {
3958 wtoken = findAppWindowToken(token);
3959 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003960 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003961 return;
3962 }
3963
3964 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003965 RuntimeException e = null;
3966 if (!HIDE_STACK_CRAWLS) {
3967 e = new RuntimeException();
3968 e.fillInStackTrace();
3969 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003970 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003971 + "): mNextAppTransition=" + mNextAppTransition
3972 + " hidden=" + wtoken.hidden
3973 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3974 }
Romain Guy06882f82009-06-10 13:36:04 -07003975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003976 // If we are preparing an app transition, then delay changing
3977 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003978 if (!mDisplayFrozen && mPolicy.isScreenOn()
3979 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003980 // Already in requested state, don't do anything more.
3981 if (wtoken.hiddenRequested != visible) {
3982 return;
3983 }
3984 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003985
Joe Onorato8a9b2202010-02-26 18:56:32 -08003986 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003987 TAG, "Setting dummy animation on: " + wtoken);
3988 wtoken.setDummyAnimation();
3989 mOpeningApps.remove(wtoken);
3990 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003991 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003992 wtoken.inPendingTransaction = true;
3993 if (visible) {
3994 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003995 wtoken.startingDisplayed = false;
3996 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003997
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003998 // If the token is currently hidden (should be the
3999 // common case), then we need to set up to wait for
4000 // its windows to be ready.
4001 if (wtoken.hidden) {
4002 wtoken.allDrawn = false;
4003 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004004
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004005 if (wtoken.clientHidden) {
4006 // In the case where we are making an app visible
4007 // but holding off for a transition, we still need
4008 // to tell the client to make its windows visible so
4009 // they get drawn. Otherwise, we will wait on
4010 // performing the transition until all windows have
4011 // been drawn, they never will be, and we are sad.
4012 wtoken.clientHidden = false;
4013 wtoken.sendAppVisibilityToClients();
4014 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004015 }
4016 } else {
4017 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004018
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004019 // If the token is currently visible (should be the
4020 // common case), then set up to wait for it to be hidden.
4021 if (!wtoken.hidden) {
4022 wtoken.waitingToHide = true;
4023 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004024 }
4025 return;
4026 }
Romain Guy06882f82009-06-10 13:36:04 -07004027
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004028 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004029 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004030 wtoken.updateReportedVisibilityLocked();
4031 Binder.restoreCallingIdentity(origId);
4032 }
4033 }
4034
4035 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4036 boolean unfreezeSurfaceNow, boolean force) {
4037 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004038 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004039 + " force=" + force);
4040 final int N = wtoken.allAppWindows.size();
4041 boolean unfrozeWindows = false;
4042 for (int i=0; i<N; i++) {
4043 WindowState w = wtoken.allAppWindows.get(i);
4044 if (w.mAppFreezing) {
4045 w.mAppFreezing = false;
4046 if (w.mSurface != null && !w.mOrientationChanging) {
4047 w.mOrientationChanging = true;
4048 }
4049 unfrozeWindows = true;
4050 }
4051 }
4052 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004053 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004054 wtoken.freezingScreen = false;
4055 mAppsFreezingScreen--;
4056 }
4057 if (unfreezeSurfaceNow) {
4058 if (unfrozeWindows) {
4059 mLayoutNeeded = true;
4060 performLayoutAndPlaceSurfacesLocked();
4061 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004062 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004063 }
4064 }
4065 }
Romain Guy06882f82009-06-10 13:36:04 -07004066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004067 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4068 int configChanges) {
4069 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004070 RuntimeException e = null;
4071 if (!HIDE_STACK_CRAWLS) {
4072 e = new RuntimeException();
4073 e.fillInStackTrace();
4074 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004075 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004076 + ": hidden=" + wtoken.hidden + " freezing="
4077 + wtoken.freezingScreen, e);
4078 }
4079 if (!wtoken.hiddenRequested) {
4080 if (!wtoken.freezingScreen) {
4081 wtoken.freezingScreen = true;
4082 mAppsFreezingScreen++;
4083 if (mAppsFreezingScreen == 1) {
4084 startFreezingDisplayLocked();
4085 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4086 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4087 5000);
4088 }
4089 }
4090 final int N = wtoken.allAppWindows.size();
4091 for (int i=0; i<N; i++) {
4092 WindowState w = wtoken.allAppWindows.get(i);
4093 w.mAppFreezing = true;
4094 }
4095 }
4096 }
Romain Guy06882f82009-06-10 13:36:04 -07004097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004098 public void startAppFreezingScreen(IBinder token, int configChanges) {
4099 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4100 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004101 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004102 }
4103
4104 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004105 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004106 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004107 return;
4108 }
Romain Guy06882f82009-06-10 13:36:04 -07004109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004110 AppWindowToken wtoken = findAppWindowToken(token);
4111 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004112 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004113 return;
4114 }
4115 final long origId = Binder.clearCallingIdentity();
4116 startAppFreezingScreenLocked(wtoken, configChanges);
4117 Binder.restoreCallingIdentity(origId);
4118 }
4119 }
Romain Guy06882f82009-06-10 13:36:04 -07004120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004121 public void stopAppFreezingScreen(IBinder token, boolean force) {
4122 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4123 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004124 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004125 }
4126
4127 synchronized(mWindowMap) {
4128 AppWindowToken wtoken = findAppWindowToken(token);
4129 if (wtoken == null || wtoken.appToken == null) {
4130 return;
4131 }
4132 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004133 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004134 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4135 unsetAppFreezingScreenLocked(wtoken, true, force);
4136 Binder.restoreCallingIdentity(origId);
4137 }
4138 }
Romain Guy06882f82009-06-10 13:36:04 -07004139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004140 public void removeAppToken(IBinder token) {
4141 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4142 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004143 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004144 }
4145
4146 AppWindowToken wtoken = null;
4147 AppWindowToken startingToken = null;
4148 boolean delayed = false;
4149
4150 final long origId = Binder.clearCallingIdentity();
4151 synchronized(mWindowMap) {
4152 WindowToken basewtoken = mTokenMap.remove(token);
4153 mTokenList.remove(basewtoken);
4154 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004155 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004156 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004157 wtoken.inPendingTransaction = false;
4158 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004159 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004160 if (mClosingApps.contains(wtoken)) {
4161 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004162 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004163 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004164 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004165 delayed = true;
4166 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004167 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004168 TAG, "Removing app " + wtoken + " delayed=" + delayed
4169 + " animation=" + wtoken.animation
4170 + " animating=" + wtoken.animating);
4171 if (delayed) {
4172 // set the token aside because it has an active animation to be finished
4173 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004174 } else {
4175 // Make sure there is no animation running on this token,
4176 // so any windows associated with it will be removed as
4177 // soon as their animations are complete
4178 wtoken.animation = null;
4179 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004180 }
4181 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07004182 if (mLastEnterAnimToken == wtoken) {
4183 mLastEnterAnimToken = null;
4184 mLastEnterAnimParams = null;
4185 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004186 wtoken.removed = true;
4187 if (wtoken.startingData != null) {
4188 startingToken = wtoken;
4189 }
4190 unsetAppFreezingScreenLocked(wtoken, true, true);
4191 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004192 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004193 mFocusedApp = null;
4194 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004195 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004196 }
4197 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004198 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004199 }
Romain Guy06882f82009-06-10 13:36:04 -07004200
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004201 if (!delayed && wtoken != null) {
4202 wtoken.updateReportedVisibilityLocked();
4203 }
4204 }
4205 Binder.restoreCallingIdentity(origId);
4206
4207 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004208 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004209 + startingToken + ": app token removed");
4210 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4211 mH.sendMessage(m);
4212 }
4213 }
4214
4215 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4216 final int NW = token.windows.size();
4217 for (int i=0; i<NW; i++) {
4218 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004219 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004220 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004221 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004222 int j = win.mChildWindows.size();
4223 while (j > 0) {
4224 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004225 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004226 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004227 "Tmp removing child window " + cwin);
4228 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004229 }
4230 }
4231 return NW > 0;
4232 }
4233
4234 void dumpAppTokensLocked() {
4235 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004236 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004237 }
4238 }
Romain Guy06882f82009-06-10 13:36:04 -07004239
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004240 void dumpWindowsLocked() {
4241 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004242 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004243 }
4244 }
Romain Guy06882f82009-06-10 13:36:04 -07004245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004246 private int findWindowOffsetLocked(int tokenPos) {
4247 final int NW = mWindows.size();
4248
4249 if (tokenPos >= mAppTokens.size()) {
4250 int i = NW;
4251 while (i > 0) {
4252 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004253 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004254 if (win.getAppToken() != null) {
4255 return i+1;
4256 }
4257 }
4258 }
4259
4260 while (tokenPos > 0) {
4261 // Find the first app token below the new position that has
4262 // a window displayed.
4263 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004264 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004265 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004266 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004267 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004268 "Skipping token -- currently sending to bottom");
4269 tokenPos--;
4270 continue;
4271 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004272 int i = wtoken.windows.size();
4273 while (i > 0) {
4274 i--;
4275 WindowState win = wtoken.windows.get(i);
4276 int j = win.mChildWindows.size();
4277 while (j > 0) {
4278 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004279 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004280 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004281 for (int pos=NW-1; pos>=0; pos--) {
4282 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004283 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004284 "Found child win @" + (pos+1));
4285 return pos+1;
4286 }
4287 }
4288 }
4289 }
4290 for (int pos=NW-1; pos>=0; pos--) {
4291 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004292 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004293 return pos+1;
4294 }
4295 }
4296 }
4297 tokenPos--;
4298 }
4299
4300 return 0;
4301 }
4302
4303 private final int reAddWindowLocked(int index, WindowState win) {
4304 final int NCW = win.mChildWindows.size();
4305 boolean added = false;
4306 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004307 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004308 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004309 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004310 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004311 mWindows.add(index, win);
4312 index++;
4313 added = true;
4314 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004315 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004316 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004317 mWindows.add(index, cwin);
4318 index++;
4319 }
4320 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004321 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004322 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004323 mWindows.add(index, win);
4324 index++;
4325 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004326 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004327 return index;
4328 }
Romain Guy06882f82009-06-10 13:36:04 -07004329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004330 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4331 final int NW = token.windows.size();
4332 for (int i=0; i<NW; i++) {
4333 index = reAddWindowLocked(index, token.windows.get(i));
4334 }
4335 return index;
4336 }
4337
4338 public void moveAppToken(int index, IBinder token) {
4339 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4340 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004341 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004342 }
4343
4344 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004345 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004346 if (DEBUG_REORDER) dumpAppTokensLocked();
4347 final AppWindowToken wtoken = findAppWindowToken(token);
4348 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004349 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004350 + token + " (" + wtoken + ")");
4351 return;
4352 }
4353 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004354 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004355 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004357 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004358 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004359 if (DEBUG_REORDER) dumpWindowsLocked();
4360 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004361 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004362 if (DEBUG_REORDER) dumpWindowsLocked();
4363 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004364 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004365 if (DEBUG_REORDER) dumpWindowsLocked();
4366 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004367 mLayoutNeeded = true;
4368 performLayoutAndPlaceSurfacesLocked();
4369 }
4370 Binder.restoreCallingIdentity(origId);
4371 }
4372 }
4373
4374 private void removeAppTokensLocked(List<IBinder> tokens) {
4375 // XXX This should be done more efficiently!
4376 // (take advantage of the fact that both lists should be
4377 // ordered in the same way.)
4378 int N = tokens.size();
4379 for (int i=0; i<N; i++) {
4380 IBinder token = tokens.get(i);
4381 final AppWindowToken wtoken = findAppWindowToken(token);
4382 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004383 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004384 + token + " (" + wtoken + ")");
4385 i--;
4386 N--;
4387 }
4388 }
4389 }
4390
Dianne Hackborna8f60182009-09-01 19:01:50 -07004391 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4392 boolean updateFocusAndLayout) {
4393 // First remove all of the windows from the list.
4394 tmpRemoveAppWindowsLocked(wtoken);
4395
4396 // Where to start adding?
4397 int pos = findWindowOffsetLocked(tokenPos);
4398
4399 // And now add them back at the correct place.
4400 pos = reAddAppWindowsLocked(pos, wtoken);
4401
4402 if (updateFocusAndLayout) {
4403 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4404 assignLayersLocked();
4405 }
4406 mLayoutNeeded = true;
4407 performLayoutAndPlaceSurfacesLocked();
4408 }
4409 }
4410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004411 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4412 // First remove all of the windows from the list.
4413 final int N = tokens.size();
4414 int i;
4415 for (i=0; i<N; i++) {
4416 WindowToken token = mTokenMap.get(tokens.get(i));
4417 if (token != null) {
4418 tmpRemoveAppWindowsLocked(token);
4419 }
4420 }
4421
4422 // Where to start adding?
4423 int pos = findWindowOffsetLocked(tokenPos);
4424
4425 // And now add them back at the correct place.
4426 for (i=0; i<N; i++) {
4427 WindowToken token = mTokenMap.get(tokens.get(i));
4428 if (token != null) {
4429 pos = reAddAppWindowsLocked(pos, token);
4430 }
4431 }
4432
Dianne Hackborna8f60182009-09-01 19:01:50 -07004433 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4434 assignLayersLocked();
4435 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004436 mLayoutNeeded = true;
4437 performLayoutAndPlaceSurfacesLocked();
4438
4439 //dump();
4440 }
4441
4442 public void moveAppTokensToTop(List<IBinder> tokens) {
4443 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4444 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004445 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004446 }
4447
4448 final long origId = Binder.clearCallingIdentity();
4449 synchronized(mWindowMap) {
4450 removeAppTokensLocked(tokens);
4451 final int N = tokens.size();
4452 for (int i=0; i<N; i++) {
4453 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4454 if (wt != null) {
4455 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004456 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004457 mToTopApps.remove(wt);
4458 mToBottomApps.remove(wt);
4459 mToTopApps.add(wt);
4460 wt.sendingToBottom = false;
4461 wt.sendingToTop = true;
4462 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004463 }
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, mAppTokens.size());
4468 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004469 }
4470 Binder.restoreCallingIdentity(origId);
4471 }
4472
4473 public void moveAppTokensToBottom(List<IBinder> tokens) {
4474 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4475 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004476 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004477 }
4478
4479 final long origId = Binder.clearCallingIdentity();
4480 synchronized(mWindowMap) {
4481 removeAppTokensLocked(tokens);
4482 final int N = tokens.size();
4483 int pos = 0;
4484 for (int i=0; i<N; i++) {
4485 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4486 if (wt != null) {
4487 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004488 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004489 mToTopApps.remove(wt);
4490 mToBottomApps.remove(wt);
4491 mToBottomApps.add(i, wt);
4492 wt.sendingToTop = false;
4493 wt.sendingToBottom = true;
4494 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004495 pos++;
4496 }
4497 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004498
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004499 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004500 moveAppWindowsLocked(tokens, 0);
4501 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004502 }
4503 Binder.restoreCallingIdentity(origId);
4504 }
4505
4506 // -------------------------------------------------------------
4507 // Misc IWindowSession methods
4508 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004509
Jim Miller284b62e2010-06-08 14:27:42 -07004510 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004511 {
Jim Miller284b62e2010-06-08 14:27:42 -07004512 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4513 // called before DevicePolicyManagerService has started.
4514 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4515 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4516 Context.DEVICE_POLICY_SERVICE);
4517 if (dpm != null) {
4518 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4519 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4520 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4521 }
Jim Millerd6b57052010-06-07 17:52:42 -07004522 }
Jim Miller284b62e2010-06-08 14:27:42 -07004523 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004524 }
4525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004526 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004527 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004528 != PackageManager.PERMISSION_GRANTED) {
4529 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4530 }
Jim Millerd6b57052010-06-07 17:52:42 -07004531
Jim Miller284b62e2010-06-08 14:27:42 -07004532 synchronized (mKeyguardTokenWatcher) {
4533 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004534 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004535 }
4536
4537 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004538 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004539 != PackageManager.PERMISSION_GRANTED) {
4540 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4541 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004542
Jim Miller284b62e2010-06-08 14:27:42 -07004543 synchronized (mKeyguardTokenWatcher) {
4544 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004545
Jim Miller284b62e2010-06-08 14:27:42 -07004546 if (!mKeyguardTokenWatcher.isAcquired()) {
4547 // If we are the last one to reenable the keyguard wait until
4548 // we have actually finished reenabling until returning.
4549 // It is possible that reenableKeyguard() can be called before
4550 // the previous disableKeyguard() is handled, in which case
4551 // neither mKeyguardTokenWatcher.acquired() or released() would
4552 // be called. In that case mKeyguardDisabled will be false here
4553 // and we have nothing to wait for.
4554 while (mKeyguardDisabled) {
4555 try {
4556 mKeyguardTokenWatcher.wait();
4557 } catch (InterruptedException e) {
4558 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004559 }
4560 }
4561 }
4562 }
4563 }
4564
4565 /**
4566 * @see android.app.KeyguardManager#exitKeyguardSecurely
4567 */
4568 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004569 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004570 != PackageManager.PERMISSION_GRANTED) {
4571 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4572 }
4573 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4574 public void onKeyguardExitResult(boolean success) {
4575 try {
4576 callback.onKeyguardExitResult(success);
4577 } catch (RemoteException e) {
4578 // Client has died, we don't care.
4579 }
4580 }
4581 });
4582 }
4583
4584 public boolean inKeyguardRestrictedInputMode() {
4585 return mPolicy.inKeyguardRestrictedKeyInputMode();
4586 }
Romain Guy06882f82009-06-10 13:36:04 -07004587
Dianne Hackbornffa42482009-09-23 22:20:11 -07004588 public void closeSystemDialogs(String reason) {
4589 synchronized(mWindowMap) {
4590 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004591 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004592 if (w.mSurface != null) {
4593 try {
4594 w.mClient.closeSystemDialogs(reason);
4595 } catch (RemoteException e) {
4596 }
4597 }
4598 }
4599 }
4600 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004602 static float fixScale(float scale) {
4603 if (scale < 0) scale = 0;
4604 else if (scale > 20) scale = 20;
4605 return Math.abs(scale);
4606 }
Romain Guy06882f82009-06-10 13:36:04 -07004607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004608 public void setAnimationScale(int which, float scale) {
4609 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4610 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004611 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004612 }
4613
4614 if (scale < 0) scale = 0;
4615 else if (scale > 20) scale = 20;
4616 scale = Math.abs(scale);
4617 switch (which) {
4618 case 0: mWindowAnimationScale = fixScale(scale); break;
4619 case 1: mTransitionAnimationScale = fixScale(scale); break;
4620 }
Romain Guy06882f82009-06-10 13:36:04 -07004621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004622 // Persist setting
4623 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4624 }
Romain Guy06882f82009-06-10 13:36:04 -07004625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004626 public void setAnimationScales(float[] scales) {
4627 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4628 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004629 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004630 }
4631
4632 if (scales != null) {
4633 if (scales.length >= 1) {
4634 mWindowAnimationScale = fixScale(scales[0]);
4635 }
4636 if (scales.length >= 2) {
4637 mTransitionAnimationScale = fixScale(scales[1]);
4638 }
4639 }
Romain Guy06882f82009-06-10 13:36:04 -07004640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004641 // Persist setting
4642 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4643 }
Romain Guy06882f82009-06-10 13:36:04 -07004644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004645 public float getAnimationScale(int which) {
4646 switch (which) {
4647 case 0: return mWindowAnimationScale;
4648 case 1: return mTransitionAnimationScale;
4649 }
4650 return 0;
4651 }
Romain Guy06882f82009-06-10 13:36:04 -07004652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004653 public float[] getAnimationScales() {
4654 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4655 }
Romain Guy06882f82009-06-10 13:36:04 -07004656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004657 public int getSwitchState(int sw) {
4658 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4659 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004660 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004661 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004662 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004663 }
Romain Guy06882f82009-06-10 13:36:04 -07004664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004665 public int getSwitchStateForDevice(int devid, int sw) {
4666 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4667 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004668 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004669 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004670 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004671 }
Romain Guy06882f82009-06-10 13:36:04 -07004672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004673 public int getScancodeState(int sw) {
4674 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4675 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004676 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004677 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004678 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004679 }
Romain Guy06882f82009-06-10 13:36:04 -07004680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004681 public int getScancodeStateForDevice(int devid, int sw) {
4682 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4683 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004684 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004685 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004686 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004687 }
Romain Guy06882f82009-06-10 13:36:04 -07004688
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004689 public int getTrackballScancodeState(int sw) {
4690 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4691 "getTrackballScancodeState()")) {
4692 throw new SecurityException("Requires READ_INPUT_STATE permission");
4693 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004694 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004695 }
4696
4697 public int getDPadScancodeState(int sw) {
4698 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4699 "getDPadScancodeState()")) {
4700 throw new SecurityException("Requires READ_INPUT_STATE permission");
4701 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004702 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004703 }
4704
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004705 public int getKeycodeState(int sw) {
4706 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4707 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004708 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004709 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004710 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004711 }
Romain Guy06882f82009-06-10 13:36:04 -07004712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004713 public int getKeycodeStateForDevice(int devid, int sw) {
4714 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4715 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004716 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004717 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004718 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004719 }
Romain Guy06882f82009-06-10 13:36:04 -07004720
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004721 public int getTrackballKeycodeState(int sw) {
4722 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4723 "getTrackballKeycodeState()")) {
4724 throw new SecurityException("Requires READ_INPUT_STATE permission");
4725 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004726 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004727 }
4728
4729 public int getDPadKeycodeState(int sw) {
4730 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4731 "getDPadKeycodeState()")) {
4732 throw new SecurityException("Requires READ_INPUT_STATE permission");
4733 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004734 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004735 }
Jeff Browna41ca772010-08-11 14:46:32 -07004736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004737 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004738 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004739 }
Romain Guy06882f82009-06-10 13:36:04 -07004740
Jeff Browna41ca772010-08-11 14:46:32 -07004741 public InputChannel monitorInput(String inputChannelName) {
4742 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4743 "monitorInput()")) {
4744 throw new SecurityException("Requires READ_INPUT_STATE permission");
4745 }
4746 return mInputManager.monitorInput(inputChannelName);
4747 }
4748
Jeff Brown8d608662010-08-30 03:02:23 -07004749 public InputDevice getInputDevice(int deviceId) {
4750 return mInputManager.getInputDevice(deviceId);
4751 }
4752
4753 public int[] getInputDeviceIds() {
4754 return mInputManager.getInputDeviceIds();
4755 }
4756
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004757 public void enableScreenAfterBoot() {
4758 synchronized(mWindowMap) {
4759 if (mSystemBooted) {
4760 return;
4761 }
4762 mSystemBooted = true;
4763 }
Romain Guy06882f82009-06-10 13:36:04 -07004764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004765 performEnableScreen();
4766 }
Romain Guy06882f82009-06-10 13:36:04 -07004767
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004768 public void enableScreenIfNeededLocked() {
4769 if (mDisplayEnabled) {
4770 return;
4771 }
4772 if (!mSystemBooted) {
4773 return;
4774 }
4775 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4776 }
Romain Guy06882f82009-06-10 13:36:04 -07004777
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004778 public void performEnableScreen() {
4779 synchronized(mWindowMap) {
4780 if (mDisplayEnabled) {
4781 return;
4782 }
4783 if (!mSystemBooted) {
4784 return;
4785 }
Romain Guy06882f82009-06-10 13:36:04 -07004786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004787 // Don't enable the screen until all existing windows
4788 // have been drawn.
4789 final int N = mWindows.size();
4790 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004791 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004792 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004793 return;
4794 }
4795 }
Romain Guy06882f82009-06-10 13:36:04 -07004796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004797 mDisplayEnabled = true;
4798 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004799 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004800 StringWriter sw = new StringWriter();
4801 PrintWriter pw = new PrintWriter(sw);
4802 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004803 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004804 }
4805 try {
4806 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4807 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004808 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004809 Parcel data = Parcel.obtain();
4810 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4811 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4812 data, null, 0);
4813 data.recycle();
4814 }
4815 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004816 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004817 }
4818 }
Romain Guy06882f82009-06-10 13:36:04 -07004819
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004820 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004821
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004822 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004823 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4824 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004825 }
Romain Guy06882f82009-06-10 13:36:04 -07004826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004827 public void setInTouchMode(boolean mode) {
4828 synchronized(mWindowMap) {
4829 mInTouchMode = mode;
4830 }
4831 }
4832
Romain Guy06882f82009-06-10 13:36:04 -07004833 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004834 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004835 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004836 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004837 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004838 }
4839
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004840 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004841 }
Romain Guy06882f82009-06-10 13:36:04 -07004842
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004843 public void setRotationUnchecked(int rotation,
4844 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004845 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004846 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004848 long origId = Binder.clearCallingIdentity();
4849 boolean changed;
4850 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004851 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004852 }
Romain Guy06882f82009-06-10 13:36:04 -07004853
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004854 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004855 sendNewConfiguration();
4856 }
Romain Guy06882f82009-06-10 13:36:04 -07004857
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004858 Binder.restoreCallingIdentity(origId);
4859 }
Romain Guy06882f82009-06-10 13:36:04 -07004860
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004861 /**
4862 * Apply a new rotation to the screen, respecting the requests of
4863 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4864 * re-evaluate the desired rotation.
4865 *
4866 * Returns null if the rotation has been changed. In this case YOU
4867 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4868 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004869 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004870 boolean changed;
4871 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4872 rotation = mRequestedRotation;
4873 } else {
4874 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004875 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004876 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004877 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004878 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004879 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004880 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004881 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004883 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004884 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004885 "Rotation changed to " + rotation
4886 + " from " + mRotation
4887 + " (forceApp=" + mForcedAppOrientation
4888 + ", req=" + mRequestedRotation + ")");
4889 mRotation = rotation;
4890 mWindowsFreezingScreen = true;
4891 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4892 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4893 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004894 mWaitingForConfig = true;
4895 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004896 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004897 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004898 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004899 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004900 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004901 }
4902 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004903 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004904 if (w.mSurface != null) {
4905 w.mOrientationChanging = true;
4906 }
4907 }
4908 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4909 try {
4910 mRotationWatchers.get(i).onRotationChanged(rotation);
4911 } catch (RemoteException e) {
4912 }
4913 }
4914 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004916 return changed;
4917 }
Romain Guy06882f82009-06-10 13:36:04 -07004918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004919 public int getRotation() {
4920 return mRotation;
4921 }
4922
4923 public int watchRotation(IRotationWatcher watcher) {
4924 final IBinder watcherBinder = watcher.asBinder();
4925 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4926 public void binderDied() {
4927 synchronized (mWindowMap) {
4928 for (int i=0; i<mRotationWatchers.size(); i++) {
4929 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004930 IRotationWatcher removed = mRotationWatchers.remove(i);
4931 if (removed != null) {
4932 removed.asBinder().unlinkToDeath(this, 0);
4933 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004934 i--;
4935 }
4936 }
4937 }
4938 }
4939 };
Romain Guy06882f82009-06-10 13:36:04 -07004940
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004941 synchronized (mWindowMap) {
4942 try {
4943 watcher.asBinder().linkToDeath(dr, 0);
4944 mRotationWatchers.add(watcher);
4945 } catch (RemoteException e) {
4946 // Client died, no cleanup needed.
4947 }
Romain Guy06882f82009-06-10 13:36:04 -07004948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004949 return mRotation;
4950 }
4951 }
4952
4953 /**
4954 * Starts the view server on the specified port.
4955 *
4956 * @param port The port to listener to.
4957 *
4958 * @return True if the server was successfully started, false otherwise.
4959 *
4960 * @see com.android.server.ViewServer
4961 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4962 */
4963 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004964 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004965 return false;
4966 }
4967
4968 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4969 return false;
4970 }
4971
4972 if (port < 1024) {
4973 return false;
4974 }
4975
4976 if (mViewServer != null) {
4977 if (!mViewServer.isRunning()) {
4978 try {
4979 return mViewServer.start();
4980 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004981 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004982 }
4983 }
4984 return false;
4985 }
4986
4987 try {
4988 mViewServer = new ViewServer(this, port);
4989 return mViewServer.start();
4990 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004991 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004992 }
4993 return false;
4994 }
4995
Romain Guy06882f82009-06-10 13:36:04 -07004996 private boolean isSystemSecure() {
4997 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4998 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4999 }
5000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005001 /**
5002 * Stops the view server if it exists.
5003 *
5004 * @return True if the server stopped, false if it wasn't started or
5005 * couldn't be stopped.
5006 *
5007 * @see com.android.server.ViewServer
5008 */
5009 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005010 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005011 return false;
5012 }
5013
5014 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5015 return false;
5016 }
5017
5018 if (mViewServer != null) {
5019 return mViewServer.stop();
5020 }
5021 return false;
5022 }
5023
5024 /**
5025 * Indicates whether the view server is running.
5026 *
5027 * @return True if the server is running, false otherwise.
5028 *
5029 * @see com.android.server.ViewServer
5030 */
5031 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005032 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005033 return false;
5034 }
5035
5036 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5037 return false;
5038 }
5039
5040 return mViewServer != null && mViewServer.isRunning();
5041 }
5042
5043 /**
5044 * Lists all availble windows in the system. The listing is written in the
5045 * specified Socket's output stream with the following syntax:
5046 * windowHashCodeInHexadecimal windowName
5047 * Each line of the ouput represents a different window.
5048 *
5049 * @param client The remote client to send the listing to.
5050 * @return False if an error occured, true otherwise.
5051 */
5052 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005053 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005054 return false;
5055 }
5056
5057 boolean result = true;
5058
Jeff Browne33348b2010-07-15 23:54:05 -07005059 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005060 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005061 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005062 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005063 }
5064
5065 BufferedWriter out = null;
5066
5067 // Any uncaught exception will crash the system process
5068 try {
5069 OutputStream clientStream = client.getOutputStream();
5070 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5071
5072 final int count = windows.length;
5073 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005074 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005075 out.write(Integer.toHexString(System.identityHashCode(w)));
5076 out.write(' ');
5077 out.append(w.mAttrs.getTitle());
5078 out.write('\n');
5079 }
5080
5081 out.write("DONE.\n");
5082 out.flush();
5083 } catch (Exception e) {
5084 result = false;
5085 } finally {
5086 if (out != null) {
5087 try {
5088 out.close();
5089 } catch (IOException e) {
5090 result = false;
5091 }
5092 }
5093 }
5094
5095 return result;
5096 }
5097
5098 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005099 * Returns the focused window in the following format:
5100 * windowHashCodeInHexadecimal windowName
5101 *
5102 * @param client The remote client to send the listing to.
5103 * @return False if an error occurred, true otherwise.
5104 */
5105 boolean viewServerGetFocusedWindow(Socket client) {
5106 if (isSystemSecure()) {
5107 return false;
5108 }
5109
5110 boolean result = true;
5111
5112 WindowState focusedWindow = getFocusedWindow();
5113
5114 BufferedWriter out = null;
5115
5116 // Any uncaught exception will crash the system process
5117 try {
5118 OutputStream clientStream = client.getOutputStream();
5119 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5120
5121 if(focusedWindow != null) {
5122 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5123 out.write(' ');
5124 out.append(focusedWindow.mAttrs.getTitle());
5125 }
5126 out.write('\n');
5127 out.flush();
5128 } catch (Exception e) {
5129 result = false;
5130 } finally {
5131 if (out != null) {
5132 try {
5133 out.close();
5134 } catch (IOException e) {
5135 result = false;
5136 }
5137 }
5138 }
5139
5140 return result;
5141 }
5142
5143 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005144 * Sends a command to a target window. The result of the command, if any, will be
5145 * written in the output stream of the specified socket.
5146 *
5147 * The parameters must follow this syntax:
5148 * windowHashcode extra
5149 *
5150 * Where XX is the length in characeters of the windowTitle.
5151 *
5152 * The first parameter is the target window. The window with the specified hashcode
5153 * will be the target. If no target can be found, nothing happens. The extra parameters
5154 * will be delivered to the target window and as parameters to the command itself.
5155 *
5156 * @param client The remote client to sent the result, if any, to.
5157 * @param command The command to execute.
5158 * @param parameters The command parameters.
5159 *
5160 * @return True if the command was successfully delivered, false otherwise. This does
5161 * not indicate whether the command itself was successful.
5162 */
5163 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005164 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005165 return false;
5166 }
5167
5168 boolean success = true;
5169 Parcel data = null;
5170 Parcel reply = null;
5171
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005172 BufferedWriter out = null;
5173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005174 // Any uncaught exception will crash the system process
5175 try {
5176 // Find the hashcode of the window
5177 int index = parameters.indexOf(' ');
5178 if (index == -1) {
5179 index = parameters.length();
5180 }
5181 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005182 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005183
5184 // Extract the command's parameter after the window description
5185 if (index < parameters.length()) {
5186 parameters = parameters.substring(index + 1);
5187 } else {
5188 parameters = "";
5189 }
5190
5191 final WindowManagerService.WindowState window = findWindow(hashCode);
5192 if (window == null) {
5193 return false;
5194 }
5195
5196 data = Parcel.obtain();
5197 data.writeInterfaceToken("android.view.IWindow");
5198 data.writeString(command);
5199 data.writeString(parameters);
5200 data.writeInt(1);
5201 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5202
5203 reply = Parcel.obtain();
5204
5205 final IBinder binder = window.mClient.asBinder();
5206 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5207 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5208
5209 reply.readException();
5210
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005211 if (!client.isOutputShutdown()) {
5212 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5213 out.write("DONE\n");
5214 out.flush();
5215 }
5216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005217 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005218 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005219 success = false;
5220 } finally {
5221 if (data != null) {
5222 data.recycle();
5223 }
5224 if (reply != null) {
5225 reply.recycle();
5226 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005227 if (out != null) {
5228 try {
5229 out.close();
5230 } catch (IOException e) {
5231
5232 }
5233 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005234 }
5235
5236 return success;
5237 }
5238
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005239 public void addWindowChangeListener(WindowChangeListener listener) {
5240 synchronized(mWindowMap) {
5241 mWindowChangeListeners.add(listener);
5242 }
5243 }
5244
5245 public void removeWindowChangeListener(WindowChangeListener listener) {
5246 synchronized(mWindowMap) {
5247 mWindowChangeListeners.remove(listener);
5248 }
5249 }
5250
5251 private void notifyWindowsChanged() {
5252 WindowChangeListener[] windowChangeListeners;
5253 synchronized(mWindowMap) {
5254 if(mWindowChangeListeners.isEmpty()) {
5255 return;
5256 }
5257 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5258 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5259 }
5260 int N = windowChangeListeners.length;
5261 for(int i = 0; i < N; i++) {
5262 windowChangeListeners[i].windowsChanged();
5263 }
5264 }
5265
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005266 private void notifyFocusChanged() {
5267 WindowChangeListener[] windowChangeListeners;
5268 synchronized(mWindowMap) {
5269 if(mWindowChangeListeners.isEmpty()) {
5270 return;
5271 }
5272 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5273 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5274 }
5275 int N = windowChangeListeners.length;
5276 for(int i = 0; i < N; i++) {
5277 windowChangeListeners[i].focusChanged();
5278 }
5279 }
5280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005281 private WindowState findWindow(int hashCode) {
5282 if (hashCode == -1) {
5283 return getFocusedWindow();
5284 }
5285
5286 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005287 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005288 final int count = windows.size();
5289
5290 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005291 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005292 if (System.identityHashCode(w) == hashCode) {
5293 return w;
5294 }
5295 }
5296 }
5297
5298 return null;
5299 }
5300
5301 /*
5302 * Instruct the Activity Manager to fetch the current configuration and broadcast
5303 * that to config-changed listeners if appropriate.
5304 */
5305 void sendNewConfiguration() {
5306 try {
5307 mActivityManager.updateConfiguration(null);
5308 } catch (RemoteException e) {
5309 }
5310 }
Romain Guy06882f82009-06-10 13:36:04 -07005311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005312 public Configuration computeNewConfiguration() {
5313 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07005314 return computeNewConfigurationLocked();
5315 }
5316 }
Romain Guy06882f82009-06-10 13:36:04 -07005317
Dianne Hackbornc485a602009-03-24 22:39:49 -07005318 Configuration computeNewConfigurationLocked() {
5319 Configuration config = new Configuration();
5320 if (!computeNewConfigurationLocked(config)) {
5321 return null;
5322 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005323 return config;
5324 }
Romain Guy06882f82009-06-10 13:36:04 -07005325
Dianne Hackbornc485a602009-03-24 22:39:49 -07005326 boolean computeNewConfigurationLocked(Configuration config) {
5327 if (mDisplay == null) {
5328 return false;
5329 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005330
5331 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005332
5333 // Use the effective "visual" dimensions based on current rotation
5334 final boolean rotated = (mRotation == Surface.ROTATION_90
5335 || mRotation == Surface.ROTATION_270);
5336 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5337 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5338
Dianne Hackbornc485a602009-03-24 22:39:49 -07005339 int orientation = Configuration.ORIENTATION_SQUARE;
5340 if (dw < dh) {
5341 orientation = Configuration.ORIENTATION_PORTRAIT;
5342 } else if (dw > dh) {
5343 orientation = Configuration.ORIENTATION_LANDSCAPE;
5344 }
5345 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005346
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005347 DisplayMetrics dm = new DisplayMetrics();
5348 mDisplay.getMetrics(dm);
5349 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5350
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005351 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005352 // Note we only do this once because at this point we don't
5353 // expect the screen to change in this way at runtime, and want
5354 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005355 int longSize = dw;
5356 int shortSize = dh;
5357 if (longSize < shortSize) {
5358 int tmp = longSize;
5359 longSize = shortSize;
5360 shortSize = tmp;
5361 }
5362 longSize = (int)(longSize/dm.density);
5363 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005364
Dianne Hackborn723738c2009-06-25 19:48:04 -07005365 // These semi-magic numbers define our compatibility modes for
5366 // applications with different screens. Don't change unless you
5367 // make sure to test lots and lots of apps!
5368 if (longSize < 470) {
5369 // This is shorter than an HVGA normal density screen (which
5370 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005371 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5372 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005373 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005374 // What size is this screen screen?
5375 if (longSize >= 800 && shortSize >= 600) {
5376 // SVGA or larger screens at medium density are the point
5377 // at which we consider it to be an extra large screen.
5378 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
5379 } else if (longSize >= 640 && shortSize >= 480) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005380 // VGA or larger screens at medium density are the point
5381 // at which we consider it to be a large screen.
5382 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5383 } else {
5384 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005385
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005386 // If this screen is wider than normal HVGA, or taller
5387 // than FWVGA, then for old apps we want to run in size
5388 // compatibility mode.
5389 if (shortSize > 321 || longSize > 570) {
5390 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5391 }
5392 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005393
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005394 // Is this a long screen?
5395 if (((longSize*3)/5) >= (shortSize-1)) {
5396 // Anything wider than WVGA (5:3) is considering to be long.
5397 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5398 } else {
5399 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5400 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005401 }
5402 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005403 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005404
Dianne Hackbornc485a602009-03-24 22:39:49 -07005405 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5406 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5407 mPolicy.adjustConfigurationLw(config);
5408 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005409 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005410
5411 // -------------------------------------------------------------
5412 // Drag and drop
5413 // -------------------------------------------------------------
5414
5415 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
5416 boolean localOnly, int width, int height, Surface outSurface) {
5417 if (DEBUG_DRAG) {
5418 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
5419 + " local=" + localOnly + " win=" + window
5420 + " asbinder=" + window.asBinder());
5421 }
5422
5423 final int callerPid = Binder.getCallingPid();
5424 final long origId = Binder.clearCallingIdentity();
5425 IBinder token = null;
5426
5427 try {
5428 synchronized (mWindowMap) {
5429 try {
5430 // !!! TODO: fail if the given window does not currently have touch focus?
5431
5432 if (mDragState == null) {
5433 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5434 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5435 outSurface.copyFrom(surface);
5436 token = new Binder();
5437 mDragState = new DragState(token, surface, localOnly);
5438 mDragState.mSurface = surface;
5439 mDragState.mLocalOnly = localOnly;
5440 token = mDragState.mToken = new Binder();
5441
5442 // 5 second timeout for this window to actually begin the drag
5443 mH.removeMessages(H.DRAG_START_TIMEOUT, window);
5444 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, window.asBinder());
5445 mH.sendMessageDelayed(msg, 5000);
5446 } else {
5447 Slog.w(TAG, "Drag already in progress");
5448 }
5449 } catch (Surface.OutOfResourcesException e) {
5450 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5451 if (mDragState != null) {
5452 mDragState.reset();
5453 mDragState = null;
5454 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005455 }
5456 }
5457 } finally {
5458 Binder.restoreCallingIdentity(origId);
5459 }
5460
5461 return token;
5462 }
5463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005464 // -------------------------------------------------------------
5465 // Input Events and Focus Management
5466 // -------------------------------------------------------------
Jeff Brown46b9ac02010-04-22 18:58:52 -07005467
Jeff Brown349703e2010-06-22 01:27:15 -07005468 InputMonitor mInputMonitor = new InputMonitor();
5469
5470 /* Tracks the progress of input dispatch and ensures that input dispatch state
5471 * is kept in sync with changes in window focus, visibility, registration, and
5472 * other relevant Window Manager state transitions. */
5473 final class InputMonitor {
5474 // Current window with input focus for keys and other non-touch events. May be null.
5475 private WindowState mInputFocus;
5476
5477 // When true, prevents input dispatch from proceeding until set to false again.
5478 private boolean mInputDispatchFrozen;
5479
5480 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5481 private boolean mInputDispatchEnabled = true;
5482
5483 // Temporary list of windows information to provide to the input dispatcher.
5484 private InputWindowList mTempInputWindows = new InputWindowList();
5485
5486 // Temporary input application object to provide to the input dispatcher.
5487 private InputApplication mTempInputApplication = new InputApplication();
5488
5489 /* Notifies the window manager about a broken input channel.
5490 *
5491 * Called by the InputManager.
5492 */
5493 public void notifyInputChannelBroken(InputChannel inputChannel) {
5494 synchronized (mWindowMap) {
5495 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5496 if (windowState == null) {
5497 return; // irrelevant
5498 }
5499
5500 Slog.i(TAG, "WINDOW DIED " + windowState);
5501 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005502 }
5503 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005504
Jeff Brown519e0242010-09-15 15:18:56 -07005505 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005506 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005507 *
5508 * Called by the InputManager.
5509 */
Jeff Brown519e0242010-09-15 15:18:56 -07005510 public long notifyANR(Object token, InputChannel inputChannel) {
5511 AppWindowToken appWindowToken = null;
5512 if (inputChannel != null) {
5513 synchronized (mWindowMap) {
5514 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5515 if (windowState != null) {
5516 Slog.i(TAG, "Input event dispatching timed out sending to "
5517 + windowState.mAttrs.getTitle());
5518 appWindowToken = windowState.mAppToken;
5519 }
Jeff Brown349703e2010-06-22 01:27:15 -07005520 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005521 }
5522
Jeff Brown519e0242010-09-15 15:18:56 -07005523 if (appWindowToken == null && token != null) {
5524 appWindowToken = (AppWindowToken) token;
5525 Slog.i(TAG, "Input event dispatching timed out sending to application "
5526 + appWindowToken.stringName);
5527 }
Jeff Brown349703e2010-06-22 01:27:15 -07005528
Jeff Brown519e0242010-09-15 15:18:56 -07005529 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005530 try {
5531 // Notify the activity manager about the timeout and let it decide whether
5532 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005533 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005534 if (! abort) {
5535 // The activity manager declined to abort dispatching.
5536 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005537 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005538 }
Jeff Brown349703e2010-06-22 01:27:15 -07005539 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005540 }
5541 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005542 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005543 }
5544
Jeff Brown349703e2010-06-22 01:27:15 -07005545 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5546 synchronized (mWindowMap) {
5547 return getWindowStateForInputChannelLocked(inputChannel);
5548 }
5549 }
5550
5551 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5552 int windowCount = mWindows.size();
5553 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005554 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005555 if (windowState.mInputChannel == inputChannel) {
5556 return windowState;
5557 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005558 }
5559
Jeff Brown349703e2010-06-22 01:27:15 -07005560 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005561 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005562
Chris Tatea32dcf72010-10-14 12:13:50 -07005563 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005564 final InputWindow inputWindow = windowList.add();
5565 inputWindow.inputChannel = mDragState.mServerChannel;
5566 inputWindow.name = "drag";
5567 inputWindow.layoutParamsFlags = 0;
5568 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5569 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5570 inputWindow.visible = true;
5571 inputWindow.canReceiveKeys = false;
5572 inputWindow.hasFocus = true;
5573 inputWindow.hasWallpaper = false;
5574 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005575 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005576 inputWindow.ownerPid = Process.myPid();
5577 inputWindow.ownerUid = Process.myUid();
5578
5579 // The drag window covers the entire display
5580 inputWindow.frameLeft = 0;
5581 inputWindow.frameTop = 0;
5582 inputWindow.frameRight = mDisplay.getWidth();
5583 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005584
Christopher Tatea53146c2010-09-07 11:57:52 -07005585 inputWindow.visibleFrameLeft = inputWindow.frameLeft;
5586 inputWindow.visibleFrameTop = inputWindow.frameTop;
5587 inputWindow.visibleFrameRight = inputWindow.frameRight;
5588 inputWindow.visibleFrameBottom = inputWindow.frameBottom;
5589
5590 inputWindow.touchableAreaLeft = inputWindow.frameLeft;
5591 inputWindow.touchableAreaTop = inputWindow.frameTop;
5592 inputWindow.touchableAreaRight = inputWindow.frameRight;
5593 inputWindow.touchableAreaBottom = inputWindow.frameBottom;
5594 }
5595
Jeff Brown349703e2010-06-22 01:27:15 -07005596 /* Updates the cached window information provided to the input dispatcher. */
5597 public void updateInputWindowsLw() {
5598 // Populate the input window list with information about all of the windows that
5599 // could potentially receive input.
5600 // As an optimization, we could try to prune the list of windows but this turns
5601 // out to be difficult because only the native code knows for sure which window
5602 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005603 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005604
5605 // If there's a drag in flight, provide a pseudowindow to catch drag input
5606 final boolean inDrag = (mDragState != null);
5607 if (inDrag) {
5608 if (DEBUG_DRAG) {
5609 Log.d(TAG, "Inserting drag window");
5610 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005611 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005612 }
5613
Jeff Brown7fbdc842010-06-17 20:52:56 -07005614 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005615 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005616 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005617 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005618 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005619 continue;
5620 }
5621
Jeff Brown349703e2010-06-22 01:27:15 -07005622 final int flags = child.mAttrs.flags;
5623 final int type = child.mAttrs.type;
5624
5625 final boolean hasFocus = (child == mInputFocus);
5626 final boolean isVisible = child.isVisibleLw();
5627 final boolean hasWallpaper = (child == mWallpaperTarget)
5628 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005629
5630 // If there's a drag in progress and 'child' is a potential drop target,
5631 // make sure it's been told about the drag
5632 if (inDrag && isVisible) {
5633 mDragState.sendDragStartedIfNeededLw(child);
5634 }
5635
Jeff Brown349703e2010-06-22 01:27:15 -07005636 // Add a window to our list of input windows.
5637 final InputWindow inputWindow = mTempInputWindows.add();
5638 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005639 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005640 inputWindow.layoutParamsFlags = flags;
5641 inputWindow.layoutParamsType = type;
5642 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5643 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005644 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005645 inputWindow.hasFocus = hasFocus;
5646 inputWindow.hasWallpaper = hasWallpaper;
5647 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005648 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005649 inputWindow.ownerPid = child.mSession.mPid;
5650 inputWindow.ownerUid = child.mSession.mUid;
5651
5652 final Rect frame = child.mFrame;
5653 inputWindow.frameLeft = frame.left;
5654 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005655 inputWindow.frameRight = frame.right;
5656 inputWindow.frameBottom = frame.bottom;
5657
5658 final Rect visibleFrame = child.mVisibleFrame;
5659 inputWindow.visibleFrameLeft = visibleFrame.left;
5660 inputWindow.visibleFrameTop = visibleFrame.top;
5661 inputWindow.visibleFrameRight = visibleFrame.right;
5662 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005663
5664 switch (child.mTouchableInsets) {
5665 default:
5666 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5667 inputWindow.touchableAreaLeft = frame.left;
5668 inputWindow.touchableAreaTop = frame.top;
5669 inputWindow.touchableAreaRight = frame.right;
5670 inputWindow.touchableAreaBottom = frame.bottom;
5671 break;
5672
5673 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5674 Rect inset = child.mGivenContentInsets;
5675 inputWindow.touchableAreaLeft = frame.left + inset.left;
5676 inputWindow.touchableAreaTop = frame.top + inset.top;
5677 inputWindow.touchableAreaRight = frame.right - inset.right;
5678 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5679 break;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005680 }
Jeff Brown349703e2010-06-22 01:27:15 -07005681
5682 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5683 Rect inset = child.mGivenVisibleInsets;
5684 inputWindow.touchableAreaLeft = frame.left + inset.left;
5685 inputWindow.touchableAreaTop = frame.top + inset.top;
5686 inputWindow.touchableAreaRight = frame.right - inset.right;
5687 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005688 break;
5689 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005690 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005691 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005692
Jeff Brown349703e2010-06-22 01:27:15 -07005693 // Send windows to native code.
5694 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac02010-04-22 18:58:52 -07005695
Jeff Brown349703e2010-06-22 01:27:15 -07005696 // Clear the list in preparation for the next round.
5697 // Also avoids keeping InputChannel objects referenced unnecessarily.
5698 mTempInputWindows.clear();
5699 }
5700
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005701 /* Notifies that the lid switch changed state. */
5702 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5703 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5704 }
5705
Jeff Brown349703e2010-06-22 01:27:15 -07005706 /* Provides an opportunity for the window manager policy to intercept early key
5707 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005708 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5709 int policyFlags, boolean isScreenOn) {
5710 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5711 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005712 }
5713
5714 /* Provides an opportunity for the window manager policy to process a key before
5715 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005716 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5717 int action, int flags, int keyCode, int metaState, int repeatCount,
5718 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005719 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005720 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5721 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005722 }
5723
5724 /* Called when the current input focus changes.
5725 * Layer assignment is assumed to be complete by the time this is called.
5726 */
5727 public void setInputFocusLw(WindowState newWindow) {
5728 if (DEBUG_INPUT) {
5729 Slog.d(TAG, "Input focus has changed to " + newWindow);
5730 }
5731
5732 if (newWindow != mInputFocus) {
5733 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005734 // Displaying a window implicitly causes dispatching to be unpaused.
5735 // This is to protect against bugs if someone pauses dispatching but
5736 // forgets to resume.
5737 newWindow.mToken.paused = false;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005738 }
Jeff Brown349703e2010-06-22 01:27:15 -07005739
5740 mInputFocus = newWindow;
5741 updateInputWindowsLw();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005742 }
5743 }
5744
Jeff Brown349703e2010-06-22 01:27:15 -07005745 public void setFocusedAppLw(AppWindowToken newApp) {
5746 // Focused app has changed.
5747 if (newApp == null) {
5748 mInputManager.setFocusedApplication(null);
5749 } else {
5750 mTempInputApplication.name = newApp.toString();
5751 mTempInputApplication.dispatchingTimeoutNanos =
5752 newApp.inputDispatchingTimeoutNanos;
5753 mTempInputApplication.token = newApp;
5754
5755 mInputManager.setFocusedApplication(mTempInputApplication);
5756 }
5757 }
5758
Jeff Brown349703e2010-06-22 01:27:15 -07005759 public void pauseDispatchingLw(WindowToken window) {
5760 if (! window.paused) {
5761 if (DEBUG_INPUT) {
5762 Slog.v(TAG, "Pausing WindowToken " + window);
5763 }
5764
5765 window.paused = true;
5766 updateInputWindowsLw();
5767 }
5768 }
5769
5770 public void resumeDispatchingLw(WindowToken window) {
5771 if (window.paused) {
5772 if (DEBUG_INPUT) {
5773 Slog.v(TAG, "Resuming WindowToken " + window);
5774 }
5775
5776 window.paused = false;
5777 updateInputWindowsLw();
5778 }
5779 }
5780
5781 public void freezeInputDispatchingLw() {
5782 if (! mInputDispatchFrozen) {
5783 if (DEBUG_INPUT) {
5784 Slog.v(TAG, "Freezing input dispatching");
5785 }
5786
5787 mInputDispatchFrozen = true;
5788 updateInputDispatchModeLw();
5789 }
5790 }
5791
5792 public void thawInputDispatchingLw() {
5793 if (mInputDispatchFrozen) {
5794 if (DEBUG_INPUT) {
5795 Slog.v(TAG, "Thawing input dispatching");
5796 }
5797
5798 mInputDispatchFrozen = false;
5799 updateInputDispatchModeLw();
5800 }
5801 }
5802
5803 public void setEventDispatchingLw(boolean enabled) {
5804 if (mInputDispatchEnabled != enabled) {
5805 if (DEBUG_INPUT) {
5806 Slog.v(TAG, "Setting event dispatching to " + enabled);
5807 }
5808
5809 mInputDispatchEnabled = enabled;
5810 updateInputDispatchModeLw();
5811 }
5812 }
5813
5814 private void updateInputDispatchModeLw() {
5815 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5816 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005817 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005818
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005819 public void pauseKeyDispatching(IBinder _token) {
5820 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5821 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005822 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005823 }
5824
5825 synchronized (mWindowMap) {
5826 WindowToken token = mTokenMap.get(_token);
5827 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005828 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005829 }
5830 }
5831 }
5832
5833 public void resumeKeyDispatching(IBinder _token) {
5834 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5835 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005836 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005837 }
5838
5839 synchronized (mWindowMap) {
5840 WindowToken token = mTokenMap.get(_token);
5841 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005842 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005843 }
5844 }
5845 }
5846
5847 public void setEventDispatching(boolean enabled) {
5848 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5849 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005850 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005851 }
5852
5853 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005854 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005855 }
5856 }
Romain Guy06882f82009-06-10 13:36:04 -07005857
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005858 /**
5859 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005860 * Even when sync is false, this method may block while waiting for current
5861 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005862 *
5863 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005864 * {@link SystemClock#uptimeMillis()} as the timebase.)
5865 * @param sync If true, wait for the event to be completed before returning to the caller.
5866 * @return Returns true if event was dispatched, false if it was dropped for any reason
5867 */
5868 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5869 long downTime = ev.getDownTime();
5870 long eventTime = ev.getEventTime();
5871
5872 int action = ev.getAction();
5873 int code = ev.getKeyCode();
5874 int repeatCount = ev.getRepeatCount();
5875 int metaState = ev.getMetaState();
5876 int deviceId = ev.getDeviceId();
5877 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005878 int source = ev.getSource();
5879
5880 if (source == InputDevice.SOURCE_UNKNOWN) {
5881 source = InputDevice.SOURCE_KEYBOARD;
5882 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005883
5884 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5885 if (downTime == 0) downTime = eventTime;
5886
5887 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005888 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005889
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005890 final int pid = Binder.getCallingPid();
5891 final int uid = Binder.getCallingUid();
5892 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005893
Jeff Brownbbda99d2010-07-28 15:48:59 -07005894 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5895 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5896 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5897 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005898
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005899 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005900 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005901 }
5902
5903 /**
5904 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005905 * Even when sync is false, this method may block while waiting for current
5906 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005907 *
5908 * @param ev A motion event describing the pointer (touch) action. (As noted in
5909 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005910 * {@link SystemClock#uptimeMillis()} as the timebase.)
5911 * @param sync If true, wait for the event to be completed before returning to the caller.
5912 * @return Returns true if event was dispatched, false if it was dropped for any reason
5913 */
5914 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005915 final int pid = Binder.getCallingPid();
5916 final int uid = Binder.getCallingUid();
5917 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005918
Jeff Brownc5ed5912010-07-14 18:48:53 -07005919 MotionEvent newEvent = MotionEvent.obtain(ev);
5920 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5921 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5922 }
5923
Jeff Brownbbda99d2010-07-28 15:48:59 -07005924 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5925 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5926 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5927 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005928
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005929 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005930 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005931 }
Romain Guy06882f82009-06-10 13:36:04 -07005932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005933 /**
5934 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005935 * Even when sync is false, this method may block while waiting for current
5936 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005937 *
5938 * @param ev A motion event describing the trackball action. (As noted in
5939 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005940 * {@link SystemClock#uptimeMillis()} as the timebase.)
5941 * @param sync If true, wait for the event to be completed before returning to the caller.
5942 * @return Returns true if event was dispatched, false if it was dropped for any reason
5943 */
5944 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005945 final int pid = Binder.getCallingPid();
5946 final int uid = Binder.getCallingUid();
5947 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005948
Jeff Brownc5ed5912010-07-14 18:48:53 -07005949 MotionEvent newEvent = MotionEvent.obtain(ev);
5950 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5951 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5952 }
5953
Jeff Brownbbda99d2010-07-28 15:48:59 -07005954 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5955 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5956 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5957 INJECTION_TIMEOUT_MILLIS);
5958
5959 Binder.restoreCallingIdentity(ident);
5960 return reportInjectionResult(result);
5961 }
5962
5963 /**
5964 * Inject an input event into the UI without waiting for dispatch to commence.
5965 * This variant is useful for fire-and-forget input event injection. It does not
5966 * block any longer than it takes to enqueue the input event.
5967 *
5968 * @param ev An input event. (Be sure to set the input source correctly.)
5969 * @return Returns true if event was dispatched, false if it was dropped for any reason
5970 */
5971 public boolean injectInputEventNoWait(InputEvent ev) {
5972 final int pid = Binder.getCallingPid();
5973 final int uid = Binder.getCallingUid();
5974 final long ident = Binder.clearCallingIdentity();
5975
5976 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5977 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5978 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005979
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005980 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005981 return reportInjectionResult(result);
5982 }
5983
5984 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005985 switch (result) {
5986 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5987 Slog.w(TAG, "Input event injection permission denied.");
5988 throw new SecurityException(
5989 "Injecting to another application requires INJECT_EVENTS permission");
5990 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07005991 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005992 return true;
5993 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5994 Slog.w(TAG, "Input event injection timed out.");
5995 return false;
5996 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5997 default:
5998 Slog.w(TAG, "Input event injection failed.");
5999 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006000 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006001 }
Romain Guy06882f82009-06-10 13:36:04 -07006002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006003 private WindowState getFocusedWindow() {
6004 synchronized (mWindowMap) {
6005 return getFocusedWindowLocked();
6006 }
6007 }
6008
6009 private WindowState getFocusedWindowLocked() {
6010 return mCurrentFocus;
6011 }
Romain Guy06882f82009-06-10 13:36:04 -07006012
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006013 public boolean detectSafeMode() {
6014 mSafeMode = mPolicy.detectSafeMode();
6015 return mSafeMode;
6016 }
Romain Guy06882f82009-06-10 13:36:04 -07006017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006018 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006019 synchronized(mWindowMap) {
6020 if (mDisplay != null) {
6021 throw new IllegalStateException("Display already initialized");
6022 }
6023 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6024 mDisplay = wm.getDefaultDisplay();
6025 mInitialDisplayWidth = mDisplay.getWidth();
6026 mInitialDisplayHeight = mDisplay.getHeight();
6027 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
6028 }
6029
6030 try {
6031 mActivityManager.updateConfiguration(null);
6032 } catch (RemoteException e) {
6033 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006034
6035 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006036 }
6037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006038 // -------------------------------------------------------------
6039 // Client Session State
6040 // -------------------------------------------------------------
6041
6042 private final class Session extends IWindowSession.Stub
6043 implements IBinder.DeathRecipient {
6044 final IInputMethodClient mClient;
6045 final IInputContext mInputContext;
6046 final int mUid;
6047 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006048 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006049 SurfaceSession mSurfaceSession;
6050 int mNumWindow = 0;
6051 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006053 public Session(IInputMethodClient client, IInputContext inputContext) {
6054 mClient = client;
6055 mInputContext = inputContext;
6056 mUid = Binder.getCallingUid();
6057 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006058 StringBuilder sb = new StringBuilder();
6059 sb.append("Session{");
6060 sb.append(Integer.toHexString(System.identityHashCode(this)));
6061 sb.append(" uid ");
6062 sb.append(mUid);
6063 sb.append("}");
6064 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006066 synchronized (mWindowMap) {
6067 if (mInputMethodManager == null && mHaveInputMethods) {
6068 IBinder b = ServiceManager.getService(
6069 Context.INPUT_METHOD_SERVICE);
6070 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6071 }
6072 }
6073 long ident = Binder.clearCallingIdentity();
6074 try {
6075 // Note: it is safe to call in to the input method manager
6076 // here because we are not holding our lock.
6077 if (mInputMethodManager != null) {
6078 mInputMethodManager.addClient(client, inputContext,
6079 mUid, mPid);
6080 } else {
6081 client.setUsingInputMethod(false);
6082 }
6083 client.asBinder().linkToDeath(this, 0);
6084 } catch (RemoteException e) {
6085 // The caller has died, so we can just forget about this.
6086 try {
6087 if (mInputMethodManager != null) {
6088 mInputMethodManager.removeClient(client);
6089 }
6090 } catch (RemoteException ee) {
6091 }
6092 } finally {
6093 Binder.restoreCallingIdentity(ident);
6094 }
6095 }
Romain Guy06882f82009-06-10 13:36:04 -07006096
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006097 @Override
6098 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6099 throws RemoteException {
6100 try {
6101 return super.onTransact(code, data, reply, flags);
6102 } catch (RuntimeException e) {
6103 // Log all 'real' exceptions thrown to the caller
6104 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006105 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006106 }
6107 throw e;
6108 }
6109 }
6110
6111 public void binderDied() {
6112 // Note: it is safe to call in to the input method manager
6113 // here because we are not holding our lock.
6114 try {
6115 if (mInputMethodManager != null) {
6116 mInputMethodManager.removeClient(mClient);
6117 }
6118 } catch (RemoteException e) {
6119 }
6120 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006121 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006122 mClientDead = true;
6123 killSessionLocked();
6124 }
6125 }
6126
6127 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac02010-04-22 18:58:52 -07006128 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6129 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6130 outInputChannel);
6131 }
6132
6133 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006134 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07006135 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006136 }
Romain Guy06882f82009-06-10 13:36:04 -07006137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006138 public void remove(IWindow window) {
6139 removeWindow(this, window);
6140 }
Romain Guy06882f82009-06-10 13:36:04 -07006141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006142 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6143 int requestedWidth, int requestedHeight, int viewFlags,
6144 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006145 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006146 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6147 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006148 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006149 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006150 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6151 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006152 }
Romain Guy06882f82009-06-10 13:36:04 -07006153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006154 public void setTransparentRegion(IWindow window, Region region) {
6155 setTransparentRegionWindow(this, window, region);
6156 }
Romain Guy06882f82009-06-10 13:36:04 -07006157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006158 public void setInsets(IWindow window, int touchableInsets,
6159 Rect contentInsets, Rect visibleInsets) {
6160 setInsetsWindow(this, window, touchableInsets, contentInsets,
6161 visibleInsets);
6162 }
Romain Guy06882f82009-06-10 13:36:04 -07006163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006164 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6165 getWindowDisplayFrame(this, window, outDisplayFrame);
6166 }
Romain Guy06882f82009-06-10 13:36:04 -07006167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006168 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006169 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006170 TAG, "IWindow finishDrawing called for " + window);
6171 finishDrawingWindow(this, window);
6172 }
6173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006174 public void setInTouchMode(boolean mode) {
6175 synchronized(mWindowMap) {
6176 mInTouchMode = mode;
6177 }
6178 }
6179
6180 public boolean getInTouchMode() {
6181 synchronized(mWindowMap) {
6182 return mInTouchMode;
6183 }
6184 }
6185
6186 public boolean performHapticFeedback(IWindow window, int effectId,
6187 boolean always) {
6188 synchronized(mWindowMap) {
6189 long ident = Binder.clearCallingIdentity();
6190 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006191 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006192 windowForClientLocked(this, window, true),
6193 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006194 } finally {
6195 Binder.restoreCallingIdentity(ident);
6196 }
6197 }
6198 }
Romain Guy06882f82009-06-10 13:36:04 -07006199
Christopher Tatea53146c2010-09-07 11:57:52 -07006200 /* Drag/drop */
6201 public IBinder prepareDrag(IWindow window, boolean localOnly,
6202 int width, int height, Surface outSurface) {
6203 return prepareDragSurface(window, mSurfaceSession, localOnly,
6204 width, height, outSurface);
6205 }
6206
6207 public boolean performDrag(IWindow window, IBinder dragToken,
6208 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6209 ClipData data) {
6210 if (DEBUG_DRAG) {
6211 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6212 }
6213
6214 synchronized (mWindowMap) {
6215 if (mDragState == null) {
6216 Slog.w(TAG, "No drag prepared");
6217 throw new IllegalStateException("performDrag() without prepareDrag()");
6218 }
6219
6220 if (dragToken != mDragState.mToken) {
6221 Slog.w(TAG, "Performing mismatched drag");
6222 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6223 }
6224
6225 WindowState callingWin = windowForClientLocked(null, window, false);
6226 if (callingWin == null) {
6227 Slog.w(TAG, "Bad requesting window " + window);
6228 return false; // !!! TODO: throw here?
6229 }
6230
6231 // !!! TODO: if input is not still focused on the initiating window, fail
6232 // the drag initiation (e.g. an alarm window popped up just as the application
6233 // called performDrag()
6234
6235 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6236
Christopher Tate2c095f32010-10-04 14:13:40 -07006237 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6238 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006239
Chris Tateb478f462010-10-15 16:02:26 -07006240 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6241 // the actual drag event dispatch stuff in the dragstate
6242
Christopher Tatea53146c2010-09-07 11:57:52 -07006243 mDragState.register();
6244 mInputMonitor.updateInputWindowsLw();
6245 mInputManager.transferTouchFocus(callingWin.mInputChannel,
6246 mDragState.mServerChannel);
6247
6248 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006249 mDragState.mCurrentX = touchX;
6250 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006251 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006252
6253 // remember the thumb offsets for later
6254 mDragState.mThumbOffsetX = thumbCenterX;
6255 mDragState.mThumbOffsetY = thumbCenterY;
6256
6257 // Make the surface visible at the proper location
6258 final Surface surface = mDragState.mSurface;
Chris Tateb478f462010-10-15 16:02:26 -07006259 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006260 try {
6261 surface.setPosition((int)(touchX - thumbCenterX),
6262 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006263 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006264 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006265 surface.show();
6266 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006267 Surface.closeTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006268 }
6269 }
6270
6271 return true; // success!
6272 }
6273
Chris Tated4533f12010-10-19 15:15:08 -07006274 public void reportDropResult(IWindow window, boolean consumed) {
6275 IBinder token = window.asBinder();
6276 if (DEBUG_DRAG) {
6277 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6278 }
6279
6280 synchronized (mWindowMap) {
6281 if (mDragState.mToken != token) {
6282 Slog.w(TAG, "Invalid drop-result claim by " + window);
6283 throw new IllegalStateException("reportDropResult() by non-recipient");
6284 }
6285
6286 // The right window has responded, even if it's no longer around,
6287 // so be sure to halt the timeout even if the later WindowState
6288 // lookup fails.
6289 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6290
6291 WindowState callingWin = windowForClientLocked(null, window, false);
6292 if (callingWin == null) {
6293 Slog.w(TAG, "Bad result-reporting window " + window);
6294 return; // !!! TODO: throw here?
6295 }
6296
6297 mDragState.mDragResult = consumed;
6298 mDragState.endDragLw();
6299 }
6300 }
6301
Christopher Tatea53146c2010-09-07 11:57:52 -07006302 public void dragRecipientEntered(IWindow window) {
6303 if (DEBUG_DRAG) {
Chris Tated4533f12010-10-19 15:15:08 -07006304 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006305 }
6306 }
6307
6308 public void dragRecipientExited(IWindow window) {
6309 if (DEBUG_DRAG) {
Chris Tated4533f12010-10-19 15:15:08 -07006310 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006311 }
6312 }
6313
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006314 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006315 synchronized(mWindowMap) {
6316 long ident = Binder.clearCallingIdentity();
6317 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006318 setWindowWallpaperPositionLocked(
6319 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006320 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006321 } finally {
6322 Binder.restoreCallingIdentity(ident);
6323 }
6324 }
6325 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006326
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006327 public void wallpaperOffsetsComplete(IBinder window) {
6328 WindowManagerService.this.wallpaperOffsetsComplete(window);
6329 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006330
Dianne Hackborn75804932009-10-20 20:15:20 -07006331 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6332 int z, Bundle extras, boolean sync) {
6333 synchronized(mWindowMap) {
6334 long ident = Binder.clearCallingIdentity();
6335 try {
6336 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006337 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006338 action, x, y, z, extras, sync);
6339 } finally {
6340 Binder.restoreCallingIdentity(ident);
6341 }
6342 }
6343 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006344
Dianne Hackborn75804932009-10-20 20:15:20 -07006345 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6346 WindowManagerService.this.wallpaperCommandComplete(window, result);
6347 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006348
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006349 void windowAddedLocked() {
6350 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006351 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006352 TAG, "First window added to " + this + ", creating SurfaceSession");
6353 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006354 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006355 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006356 mSessions.add(this);
6357 }
6358 mNumWindow++;
6359 }
6360
6361 void windowRemovedLocked() {
6362 mNumWindow--;
6363 killSessionLocked();
6364 }
Romain Guy06882f82009-06-10 13:36:04 -07006365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006366 void killSessionLocked() {
6367 if (mNumWindow <= 0 && mClientDead) {
6368 mSessions.remove(this);
6369 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006370 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006371 TAG, "Last window removed from " + this
6372 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006373 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006374 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006375 try {
6376 mSurfaceSession.kill();
6377 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006378 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006379 + mSurfaceSession + " in session " + this
6380 + ": " + e.toString());
6381 }
6382 mSurfaceSession = null;
6383 }
6384 }
6385 }
Romain Guy06882f82009-06-10 13:36:04 -07006386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006387 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006388 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6389 pw.print(" mClientDead="); pw.print(mClientDead);
6390 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006391 }
6392
6393 @Override
6394 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006395 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006396 }
6397 }
6398
6399 // -------------------------------------------------------------
6400 // Client Window State
6401 // -------------------------------------------------------------
6402
6403 private final class WindowState implements WindowManagerPolicy.WindowState {
6404 final Session mSession;
6405 final IWindow mClient;
6406 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006407 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006408 AppWindowToken mAppToken;
6409 AppWindowToken mTargetAppToken;
6410 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6411 final DeathRecipient mDeathRecipient;
6412 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006413 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006414 final int mBaseLayer;
6415 final int mSubLayer;
6416 final boolean mLayoutAttached;
6417 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006418 final boolean mIsWallpaper;
6419 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006420 int mViewVisibility;
6421 boolean mPolicyVisibility = true;
6422 boolean mPolicyVisibilityAfterAnim = true;
6423 boolean mAppFreezing;
6424 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006425 boolean mReportDestroySurface;
6426 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006427 boolean mAttachedHidden; // is our parent window hidden?
6428 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006429 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006430 int mRequestedWidth;
6431 int mRequestedHeight;
6432 int mLastRequestedWidth;
6433 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006434 int mLayer;
6435 int mAnimLayer;
6436 int mLastLayer;
6437 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006438 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006439 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006440
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006441 int mLayoutSeq = -1;
6442
6443 Configuration mConfiguration = null;
6444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006445 // Actual frame shown on-screen (may be modified by animation)
6446 final Rect mShownFrame = new Rect();
6447 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006449 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006450 * Set when we have changed the size of the surface, to know that
6451 * we must tell them application to resize (and thus redraw itself).
6452 */
6453 boolean mSurfaceResized;
6454
6455 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006456 * Insets that determine the actually visible area
6457 */
6458 final Rect mVisibleInsets = new Rect();
6459 final Rect mLastVisibleInsets = new Rect();
6460 boolean mVisibleInsetsChanged;
6461
6462 /**
6463 * Insets that are covered by system windows
6464 */
6465 final Rect mContentInsets = new Rect();
6466 final Rect mLastContentInsets = new Rect();
6467 boolean mContentInsetsChanged;
6468
6469 /**
6470 * Set to true if we are waiting for this window to receive its
6471 * given internal insets before laying out other windows based on it.
6472 */
6473 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006475 /**
6476 * These are the content insets that were given during layout for
6477 * this window, to be applied to windows behind it.
6478 */
6479 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006480
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006481 /**
6482 * These are the visible insets that were given during layout for
6483 * this window, to be applied to windows behind it.
6484 */
6485 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006487 /**
6488 * Flag indicating whether the touchable region should be adjusted by
6489 * the visible insets; if false the area outside the visible insets is
6490 * NOT touchable, so we must use those to adjust the frame during hit
6491 * tests.
6492 */
6493 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006495 // Current transformation being applied.
6496 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6497 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6498 float mHScale=1, mVScale=1;
6499 float mLastHScale=1, mLastVScale=1;
6500 final Matrix mTmpMatrix = new Matrix();
6501
6502 // "Real" frame that the application sees.
6503 final Rect mFrame = new Rect();
6504 final Rect mLastFrame = new Rect();
6505
6506 final Rect mContainingFrame = new Rect();
6507 final Rect mDisplayFrame = new Rect();
6508 final Rect mContentFrame = new Rect();
6509 final Rect mVisibleFrame = new Rect();
6510
6511 float mShownAlpha = 1;
6512 float mAlpha = 1;
6513 float mLastAlpha = 1;
6514
6515 // Set to true if, when the window gets displayed, it should perform
6516 // an enter animation.
6517 boolean mEnterAnimationPending;
6518
6519 // Currently running animation.
6520 boolean mAnimating;
6521 boolean mLocalAnimating;
6522 Animation mAnimation;
6523 boolean mAnimationIsEntrance;
6524 boolean mHasTransformation;
6525 boolean mHasLocalTransformation;
6526 final Transformation mTransformation = new Transformation();
6527
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006528 // If a window showing a wallpaper: the requested offset for the
6529 // wallpaper; if a wallpaper window: the currently applied offset.
6530 float mWallpaperX = -1;
6531 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006532
6533 // If a window showing a wallpaper: what fraction of the offset
6534 // range corresponds to a full virtual screen.
6535 float mWallpaperXStep = -1;
6536 float mWallpaperYStep = -1;
6537
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006538 // Wallpaper windows: pixels offset based on above variables.
6539 int mXOffset;
6540 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006542 // This is set after IWindowSession.relayout() has been called at
6543 // least once for the window. It allows us to detect the situation
6544 // where we don't yet have a surface, but should have one soon, so
6545 // we can give the window focus before waiting for the relayout.
6546 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006548 // This is set after the Surface has been created but before the
6549 // window has been drawn. During this time the surface is hidden.
6550 boolean mDrawPending;
6551
6552 // This is set after the window has finished drawing for the first
6553 // time but before its surface is shown. The surface will be
6554 // displayed when the next layout is run.
6555 boolean mCommitDrawPending;
6556
6557 // This is set during the time after the window's drawing has been
6558 // committed, and before its surface is actually shown. It is used
6559 // to delay showing the surface until all windows in a token are ready
6560 // to be shown.
6561 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006563 // Set when the window has been shown in the screen the first time.
6564 boolean mHasDrawn;
6565
6566 // Currently running an exit animation?
6567 boolean mExiting;
6568
6569 // Currently on the mDestroySurface list?
6570 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006572 // Completely remove from window manager after exit animation?
6573 boolean mRemoveOnExit;
6574
6575 // Set when the orientation is changing and this window has not yet
6576 // been updated for the new orientation.
6577 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006579 // Is this window now (or just being) removed?
6580 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006581
Dianne Hackborn16064f92010-03-25 00:47:24 -07006582 // For debugging, this is the last information given to the surface flinger.
6583 boolean mSurfaceShown;
6584 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6585 int mSurfaceLayer;
6586 float mSurfaceAlpha;
6587
Jeff Brown46b9ac02010-04-22 18:58:52 -07006588 // Input channel
6589 InputChannel mInputChannel;
6590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006591 WindowState(Session s, IWindow c, WindowToken token,
6592 WindowState attachedWindow, WindowManager.LayoutParams a,
6593 int viewVisibility) {
6594 mSession = s;
6595 mClient = c;
6596 mToken = token;
6597 mAttrs.copyFrom(a);
6598 mViewVisibility = viewVisibility;
6599 DeathRecipient deathRecipient = new DeathRecipient();
6600 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006601 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006602 TAG, "Window " + this + " client=" + c.asBinder()
6603 + " token=" + token + " (" + mAttrs.token + ")");
6604 try {
6605 c.asBinder().linkToDeath(deathRecipient, 0);
6606 } catch (RemoteException e) {
6607 mDeathRecipient = null;
6608 mAttachedWindow = null;
6609 mLayoutAttached = false;
6610 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006611 mIsWallpaper = false;
6612 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006613 mBaseLayer = 0;
6614 mSubLayer = 0;
6615 return;
6616 }
6617 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006619 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6620 mAttrs.type <= LAST_SUB_WINDOW)) {
6621 // The multiplier here is to reserve space for multiple
6622 // windows in the same type layer.
6623 mBaseLayer = mPolicy.windowTypeToLayerLw(
6624 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6625 + TYPE_LAYER_OFFSET;
6626 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6627 mAttachedWindow = attachedWindow;
6628 mAttachedWindow.mChildWindows.add(this);
6629 mLayoutAttached = mAttrs.type !=
6630 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6631 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6632 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006633 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6634 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006635 } else {
6636 // The multiplier here is to reserve space for multiple
6637 // windows in the same type layer.
6638 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6639 * TYPE_LAYER_MULTIPLIER
6640 + TYPE_LAYER_OFFSET;
6641 mSubLayer = 0;
6642 mAttachedWindow = null;
6643 mLayoutAttached = false;
6644 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6645 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006646 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6647 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006648 }
6649
6650 WindowState appWin = this;
6651 while (appWin.mAttachedWindow != null) {
6652 appWin = mAttachedWindow;
6653 }
6654 WindowToken appToken = appWin.mToken;
6655 while (appToken.appWindowToken == null) {
6656 WindowToken parent = mTokenMap.get(appToken.token);
6657 if (parent == null || appToken == parent) {
6658 break;
6659 }
6660 appToken = parent;
6661 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006662 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006663 mAppToken = appToken.appWindowToken;
6664
6665 mSurface = null;
6666 mRequestedWidth = 0;
6667 mRequestedHeight = 0;
6668 mLastRequestedWidth = 0;
6669 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006670 mXOffset = 0;
6671 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006672 mLayer = 0;
6673 mAnimLayer = 0;
6674 mLastLayer = 0;
6675 }
6676
6677 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006678 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006679 TAG, "Attaching " + this + " token=" + mToken
6680 + ", list=" + mToken.windows);
6681 mSession.windowAddedLocked();
6682 }
6683
6684 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6685 mHaveFrame = true;
6686
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006687 final Rect container = mContainingFrame;
6688 container.set(pf);
6689
6690 final Rect display = mDisplayFrame;
6691 display.set(df);
6692
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006693 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006694 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006695 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6696 display.intersect(mCompatibleScreenFrame);
6697 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006698 }
6699
6700 final int pw = container.right - container.left;
6701 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006702
6703 int w,h;
6704 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6705 w = mAttrs.width < 0 ? pw : mAttrs.width;
6706 h = mAttrs.height< 0 ? ph : mAttrs.height;
6707 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006708 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6709 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006710 }
Romain Guy06882f82009-06-10 13:36:04 -07006711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006712 final Rect content = mContentFrame;
6713 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006715 final Rect visible = mVisibleFrame;
6716 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006717
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006718 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006719 final int fw = frame.width();
6720 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006722 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6723 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6724
6725 Gravity.apply(mAttrs.gravity, w, h, container,
6726 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6727 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6728
6729 //System.out.println("Out: " + mFrame);
6730
6731 // Now make sure the window fits in the overall display.
6732 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006733
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006734 // Make sure the content and visible frames are inside of the
6735 // final window frame.
6736 if (content.left < frame.left) content.left = frame.left;
6737 if (content.top < frame.top) content.top = frame.top;
6738 if (content.right > frame.right) content.right = frame.right;
6739 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6740 if (visible.left < frame.left) visible.left = frame.left;
6741 if (visible.top < frame.top) visible.top = frame.top;
6742 if (visible.right > frame.right) visible.right = frame.right;
6743 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006745 final Rect contentInsets = mContentInsets;
6746 contentInsets.left = content.left-frame.left;
6747 contentInsets.top = content.top-frame.top;
6748 contentInsets.right = frame.right-content.right;
6749 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006750
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006751 final Rect visibleInsets = mVisibleInsets;
6752 visibleInsets.left = visible.left-frame.left;
6753 visibleInsets.top = visible.top-frame.top;
6754 visibleInsets.right = frame.right-visible.right;
6755 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006756
Dianne Hackborn284ac932009-08-28 10:34:25 -07006757 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6758 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006759 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006760 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006762 if (localLOGV) {
6763 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6764 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006765 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006766 + mRequestedWidth + ", mRequestedheight="
6767 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6768 + "): frame=" + mFrame.toShortString()
6769 + " ci=" + contentInsets.toShortString()
6770 + " vi=" + visibleInsets.toShortString());
6771 //}
6772 }
6773 }
Romain Guy06882f82009-06-10 13:36:04 -07006774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006775 public Rect getFrameLw() {
6776 return mFrame;
6777 }
6778
6779 public Rect getShownFrameLw() {
6780 return mShownFrame;
6781 }
6782
6783 public Rect getDisplayFrameLw() {
6784 return mDisplayFrame;
6785 }
6786
6787 public Rect getContentFrameLw() {
6788 return mContentFrame;
6789 }
6790
6791 public Rect getVisibleFrameLw() {
6792 return mVisibleFrame;
6793 }
6794
6795 public boolean getGivenInsetsPendingLw() {
6796 return mGivenInsetsPending;
6797 }
6798
6799 public Rect getGivenContentInsetsLw() {
6800 return mGivenContentInsets;
6801 }
Romain Guy06882f82009-06-10 13:36:04 -07006802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006803 public Rect getGivenVisibleInsetsLw() {
6804 return mGivenVisibleInsets;
6805 }
Romain Guy06882f82009-06-10 13:36:04 -07006806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006807 public WindowManager.LayoutParams getAttrs() {
6808 return mAttrs;
6809 }
6810
6811 public int getSurfaceLayer() {
6812 return mLayer;
6813 }
Romain Guy06882f82009-06-10 13:36:04 -07006814
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006815 public IApplicationToken getAppToken() {
6816 return mAppToken != null ? mAppToken.appToken : null;
6817 }
Jeff Brown349703e2010-06-22 01:27:15 -07006818
6819 public long getInputDispatchingTimeoutNanos() {
6820 return mAppToken != null
6821 ? mAppToken.inputDispatchingTimeoutNanos
6822 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6823 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006824
6825 public boolean hasAppShownWindows() {
6826 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6827 }
6828
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006829 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006830 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006831 TAG, "Setting animation in " + this + ": " + anim);
6832 mAnimating = false;
6833 mLocalAnimating = false;
6834 mAnimation = anim;
6835 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6836 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6837 }
6838
6839 public void clearAnimation() {
6840 if (mAnimation != null) {
6841 mAnimating = true;
6842 mLocalAnimating = false;
6843 mAnimation = null;
6844 }
6845 }
Romain Guy06882f82009-06-10 13:36:04 -07006846
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006847 Surface createSurfaceLocked() {
6848 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006849 mReportDestroySurface = false;
6850 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006851 mDrawPending = true;
6852 mCommitDrawPending = false;
6853 mReadyToShow = false;
6854 if (mAppToken != null) {
6855 mAppToken.allDrawn = false;
6856 }
6857
6858 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006859 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006860 flags |= Surface.PUSH_BUFFERS;
6861 }
6862
6863 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6864 flags |= Surface.SECURE;
6865 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006866 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006867 TAG, "Creating surface in session "
6868 + mSession.mSurfaceSession + " window " + this
6869 + " w=" + mFrame.width()
6870 + " h=" + mFrame.height() + " format="
6871 + mAttrs.format + " flags=" + flags);
6872
6873 int w = mFrame.width();
6874 int h = mFrame.height();
6875 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6876 // for a scaled surface, we always want the requested
6877 // size.
6878 w = mRequestedWidth;
6879 h = mRequestedHeight;
6880 }
6881
Romain Guy9825ec62009-10-01 00:58:09 -07006882 // Something is wrong and SurfaceFlinger will not like this,
6883 // try to revert to sane values
6884 if (w <= 0) w = 1;
6885 if (h <= 0) h = 1;
6886
Dianne Hackborn16064f92010-03-25 00:47:24 -07006887 mSurfaceShown = false;
6888 mSurfaceLayer = 0;
6889 mSurfaceAlpha = 1;
6890 mSurfaceX = 0;
6891 mSurfaceY = 0;
6892 mSurfaceW = w;
6893 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006894 try {
Romain Guyd10cd572010-10-10 13:33:22 -07006895 final boolean isHwAccelerated = (mAttrs.flags &
6896 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
6897 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
6898 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
6899 flags |= Surface.OPAQUE;
6900 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006901 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006902 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006903 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07006904 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006905 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006906 + mSurface + " IN SESSION "
6907 + mSession.mSurfaceSession
6908 + ": pid=" + mSession.mPid + " format="
6909 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006910 + Integer.toHexString(flags)
6911 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006912 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006913 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006914 reclaimSomeSurfaceMemoryLocked(this, "create");
6915 return null;
6916 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006917 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006918 return null;
6919 }
Romain Guy06882f82009-06-10 13:36:04 -07006920
Joe Onorato8a9b2202010-02-26 18:56:32 -08006921 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006922 TAG, "Got surface: " + mSurface
6923 + ", set left=" + mFrame.left + " top=" + mFrame.top
6924 + ", animLayer=" + mAnimLayer);
6925 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006926 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006927 if (SHOW_TRANSACTIONS) logSurface(this,
6928 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6929 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6930 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006931 }
6932 Surface.openTransaction();
6933 try {
6934 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006935 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006936 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006937 mSurface.setPosition(mSurfaceX, mSurfaceY);
6938 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006939 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006940 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006941 mSurface.hide();
6942 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006943 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006944 mSurface.setFlags(Surface.SURFACE_DITHER,
6945 Surface.SURFACE_DITHER);
6946 }
6947 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006948 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006949 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6950 }
6951 mLastHidden = true;
6952 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006953 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006954 Surface.closeTransaction();
6955 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006956 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006957 TAG, "Created surface " + this);
6958 }
6959 return mSurface;
6960 }
Romain Guy06882f82009-06-10 13:36:04 -07006961
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006962 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006963 if (mAppToken != null && this == mAppToken.startingWindow) {
6964 mAppToken.startingDisplayed = false;
6965 }
Romain Guy06882f82009-06-10 13:36:04 -07006966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006967 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006968 mDrawPending = false;
6969 mCommitDrawPending = false;
6970 mReadyToShow = false;
6971
6972 int i = mChildWindows.size();
6973 while (i > 0) {
6974 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006975 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006976 c.mAttachedHidden = true;
6977 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006978
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006979 if (mReportDestroySurface) {
6980 mReportDestroySurface = false;
6981 mSurfacePendingDestroy = true;
6982 try {
6983 mClient.dispatchGetNewSurface();
6984 // We'll really destroy on the next time around.
6985 return;
6986 } catch (RemoteException e) {
6987 }
6988 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006989
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006990 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006991 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006992 RuntimeException e = null;
6993 if (!HIDE_STACK_CRAWLS) {
6994 e = new RuntimeException();
6995 e.fillInStackTrace();
6996 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006997 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006998 + mSurface + ", session " + mSession, e);
6999 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007000 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007001 RuntimeException e = null;
7002 if (!HIDE_STACK_CRAWLS) {
7003 e = new RuntimeException();
7004 e.fillInStackTrace();
7005 }
7006 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007007 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007008 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007009 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007010 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007011 + " surface " + mSurface + " session " + mSession
7012 + ": " + e.toString());
7013 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007014
Dianne Hackborn16064f92010-03-25 00:47:24 -07007015 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007016 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007017 }
7018 }
7019
7020 boolean finishDrawingLocked() {
7021 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007022 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007023 TAG, "finishDrawingLocked: " + mSurface);
7024 mCommitDrawPending = true;
7025 mDrawPending = false;
7026 return true;
7027 }
7028 return false;
7029 }
7030
7031 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007032 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007033 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007034 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007035 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007036 }
7037 mCommitDrawPending = false;
7038 mReadyToShow = true;
7039 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7040 final AppWindowToken atoken = mAppToken;
7041 if (atoken == null || atoken.allDrawn || starting) {
7042 performShowLocked();
7043 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007044 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007045 }
7046
7047 // This must be called while inside a transaction.
7048 boolean performShowLocked() {
7049 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007050 RuntimeException e = null;
7051 if (!HIDE_STACK_CRAWLS) {
7052 e = new RuntimeException();
7053 e.fillInStackTrace();
7054 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007055 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007056 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7057 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7058 }
7059 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007060 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7061 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007062 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007063 + " during animation: policyVis=" + mPolicyVisibility
7064 + " attHidden=" + mAttachedHidden
7065 + " tok.hiddenRequested="
7066 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007067 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007068 + (mAppToken != null ? mAppToken.hidden : false)
7069 + " animating=" + mAnimating
7070 + " tok animating="
7071 + (mAppToken != null ? mAppToken.animating : false));
7072 if (!showSurfaceRobustlyLocked(this)) {
7073 return false;
7074 }
7075 mLastAlpha = -1;
7076 mHasDrawn = true;
7077 mLastHidden = false;
7078 mReadyToShow = false;
7079 enableScreenIfNeededLocked();
7080
7081 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007083 int i = mChildWindows.size();
7084 while (i > 0) {
7085 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007086 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007087 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007088 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007089 if (c.mSurface != null) {
7090 c.performShowLocked();
7091 // It hadn't been shown, which means layout not
7092 // performed on it, so now we want to make sure to
7093 // do a layout. If called from within the transaction
7094 // loop, this will cause it to restart with a new
7095 // layout.
7096 mLayoutNeeded = true;
7097 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007098 }
7099 }
Romain Guy06882f82009-06-10 13:36:04 -07007100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007101 if (mAttrs.type != TYPE_APPLICATION_STARTING
7102 && mAppToken != null) {
7103 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007104
Dianne Hackborn248b1882009-09-16 16:46:44 -07007105 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007106 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007107 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007108 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007109 // If this initial window is animating, stop it -- we
7110 // will do an animation to reveal it from behind the
7111 // starting window, so there is no need for it to also
7112 // be doing its own stuff.
7113 if (mAnimation != null) {
7114 mAnimation = null;
7115 // Make sure we clean up the animation.
7116 mAnimating = true;
7117 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007118 mFinishedStarting.add(mAppToken);
7119 mH.sendEmptyMessage(H.FINISHED_STARTING);
7120 }
7121 mAppToken.updateReportedVisibilityLocked();
7122 }
7123 }
7124 return true;
7125 }
Romain Guy06882f82009-06-10 13:36:04 -07007126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007127 // This must be called while inside a transaction. Returns true if
7128 // there is more animation to run.
7129 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007130 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007131 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007133 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7134 mHasTransformation = true;
7135 mHasLocalTransformation = true;
7136 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007137 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007138 TAG, "Starting animation in " + this +
7139 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7140 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7141 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7142 mAnimation.setStartTime(currentTime);
7143 mLocalAnimating = true;
7144 mAnimating = true;
7145 }
7146 mTransformation.clear();
7147 final boolean more = mAnimation.getTransformation(
7148 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007149 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007150 TAG, "Stepped animation in " + this +
7151 ": more=" + more + ", xform=" + mTransformation);
7152 if (more) {
7153 // we're not done!
7154 return true;
7155 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007156 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007157 TAG, "Finished animation in " + this +
7158 " @ " + currentTime);
7159 mAnimation = null;
7160 //WindowManagerService.this.dump();
7161 }
7162 mHasLocalTransformation = false;
7163 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007164 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007165 // When our app token is animating, we kind-of pretend like
7166 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7167 // part of this check means that we will only do this if
7168 // our window is not currently exiting, or it is not
7169 // locally animating itself. The idea being that one that
7170 // is exiting and doing a local animation should be removed
7171 // once that animation is done.
7172 mAnimating = true;
7173 mHasTransformation = true;
7174 mTransformation.clear();
7175 return false;
7176 } else if (mHasTransformation) {
7177 // Little trick to get through the path below to act like
7178 // we have finished an animation.
7179 mAnimating = true;
7180 } else if (isAnimating()) {
7181 mAnimating = true;
7182 }
7183 } else if (mAnimation != null) {
7184 // If the display is frozen, and there is a pending animation,
7185 // clear it and make sure we run the cleanup code.
7186 mAnimating = true;
7187 mLocalAnimating = true;
7188 mAnimation = null;
7189 }
Romain Guy06882f82009-06-10 13:36:04 -07007190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007191 if (!mAnimating && !mLocalAnimating) {
7192 return false;
7193 }
7194
Joe Onorato8a9b2202010-02-26 18:56:32 -08007195 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007196 TAG, "Animation done in " + this + ": exiting=" + mExiting
7197 + ", reportedVisible="
7198 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007200 mAnimating = false;
7201 mLocalAnimating = false;
7202 mAnimation = null;
7203 mAnimLayer = mLayer;
7204 if (mIsImWindow) {
7205 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007206 } else if (mIsWallpaper) {
7207 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007208 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007209 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007210 + " anim layer: " + mAnimLayer);
7211 mHasTransformation = false;
7212 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007213 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7214 if (DEBUG_VISIBILITY) {
7215 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7216 + mPolicyVisibilityAfterAnim);
7217 }
7218 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7219 if (!mPolicyVisibility) {
7220 if (mCurrentFocus == this) {
7221 mFocusMayChange = true;
7222 }
7223 // Window is no longer visible -- make sure if we were waiting
7224 // for it to be displayed before enabling the display, that
7225 // we allow the display to be enabled now.
7226 enableScreenIfNeededLocked();
7227 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007228 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007229 mTransformation.clear();
7230 if (mHasDrawn
7231 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7232 && mAppToken != null
7233 && mAppToken.firstWindowDrawn
7234 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007235 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007236 + mToken + ": first real window done animating");
7237 mFinishedStarting.add(mAppToken);
7238 mH.sendEmptyMessage(H.FINISHED_STARTING);
7239 }
Romain Guy06882f82009-06-10 13:36:04 -07007240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007241 finishExit();
7242
7243 if (mAppToken != null) {
7244 mAppToken.updateReportedVisibilityLocked();
7245 }
7246
7247 return false;
7248 }
7249
7250 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007251 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007252 TAG, "finishExit in " + this
7253 + ": exiting=" + mExiting
7254 + " remove=" + mRemoveOnExit
7255 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007257 final int N = mChildWindows.size();
7258 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007259 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007260 }
Romain Guy06882f82009-06-10 13:36:04 -07007261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007262 if (!mExiting) {
7263 return;
7264 }
Romain Guy06882f82009-06-10 13:36:04 -07007265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007266 if (isWindowAnimating()) {
7267 return;
7268 }
7269
Joe Onorato8a9b2202010-02-26 18:56:32 -08007270 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007271 TAG, "Exit animation finished in " + this
7272 + ": remove=" + mRemoveOnExit);
7273 if (mSurface != null) {
7274 mDestroySurface.add(this);
7275 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007276 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007277 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007278 try {
7279 mSurface.hide();
7280 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007281 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007282 }
7283 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007284 }
7285 mExiting = false;
7286 if (mRemoveOnExit) {
7287 mPendingRemove.add(this);
7288 mRemoveOnExit = false;
7289 }
7290 }
Romain Guy06882f82009-06-10 13:36:04 -07007291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007292 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7293 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7294 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7295 if (dtdx < -.000001f || dtdx > .000001f) return false;
7296 if (dsdy < -.000001f || dsdy > .000001f) return false;
7297 return true;
7298 }
Romain Guy06882f82009-06-10 13:36:04 -07007299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007300 void computeShownFrameLocked() {
7301 final boolean selfTransformation = mHasLocalTransformation;
7302 Transformation attachedTransformation =
7303 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7304 ? mAttachedWindow.mTransformation : null;
7305 Transformation appTransformation =
7306 (mAppToken != null && mAppToken.hasTransformation)
7307 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007308
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007309 // Wallpapers are animated based on the "real" window they
7310 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007311 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007312 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007313 if (mWallpaperTarget.mHasLocalTransformation &&
7314 mWallpaperTarget.mAnimation != null &&
7315 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007316 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007317 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007318 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007319 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007320 }
7321 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007322 mWallpaperTarget.mAppToken.hasTransformation &&
7323 mWallpaperTarget.mAppToken.animation != null &&
7324 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007325 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007326 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007327 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007328 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007329 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007330 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007332 if (selfTransformation || attachedTransformation != null
7333 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007334 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007335 final Rect frame = mFrame;
7336 final float tmpFloats[] = mTmpFloats;
7337 final Matrix tmpMatrix = mTmpMatrix;
7338
7339 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007340 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007341 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007342 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007343 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007344 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007345 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007346 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007347 }
7348 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007349 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007350 }
7351
7352 // "convert" it into SurfaceFlinger's format
7353 // (a 2x2 matrix + an offset)
7354 // Here we must not transform the position of the surface
7355 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007356 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007358 tmpMatrix.getValues(tmpFloats);
7359 mDsDx = tmpFloats[Matrix.MSCALE_X];
7360 mDtDx = tmpFloats[Matrix.MSKEW_X];
7361 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7362 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007363 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7364 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007365 int w = frame.width();
7366 int h = frame.height();
7367 mShownFrame.set(x, y, x+w, y+h);
7368
7369 // Now set the alpha... but because our current hardware
7370 // can't do alpha transformation on a non-opaque surface,
7371 // turn it off if we are running an animation that is also
7372 // transforming since it is more important to have that
7373 // animation be smooth.
7374 mShownAlpha = mAlpha;
7375 if (!mLimitedAlphaCompositing
7376 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7377 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7378 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007379 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007380 if (selfTransformation) {
7381 mShownAlpha *= mTransformation.getAlpha();
7382 }
7383 if (attachedTransformation != null) {
7384 mShownAlpha *= attachedTransformation.getAlpha();
7385 }
7386 if (appTransformation != null) {
7387 mShownAlpha *= appTransformation.getAlpha();
7388 }
7389 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007390 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007391 }
Romain Guy06882f82009-06-10 13:36:04 -07007392
Joe Onorato8a9b2202010-02-26 18:56:32 -08007393 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007394 TAG, "Continuing animation in " + this +
7395 ": " + mShownFrame +
7396 ", alpha=" + mTransformation.getAlpha());
7397 return;
7398 }
Romain Guy06882f82009-06-10 13:36:04 -07007399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007400 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007401 if (mXOffset != 0 || mYOffset != 0) {
7402 mShownFrame.offset(mXOffset, mYOffset);
7403 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007404 mShownAlpha = mAlpha;
7405 mDsDx = 1;
7406 mDtDx = 0;
7407 mDsDy = 0;
7408 mDtDy = 1;
7409 }
Romain Guy06882f82009-06-10 13:36:04 -07007410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007411 /**
7412 * Is this window visible? It is not visible if there is no
7413 * surface, or we are in the process of running an exit animation
7414 * that will remove the surface, or its app token has been hidden.
7415 */
7416 public boolean isVisibleLw() {
7417 final AppWindowToken atoken = mAppToken;
7418 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7419 && (atoken == null || !atoken.hiddenRequested)
7420 && !mExiting && !mDestroying;
7421 }
7422
7423 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007424 * Like {@link #isVisibleLw}, but also counts a window that is currently
7425 * "hidden" behind the keyguard as visible. This allows us to apply
7426 * things like window flags that impact the keyguard.
7427 * XXX I am starting to think we need to have ANOTHER visibility flag
7428 * for this "hidden behind keyguard" state rather than overloading
7429 * mPolicyVisibility. Ungh.
7430 */
7431 public boolean isVisibleOrBehindKeyguardLw() {
7432 final AppWindowToken atoken = mAppToken;
7433 return mSurface != null && !mAttachedHidden
7434 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007435 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007436 && !mExiting && !mDestroying;
7437 }
7438
7439 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007440 * Is this window visible, ignoring its app token? It is not visible
7441 * if there is no surface, or we are in the process of running an exit animation
7442 * that will remove the surface.
7443 */
7444 public boolean isWinVisibleLw() {
7445 final AppWindowToken atoken = mAppToken;
7446 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7447 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7448 && !mExiting && !mDestroying;
7449 }
7450
7451 /**
7452 * The same as isVisible(), but follows the current hidden state of
7453 * the associated app token, not the pending requested hidden state.
7454 */
7455 boolean isVisibleNow() {
7456 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007457 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007458 }
7459
7460 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007461 * Can this window possibly be a drag/drop target? The test here is
7462 * a combination of the above "visible now" with the check that the
7463 * Input Manager uses when discarding windows from input consideration.
7464 */
7465 boolean isPotentialDragTarget() {
7466 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7467 }
7468
7469 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007470 * Same as isVisible(), but we also count it as visible between the
7471 * call to IWindowSession.add() and the first relayout().
7472 */
7473 boolean isVisibleOrAdding() {
7474 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007475 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007476 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7477 && mPolicyVisibility && !mAttachedHidden
7478 && (atoken == null || !atoken.hiddenRequested)
7479 && !mExiting && !mDestroying;
7480 }
7481
7482 /**
7483 * Is this window currently on-screen? It is on-screen either if it
7484 * is visible or it is currently running an animation before no longer
7485 * being visible.
7486 */
7487 boolean isOnScreen() {
7488 final AppWindowToken atoken = mAppToken;
7489 if (atoken != null) {
7490 return mSurface != null && mPolicyVisibility && !mDestroying
7491 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007492 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007493 } else {
7494 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007495 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007496 }
7497 }
Romain Guy06882f82009-06-10 13:36:04 -07007498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007499 /**
7500 * Like isOnScreen(), but we don't return true if the window is part
7501 * of a transition that has not yet been started.
7502 */
7503 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007504 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007505 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007506 return false;
7507 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007508 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007509 final boolean animating = atoken != null
7510 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007511 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007512 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7513 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007514 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007515 }
7516
7517 /** Is the window or its container currently animating? */
7518 boolean isAnimating() {
7519 final WindowState attached = mAttachedWindow;
7520 final AppWindowToken atoken = mAppToken;
7521 return mAnimation != null
7522 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007523 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007524 (atoken.animation != null
7525 || atoken.inPendingTransaction));
7526 }
7527
7528 /** Is this window currently animating? */
7529 boolean isWindowAnimating() {
7530 return mAnimation != null;
7531 }
7532
7533 /**
7534 * Like isOnScreen, but returns false if the surface hasn't yet
7535 * been drawn.
7536 */
7537 public boolean isDisplayedLw() {
7538 final AppWindowToken atoken = mAppToken;
7539 return mSurface != null && mPolicyVisibility && !mDestroying
7540 && !mDrawPending && !mCommitDrawPending
7541 && ((!mAttachedHidden &&
7542 (atoken == null || !atoken.hiddenRequested))
7543 || mAnimating);
7544 }
7545
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007546 /**
7547 * Returns true if the window has a surface that it has drawn a
7548 * complete UI in to.
7549 */
7550 public boolean isDrawnLw() {
7551 final AppWindowToken atoken = mAppToken;
7552 return mSurface != null && !mDestroying
7553 && !mDrawPending && !mCommitDrawPending;
7554 }
7555
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007556 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007557 * Return true if the window is opaque and fully drawn. This indicates
7558 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007559 */
7560 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007561 return (mAttrs.format == PixelFormat.OPAQUE
7562 || mAttrs.type == TYPE_WALLPAPER)
7563 && mSurface != null && mAnimation == null
7564 && (mAppToken == null || mAppToken.animation == null)
7565 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007566 }
7567
7568 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7569 return
7570 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007571 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7572 // only if it's visible
7573 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007574 // and only if the application fills the compatible screen
7575 mFrame.left <= mCompatibleScreenFrame.left &&
7576 mFrame.top <= mCompatibleScreenFrame.top &&
7577 mFrame.right >= mCompatibleScreenFrame.right &&
7578 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007579 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007580 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007581 }
7582
7583 boolean isFullscreen(int screenWidth, int screenHeight) {
7584 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007585 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007586 }
7587
7588 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007589 disposeInputChannel();
7590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007591 if (mAttachedWindow != null) {
7592 mAttachedWindow.mChildWindows.remove(this);
7593 }
7594 destroySurfaceLocked();
7595 mSession.windowRemovedLocked();
7596 try {
7597 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7598 } catch (RuntimeException e) {
7599 // Ignore if it has already been removed (usually because
7600 // we are doing this as part of processing a death note.)
7601 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007602 }
7603
7604 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007605 if (mInputChannel != null) {
7606 mInputManager.unregisterInputChannel(mInputChannel);
7607
7608 mInputChannel.dispose();
7609 mInputChannel = null;
Jeff Brown46b9ac02010-04-22 18:58:52 -07007610 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007611 }
7612
7613 private class DeathRecipient implements IBinder.DeathRecipient {
7614 public void binderDied() {
7615 try {
7616 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007617 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007618 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007619 if (win != null) {
7620 removeWindowLocked(mSession, win);
7621 }
7622 }
7623 } catch (IllegalArgumentException ex) {
7624 // This will happen if the window has already been
7625 // removed.
7626 }
7627 }
7628 }
7629
7630 /** Returns true if this window desires key events. */
7631 public final boolean canReceiveKeys() {
7632 return isVisibleOrAdding()
7633 && (mViewVisibility == View.VISIBLE)
7634 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7635 }
7636
7637 public boolean hasDrawnLw() {
7638 return mHasDrawn;
7639 }
7640
7641 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007642 return showLw(doAnimation, true);
7643 }
7644
7645 boolean showLw(boolean doAnimation, boolean requestAnim) {
7646 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7647 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007648 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007649 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007650 if (doAnimation) {
7651 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7652 + mPolicyVisibility + " mAnimation=" + mAnimation);
7653 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7654 doAnimation = false;
7655 } else if (mPolicyVisibility && mAnimation == null) {
7656 // Check for the case where we are currently visible and
7657 // not animating; we do not want to do animation at such a
7658 // point to become visible when we already are.
7659 doAnimation = false;
7660 }
7661 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007662 mPolicyVisibility = true;
7663 mPolicyVisibilityAfterAnim = true;
7664 if (doAnimation) {
7665 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7666 }
7667 if (requestAnim) {
7668 requestAnimationLocked(0);
7669 }
7670 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007671 }
7672
7673 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007674 return hideLw(doAnimation, true);
7675 }
7676
7677 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007678 if (doAnimation) {
7679 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7680 doAnimation = false;
7681 }
7682 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007683 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7684 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007685 if (!current) {
7686 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007687 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007688 if (doAnimation) {
7689 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7690 if (mAnimation == null) {
7691 doAnimation = false;
7692 }
7693 }
7694 if (doAnimation) {
7695 mPolicyVisibilityAfterAnim = false;
7696 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007697 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007698 mPolicyVisibilityAfterAnim = false;
7699 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007700 // Window is no longer visible -- make sure if we were waiting
7701 // for it to be displayed before enabling the display, that
7702 // we allow the display to be enabled now.
7703 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007704 if (mCurrentFocus == this) {
7705 mFocusMayChange = true;
7706 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007707 }
7708 if (requestAnim) {
7709 requestAnimationLocked(0);
7710 }
7711 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007712 }
7713
7714 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007715 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7716 pw.print(" mClient="); pw.println(mClient.asBinder());
7717 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7718 if (mAttachedWindow != null || mLayoutAttached) {
7719 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7720 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7721 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007722 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7723 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7724 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007725 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7726 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007727 }
7728 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7729 pw.print(" mSubLayer="); pw.print(mSubLayer);
7730 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7731 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7732 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7733 pw.print("="); pw.print(mAnimLayer);
7734 pw.print(" mLastLayer="); pw.println(mLastLayer);
7735 if (mSurface != null) {
7736 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007737 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7738 pw.print(" layer="); pw.print(mSurfaceLayer);
7739 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7740 pw.print(" rect=("); pw.print(mSurfaceX);
7741 pw.print(","); pw.print(mSurfaceY);
7742 pw.print(") "); pw.print(mSurfaceW);
7743 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007744 }
7745 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7746 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7747 if (mAppToken != null) {
7748 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7749 }
7750 if (mTargetAppToken != null) {
7751 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7752 }
7753 pw.print(prefix); pw.print("mViewVisibility=0x");
7754 pw.print(Integer.toHexString(mViewVisibility));
7755 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007756 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7757 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007758 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7759 pw.print(prefix); pw.print("mPolicyVisibility=");
7760 pw.print(mPolicyVisibility);
7761 pw.print(" mPolicyVisibilityAfterAnim=");
7762 pw.print(mPolicyVisibilityAfterAnim);
7763 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7764 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007765 if (!mRelayoutCalled) {
7766 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7767 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007768 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007769 pw.print(" h="); pw.print(mRequestedHeight);
7770 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007771 if (mXOffset != 0 || mYOffset != 0) {
7772 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7773 pw.print(" y="); pw.println(mYOffset);
7774 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007775 pw.print(prefix); pw.print("mGivenContentInsets=");
7776 mGivenContentInsets.printShortString(pw);
7777 pw.print(" mGivenVisibleInsets=");
7778 mGivenVisibleInsets.printShortString(pw);
7779 pw.println();
7780 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7781 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7782 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7783 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007784 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007785 pw.print(prefix); pw.print("mShownFrame=");
7786 mShownFrame.printShortString(pw);
7787 pw.print(" last="); mLastShownFrame.printShortString(pw);
7788 pw.println();
7789 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7790 pw.print(" last="); mLastFrame.printShortString(pw);
7791 pw.println();
7792 pw.print(prefix); pw.print("mContainingFrame=");
7793 mContainingFrame.printShortString(pw);
7794 pw.print(" mDisplayFrame=");
7795 mDisplayFrame.printShortString(pw);
7796 pw.println();
7797 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7798 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7799 pw.println();
7800 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7801 pw.print(" last="); mLastContentInsets.printShortString(pw);
7802 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7803 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7804 pw.println();
7805 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7806 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7807 pw.print(" mAlpha="); pw.print(mAlpha);
7808 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7809 }
7810 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7811 || mAnimation != null) {
7812 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7813 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7814 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7815 pw.print(" mAnimation="); pw.println(mAnimation);
7816 }
7817 if (mHasTransformation || mHasLocalTransformation) {
7818 pw.print(prefix); pw.print("XForm: has=");
7819 pw.print(mHasTransformation);
7820 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7821 pw.print(" "); mTransformation.printShortString(pw);
7822 pw.println();
7823 }
7824 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7825 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7826 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7827 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7828 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7829 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7830 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7831 pw.print(" mDestroying="); pw.print(mDestroying);
7832 pw.print(" mRemoved="); pw.println(mRemoved);
7833 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007834 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007835 pw.print(prefix); pw.print("mOrientationChanging=");
7836 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007837 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7838 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007839 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007840 if (mHScale != 1 || mVScale != 1) {
7841 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7842 pw.print(" mVScale="); pw.println(mVScale);
7843 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007844 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007845 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7846 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7847 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007848 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7849 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7850 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7851 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007852 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07007853
7854 String makeInputChannelName() {
7855 return Integer.toHexString(System.identityHashCode(this))
7856 + " " + mAttrs.getTitle();
7857 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007858
7859 @Override
7860 public String toString() {
7861 return "Window{"
7862 + Integer.toHexString(System.identityHashCode(this))
7863 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7864 }
7865 }
Romain Guy06882f82009-06-10 13:36:04 -07007866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007867 // -------------------------------------------------------------
7868 // Window Token State
7869 // -------------------------------------------------------------
7870
7871 class WindowToken {
7872 // The actual token.
7873 final IBinder token;
7874
7875 // The type of window this token is for, as per WindowManager.LayoutParams.
7876 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007878 // Set if this token was explicitly added by a client, so should
7879 // not be removed when all windows are removed.
7880 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007881
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007882 // For printing.
7883 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007885 // If this is an AppWindowToken, this is non-null.
7886 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007888 // All of the windows associated with this token.
7889 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7890
7891 // Is key dispatching paused for this token?
7892 boolean paused = false;
7893
7894 // Should this token's windows be hidden?
7895 boolean hidden;
7896
7897 // Temporary for finding which tokens no longer have visible windows.
7898 boolean hasVisible;
7899
Dianne Hackborna8f60182009-09-01 19:01:50 -07007900 // Set to true when this token is in a pending transaction where it
7901 // will be shown.
7902 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007903
Dianne Hackborna8f60182009-09-01 19:01:50 -07007904 // Set to true when this token is in a pending transaction where it
7905 // will be hidden.
7906 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007907
Dianne Hackborna8f60182009-09-01 19:01:50 -07007908 // Set to true when this token is in a pending transaction where its
7909 // windows will be put to the bottom of the list.
7910 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007911
Dianne Hackborna8f60182009-09-01 19:01:50 -07007912 // Set to true when this token is in a pending transaction where its
7913 // windows will be put to the top of the list.
7914 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007916 WindowToken(IBinder _token, int type, boolean _explicit) {
7917 token = _token;
7918 windowType = type;
7919 explicit = _explicit;
7920 }
7921
7922 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007923 pw.print(prefix); pw.print("token="); pw.println(token);
7924 pw.print(prefix); pw.print("windows="); pw.println(windows);
7925 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7926 pw.print(" hidden="); pw.print(hidden);
7927 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007928 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7929 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7930 pw.print(" waitingToHide="); pw.print(waitingToHide);
7931 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7932 pw.print(" sendingToTop="); pw.println(sendingToTop);
7933 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007934 }
7935
7936 @Override
7937 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007938 if (stringName == null) {
7939 StringBuilder sb = new StringBuilder();
7940 sb.append("WindowToken{");
7941 sb.append(Integer.toHexString(System.identityHashCode(this)));
7942 sb.append(" token="); sb.append(token); sb.append('}');
7943 stringName = sb.toString();
7944 }
7945 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007946 }
7947 };
7948
7949 class AppWindowToken extends WindowToken {
7950 // Non-null only for application tokens.
7951 final IApplicationToken appToken;
7952
7953 // All of the windows and child windows that are included in this
7954 // application token. Note this list is NOT sorted!
7955 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7956
7957 int groupId = -1;
7958 boolean appFullscreen;
7959 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007960
7961 // The input dispatching timeout for this application token in nanoseconds.
7962 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007964 // These are used for determining when all windows associated with
7965 // an activity have been drawn, so they can be made visible together
7966 // at the same time.
7967 int lastTransactionSequence = mTransactionSequence-1;
7968 int numInterestingWindows;
7969 int numDrawnWindows;
7970 boolean inPendingTransaction;
7971 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007973 // Is this token going to be hidden in a little while? If so, it
7974 // won't be taken into account for setting the screen orientation.
7975 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007977 // Is this window's surface needed? This is almost like hidden, except
7978 // it will sometimes be true a little earlier: when the token has
7979 // been shown, but is still waiting for its app transition to execute
7980 // before making its windows shown.
7981 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007983 // Have we told the window clients to hide themselves?
7984 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007986 // Last visibility state we reported to the app token.
7987 boolean reportedVisible;
7988
7989 // Set to true when the token has been removed from the window mgr.
7990 boolean removed;
7991
7992 // Have we been asked to have this token keep the screen frozen?
7993 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007995 boolean animating;
7996 Animation animation;
7997 boolean hasTransformation;
7998 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008000 // Offset to the window of all layers in the token, for use by
8001 // AppWindowToken animations.
8002 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008004 // Information about an application starting window if displayed.
8005 StartingData startingData;
8006 WindowState startingWindow;
8007 View startingView;
8008 boolean startingDisplayed;
8009 boolean startingMoved;
8010 boolean firstWindowDrawn;
8011
8012 AppWindowToken(IApplicationToken _token) {
8013 super(_token.asBinder(),
8014 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8015 appWindowToken = this;
8016 appToken = _token;
8017 }
Romain Guy06882f82009-06-10 13:36:04 -07008018
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008019 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008020 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008021 TAG, "Setting animation in " + this + ": " + anim);
8022 animation = anim;
8023 animating = false;
8024 anim.restrictDuration(MAX_ANIMATION_DURATION);
8025 anim.scaleCurrentDuration(mTransitionAnimationScale);
8026 int zorder = anim.getZAdjustment();
8027 int adj = 0;
8028 if (zorder == Animation.ZORDER_TOP) {
8029 adj = TYPE_LAYER_OFFSET;
8030 } else if (zorder == Animation.ZORDER_BOTTOM) {
8031 adj = -TYPE_LAYER_OFFSET;
8032 }
Romain Guy06882f82009-06-10 13:36:04 -07008033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008034 if (animLayerAdjustment != adj) {
8035 animLayerAdjustment = adj;
8036 updateLayers();
8037 }
8038 }
Romain Guy06882f82009-06-10 13:36:04 -07008039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008040 public void setDummyAnimation() {
8041 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008042 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008043 TAG, "Setting dummy animation in " + this);
8044 animation = sDummyAnimation;
8045 }
8046 }
8047
8048 public void clearAnimation() {
8049 if (animation != null) {
8050 animation = null;
8051 animating = true;
8052 }
8053 }
Romain Guy06882f82009-06-10 13:36:04 -07008054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008055 void updateLayers() {
8056 final int N = allAppWindows.size();
8057 final int adj = animLayerAdjustment;
8058 for (int i=0; i<N; i++) {
8059 WindowState w = allAppWindows.get(i);
8060 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008061 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008062 + w.mAnimLayer);
8063 if (w == mInputMethodTarget) {
8064 setInputMethodAnimLayerAdjustment(adj);
8065 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008066 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008067 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008068 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008069 }
8070 }
Romain Guy06882f82009-06-10 13:36:04 -07008071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008072 void sendAppVisibilityToClients() {
8073 final int N = allAppWindows.size();
8074 for (int i=0; i<N; i++) {
8075 WindowState win = allAppWindows.get(i);
8076 if (win == startingWindow && clientHidden) {
8077 // Don't hide the starting window.
8078 continue;
8079 }
8080 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008081 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008082 "Setting visibility of " + win + ": " + (!clientHidden));
8083 win.mClient.dispatchAppVisibility(!clientHidden);
8084 } catch (RemoteException e) {
8085 }
8086 }
8087 }
Romain Guy06882f82009-06-10 13:36:04 -07008088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008089 void showAllWindowsLocked() {
8090 final int NW = allAppWindows.size();
8091 for (int i=0; i<NW; i++) {
8092 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008093 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008094 "performing show on: " + w);
8095 w.performShowLocked();
8096 }
8097 }
Romain Guy06882f82009-06-10 13:36:04 -07008098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008099 // This must be called while inside a transaction.
8100 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008101 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008102 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008104 if (animation == sDummyAnimation) {
8105 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008106 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008107 // when it is really time to animate, this will be set to
8108 // a real animation and the next call will execute normally.
8109 return false;
8110 }
Romain Guy06882f82009-06-10 13:36:04 -07008111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008112 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8113 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008114 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008115 TAG, "Starting animation in " + this +
8116 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8117 + " scale=" + mTransitionAnimationScale
8118 + " allDrawn=" + allDrawn + " animating=" + animating);
8119 animation.initialize(dw, dh, dw, dh);
8120 animation.setStartTime(currentTime);
8121 animating = true;
8122 }
8123 transformation.clear();
8124 final boolean more = animation.getTransformation(
8125 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008126 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008127 TAG, "Stepped animation in " + this +
8128 ": more=" + more + ", xform=" + transformation);
8129 if (more) {
8130 // we're done!
8131 hasTransformation = true;
8132 return true;
8133 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008134 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008135 TAG, "Finished animation in " + this +
8136 " @ " + currentTime);
8137 animation = null;
8138 }
8139 } else if (animation != null) {
8140 // If the display is frozen, and there is a pending animation,
8141 // clear it and make sure we run the cleanup code.
8142 animating = true;
8143 animation = null;
8144 }
8145
8146 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008148 if (!animating) {
8149 return false;
8150 }
8151
8152 clearAnimation();
8153 animating = false;
8154 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8155 moveInputMethodWindowsIfNeededLocked(true);
8156 }
Romain Guy06882f82009-06-10 13:36:04 -07008157
Joe Onorato8a9b2202010-02-26 18:56:32 -08008158 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008159 TAG, "Animation done in " + this
8160 + ": reportedVisible=" + reportedVisible);
8161
8162 transformation.clear();
8163 if (animLayerAdjustment != 0) {
8164 animLayerAdjustment = 0;
8165 updateLayers();
8166 }
Romain Guy06882f82009-06-10 13:36:04 -07008167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008168 final int N = windows.size();
8169 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008170 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008171 }
8172 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008174 return false;
8175 }
8176
8177 void updateReportedVisibilityLocked() {
8178 if (appToken == null) {
8179 return;
8180 }
Romain Guy06882f82009-06-10 13:36:04 -07008181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008182 int numInteresting = 0;
8183 int numVisible = 0;
8184 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008185
Joe Onorato8a9b2202010-02-26 18:56:32 -08008186 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008187 final int N = allAppWindows.size();
8188 for (int i=0; i<N; i++) {
8189 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008190 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008191 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008192 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8193 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008194 continue;
8195 }
8196 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008197 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008198 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008199 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008200 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008201 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008202 + " pv=" + win.mPolicyVisibility
8203 + " dp=" + win.mDrawPending
8204 + " cdp=" + win.mCommitDrawPending
8205 + " ah=" + win.mAttachedHidden
8206 + " th="
8207 + (win.mAppToken != null
8208 ? win.mAppToken.hiddenRequested : false)
8209 + " a=" + win.mAnimating);
8210 }
8211 }
8212 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008213 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008214 if (!win.isAnimating()) {
8215 numVisible++;
8216 }
8217 nowGone = false;
8218 } else if (win.isAnimating()) {
8219 nowGone = false;
8220 }
8221 }
Romain Guy06882f82009-06-10 13:36:04 -07008222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008223 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008224 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008225 + numInteresting + " visible=" + numVisible);
8226 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008227 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008228 TAG, "Visibility changed in " + this
8229 + ": vis=" + nowVisible);
8230 reportedVisible = nowVisible;
8231 Message m = mH.obtainMessage(
8232 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8233 nowVisible ? 1 : 0,
8234 nowGone ? 1 : 0,
8235 this);
8236 mH.sendMessage(m);
8237 }
8238 }
Romain Guy06882f82009-06-10 13:36:04 -07008239
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008240 WindowState findMainWindow() {
8241 int j = windows.size();
8242 while (j > 0) {
8243 j--;
8244 WindowState win = windows.get(j);
8245 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8246 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8247 return win;
8248 }
8249 }
8250 return null;
8251 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008253 void dump(PrintWriter pw, String prefix) {
8254 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008255 if (appToken != null) {
8256 pw.print(prefix); pw.println("app=true");
8257 }
8258 if (allAppWindows.size() > 0) {
8259 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8260 }
8261 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008262 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008263 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8264 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8265 pw.print(" clientHidden="); pw.print(clientHidden);
8266 pw.print(" willBeHidden="); pw.print(willBeHidden);
8267 pw.print(" reportedVisible="); pw.println(reportedVisible);
8268 if (paused || freezingScreen) {
8269 pw.print(prefix); pw.print("paused="); pw.print(paused);
8270 pw.print(" freezingScreen="); pw.println(freezingScreen);
8271 }
8272 if (numInterestingWindows != 0 || numDrawnWindows != 0
8273 || inPendingTransaction || allDrawn) {
8274 pw.print(prefix); pw.print("numInterestingWindows=");
8275 pw.print(numInterestingWindows);
8276 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8277 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8278 pw.print(" allDrawn="); pw.println(allDrawn);
8279 }
8280 if (animating || animation != null) {
8281 pw.print(prefix); pw.print("animating="); pw.print(animating);
8282 pw.print(" animation="); pw.println(animation);
8283 }
8284 if (animLayerAdjustment != 0) {
8285 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8286 }
8287 if (hasTransformation) {
8288 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8289 pw.print(" transformation="); transformation.printShortString(pw);
8290 pw.println();
8291 }
8292 if (startingData != null || removed || firstWindowDrawn) {
8293 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8294 pw.print(" removed="); pw.print(removed);
8295 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8296 }
8297 if (startingWindow != null || startingView != null
8298 || startingDisplayed || startingMoved) {
8299 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8300 pw.print(" startingView="); pw.print(startingView);
8301 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8302 pw.print(" startingMoved"); pw.println(startingMoved);
8303 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008304 }
8305
8306 @Override
8307 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008308 if (stringName == null) {
8309 StringBuilder sb = new StringBuilder();
8310 sb.append("AppWindowToken{");
8311 sb.append(Integer.toHexString(System.identityHashCode(this)));
8312 sb.append(" token="); sb.append(token); sb.append('}');
8313 stringName = sb.toString();
8314 }
8315 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008316 }
8317 }
Romain Guy06882f82009-06-10 13:36:04 -07008318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008319 // -------------------------------------------------------------
8320 // DummyAnimation
8321 // -------------------------------------------------------------
8322
8323 // This is an animation that does nothing: it just immediately finishes
8324 // itself every time it is called. It is used as a stub animation in cases
8325 // where we want to synchronize multiple things that may be animating.
8326 static final class DummyAnimation extends Animation {
8327 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8328 return false;
8329 }
8330 }
8331 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008332
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008333 // -------------------------------------------------------------
8334 // Async Handler
8335 // -------------------------------------------------------------
8336
8337 static final class StartingData {
8338 final String pkg;
8339 final int theme;
8340 final CharSequence nonLocalizedLabel;
8341 final int labelRes;
8342 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008344 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8345 int _labelRes, int _icon) {
8346 pkg = _pkg;
8347 theme = _theme;
8348 nonLocalizedLabel = _nonLocalizedLabel;
8349 labelRes = _labelRes;
8350 icon = _icon;
8351 }
8352 }
8353
8354 private final class H extends Handler {
8355 public static final int REPORT_FOCUS_CHANGE = 2;
8356 public static final int REPORT_LOSING_FOCUS = 3;
8357 public static final int ANIMATE = 4;
8358 public static final int ADD_STARTING = 5;
8359 public static final int REMOVE_STARTING = 6;
8360 public static final int FINISHED_STARTING = 7;
8361 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008362 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8363 public static final int HOLD_SCREEN_CHANGED = 12;
8364 public static final int APP_TRANSITION_TIMEOUT = 13;
8365 public static final int PERSIST_ANIMATION_SCALE = 14;
8366 public static final int FORCE_GC = 15;
8367 public static final int ENABLE_SCREEN = 16;
8368 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008369 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008370 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008371 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f12010-10-19 15:15:08 -07008372 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008374 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008376 public H() {
8377 }
Romain Guy06882f82009-06-10 13:36:04 -07008378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008379 @Override
8380 public void handleMessage(Message msg) {
8381 switch (msg.what) {
8382 case REPORT_FOCUS_CHANGE: {
8383 WindowState lastFocus;
8384 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008386 synchronized(mWindowMap) {
8387 lastFocus = mLastFocus;
8388 newFocus = mCurrentFocus;
8389 if (lastFocus == newFocus) {
8390 // Focus is not changing, so nothing to do.
8391 return;
8392 }
8393 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008394 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008395 // + " to " + newFocus);
8396 if (newFocus != null && lastFocus != null
8397 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008398 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008399 mLosingFocus.add(lastFocus);
8400 lastFocus = null;
8401 }
8402 }
8403
8404 if (lastFocus != newFocus) {
8405 //System.out.println("Changing focus from " + lastFocus
8406 // + " to " + newFocus);
8407 if (newFocus != null) {
8408 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008409 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008410 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8411 } catch (RemoteException e) {
8412 // Ignore if process has died.
8413 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008414 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008415 }
8416
8417 if (lastFocus != null) {
8418 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008419 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008420 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8421 } catch (RemoteException e) {
8422 // Ignore if process has died.
8423 }
8424 }
8425 }
8426 } break;
8427
8428 case REPORT_LOSING_FOCUS: {
8429 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008431 synchronized(mWindowMap) {
8432 losers = mLosingFocus;
8433 mLosingFocus = new ArrayList<WindowState>();
8434 }
8435
8436 final int N = losers.size();
8437 for (int i=0; i<N; i++) {
8438 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008439 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008440 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8441 } catch (RemoteException e) {
8442 // Ignore if process has died.
8443 }
8444 }
8445 } break;
8446
8447 case ANIMATE: {
8448 synchronized(mWindowMap) {
8449 mAnimationPending = false;
8450 performLayoutAndPlaceSurfacesLocked();
8451 }
8452 } break;
8453
8454 case ADD_STARTING: {
8455 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8456 final StartingData sd = wtoken.startingData;
8457
8458 if (sd == null) {
8459 // Animation has been canceled... do nothing.
8460 return;
8461 }
Romain Guy06882f82009-06-10 13:36:04 -07008462
Joe Onorato8a9b2202010-02-26 18:56:32 -08008463 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008464 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008466 View view = null;
8467 try {
8468 view = mPolicy.addStartingWindow(
8469 wtoken.token, sd.pkg,
8470 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8471 sd.icon);
8472 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008473 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008474 }
8475
8476 if (view != null) {
8477 boolean abort = false;
8478
8479 synchronized(mWindowMap) {
8480 if (wtoken.removed || wtoken.startingData == null) {
8481 // If the window was successfully added, then
8482 // we need to remove it.
8483 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008484 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008485 "Aborted starting " + wtoken
8486 + ": removed=" + wtoken.removed
8487 + " startingData=" + wtoken.startingData);
8488 wtoken.startingWindow = null;
8489 wtoken.startingData = null;
8490 abort = true;
8491 }
8492 } else {
8493 wtoken.startingView = view;
8494 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008495 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008496 "Added starting " + wtoken
8497 + ": startingWindow="
8498 + wtoken.startingWindow + " startingView="
8499 + wtoken.startingView);
8500 }
8501
8502 if (abort) {
8503 try {
8504 mPolicy.removeStartingWindow(wtoken.token, view);
8505 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008506 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008507 }
8508 }
8509 }
8510 } break;
8511
8512 case REMOVE_STARTING: {
8513 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8514 IBinder token = null;
8515 View view = null;
8516 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008517 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008518 + wtoken + ": startingWindow="
8519 + wtoken.startingWindow + " startingView="
8520 + wtoken.startingView);
8521 if (wtoken.startingWindow != null) {
8522 view = wtoken.startingView;
8523 token = wtoken.token;
8524 wtoken.startingData = null;
8525 wtoken.startingView = null;
8526 wtoken.startingWindow = null;
8527 }
8528 }
8529 if (view != null) {
8530 try {
8531 mPolicy.removeStartingWindow(token, view);
8532 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008533 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008534 }
8535 }
8536 } break;
8537
8538 case FINISHED_STARTING: {
8539 IBinder token = null;
8540 View view = null;
8541 while (true) {
8542 synchronized (mWindowMap) {
8543 final int N = mFinishedStarting.size();
8544 if (N <= 0) {
8545 break;
8546 }
8547 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8548
Joe Onorato8a9b2202010-02-26 18:56:32 -08008549 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008550 "Finished starting " + wtoken
8551 + ": startingWindow=" + wtoken.startingWindow
8552 + " startingView=" + wtoken.startingView);
8553
8554 if (wtoken.startingWindow == null) {
8555 continue;
8556 }
8557
8558 view = wtoken.startingView;
8559 token = wtoken.token;
8560 wtoken.startingData = null;
8561 wtoken.startingView = null;
8562 wtoken.startingWindow = null;
8563 }
8564
8565 try {
8566 mPolicy.removeStartingWindow(token, view);
8567 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008568 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008569 }
8570 }
8571 } break;
8572
8573 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8574 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8575
8576 boolean nowVisible = msg.arg1 != 0;
8577 boolean nowGone = msg.arg2 != 0;
8578
8579 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008580 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008581 TAG, "Reporting visible in " + wtoken
8582 + " visible=" + nowVisible
8583 + " gone=" + nowGone);
8584 if (nowVisible) {
8585 wtoken.appToken.windowsVisible();
8586 } else {
8587 wtoken.appToken.windowsGone();
8588 }
8589 } catch (RemoteException ex) {
8590 }
8591 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008593 case WINDOW_FREEZE_TIMEOUT: {
8594 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008595 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008596 int i = mWindows.size();
8597 while (i > 0) {
8598 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008599 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008600 if (w.mOrientationChanging) {
8601 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008602 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008603 }
8604 }
8605 performLayoutAndPlaceSurfacesLocked();
8606 }
8607 break;
8608 }
Romain Guy06882f82009-06-10 13:36:04 -07008609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008610 case HOLD_SCREEN_CHANGED: {
8611 Session oldHold;
8612 Session newHold;
8613 synchronized (mWindowMap) {
8614 oldHold = mLastReportedHold;
8615 newHold = (Session)msg.obj;
8616 mLastReportedHold = newHold;
8617 }
Romain Guy06882f82009-06-10 13:36:04 -07008618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008619 if (oldHold != newHold) {
8620 try {
8621 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008622 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008623 "window",
8624 BatteryStats.WAKE_TYPE_WINDOW);
8625 }
8626 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008627 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008628 "window",
8629 BatteryStats.WAKE_TYPE_WINDOW);
8630 }
8631 } catch (RemoteException e) {
8632 }
8633 }
8634 break;
8635 }
Romain Guy06882f82009-06-10 13:36:04 -07008636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008637 case APP_TRANSITION_TIMEOUT: {
8638 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008639 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008640 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008641 "*** APP TRANSITION TIMEOUT");
8642 mAppTransitionReady = true;
8643 mAppTransitionTimeout = true;
8644 performLayoutAndPlaceSurfacesLocked();
8645 }
8646 }
8647 break;
8648 }
Romain Guy06882f82009-06-10 13:36:04 -07008649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008650 case PERSIST_ANIMATION_SCALE: {
8651 Settings.System.putFloat(mContext.getContentResolver(),
8652 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8653 Settings.System.putFloat(mContext.getContentResolver(),
8654 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8655 break;
8656 }
Romain Guy06882f82009-06-10 13:36:04 -07008657
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008658 case FORCE_GC: {
8659 synchronized(mWindowMap) {
8660 if (mAnimationPending) {
8661 // If we are animating, don't do the gc now but
8662 // delay a bit so we don't interrupt the animation.
8663 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8664 2000);
8665 return;
8666 }
8667 // If we are currently rotating the display, it will
8668 // schedule a new message when done.
8669 if (mDisplayFrozen) {
8670 return;
8671 }
8672 mFreezeGcPending = 0;
8673 }
8674 Runtime.getRuntime().gc();
8675 break;
8676 }
Romain Guy06882f82009-06-10 13:36:04 -07008677
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008678 case ENABLE_SCREEN: {
8679 performEnableScreen();
8680 break;
8681 }
Romain Guy06882f82009-06-10 13:36:04 -07008682
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008683 case APP_FREEZE_TIMEOUT: {
8684 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008685 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008686 int i = mAppTokens.size();
8687 while (i > 0) {
8688 i--;
8689 AppWindowToken tok = mAppTokens.get(i);
8690 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008691 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008692 unsetAppFreezingScreenLocked(tok, true, true);
8693 }
8694 }
8695 }
8696 break;
8697 }
Romain Guy06882f82009-06-10 13:36:04 -07008698
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008699 case SEND_NEW_CONFIGURATION: {
8700 removeMessages(SEND_NEW_CONFIGURATION);
8701 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008702 break;
8703 }
Romain Guy06882f82009-06-10 13:36:04 -07008704
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008705 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008706 if (mWindowsChanged) {
8707 synchronized (mWindowMap) {
8708 mWindowsChanged = false;
8709 }
8710 notifyWindowsChanged();
8711 }
8712 break;
8713 }
8714
Christopher Tatea53146c2010-09-07 11:57:52 -07008715 case DRAG_START_TIMEOUT: {
8716 IBinder win = (IBinder)msg.obj;
8717 if (DEBUG_DRAG) {
8718 Slog.w(TAG, "Timeout starting drag by win " + win);
8719 }
8720 synchronized (mWindowMap) {
8721 // !!! TODO: ANR the app that has failed to start the drag in time
8722 if (mDragState != null) {
Chris Tated4533f12010-10-19 15:15:08 -07008723 mDragState.unregister();
8724 mInputMonitor.updateInputWindowsLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07008725 mDragState.reset();
8726 mDragState = null;
8727 }
8728 }
Chris Tated4533f12010-10-19 15:15:08 -07008729 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07008730 }
8731
Chris Tated4533f12010-10-19 15:15:08 -07008732 case DRAG_END_TIMEOUT: {
8733 IBinder win = (IBinder)msg.obj;
8734 if (DEBUG_DRAG) {
8735 Slog.w(TAG, "Timeout ending drag to win " + win);
8736 }
8737 synchronized (mWindowMap) {
8738 // !!! TODO: ANR the drag-receiving app
8739 mDragState.mDragResult = false;
8740 mDragState.endDragLw();
8741 }
8742 break;
8743 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008744 }
8745 }
8746 }
8747
8748 // -------------------------------------------------------------
8749 // IWindowManager API
8750 // -------------------------------------------------------------
8751
8752 public IWindowSession openSession(IInputMethodClient client,
8753 IInputContext inputContext) {
8754 if (client == null) throw new IllegalArgumentException("null client");
8755 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac02010-04-22 18:58:52 -07008756 Session session = new Session(client, inputContext);
8757 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008758 }
8759
8760 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8761 synchronized (mWindowMap) {
8762 // The focus for the client is the window immediately below
8763 // where we would place the input method window.
8764 int idx = findDesiredInputMethodWindowIndexLocked(false);
8765 WindowState imFocus;
8766 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008767 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008768 if (imFocus != null) {
8769 if (imFocus.mSession.mClient != null &&
8770 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8771 return true;
8772 }
8773 }
8774 }
8775 }
8776 return false;
8777 }
Romain Guy06882f82009-06-10 13:36:04 -07008778
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008779 // -------------------------------------------------------------
8780 // Internals
8781 // -------------------------------------------------------------
8782
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008783 final WindowState windowForClientLocked(Session session, IWindow client,
8784 boolean throwOnError) {
8785 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008786 }
Romain Guy06882f82009-06-10 13:36:04 -07008787
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008788 final WindowState windowForClientLocked(Session session, IBinder client,
8789 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008790 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008791 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008792 TAG, "Looking up client " + client + ": " + win);
8793 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008794 RuntimeException ex = new IllegalArgumentException(
8795 "Requested window " + client + " does not exist");
8796 if (throwOnError) {
8797 throw ex;
8798 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008799 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008800 return null;
8801 }
8802 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008803 RuntimeException ex = new IllegalArgumentException(
8804 "Requested window " + client + " is in session " +
8805 win.mSession + ", not " + session);
8806 if (throwOnError) {
8807 throw ex;
8808 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008809 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008810 return null;
8811 }
8812
8813 return win;
8814 }
8815
Dianne Hackborna8f60182009-09-01 19:01:50 -07008816 final void rebuildAppWindowListLocked() {
8817 int NW = mWindows.size();
8818 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008819 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008820 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008821
Dianne Hackborna8f60182009-09-01 19:01:50 -07008822 // First remove all existing app windows.
8823 i=0;
8824 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008825 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008826 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008827 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008828 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008829 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008830 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008831 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008832 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008833 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008834 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8835 && lastWallpaper == i-1) {
8836 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008837 }
8838 i++;
8839 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008840
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008841 // The wallpaper window(s) typically live at the bottom of the stack,
8842 // so skip them before adding app tokens.
8843 lastWallpaper++;
8844 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008845
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008846 // First add all of the exiting app tokens... these are no longer
8847 // in the main app list, but still have windows shown. We put them
8848 // in the back because now that the animation is over we no longer
8849 // will care about them.
8850 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008851 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008852 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8853 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008854
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008855 // And add in the still active app tokens in Z order.
8856 NT = mAppTokens.size();
8857 for (int j=0; j<NT; j++) {
8858 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008859 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008860
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008861 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008862 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008863 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008864 + " windows but added " + i);
8865 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008866 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008867
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008868 private final void assignLayersLocked() {
8869 int N = mWindows.size();
8870 int curBaseLayer = 0;
8871 int curLayer = 0;
8872 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008873
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008874 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008875 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008876 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8877 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008878 curLayer += WINDOW_LAYER_MULTIPLIER;
8879 w.mLayer = curLayer;
8880 } else {
8881 curBaseLayer = curLayer = w.mBaseLayer;
8882 w.mLayer = curLayer;
8883 }
8884 if (w.mTargetAppToken != null) {
8885 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8886 } else if (w.mAppToken != null) {
8887 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8888 } else {
8889 w.mAnimLayer = w.mLayer;
8890 }
8891 if (w.mIsImWindow) {
8892 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008893 } else if (w.mIsWallpaper) {
8894 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008895 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008896 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008897 + w.mAnimLayer);
8898 //System.out.println(
8899 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8900 }
8901 }
8902
8903 private boolean mInLayout = false;
8904 private final void performLayoutAndPlaceSurfacesLocked() {
8905 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008906 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008907 throw new RuntimeException("Recursive call!");
8908 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008909 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008910 return;
8911 }
8912
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008913 if (mWaitingForConfig) {
8914 // Our configuration has changed (most likely rotation), but we
8915 // don't yet have the complete configuration to report to
8916 // applications. Don't do any window layout until we have it.
8917 return;
8918 }
8919
Dianne Hackbornce2ef762010-09-20 11:39:14 -07008920 if (mDisplay == null) {
8921 // Not yet initialized, nothing to do.
8922 return;
8923 }
8924
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008925 boolean recoveringMemory = false;
8926 if (mForceRemoves != null) {
8927 recoveringMemory = true;
8928 // Wait a little it for things to settle down, and off we go.
8929 for (int i=0; i<mForceRemoves.size(); i++) {
8930 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008931 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008932 removeWindowInnerLocked(ws.mSession, ws);
8933 }
8934 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008935 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008936 Object tmp = new Object();
8937 synchronized (tmp) {
8938 try {
8939 tmp.wait(250);
8940 } catch (InterruptedException e) {
8941 }
8942 }
8943 }
Romain Guy06882f82009-06-10 13:36:04 -07008944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008945 mInLayout = true;
8946 try {
8947 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008949 int i = mPendingRemove.size()-1;
8950 if (i >= 0) {
8951 while (i >= 0) {
8952 WindowState w = mPendingRemove.get(i);
8953 removeWindowInnerLocked(w.mSession, w);
8954 i--;
8955 }
8956 mPendingRemove.clear();
8957
8958 mInLayout = false;
8959 assignLayersLocked();
8960 mLayoutNeeded = true;
8961 performLayoutAndPlaceSurfacesLocked();
8962
8963 } else {
8964 mInLayout = false;
8965 if (mLayoutNeeded) {
8966 requestAnimationLocked(0);
8967 }
8968 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008969 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008970 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8971 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008972 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008973 } catch (RuntimeException e) {
8974 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008975 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008976 }
8977 }
8978
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008979 private final int performLayoutLockedInner() {
8980 if (!mLayoutNeeded) {
8981 return 0;
8982 }
8983
8984 mLayoutNeeded = false;
8985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008986 final int dw = mDisplay.getWidth();
8987 final int dh = mDisplay.getHeight();
8988
8989 final int N = mWindows.size();
8990 int i;
8991
Joe Onorato8a9b2202010-02-26 18:56:32 -08008992 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008993 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8994
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008995 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008996
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008997 int seq = mLayoutSeq+1;
8998 if (seq < 0) seq = 0;
8999 mLayoutSeq = seq;
9000
9001 // First perform layout of any root windows (not attached
9002 // to another window).
9003 int topAttached = -1;
9004 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009005 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009006
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009007 // Don't do layout of a window if it is not visible, or
9008 // soon won't be visible, to avoid wasting time and funky
9009 // changes while a window is animating away.
9010 final AppWindowToken atoken = win.mAppToken;
9011 final boolean gone = win.mViewVisibility == View.GONE
9012 || !win.mRelayoutCalled
9013 || win.mRootToken.hidden
9014 || (atoken != null && atoken.hiddenRequested)
9015 || win.mAttachedHidden
9016 || win.mExiting || win.mDestroying;
9017
9018 if (!win.mLayoutAttached) {
9019 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
9020 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9021 + " mLayoutAttached=" + win.mLayoutAttached);
9022 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
9023 + win.mViewVisibility + " mRelayoutCalled="
9024 + win.mRelayoutCalled + " hidden="
9025 + win.mRootToken.hidden + " hiddenRequested="
9026 + (atoken != null && atoken.hiddenRequested)
9027 + " mAttachedHidden=" + win.mAttachedHidden);
9028 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009029
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009030 // If this view is GONE, then skip it -- keep the current
9031 // frame, and let the caller know so they can ignore it
9032 // if they want. (We do the normal layout for INVISIBLE
9033 // windows, since that means "perform layout as normal,
9034 // just don't display").
9035 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009036 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009037 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9038 win.mLayoutSeq = seq;
9039 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9040 + win.mFrame + " mContainingFrame="
9041 + win.mContainingFrame + " mDisplayFrame="
9042 + win.mDisplayFrame);
9043 } else {
9044 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009045 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009046 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009047 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009048
9049 // Now perform layout of attached windows, which usually
9050 // depend on the position of the window they are attached to.
9051 // XXX does not deal with windows that are attached to windows
9052 // that are themselves attached.
9053 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009054 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009055
9056 // If this view is GONE, then skip it -- keep the current
9057 // frame, and let the caller know so they can ignore it
9058 // if they want. (We do the normal layout for INVISIBLE
9059 // windows, since that means "perform layout as normal,
9060 // just don't display").
9061 if (win.mLayoutAttached) {
9062 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9063 + " mHaveFrame=" + win.mHaveFrame
9064 + " mViewVisibility=" + win.mViewVisibility
9065 + " mRelayoutCalled=" + win.mRelayoutCalled);
9066 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9067 || !win.mHaveFrame) {
9068 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9069 win.mLayoutSeq = seq;
9070 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9071 + win.mFrame + " mContainingFrame="
9072 + win.mContainingFrame + " mDisplayFrame="
9073 + win.mDisplayFrame);
9074 }
9075 }
9076 }
Jeff Brown349703e2010-06-22 01:27:15 -07009077
9078 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009079 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009080
9081 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009082 }
Romain Guy06882f82009-06-10 13:36:04 -07009083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009084 private final void performLayoutAndPlaceSurfacesLockedInner(
9085 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009086 if (mDisplay == null) {
9087 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9088 return;
9089 }
9090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009091 final long currentTime = SystemClock.uptimeMillis();
9092 final int dw = mDisplay.getWidth();
9093 final int dh = mDisplay.getHeight();
9094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009095 int i;
9096
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009097 if (mFocusMayChange) {
9098 mFocusMayChange = false;
9099 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9100 }
9101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009102 // Initialize state of exiting tokens.
9103 for (i=mExitingTokens.size()-1; i>=0; i--) {
9104 mExitingTokens.get(i).hasVisible = false;
9105 }
9106
9107 // Initialize state of exiting applications.
9108 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9109 mExitingAppTokens.get(i).hasVisible = false;
9110 }
9111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009112 boolean orientationChangeComplete = true;
9113 Session holdScreen = null;
9114 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009115 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009116 boolean focusDisplayed = false;
9117 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009118 boolean createWatermark = false;
9119
9120 if (mFxSession == null) {
9121 mFxSession = new SurfaceSession();
9122 createWatermark = true;
9123 }
9124
9125 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009126
9127 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009128
9129 if (createWatermark) {
9130 createWatermark();
9131 }
9132 if (mWatermark != null) {
9133 mWatermark.positionSurface(dw, dh);
9134 }
9135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009136 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009137 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009138 int repeats = 0;
9139 int changes = 0;
9140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009141 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009142 repeats++;
9143 if (repeats > 6) {
9144 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9145 mLayoutNeeded = false;
9146 break;
9147 }
9148
9149 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9150 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9151 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9152 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9153 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9154 assignLayersLocked();
9155 mLayoutNeeded = true;
9156 }
9157 }
9158 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9159 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9160 if (updateOrientationFromAppTokensLocked()) {
9161 mLayoutNeeded = true;
9162 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9163 }
9164 }
9165 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9166 mLayoutNeeded = true;
9167 }
9168 }
9169
9170 // FIRST LOOP: Perform a layout, if needed.
9171 if (repeats < 4) {
9172 changes = performLayoutLockedInner();
9173 if (changes != 0) {
9174 continue;
9175 }
9176 } else {
9177 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9178 changes = 0;
9179 }
9180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009181 final int transactionSequence = ++mTransactionSequence;
9182
9183 // Update animations of all applications, including those
9184 // associated with exiting/removed apps
9185 boolean tokensAnimating = false;
9186 final int NAT = mAppTokens.size();
9187 for (i=0; i<NAT; i++) {
9188 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9189 tokensAnimating = true;
9190 }
9191 }
9192 final int NEAT = mExitingAppTokens.size();
9193 for (i=0; i<NEAT; i++) {
9194 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9195 tokensAnimating = true;
9196 }
9197 }
9198
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009199 // SECOND LOOP: Execute animations and update visibility of windows.
9200
Joe Onorato8a9b2202010-02-26 18:56:32 -08009201 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009202 + transactionSequence + " tokensAnimating="
9203 + tokensAnimating);
9204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009205 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009206
9207 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009208 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009209 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009210
9211 mPolicy.beginAnimationLw(dw, dh);
9212
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009213 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009215 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009216 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009217
9218 final WindowManager.LayoutParams attrs = w.mAttrs;
9219
9220 if (w.mSurface != null) {
9221 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009222 if (w.commitFinishDrawingLocked(currentTime)) {
9223 if ((w.mAttrs.flags
9224 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009225 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009226 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009227 wallpaperMayChange = true;
9228 }
9229 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009230
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009231 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009232 if (w.stepAnimationLocked(currentTime, dw, dh)) {
9233 animating = true;
9234 //w.dump(" ");
9235 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009236 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9237 wallpaperMayChange = true;
9238 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009239
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009240 if (mPolicy.doesForceHide(w, attrs)) {
9241 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009242 if (DEBUG_VISIBILITY) Slog.v(TAG,
9243 "Animation done that could impact force hide: "
9244 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009245 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009246 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009247 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9248 forceHiding = true;
9249 }
9250 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9251 boolean changed;
9252 if (forceHiding) {
9253 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009254 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9255 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009256 } else {
9257 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009258 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9259 "Now policy shown: " + w);
9260 if (changed) {
9261 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009262 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009263 // Assume we will need to animate. If
9264 // we don't (because the wallpaper will
9265 // stay with the lock screen), then we will
9266 // clean up later.
9267 Animation a = mPolicy.createForceHideEnterAnimation();
9268 if (a != null) {
9269 w.setAnimation(a);
9270 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009271 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009272 if (mCurrentFocus == null ||
9273 mCurrentFocus.mLayer < w.mLayer) {
9274 // We are showing on to of the current
9275 // focus, so re-evaluate focus to make
9276 // sure it is correct.
9277 mFocusMayChange = true;
9278 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009279 }
9280 }
9281 if (changed && (attrs.flags
9282 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9283 wallpaperMayChange = true;
9284 }
9285 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009287 mPolicy.animatingWindowLw(w, attrs);
9288 }
9289
9290 final AppWindowToken atoken = w.mAppToken;
9291 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9292 if (atoken.lastTransactionSequence != transactionSequence) {
9293 atoken.lastTransactionSequence = transactionSequence;
9294 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9295 atoken.startingDisplayed = false;
9296 }
9297 if ((w.isOnScreen() || w.mAttrs.type
9298 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9299 && !w.mExiting && !w.mDestroying) {
9300 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009301 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009302 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009303 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009304 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009305 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009306 + " pv=" + w.mPolicyVisibility
9307 + " dp=" + w.mDrawPending
9308 + " cdp=" + w.mCommitDrawPending
9309 + " ah=" + w.mAttachedHidden
9310 + " th=" + atoken.hiddenRequested
9311 + " a=" + w.mAnimating);
9312 }
9313 }
9314 if (w != atoken.startingWindow) {
9315 if (!atoken.freezingScreen || !w.mAppFreezing) {
9316 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009317 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009318 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009319 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009320 "tokenMayBeDrawn: " + atoken
9321 + " freezingScreen=" + atoken.freezingScreen
9322 + " mAppFreezing=" + w.mAppFreezing);
9323 tokenMayBeDrawn = true;
9324 }
9325 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009326 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009327 atoken.startingDisplayed = true;
9328 }
9329 }
9330 } else if (w.mReadyToShow) {
9331 w.performShowLocked();
9332 }
9333 }
9334
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009335 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009336
9337 if (tokenMayBeDrawn) {
9338 // See if any windows have been drawn, so they (and others
9339 // associated with them) can now be shown.
9340 final int NT = mTokenList.size();
9341 for (i=0; i<NT; i++) {
9342 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9343 if (wtoken == null) {
9344 continue;
9345 }
9346 if (wtoken.freezingScreen) {
9347 int numInteresting = wtoken.numInterestingWindows;
9348 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009349 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009350 "allDrawn: " + wtoken
9351 + " interesting=" + numInteresting
9352 + " drawn=" + wtoken.numDrawnWindows);
9353 wtoken.showAllWindowsLocked();
9354 unsetAppFreezingScreenLocked(wtoken, false, true);
9355 orientationChangeComplete = true;
9356 }
9357 } else if (!wtoken.allDrawn) {
9358 int numInteresting = wtoken.numInterestingWindows;
9359 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009360 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009361 "allDrawn: " + wtoken
9362 + " interesting=" + numInteresting
9363 + " drawn=" + wtoken.numDrawnWindows);
9364 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009365 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009366
9367 // We can now show all of the drawn windows!
9368 if (!mOpeningApps.contains(wtoken)) {
9369 wtoken.showAllWindowsLocked();
9370 }
9371 }
9372 }
9373 }
9374 }
9375
9376 // If we are ready to perform an app transition, check through
9377 // all of the app tokens to be shown and see if they are ready
9378 // to go.
9379 if (mAppTransitionReady) {
9380 int NN = mOpeningApps.size();
9381 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009382 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009383 "Checking " + NN + " opening apps (frozen="
9384 + mDisplayFrozen + " timeout="
9385 + mAppTransitionTimeout + ")...");
9386 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9387 // If the display isn't frozen, wait to do anything until
9388 // all of the apps are ready. Otherwise just go because
9389 // we'll unfreeze the display when everyone is ready.
9390 for (i=0; i<NN && goodToGo; i++) {
9391 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009392 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009393 "Check opening app" + wtoken + ": allDrawn="
9394 + wtoken.allDrawn + " startingDisplayed="
9395 + wtoken.startingDisplayed);
9396 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9397 && !wtoken.startingMoved) {
9398 goodToGo = false;
9399 }
9400 }
9401 }
9402 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009403 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009404 int transit = mNextAppTransition;
9405 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009406 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009407 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009408 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009409 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009410 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009411 mAppTransitionTimeout = false;
9412 mStartingIconInTransition = false;
9413 mSkipAppTransitionAnimation = false;
9414
9415 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9416
Dianne Hackborna8f60182009-09-01 19:01:50 -07009417 // If there are applications waiting to come to the
9418 // top of the stack, now is the time to move their windows.
9419 // (Note that we don't do apps going to the bottom
9420 // here -- we want to keep their windows in the old
9421 // Z-order until the animation completes.)
9422 if (mToTopApps.size() > 0) {
9423 NN = mAppTokens.size();
9424 for (i=0; i<NN; i++) {
9425 AppWindowToken wtoken = mAppTokens.get(i);
9426 if (wtoken.sendingToTop) {
9427 wtoken.sendingToTop = false;
9428 moveAppWindowsLocked(wtoken, NN, false);
9429 }
9430 }
9431 mToTopApps.clear();
9432 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009433
Dianne Hackborn25994b42009-09-04 14:21:19 -07009434 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009435
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009436 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009437 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009438
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009439 // The top-most window will supply the layout params,
9440 // and we will determine it below.
9441 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009442 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009443 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009444
Joe Onorato8a9b2202010-02-26 18:56:32 -08009445 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009446 "New wallpaper target=" + mWallpaperTarget
9447 + ", lower target=" + mLowerWallpaperTarget
9448 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009449 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009450 // Do a first pass through the tokens for two
9451 // things:
9452 // (1) Determine if both the closing and opening
9453 // app token sets are wallpaper targets, in which
9454 // case special animations are needed
9455 // (since the wallpaper needs to stay static
9456 // behind them).
9457 // (2) Find the layout params of the top-most
9458 // application window in the tokens, which is
9459 // what will control the animation theme.
9460 final int NC = mClosingApps.size();
9461 NN = NC + mOpeningApps.size();
9462 for (i=0; i<NN; i++) {
9463 AppWindowToken wtoken;
9464 int mode;
9465 if (i < NC) {
9466 wtoken = mClosingApps.get(i);
9467 mode = 1;
9468 } else {
9469 wtoken = mOpeningApps.get(i-NC);
9470 mode = 2;
9471 }
9472 if (mLowerWallpaperTarget != null) {
9473 if (mLowerWallpaperTarget.mAppToken == wtoken
9474 || mUpperWallpaperTarget.mAppToken == wtoken) {
9475 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009476 }
9477 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009478 if (wtoken.appFullscreen) {
9479 WindowState ws = wtoken.findMainWindow();
9480 if (ws != null) {
9481 // If this is a compatibility mode
9482 // window, we will always use its anim.
9483 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9484 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009485 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009486 bestAnimLayer = Integer.MAX_VALUE;
9487 } else if (ws.mLayer > bestAnimLayer) {
9488 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009489 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009490 bestAnimLayer = ws.mLayer;
9491 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009492 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009493 }
9494 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009495
Dianne Hackborn25994b42009-09-04 14:21:19 -07009496 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009497 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009498 "Wallpaper animation!");
9499 switch (transit) {
9500 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9501 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9502 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9503 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9504 break;
9505 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9506 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9507 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9508 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9509 break;
9510 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009511 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009512 "New transit: " + transit);
9513 } else if (oldWallpaper != null) {
9514 // We are transitioning from an activity with
9515 // a wallpaper to one without.
9516 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009517 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009518 "New transit away from wallpaper: " + transit);
9519 } else if (mWallpaperTarget != null) {
9520 // We are transitioning from an activity without
9521 // a wallpaper to now showing the wallpaper
9522 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009523 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009524 "New transit into wallpaper: " + transit);
9525 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009526
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009527 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9528 mLastEnterAnimToken = animToken;
9529 mLastEnterAnimParams = animLp;
9530 } else if (mLastEnterAnimParams != null) {
9531 animLp = mLastEnterAnimParams;
9532 mLastEnterAnimToken = null;
9533 mLastEnterAnimParams = null;
9534 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009535
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009536 // If all closing windows are obscured, then there is
9537 // no need to do an animation. This is the case, for
9538 // example, when this transition is being done behind
9539 // the lock screen.
9540 if (!mPolicy.allowAppAnimationsLw()) {
9541 animLp = null;
9542 }
9543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009544 NN = mOpeningApps.size();
9545 for (i=0; i<NN; i++) {
9546 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009547 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009548 "Now opening app" + wtoken);
9549 wtoken.reportedVisible = false;
9550 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009551 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009552 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009553 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009554 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009555 wtoken.showAllWindowsLocked();
9556 }
9557 NN = mClosingApps.size();
9558 for (i=0; i<NN; i++) {
9559 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009560 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009561 "Now closing app" + wtoken);
9562 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009563 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009564 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009565 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009566 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009567 // Force the allDrawn flag, because we want to start
9568 // this guy's animations regardless of whether it's
9569 // gotten drawn.
9570 wtoken.allDrawn = true;
9571 }
9572
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009573 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009575 mOpeningApps.clear();
9576 mClosingApps.clear();
9577
9578 // This has changed the visibility of windows, so perform
9579 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009580 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009581 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009582 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9583 assignLayersLocked();
9584 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009585 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009586 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009587 }
9588 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009589
Dianne Hackborn16064f92010-03-25 00:47:24 -07009590 int adjResult = 0;
9591
Dianne Hackborna8f60182009-09-01 19:01:50 -07009592 if (!animating && mAppTransitionRunning) {
9593 // We have finished the animation of an app transition. To do
9594 // this, we have delayed a lot of operations like showing and
9595 // hiding apps, moving apps in Z-order, etc. The app token list
9596 // reflects the correct Z-order, but the window list may now
9597 // be out of sync with it. So here we will just rebuild the
9598 // entire app window list. Fun!
9599 mAppTransitionRunning = false;
9600 // Clear information about apps that were moving.
9601 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009602
Dianne Hackborna8f60182009-09-01 19:01:50 -07009603 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009604 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009605 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009606 moveInputMethodWindowsIfNeededLocked(false);
9607 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009608 // Since the window list has been rebuilt, focus might
9609 // have to be recomputed since the actual order of windows
9610 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009611 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009612 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009613
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009614 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009615 // At this point, there was a window with a wallpaper that
9616 // was force hiding other windows behind it, but now it
9617 // is going away. This may be simple -- just animate
9618 // away the wallpaper and its window -- or it may be
9619 // hard -- the wallpaper now needs to be shown behind
9620 // something that was hidden.
9621 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009622 if (mLowerWallpaperTarget != null
9623 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009624 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009625 "wallpaperForceHiding changed with lower="
9626 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009627 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009628 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9629 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9630 if (mLowerWallpaperTarget.mAppToken.hidden) {
9631 // The lower target has become hidden before we
9632 // actually started the animation... let's completely
9633 // re-evaluate everything.
9634 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009635 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009636 }
9637 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009638 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009639 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009640 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009641 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009642 + " NEW: " + mWallpaperTarget
9643 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009644 if (mLowerWallpaperTarget == null) {
9645 // Whoops, we don't need a special wallpaper animation.
9646 // Clear them out.
9647 forceHiding = false;
9648 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009649 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009650 if (w.mSurface != null) {
9651 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009652 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009653 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009654 forceHiding = true;
9655 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9656 if (!w.mAnimating) {
9657 // We set the animation above so it
9658 // is not yet running.
9659 w.clearAnimation();
9660 }
9661 }
9662 }
9663 }
9664 }
9665 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009666
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009667 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009668 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009669 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009670 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009671 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009672
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009673 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009674 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009675 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009676 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009677 assignLayersLocked();
9678 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009679 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009680 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009681 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009682 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009683
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009684 if (mFocusMayChange) {
9685 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009686 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009687 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009688 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009689 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009690 }
9691
9692 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009693 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009694 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009695
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009696 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9697 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009698
Jeff Browne33348b2010-07-15 23:54:05 -07009699 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009700 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009701
9702 // THIRD LOOP: Update the surfaces of all windows.
9703
9704 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9705
9706 boolean obscured = false;
9707 boolean blurring = false;
9708 boolean dimming = false;
9709 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009710 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009711 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009712
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009713 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009715 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009716 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009717
9718 boolean displayed = false;
9719 final WindowManager.LayoutParams attrs = w.mAttrs;
9720 final int attrFlags = attrs.flags;
9721
9722 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009723 // XXX NOTE: The logic here could be improved. We have
9724 // the decision about whether to resize a window separated
9725 // from whether to hide the surface. This can cause us to
9726 // resize a surface even if we are going to hide it. You
9727 // can see this by (1) holding device in landscape mode on
9728 // home screen; (2) tapping browser icon (device will rotate
9729 // to landscape; (3) tap home. The wallpaper will be resized
9730 // in step 2 but then immediately hidden, causing us to
9731 // have to resize and then redraw it again in step 3. It
9732 // would be nice to figure out how to avoid this, but it is
9733 // difficult because we do need to resize surfaces in some
9734 // cases while they are hidden such as when first showing a
9735 // window.
9736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009737 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009738 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009739 TAG, "Placing surface #" + i + " " + w.mSurface
9740 + ": new=" + w.mShownFrame + ", old="
9741 + w.mLastShownFrame);
9742
9743 boolean resize;
9744 int width, height;
9745 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9746 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9747 w.mLastRequestedHeight != w.mRequestedHeight;
9748 // for a scaled surface, we just want to use
9749 // the requested size.
9750 width = w.mRequestedWidth;
9751 height = w.mRequestedHeight;
9752 w.mLastRequestedWidth = width;
9753 w.mLastRequestedHeight = height;
9754 w.mLastShownFrame.set(w.mShownFrame);
9755 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009756 if (SHOW_TRANSACTIONS) logSurface(w,
9757 "POS " + w.mShownFrame.left
9758 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009759 w.mSurfaceX = w.mShownFrame.left;
9760 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009761 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9762 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009763 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009764 if (!recoveringMemory) {
9765 reclaimSomeSurfaceMemoryLocked(w, "position");
9766 }
9767 }
9768 } else {
9769 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9770 width = w.mShownFrame.width();
9771 height = w.mShownFrame.height();
9772 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009773 }
9774
9775 if (resize) {
9776 if (width < 1) width = 1;
9777 if (height < 1) height = 1;
9778 if (w.mSurface != null) {
9779 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009780 if (SHOW_TRANSACTIONS) logSurface(w,
9781 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009782 + w.mShownFrame.top + " SIZE "
9783 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009784 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009785 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009786 w.mSurfaceW = width;
9787 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009788 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009789 w.mSurfaceX = w.mShownFrame.left;
9790 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009791 w.mSurface.setPosition(w.mShownFrame.left,
9792 w.mShownFrame.top);
9793 } catch (RuntimeException e) {
9794 // If something goes wrong with the surface (such
9795 // as running out of memory), don't take down the
9796 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009797 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009798 + "size=(" + width + "x" + height
9799 + "), pos=(" + w.mShownFrame.left
9800 + "," + w.mShownFrame.top + ")", e);
9801 if (!recoveringMemory) {
9802 reclaimSomeSurfaceMemoryLocked(w, "size");
9803 }
9804 }
9805 }
9806 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009807 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009808 w.mContentInsetsChanged =
9809 !w.mLastContentInsets.equals(w.mContentInsets);
9810 w.mVisibleInsetsChanged =
9811 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009812 boolean configChanged =
9813 w.mConfiguration != mCurConfiguration
9814 && (w.mConfiguration == null
9815 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009816 if (DEBUG_CONFIGURATION && configChanged) {
9817 Slog.v(TAG, "Win " + w + " config changed: "
9818 + mCurConfiguration);
9819 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009820 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009821 + ": configChanged=" + configChanged
9822 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009823 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009824 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009825 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009826 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009827 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009828 w.mLastFrame.set(w.mFrame);
9829 w.mLastContentInsets.set(w.mContentInsets);
9830 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009831 // If the screen is currently frozen, then keep
9832 // it frozen until this window draws at its new
9833 // orientation.
9834 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009835 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009836 "Resizing while display frozen: " + w);
9837 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009838 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009839 mWindowsFreezingScreen = true;
9840 // XXX should probably keep timeout from
9841 // when we first froze the display.
9842 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9843 mH.sendMessageDelayed(mH.obtainMessage(
9844 H.WINDOW_FREEZE_TIMEOUT), 2000);
9845 }
9846 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009847 // If the orientation is changing, then we need to
9848 // hold off on unfreezing the display until this
9849 // window has been redrawn; to do that, we need
9850 // to go through the process of getting informed
9851 // by the application when it has finished drawing.
9852 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009853 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009854 "Orientation start waiting for draw in "
9855 + w + ", surface " + w.mSurface);
9856 w.mDrawPending = true;
9857 w.mCommitDrawPending = false;
9858 w.mReadyToShow = false;
9859 if (w.mAppToken != null) {
9860 w.mAppToken.allDrawn = false;
9861 }
9862 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009863 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009864 "Resizing window " + w + " to " + w.mFrame);
9865 mResizingWindows.add(w);
9866 } else if (w.mOrientationChanging) {
9867 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009868 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009869 "Orientation not waiting for draw in "
9870 + w + ", surface " + w.mSurface);
9871 w.mOrientationChanging = false;
9872 }
9873 }
9874 }
9875
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009876 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009877 if (!w.mLastHidden) {
9878 //dump();
9879 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009880 if (SHOW_TRANSACTIONS) logSurface(w,
9881 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009882 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009883 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009884 try {
9885 w.mSurface.hide();
9886 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009887 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009888 }
9889 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009890 }
9891 // If we are waiting for this window to handle an
9892 // orientation change, well, it is hidden, so
9893 // doesn't really matter. Note that this does
9894 // introduce a potential glitch if the window
9895 // becomes unhidden before it has drawn for the
9896 // new orientation.
9897 if (w.mOrientationChanging) {
9898 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009899 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009900 "Orientation change skips hidden " + w);
9901 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009902 } else if (w.mLastLayer != w.mAnimLayer
9903 || w.mLastAlpha != w.mShownAlpha
9904 || w.mLastDsDx != w.mDsDx
9905 || w.mLastDtDx != w.mDtDx
9906 || w.mLastDsDy != w.mDsDy
9907 || w.mLastDtDy != w.mDtDy
9908 || w.mLastHScale != w.mHScale
9909 || w.mLastVScale != w.mVScale
9910 || w.mLastHidden) {
9911 displayed = true;
9912 w.mLastAlpha = w.mShownAlpha;
9913 w.mLastLayer = w.mAnimLayer;
9914 w.mLastDsDx = w.mDsDx;
9915 w.mLastDtDx = w.mDtDx;
9916 w.mLastDsDy = w.mDsDy;
9917 w.mLastDtDy = w.mDtDy;
9918 w.mLastHScale = w.mHScale;
9919 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009920 if (SHOW_TRANSACTIONS) logSurface(w,
9921 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009922 + " matrix=[" + (w.mDsDx*w.mHScale)
9923 + "," + (w.mDtDx*w.mVScale)
9924 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009925 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009926 if (w.mSurface != null) {
9927 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009928 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009929 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009930 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009931 w.mSurface.setLayer(w.mAnimLayer);
9932 w.mSurface.setMatrix(
9933 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9934 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9935 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009936 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009937 if (!recoveringMemory) {
9938 reclaimSomeSurfaceMemoryLocked(w, "update");
9939 }
9940 }
9941 }
9942
9943 if (w.mLastHidden && !w.mDrawPending
9944 && !w.mCommitDrawPending
9945 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009946 if (SHOW_TRANSACTIONS) logSurface(w,
9947 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009948 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009949 + " during relayout");
9950 if (showSurfaceRobustlyLocked(w)) {
9951 w.mHasDrawn = true;
9952 w.mLastHidden = false;
9953 } else {
9954 w.mOrientationChanging = false;
9955 }
9956 }
9957 if (w.mSurface != null) {
9958 w.mToken.hasVisible = true;
9959 }
9960 } else {
9961 displayed = true;
9962 }
9963
9964 if (displayed) {
9965 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009966 if (attrs.width == LayoutParams.MATCH_PARENT
9967 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009968 covered = true;
9969 }
9970 }
9971 if (w.mOrientationChanging) {
9972 if (w.mDrawPending || w.mCommitDrawPending) {
9973 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009974 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009975 "Orientation continue waiting for draw in " + w);
9976 } else {
9977 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009978 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009979 "Orientation change complete in " + w);
9980 }
9981 }
9982 w.mToken.hasVisible = true;
9983 }
9984 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009985 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009986 "Orientation change skips hidden " + w);
9987 w.mOrientationChanging = false;
9988 }
9989
9990 final boolean canBeSeen = w.isDisplayedLw();
9991
9992 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9993 focusDisplayed = true;
9994 }
9995
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009996 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009998 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009999 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010000 if (w.mSurface != null) {
10001 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10002 holdScreen = w.mSession;
10003 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010004 if (!syswin && w.mAttrs.screenBrightness >= 0
10005 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010006 screenBrightness = w.mAttrs.screenBrightness;
10007 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010008 if (!syswin && w.mAttrs.buttonBrightness >= 0
10009 && buttonBrightness < 0) {
10010 buttonBrightness = w.mAttrs.buttonBrightness;
10011 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010012 if (canBeSeen
10013 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10014 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10015 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010016 syswin = true;
10017 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010018 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010019
Dianne Hackborn25994b42009-09-04 14:21:19 -070010020 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10021 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010022 // This window completely covers everything behind it,
10023 // so we want to leave all of them as unblurred (for
10024 // performance reasons).
10025 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010026 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010027 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010028 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010029 obscured = true;
10030 if (mBackgroundFillerSurface == null) {
10031 try {
10032 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010033 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010034 0, dw, dh,
10035 PixelFormat.OPAQUE,
10036 Surface.FX_SURFACE_NORMAL);
10037 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010038 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010039 }
10040 }
10041 try {
10042 mBackgroundFillerSurface.setPosition(0, 0);
10043 mBackgroundFillerSurface.setSize(dw, dh);
10044 // Using the same layer as Dim because they will never be shown at the
10045 // same time.
10046 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10047 mBackgroundFillerSurface.show();
10048 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010049 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010050 }
10051 backgroundFillerShown = true;
10052 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010053 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010054 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010055 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010056 + ": blurring=" + blurring
10057 + " obscured=" + obscured
10058 + " displayed=" + displayed);
10059 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10060 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010061 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010062 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010063 if (mDimAnimator == null) {
10064 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010065 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010066 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010067 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010068 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010069 }
10070 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10071 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010072 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010073 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010074 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010075 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010076 + mBlurSurface + ": CREATE");
10077 try {
Romain Guy06882f82009-06-10 13:36:04 -070010078 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010079 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010080 -1, 16, 16,
10081 PixelFormat.OPAQUE,
10082 Surface.FX_SURFACE_BLUR);
10083 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010084 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010085 }
10086 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010087 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010088 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10089 + mBlurSurface + ": pos=(0,0) (" +
10090 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010091 mBlurSurface.setPosition(0, 0);
10092 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010093 mBlurSurface.setLayer(w.mAnimLayer-2);
10094 if (!mBlurShown) {
10095 try {
10096 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10097 + mBlurSurface + ": SHOW");
10098 mBlurSurface.show();
10099 } catch (RuntimeException e) {
10100 Slog.w(TAG, "Failure showing blur surface", e);
10101 }
10102 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010103 }
10104 }
10105 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010106 }
10107 }
10108 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010109
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010110 if (obscuredChanged && mWallpaperTarget == w) {
10111 // This is the wallpaper target and its obscured state
10112 // changed... make sure the current wallaper's visibility
10113 // has been updated accordingly.
10114 updateWallpaperVisibilityLocked();
10115 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010116 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010117
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010118 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10119 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010120 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010121 try {
10122 mBackgroundFillerSurface.hide();
10123 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010124 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010125 }
10126 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010127
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010128 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010129 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10130 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010131 }
Romain Guy06882f82009-06-10 13:36:04 -070010132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010133 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010134 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010135 + ": HIDE");
10136 try {
10137 mBlurSurface.hide();
10138 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010139 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010140 }
10141 mBlurShown = false;
10142 }
10143
Joe Onorato8a9b2202010-02-26 18:56:32 -080010144 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010145 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010146 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010147 }
10148
Jeff Browne33348b2010-07-15 23:54:05 -070010149 mInputMonitor.updateInputWindowsLw();
10150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010151 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010152
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010153 if (mWatermark != null) {
10154 mWatermark.drawIfNeeded();
10155 }
10156
Joe Onorato8a9b2202010-02-26 18:56:32 -080010157 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010158 "With display frozen, orientationChangeComplete="
10159 + orientationChangeComplete);
10160 if (orientationChangeComplete) {
10161 if (mWindowsFreezingScreen) {
10162 mWindowsFreezingScreen = false;
10163 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10164 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010165 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010166 }
Romain Guy06882f82009-06-10 13:36:04 -070010167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010168 i = mResizingWindows.size();
10169 if (i > 0) {
10170 do {
10171 i--;
10172 WindowState win = mResizingWindows.get(i);
10173 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010174 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10175 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010176 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010177 boolean configChanged =
10178 win.mConfiguration != mCurConfiguration
10179 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010180 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10181 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10182 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010183 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010184 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010185 + " / " + mCurConfiguration + " / 0x"
10186 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010187 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010188 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010189 win.mClient.resized(win.mFrame.width(),
10190 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010191 win.mLastVisibleInsets, win.mDrawPending,
10192 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010193 win.mContentInsetsChanged = false;
10194 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010195 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010196 } catch (RemoteException e) {
10197 win.mOrientationChanging = false;
10198 }
10199 } while (i > 0);
10200 mResizingWindows.clear();
10201 }
Romain Guy06882f82009-06-10 13:36:04 -070010202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010203 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010204 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010205 i = mDestroySurface.size();
10206 if (i > 0) {
10207 do {
10208 i--;
10209 WindowState win = mDestroySurface.get(i);
10210 win.mDestroying = false;
10211 if (mInputMethodWindow == win) {
10212 mInputMethodWindow = null;
10213 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010214 if (win == mWallpaperTarget) {
10215 wallpaperDestroyed = true;
10216 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010217 win.destroySurfaceLocked();
10218 } while (i > 0);
10219 mDestroySurface.clear();
10220 }
10221
10222 // Time to remove any exiting tokens?
10223 for (i=mExitingTokens.size()-1; i>=0; i--) {
10224 WindowToken token = mExitingTokens.get(i);
10225 if (!token.hasVisible) {
10226 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010227 if (token.windowType == TYPE_WALLPAPER) {
10228 mWallpaperTokens.remove(token);
10229 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010230 }
10231 }
10232
10233 // Time to remove any exiting applications?
10234 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10235 AppWindowToken token = mExitingAppTokens.get(i);
10236 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010237 // Make sure there is no animation running on this token,
10238 // so any windows associated with it will be removed as
10239 // soon as their animations are complete
10240 token.animation = null;
10241 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010242 mAppTokens.remove(token);
10243 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010244 if (mLastEnterAnimToken == token) {
10245 mLastEnterAnimToken = null;
10246 mLastEnterAnimParams = null;
10247 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010248 }
10249 }
10250
Dianne Hackborna8f60182009-09-01 19:01:50 -070010251 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010252
Dianne Hackborna8f60182009-09-01 19:01:50 -070010253 if (!animating && mAppTransitionRunning) {
10254 // We have finished the animation of an app transition. To do
10255 // this, we have delayed a lot of operations like showing and
10256 // hiding apps, moving apps in Z-order, etc. The app token list
10257 // reflects the correct Z-order, but the window list may now
10258 // be out of sync with it. So here we will just rebuild the
10259 // entire app window list. Fun!
10260 mAppTransitionRunning = false;
10261 needRelayout = true;
10262 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010263 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010264 // Clear information about apps that were moving.
10265 mToBottomApps.clear();
10266 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010268 if (focusDisplayed) {
10269 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10270 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010271 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010272 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010273 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010274 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010275 requestAnimationLocked(0);
10276 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010277 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10278 }
Jeff Browneb857f12010-07-16 10:06:33 -070010279
Jeff Browne33348b2010-07-15 23:54:05 -070010280 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010281
Jeff Brown8e03b752010-06-13 19:16:55 -070010282 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010283 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10284 mPowerManager.setScreenBrightnessOverride(-1);
10285 } else {
10286 mPowerManager.setScreenBrightnessOverride((int)
10287 (screenBrightness * Power.BRIGHTNESS_ON));
10288 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010289 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10290 mPowerManager.setButtonBrightnessOverride(-1);
10291 } else {
10292 mPowerManager.setButtonBrightnessOverride((int)
10293 (buttonBrightness * Power.BRIGHTNESS_ON));
10294 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010295 if (holdScreen != mHoldingScreenOn) {
10296 mHoldingScreenOn = holdScreen;
10297 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10298 mH.sendMessage(m);
10299 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010300
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010301 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010302 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010303 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10304 LocalPowerManager.BUTTON_EVENT, true);
10305 mTurnOnScreen = false;
10306 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010307
10308 // Check to see if we are now in a state where the screen should
10309 // be enabled, because the window obscured flags have changed.
10310 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010311 }
Jeff Brown46b9ac02010-04-22 18:58:52 -070010312
10313 /**
10314 * Must be called with the main window manager lock held.
10315 */
10316 void setHoldScreenLocked(boolean holding) {
10317 boolean state = mHoldingScreenWakeLock.isHeld();
10318 if (holding != state) {
10319 if (holding) {
10320 mHoldingScreenWakeLock.acquire();
10321 } else {
10322 mPolicy.screenOnStoppedLw();
10323 mHoldingScreenWakeLock.release();
10324 }
10325 }
10326 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010327
10328 void requestAnimationLocked(long delay) {
10329 if (!mAnimationPending) {
10330 mAnimationPending = true;
10331 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10332 }
10333 }
Romain Guy06882f82009-06-10 13:36:04 -070010334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010335 /**
10336 * Have the surface flinger show a surface, robustly dealing with
10337 * error conditions. In particular, if there is not enough memory
10338 * to show the surface, then we will try to get rid of other surfaces
10339 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010340 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010341 * @return Returns true if the surface was successfully shown.
10342 */
10343 boolean showSurfaceRobustlyLocked(WindowState win) {
10344 try {
10345 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010346 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010347 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010348 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010349 if (DEBUG_VISIBILITY) Slog.v(TAG,
10350 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010351 win.mTurnOnScreen = false;
10352 mTurnOnScreen = true;
10353 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010354 }
10355 return true;
10356 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010357 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010358 }
Romain Guy06882f82009-06-10 13:36:04 -070010359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010360 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010362 return false;
10363 }
Romain Guy06882f82009-06-10 13:36:04 -070010364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010365 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10366 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010367
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010368 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010369 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010371 if (mForceRemoves == null) {
10372 mForceRemoves = new ArrayList<WindowState>();
10373 }
Romain Guy06882f82009-06-10 13:36:04 -070010374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010375 long callingIdentity = Binder.clearCallingIdentity();
10376 try {
10377 // There was some problem... first, do a sanity check of the
10378 // window list to make sure we haven't left any dangling surfaces
10379 // around.
10380 int N = mWindows.size();
10381 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010382 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010383 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010384 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010385 if (ws.mSurface != null) {
10386 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010387 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010388 + ws + " surface=" + ws.mSurface
10389 + " token=" + win.mToken
10390 + " pid=" + ws.mSession.mPid
10391 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010392 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010393 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010394 ws.mSurface = null;
10395 mForceRemoves.add(ws);
10396 i--;
10397 N--;
10398 leakedSurface = true;
10399 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010400 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010401 + ws + " surface=" + ws.mSurface
10402 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010403 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010404 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010405 ws.mSurface = null;
10406 leakedSurface = true;
10407 }
10408 }
10409 }
Romain Guy06882f82009-06-10 13:36:04 -070010410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010411 boolean killedApps = false;
10412 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010413 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010414 SparseIntArray pidCandidates = new SparseIntArray();
10415 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010416 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010417 if (ws.mSurface != null) {
10418 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10419 }
10420 }
10421 if (pidCandidates.size() > 0) {
10422 int[] pids = new int[pidCandidates.size()];
10423 for (int i=0; i<pids.length; i++) {
10424 pids[i] = pidCandidates.keyAt(i);
10425 }
10426 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010427 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010428 killedApps = true;
10429 }
10430 } catch (RemoteException e) {
10431 }
10432 }
10433 }
Romain Guy06882f82009-06-10 13:36:04 -070010434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010435 if (leakedSurface || killedApps) {
10436 // We managed to reclaim some memory, so get rid of the trouble
10437 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010438 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010439 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010440 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010441 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010442 win.mSurface = null;
10443 }
Romain Guy06882f82009-06-10 13:36:04 -070010444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010445 try {
10446 win.mClient.dispatchGetNewSurface();
10447 } catch (RemoteException e) {
10448 }
10449 }
10450 } finally {
10451 Binder.restoreCallingIdentity(callingIdentity);
10452 }
10453 }
Romain Guy06882f82009-06-10 13:36:04 -070010454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010455 private boolean updateFocusedWindowLocked(int mode) {
10456 WindowState newFocus = computeFocusedWindowLocked();
10457 if (mCurrentFocus != newFocus) {
10458 // This check makes sure that we don't already have the focus
10459 // change message pending.
10460 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10461 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010462 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010463 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10464 final WindowState oldFocus = mCurrentFocus;
10465 mCurrentFocus = newFocus;
10466 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010468 final WindowState imWindow = mInputMethodWindow;
10469 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010470 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010471 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010472 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10473 mLayoutNeeded = true;
10474 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010475 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
10476 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010477 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10478 // Client will do the layout, but we need to assign layers
10479 // for handleNewWindowLocked() below.
10480 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010481 }
10482 }
Jeff Brown349703e2010-06-22 01:27:15 -070010483
10484 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10485 // If we defer assigning layers, then the caller is responsible for
10486 // doing this part.
10487 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010488 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010489 return true;
10490 }
10491 return false;
10492 }
Jeff Brown349703e2010-06-22 01:27:15 -070010493
10494 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010495 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070010496 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010497
10498 private WindowState computeFocusedWindowLocked() {
10499 WindowState result = null;
10500 WindowState win;
10501
10502 int i = mWindows.size() - 1;
10503 int nextAppIndex = mAppTokens.size()-1;
10504 WindowToken nextApp = nextAppIndex >= 0
10505 ? mAppTokens.get(nextAppIndex) : null;
10506
10507 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070010508 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010509
Joe Onorato8a9b2202010-02-26 18:56:32 -080010510 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010511 TAG, "Looking for focus: " + i
10512 + " = " + win
10513 + ", flags=" + win.mAttrs.flags
10514 + ", canReceive=" + win.canReceiveKeys());
10515
10516 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010518 // If this window's application has been removed, just skip it.
10519 if (thisApp != null && thisApp.removed) {
10520 i--;
10521 continue;
10522 }
Romain Guy06882f82009-06-10 13:36:04 -070010523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010524 // If there is a focused app, don't allow focus to go to any
10525 // windows below it. If this is an application window, step
10526 // through the app tokens until we find its app.
10527 if (thisApp != null && nextApp != null && thisApp != nextApp
10528 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10529 int origAppIndex = nextAppIndex;
10530 while (nextAppIndex > 0) {
10531 if (nextApp == mFocusedApp) {
10532 // Whoops, we are below the focused app... no focus
10533 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010534 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010535 TAG, "Reached focused app: " + mFocusedApp);
10536 return null;
10537 }
10538 nextAppIndex--;
10539 nextApp = mAppTokens.get(nextAppIndex);
10540 if (nextApp == thisApp) {
10541 break;
10542 }
10543 }
10544 if (thisApp != nextApp) {
10545 // Uh oh, the app token doesn't exist! This shouldn't
10546 // happen, but if it does we can get totally hosed...
10547 // so restart at the original app.
10548 nextAppIndex = origAppIndex;
10549 nextApp = mAppTokens.get(nextAppIndex);
10550 }
10551 }
10552
10553 // Dispatch to this window if it is wants key events.
10554 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010555 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010556 TAG, "Found focus @ " + i + " = " + win);
10557 result = win;
10558 break;
10559 }
10560
10561 i--;
10562 }
10563
10564 return result;
10565 }
10566
10567 private void startFreezingDisplayLocked() {
10568 if (mDisplayFrozen) {
10569 return;
10570 }
Romain Guy06882f82009-06-10 13:36:04 -070010571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010572 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010574 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010575 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010576 if (mFreezeGcPending != 0) {
10577 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010578 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010579 mH.removeMessages(H.FORCE_GC);
10580 Runtime.getRuntime().gc();
10581 mFreezeGcPending = now;
10582 }
10583 } else {
10584 mFreezeGcPending = now;
10585 }
Romain Guy06882f82009-06-10 13:36:04 -070010586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010587 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010588
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010589 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010590
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010591 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10592 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010593 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010594 mAppTransitionReady = true;
10595 }
Romain Guy06882f82009-06-10 13:36:04 -070010596
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010597 if (PROFILE_ORIENTATION) {
10598 File file = new File("/data/system/frozen");
10599 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10600 }
10601 Surface.freezeDisplay(0);
10602 }
Romain Guy06882f82009-06-10 13:36:04 -070010603
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010604 private void stopFreezingDisplayLocked() {
10605 if (!mDisplayFrozen) {
10606 return;
10607 }
Romain Guy06882f82009-06-10 13:36:04 -070010608
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010609 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10610 return;
10611 }
10612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010613 mDisplayFrozen = false;
10614 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10615 if (PROFILE_ORIENTATION) {
10616 Debug.stopMethodTracing();
10617 }
10618 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010619
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010620 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010621
Christopher Tateb696aee2010-04-02 19:08:30 -070010622 // While the display is frozen we don't re-compute the orientation
10623 // to avoid inconsistent states. However, something interesting
10624 // could have actually changed during that time so re-evaluate it
10625 // now to catch that.
10626 if (updateOrientationFromAppTokensLocked()) {
10627 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10628 }
10629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010630 // A little kludge: a lot could have happened while the
10631 // display was frozen, so now that we are coming back we
10632 // do a gc so that any remote references the system
10633 // processes holds on others can be released if they are
10634 // no longer needed.
10635 mH.removeMessages(H.FORCE_GC);
10636 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10637 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010639 mScreenFrozenLock.release();
10640 }
Romain Guy06882f82009-06-10 13:36:04 -070010641
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010642 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10643 DisplayMetrics dm) {
10644 if (index < tokens.length) {
10645 String str = tokens[index];
10646 if (str != null && str.length() > 0) {
10647 try {
10648 int val = Integer.parseInt(str);
10649 return val;
10650 } catch (Exception e) {
10651 }
10652 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010653 }
10654 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10655 return defDps;
10656 }
10657 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10658 return val;
10659 }
10660
10661 class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010662 final String[] mTokens;
10663 final String mText;
10664 final Paint mTextPaint;
10665 final int mTextWidth;
10666 final int mTextHeight;
10667 final int mTextAscent;
10668 final int mTextDescent;
10669 final int mDeltaX;
10670 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010671
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010672 Surface mSurface;
10673 int mLastDW;
10674 int mLastDH;
10675 boolean mDrawNeeded;
10676
10677 Watermark(SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010678 final DisplayMetrics dm = new DisplayMetrics();
10679 mDisplay.getMetrics(dm);
10680
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010681 if (false) {
10682 Log.i(TAG, "*********************** WATERMARK");
10683 for (int i=0; i<tokens.length; i++) {
10684 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10685 }
10686 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010687
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010688 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010689
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010690 StringBuilder builder = new StringBuilder(32);
10691 int len = mTokens[0].length();
10692 len = len & ~1;
10693 for (int i=0; i<len; i+=2) {
10694 int c1 = mTokens[0].charAt(i);
10695 int c2 = mTokens[0].charAt(i+1);
10696 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10697 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10698 else c1 -= '0';
10699 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10700 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10701 else c2 -= '0';
10702 builder.append((char)(255-((c1*16)+c2)));
10703 }
10704 mText = builder.toString();
10705 if (false) {
10706 Log.i(TAG, "Final text: " + mText);
10707 }
10708
10709 int fontSize = getPropertyInt(tokens, 1,
10710 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10711
10712 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10713 mTextPaint.setTextSize(fontSize);
10714 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10715
10716 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
10717 mTextWidth = (int)mTextPaint.measureText(mText);
10718 mTextAscent = fm.ascent;
10719 mTextDescent = fm.descent;
10720 mTextHeight = fm.descent - fm.ascent;
10721
10722 mDeltaX = getPropertyInt(tokens, 2,
10723 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
10724 mDeltaY = getPropertyInt(tokens, 3,
10725 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
10726 int shadowColor = getPropertyInt(tokens, 4,
10727 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
10728 int color = getPropertyInt(tokens, 5,
10729 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
10730 int shadowRadius = getPropertyInt(tokens, 6,
10731 TypedValue.COMPLEX_UNIT_PX, 7, dm);
10732 int shadowDx = getPropertyInt(tokens, 8,
10733 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10734 int shadowDy = getPropertyInt(tokens, 9,
10735 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10736
10737 mTextPaint.setColor(color);
10738 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010739
10740 try {
10741 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010742 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010743 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010744 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010745 mSurface.show();
10746 } catch (OutOfResourcesException e) {
10747 }
10748 }
10749
10750 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010751 if (mLastDW != dw || mLastDH != dh) {
10752 mLastDW = dw;
10753 mLastDH = dh;
10754 mSurface.setSize(dw, dh);
10755 mDrawNeeded = true;
10756 }
10757 }
10758
10759 void drawIfNeeded() {
10760 if (mDrawNeeded) {
10761 final int dw = mLastDW;
10762 final int dh = mLastDH;
10763
10764 mDrawNeeded = false;
10765 Rect dirty = new Rect(0, 0, dw, dh);
10766 Canvas c = null;
10767 try {
10768 c = mSurface.lockCanvas(dirty);
10769 } catch (IllegalArgumentException e) {
10770 } catch (OutOfResourcesException e) {
10771 }
10772 if (c != null) {
10773 int deltaX = mDeltaX;
10774 int deltaY = mDeltaY;
10775
10776 // deltaX shouldn't be close to a round fraction of our
10777 // x step, or else things will line up too much.
10778 int div = (dw+mTextWidth)/deltaX;
10779 int rem = (dw+mTextWidth) - (div*deltaX);
10780 int qdelta = deltaX/4;
10781 if (rem < qdelta || rem > (deltaX-qdelta)) {
10782 deltaX += deltaX/3;
10783 }
10784
10785 int y = -mTextHeight;
10786 int x = -mTextWidth;
10787 while (y < (dh+mTextHeight)) {
10788 c.drawText(mText, x, y, mTextPaint);
10789 x += deltaX;
10790 if (x >= dw) {
10791 x -= (dw+mTextWidth);
10792 y += deltaY;
10793 }
10794 }
10795 mSurface.unlockCanvasAndPost(c);
10796 }
10797 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010798 }
10799 }
10800
10801 void createWatermark() {
10802 if (mWatermark != null) {
10803 return;
10804 }
10805
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010806 File file = new File("/system/etc/setup.conf");
10807 FileInputStream in = null;
10808 try {
10809 in = new FileInputStream(file);
10810 DataInputStream ind = new DataInputStream(in);
10811 String line = ind.readLine();
10812 if (line != null) {
10813 String[] toks = line.split("%");
10814 if (toks != null && toks.length > 0) {
10815 mWatermark = new Watermark(mFxSession, toks);
10816 }
10817 }
10818 } catch (FileNotFoundException e) {
10819 } catch (IOException e) {
10820 } finally {
10821 if (in != null) {
10822 try {
10823 in.close();
10824 } catch (IOException e) {
10825 }
10826 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010827 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010828 }
10829
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010830 @Override
10831 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10832 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10833 != PackageManager.PERMISSION_GRANTED) {
10834 pw.println("Permission Denial: can't dump WindowManager from from pid="
10835 + Binder.getCallingPid()
10836 + ", uid=" + Binder.getCallingUid());
10837 return;
10838 }
Romain Guy06882f82009-06-10 13:36:04 -070010839
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010840 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010841 pw.println(" ");
10842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010843 synchronized(mWindowMap) {
10844 pw.println("Current Window Manager state:");
10845 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010846 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010847 pw.print(" Window #"); pw.print(i); pw.print(' ');
10848 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010849 w.dump(pw, " ");
10850 }
10851 if (mInputMethodDialogs.size() > 0) {
10852 pw.println(" ");
10853 pw.println(" Input method dialogs:");
10854 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10855 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010856 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010857 }
10858 }
10859 if (mPendingRemove.size() > 0) {
10860 pw.println(" ");
10861 pw.println(" Remove pending for:");
10862 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10863 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010864 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10865 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010866 w.dump(pw, " ");
10867 }
10868 }
10869 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10870 pw.println(" ");
10871 pw.println(" Windows force removing:");
10872 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10873 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010874 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10875 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010876 w.dump(pw, " ");
10877 }
10878 }
10879 if (mDestroySurface.size() > 0) {
10880 pw.println(" ");
10881 pw.println(" Windows waiting to destroy their surface:");
10882 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10883 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010884 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10885 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010886 w.dump(pw, " ");
10887 }
10888 }
10889 if (mLosingFocus.size() > 0) {
10890 pw.println(" ");
10891 pw.println(" Windows losing focus:");
10892 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10893 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010894 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10895 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010896 w.dump(pw, " ");
10897 }
10898 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010899 if (mResizingWindows.size() > 0) {
10900 pw.println(" ");
10901 pw.println(" Windows waiting to resize:");
10902 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10903 WindowState w = mResizingWindows.get(i);
10904 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10905 pw.print(w); pw.println(":");
10906 w.dump(pw, " ");
10907 }
10908 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010909 if (mSessions.size() > 0) {
10910 pw.println(" ");
10911 pw.println(" All active sessions:");
10912 Iterator<Session> it = mSessions.iterator();
10913 while (it.hasNext()) {
10914 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010915 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010916 s.dump(pw, " ");
10917 }
10918 }
10919 if (mTokenMap.size() > 0) {
10920 pw.println(" ");
10921 pw.println(" All tokens:");
10922 Iterator<WindowToken> it = mTokenMap.values().iterator();
10923 while (it.hasNext()) {
10924 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010925 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010926 token.dump(pw, " ");
10927 }
10928 }
10929 if (mTokenList.size() > 0) {
10930 pw.println(" ");
10931 pw.println(" Window token list:");
10932 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010933 pw.print(" #"); pw.print(i); pw.print(": ");
10934 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010935 }
10936 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010937 if (mWallpaperTokens.size() > 0) {
10938 pw.println(" ");
10939 pw.println(" Wallpaper tokens:");
10940 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10941 WindowToken token = mWallpaperTokens.get(i);
10942 pw.print(" Wallpaper #"); pw.print(i);
10943 pw.print(' '); pw.print(token); pw.println(':');
10944 token.dump(pw, " ");
10945 }
10946 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010947 if (mAppTokens.size() > 0) {
10948 pw.println(" ");
10949 pw.println(" Application tokens in Z order:");
10950 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010951 pw.print(" App #"); pw.print(i); pw.print(": ");
10952 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010953 }
10954 }
10955 if (mFinishedStarting.size() > 0) {
10956 pw.println(" ");
10957 pw.println(" Finishing start of application tokens:");
10958 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10959 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010960 pw.print(" Finished Starting #"); pw.print(i);
10961 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010962 token.dump(pw, " ");
10963 }
10964 }
10965 if (mExitingTokens.size() > 0) {
10966 pw.println(" ");
10967 pw.println(" Exiting tokens:");
10968 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10969 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010970 pw.print(" Exiting #"); pw.print(i);
10971 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010972 token.dump(pw, " ");
10973 }
10974 }
10975 if (mExitingAppTokens.size() > 0) {
10976 pw.println(" ");
10977 pw.println(" Exiting application tokens:");
10978 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10979 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010980 pw.print(" Exiting App #"); pw.print(i);
10981 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010982 token.dump(pw, " ");
10983 }
10984 }
10985 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010986 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10987 pw.print(" mLastFocus="); pw.println(mLastFocus);
10988 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10989 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10990 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010991 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010992 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10993 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10994 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10995 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010996 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10997 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10998 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010999 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11000 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11001 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11002 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011003 if (mDimAnimator != null) {
11004 mDimAnimator.printTo(pw);
11005 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011006 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011007 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011008 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011009 pw.print(mInputMethodAnimLayerAdjustment);
11010 pw.print(" mWallpaperAnimLayerAdjustment=");
11011 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011012 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11013 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011014 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11015 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011016 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11017 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011018 pw.print(" mRotation="); pw.print(mRotation);
11019 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11020 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11021 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11022 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11023 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11024 pw.print(" mNextAppTransition=0x");
11025 pw.print(Integer.toHexString(mNextAppTransition));
11026 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011027 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011028 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011029 if (mNextAppTransitionPackage != null) {
11030 pw.print(" mNextAppTransitionPackage=");
11031 pw.print(mNextAppTransitionPackage);
11032 pw.print(", mNextAppTransitionEnter=0x");
11033 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11034 pw.print(", mNextAppTransitionExit=0x");
11035 pw.print(Integer.toHexString(mNextAppTransitionExit));
11036 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011037 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11038 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011039 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
11040 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
11041 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
11042 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011043 if (mOpeningApps.size() > 0) {
11044 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11045 }
11046 if (mClosingApps.size() > 0) {
11047 pw.print(" mClosingApps="); pw.println(mClosingApps);
11048 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011049 if (mToTopApps.size() > 0) {
11050 pw.print(" mToTopApps="); pw.println(mToTopApps);
11051 }
11052 if (mToBottomApps.size() > 0) {
11053 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11054 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011055 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11056 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011057 }
11058 }
11059
Jeff Brown349703e2010-06-22 01:27:15 -070011060 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011061 public void monitor() {
11062 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011063 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011064 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011065
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011066 /**
11067 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011068 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011069 */
11070 private static class DimAnimator {
11071 Surface mDimSurface;
11072 boolean mDimShown = false;
11073 float mDimCurrentAlpha;
11074 float mDimTargetAlpha;
11075 float mDimDeltaPerMs;
11076 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011077
11078 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011079
11080 DimAnimator (SurfaceSession session) {
11081 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011082 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011083 + mDimSurface + ": CREATE");
11084 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011085 mDimSurface = new Surface(session, 0,
11086 "DimSurface",
11087 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011088 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011089 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011090 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011091 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011092 }
11093 }
11094 }
11095
11096 /**
11097 * Show the dim surface.
11098 */
11099 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011100 if (!mDimShown) {
11101 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11102 dw + "x" + dh + ")");
11103 mDimShown = true;
11104 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011105 mLastDimWidth = dw;
11106 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011107 mDimSurface.setPosition(0, 0);
11108 mDimSurface.setSize(dw, dh);
11109 mDimSurface.show();
11110 } catch (RuntimeException e) {
11111 Slog.w(TAG, "Failure showing dim surface", e);
11112 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011113 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11114 mLastDimWidth = dw;
11115 mLastDimHeight = dh;
11116 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011117 }
11118 }
11119
11120 /**
11121 * Set's the dim surface's layer and update dim parameters that will be used in
11122 * {@link updateSurface} after all windows are examined.
11123 */
11124 void updateParameters(WindowState w, long currentTime) {
11125 mDimSurface.setLayer(w.mAnimLayer-1);
11126
11127 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011128 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011129 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011130 if (mDimTargetAlpha != target) {
11131 // If the desired dim level has changed, then
11132 // start an animation to it.
11133 mLastDimAnimTime = currentTime;
11134 long duration = (w.mAnimating && w.mAnimation != null)
11135 ? w.mAnimation.computeDurationHint()
11136 : DEFAULT_DIM_DURATION;
11137 if (target > mDimTargetAlpha) {
11138 // This is happening behind the activity UI,
11139 // so we can make it run a little longer to
11140 // give a stronger impression without disrupting
11141 // the user.
11142 duration *= DIM_DURATION_MULTIPLIER;
11143 }
11144 if (duration < 1) {
11145 // Don't divide by zero
11146 duration = 1;
11147 }
11148 mDimTargetAlpha = target;
11149 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11150 }
11151 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011152
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011153 /**
11154 * Updating the surface's alpha. Returns true if the animation continues, or returns
11155 * false when the animation is finished and the dim surface is hidden.
11156 */
11157 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11158 if (!dimming) {
11159 if (mDimTargetAlpha != 0) {
11160 mLastDimAnimTime = currentTime;
11161 mDimTargetAlpha = 0;
11162 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11163 }
11164 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011165
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011166 boolean animating = false;
11167 if (mLastDimAnimTime != 0) {
11168 mDimCurrentAlpha += mDimDeltaPerMs
11169 * (currentTime-mLastDimAnimTime);
11170 boolean more = true;
11171 if (displayFrozen) {
11172 // If the display is frozen, there is no reason to animate.
11173 more = false;
11174 } else if (mDimDeltaPerMs > 0) {
11175 if (mDimCurrentAlpha > mDimTargetAlpha) {
11176 more = false;
11177 }
11178 } else if (mDimDeltaPerMs < 0) {
11179 if (mDimCurrentAlpha < mDimTargetAlpha) {
11180 more = false;
11181 }
11182 } else {
11183 more = false;
11184 }
11185
11186 // Do we need to continue animating?
11187 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011188 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011189 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11190 mLastDimAnimTime = currentTime;
11191 mDimSurface.setAlpha(mDimCurrentAlpha);
11192 animating = true;
11193 } else {
11194 mDimCurrentAlpha = mDimTargetAlpha;
11195 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011196 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011197 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11198 mDimSurface.setAlpha(mDimCurrentAlpha);
11199 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011200 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011201 + ": HIDE");
11202 try {
11203 mDimSurface.hide();
11204 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011205 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011206 }
11207 mDimShown = false;
11208 }
11209 }
11210 }
11211 return animating;
11212 }
11213
11214 public void printTo(PrintWriter pw) {
11215 pw.print(" mDimShown="); pw.print(mDimShown);
11216 pw.print(" current="); pw.print(mDimCurrentAlpha);
11217 pw.print(" target="); pw.print(mDimTargetAlpha);
11218 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11219 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11220 }
11221 }
11222
11223 /**
11224 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11225 * This is used for opening/closing transition for apps in compatible mode.
11226 */
11227 private static class FadeInOutAnimation extends Animation {
11228 int mWidth;
11229 boolean mFadeIn;
11230
11231 public FadeInOutAnimation(boolean fadeIn) {
11232 setInterpolator(new AccelerateInterpolator());
11233 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11234 mFadeIn = fadeIn;
11235 }
11236
11237 @Override
11238 protected void applyTransformation(float interpolatedTime, Transformation t) {
11239 float x = interpolatedTime;
11240 if (!mFadeIn) {
11241 x = 1.0f - x; // reverse the interpolation for fade out
11242 }
11243 if (x < 0.5) {
11244 // move the window out of the screen.
11245 t.getMatrix().setTranslate(mWidth, 0);
11246 } else {
11247 t.getMatrix().setTranslate(0, 0);// show
11248 t.setAlpha((x - 0.5f) * 2);
11249 }
11250 }
11251
11252 @Override
11253 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11254 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11255 mWidth = width;
11256 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011257
11258 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011259 public int getZAdjustment() {
11260 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011261 }
11262 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011263}