blob: 92c5cc8b1b744b0a8bcb751c119b8149dfd2fdba [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
20import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
21import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070022import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
24import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070025import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
Joe Onorato93056472010-09-10 10:30:46 -040026import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR;
28import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
29import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070030import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
32import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS;
34import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
35import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
36import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
37import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070038import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039
40import com.android.internal.app.IBatteryStats;
41import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080042import com.android.internal.policy.impl.PhoneWindowManager;
Christopher Tatea53146c2010-09-07 11:57:52 -070043import com.android.internal.view.BaseInputHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import com.android.internal.view.IInputContext;
45import com.android.internal.view.IInputMethodClient;
46import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080047import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import com.android.server.am.BatteryStatsService;
49
50import android.Manifest;
51import android.app.ActivityManagerNative;
52import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070053import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070054import android.content.BroadcastReceiver;
Christopher Tatea53146c2010-09-07 11:57:52 -070055import android.content.ClipData;
56import android.content.ClipDescription;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070058import android.content.Intent;
59import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.content.pm.ActivityInfo;
61import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070062import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import android.content.res.Configuration;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070064import android.graphics.Canvas;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065import android.graphics.Matrix;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070066import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import android.graphics.PixelFormat;
68import android.graphics.Rect;
69import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070070import android.graphics.Typeface;
71import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072import android.os.BatteryStats;
73import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070074import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075import android.os.Debug;
76import android.os.Handler;
77import android.os.IBinder;
78import android.os.LocalPowerManager;
79import android.os.Looper;
80import android.os.Message;
81import android.os.Parcel;
82import android.os.ParcelFileDescriptor;
83import android.os.Power;
84import android.os.PowerManager;
85import android.os.Process;
86import android.os.RemoteException;
87import android.os.ServiceManager;
88import android.os.SystemClock;
89import android.os.SystemProperties;
90import android.os.TokenWatcher;
91import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070092import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070094import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080095import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070097import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098import android.view.Display;
Christopher Tatea53146c2010-09-07 11:57:52 -070099import android.view.DragEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100import android.view.Gravity;
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700101import android.view.HapticFeedbackConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102import android.view.IApplicationToken;
103import android.view.IOnKeyguardExitResult;
104import android.view.IRotationWatcher;
105import android.view.IWindow;
106import android.view.IWindowManager;
107import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700108import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700109import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700110import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700111import android.view.InputHandler;
112import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113import android.view.KeyEvent;
114import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115import android.view.Surface;
116import android.view.SurfaceSession;
117import android.view.View;
118import android.view.ViewTreeObserver;
119import android.view.WindowManager;
120import android.view.WindowManagerImpl;
121import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700122import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700124import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125import android.view.animation.Animation;
126import android.view.animation.AnimationUtils;
127import android.view.animation.Transformation;
128
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700129import java.io.BufferedReader;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700131import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132import java.io.File;
133import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700134import java.io.FileInputStream;
135import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136import java.io.IOException;
137import java.io.OutputStream;
138import java.io.OutputStreamWriter;
139import java.io.PrintWriter;
140import java.io.StringWriter;
141import java.net.Socket;
142import java.util.ArrayList;
143import java.util.HashMap;
144import java.util.HashSet;
145import java.util.Iterator;
146import java.util.List;
147
148/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700149public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700150 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 static final String TAG = "WindowManager";
152 static final boolean DEBUG = false;
153 static final boolean DEBUG_FOCUS = false;
154 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800155 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800156 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 static final boolean DEBUG_LAYERS = false;
158 static final boolean DEBUG_INPUT = false;
159 static final boolean DEBUG_INPUT_METHOD = false;
160 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700161 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700163 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 static final boolean DEBUG_APP_TRANSITIONS = false;
165 static final boolean DEBUG_STARTING_WINDOW = false;
166 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700167 static final boolean DEBUG_WALLPAPER = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700168 static final boolean DEBUG_DRAG = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700170 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172 static final boolean PROFILE_ORIENTATION = false;
173 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700174 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 /** How much to multiply the policy's type layer, to reserve room
177 * for multiple windows of the same type and Z-ordering adjustment
178 * with TYPE_LAYER_OFFSET. */
179 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
182 * or below others in the same layer. */
183 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 /** How much to increment the layer for each window, to reserve room
186 * for effect surfaces between them.
187 */
188 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 /** The maximum length we will accept for a loaded animation duration:
191 * this is 10 seconds.
192 */
193 static final int MAX_ANIMATION_DURATION = 10*1000;
194
195 /** Amount of time (in milliseconds) to animate the dim surface from one
196 * value to another, when no window animation is driving it.
197 */
198 static final int DEFAULT_DIM_DURATION = 200;
199
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700200 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
201 * compatible windows.
202 */
203 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 /** Adjustment to time to perform a dim, to make it more dramatic.
206 */
207 static final int DIM_DURATION_MULTIPLIER = 6;
Jeff Brown7fbdc842010-06-17 20:52:56 -0700208
209 // Maximum number of milliseconds to wait for input event injection.
210 // FIXME is this value reasonable?
211 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700212
213 // Default input dispatching timeout in nanoseconds.
214 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 static final int UPDATE_FOCUS_NORMAL = 0;
217 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
218 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
219 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700222 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223
224 /**
225 * Condition waited on by {@link #reenableKeyguard} to know the call to
226 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500227 * This is set to true only if mKeyguardTokenWatcher.acquired() has
228 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500230 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231
Jim Miller284b62e2010-06-08 14:27:42 -0700232 private static final int ALLOW_DISABLE_YES = 1;
233 private static final int ALLOW_DISABLE_NO = 0;
234 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
235 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
236
Mike Lockwood983ee092009-11-22 01:42:24 -0500237 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
238 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700240 if (shouldAllowDisableKeyguard()) {
241 mPolicy.enableKeyguard(false);
242 mKeyguardDisabled = true;
243 } else {
244 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
245 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 }
247 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700248 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500249 synchronized (mKeyguardTokenWatcher) {
250 mKeyguardDisabled = false;
251 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252 }
253 }
254 };
255
Jim Miller284b62e2010-06-08 14:27:42 -0700256 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
257 @Override
258 public void onReceive(Context context, Intent intent) {
259 mPolicy.enableKeyguard(true);
260 synchronized(mKeyguardTokenWatcher) {
261 // lazily evaluate this next time we're asked to disable keyguard
262 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
263 mKeyguardDisabled = false;
264 }
265 }
266 };
267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 final Context mContext;
269
270 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
275
276 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280 /**
281 * All currently active sessions with clients.
282 */
283 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 /**
286 * Mapping from an IWindow IBinder to the server's Window object.
287 * This is also used as the lock for all of our state.
288 */
289 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
290
291 /**
292 * Mapping from a token IBinder to a WindowToken object.
293 */
294 final HashMap<IBinder, WindowToken> mTokenMap =
295 new HashMap<IBinder, WindowToken>();
296
297 /**
298 * The same tokens as mTokenMap, stored in a list for efficient iteration
299 * over them.
300 */
301 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800303 /**
304 * Window tokens that are in the process of exiting, but still
305 * on screen for animations.
306 */
307 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
308
309 /**
310 * Z-ordered (bottom-most first) list of all application tokens, for
311 * controlling the ordering of windows in different applications. This
312 * contains WindowToken objects.
313 */
314 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
315
316 /**
317 * Application tokens that are in the process of exiting, but still
318 * on screen for animations.
319 */
320 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
321
322 /**
323 * List of window tokens that have finished starting their application,
324 * and now need to have the policy remove their windows.
325 */
326 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
327
328 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700329 * This was the app token that was used to retrieve the last enter
330 * animation. It will be used for the next exit animation.
331 */
332 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800333
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700334 /**
335 * These were the layout params used to retrieve the last enter animation.
336 * They will be used for the next exit animation.
337 */
338 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800339
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700340 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 * Z-ordered (bottom-most first) list of all Window objects.
342 */
Jeff Browne33348b2010-07-15 23:54:05 -0700343 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344
345 /**
346 * Windows that are being resized. Used so we can tell the client about
347 * the resize after closing the transaction in which we resized the
348 * underlying surface.
349 */
350 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
351
352 /**
353 * Windows whose animations have ended and now must be removed.
354 */
355 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
356
357 /**
358 * Windows whose surface should be destroyed.
359 */
360 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
361
362 /**
363 * Windows that have lost input focus and are waiting for the new
364 * focus window to be displayed before they are told about this.
365 */
366 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
367
368 /**
369 * This is set when we have run out of memory, and will either be an empty
370 * list or contain windows that need to be force removed.
371 */
372 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700377 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 Surface mBlurSurface;
379 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700380 Watermark mWatermark;
Romain Guy06882f82009-06-10 13:36:04 -0700381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 final float[] mTmpFloats = new float[9];
385
386 boolean mSafeMode;
387 boolean mDisplayEnabled = false;
388 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700389 int mInitialDisplayWidth = 0;
390 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 int mRotation = 0;
392 int mRequestedRotation = 0;
393 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700394 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 ArrayList<IRotationWatcher> mRotationWatchers
396 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800398 boolean mLayoutNeeded = true;
399 boolean mAnimationPending = false;
400 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800401 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 boolean mWindowsFreezingScreen = false;
403 long mFreezeGcPending = 0;
404 int mAppsFreezingScreen = 0;
405
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800406 int mLayoutSeq = 0;
407
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800408 // State while inside of layoutAndPlaceSurfacesLocked().
409 boolean mFocusMayChange;
410
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800411 Configuration mCurConfiguration = new Configuration();
412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 // This is held as long as we have the screen frozen, to give us time to
414 // perform a rotation animation when turning off shows the lock screen which
415 // changes the orientation.
416 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418 // State management of app transitions. When we are preparing for a
419 // transition, mNextAppTransition will be the kind of transition to
420 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
421 // mOpeningApps and mClosingApps are the lists of tokens that will be
422 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700423 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700424 String mNextAppTransitionPackage;
425 int mNextAppTransitionEnter;
426 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700428 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 boolean mAppTransitionTimeout = false;
430 boolean mStartingIconInTransition = false;
431 boolean mSkipAppTransitionAnimation = false;
432 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
433 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700434 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
435 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 H mH = new H();
440
441 WindowState mCurrentFocus = null;
442 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 // This just indicates the window the input method is on top of, not
445 // necessarily the window its input is going to.
446 WindowState mInputMethodTarget = null;
447 WindowState mUpcomingInputMethodTarget = null;
448 boolean mInputMethodTargetWaitingAnim;
449 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 WindowState mInputMethodWindow = null;
452 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
453
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700454 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800455
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700456 // If non-null, this is the currently visible window that is associated
457 // with the wallpaper.
458 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700459 // If non-null, we are in the middle of animating from one wallpaper target
460 // to another, and this is the lower one in Z-order.
461 WindowState mLowerWallpaperTarget = null;
462 // If non-null, we are in the middle of animating from one wallpaper target
463 // to another, and this is the higher one in Z-order.
464 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700465 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700466 float mLastWallpaperX = -1;
467 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800468 float mLastWallpaperXStep = -1;
469 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700470 // This is set when we are waiting for a wallpaper to tell us it is done
471 // changing its scroll position.
472 WindowState mWaitingOnWallpaper;
473 // The last time we had a timeout when waiting for a wallpaper.
474 long mLastWallpaperTimeoutTime;
475 // We give a wallpaper up to 150ms to finish scrolling.
476 static final long WALLPAPER_TIMEOUT = 150;
477 // Time we wait after a timeout before trying to wait again.
478 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800480 AppWindowToken mFocusedApp = null;
481
482 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800484 float mWindowAnimationScale = 1.0f;
485 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700486
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700487 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488
489 // Who is holding the screen on.
490 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700491 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700492
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700493 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700496 * Drag/drop state
497 */
498 class DragState {
499 IBinder mToken;
500 Surface mSurface;
501 boolean mLocalOnly;
502 ClipData mData;
503 ClipDescription mDataDescription;
504 float mThumbOffsetX, mThumbOffsetY;
505 InputChannel mServerChannel, mClientChannel;
506 WindowState mTargetWindow;
507 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700508 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700509
510 private final Rect tmpRect = new Rect();
511
512 DragState(IBinder token, Surface surface, boolean localOnly) {
513 mToken = token;
514 mSurface = surface;
515 mLocalOnly = localOnly;
516 mNotifiedWindows = new ArrayList<WindowState>();
517 }
518
519 void reset() {
520 if (mSurface != null) {
521 mSurface.destroy();
522 }
523 mSurface = null;
524 mLocalOnly = false;
525 mToken = null;
526 mData = null;
527 mThumbOffsetX = mThumbOffsetY = 0;
528 mNotifiedWindows = null;
529 }
530
531 void register() {
532 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
533 if (mClientChannel != null) {
534 Slog.e(TAG, "Duplicate register of drag input channel");
535 } else {
536 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
537 mServerChannel = channels[0];
538 mClientChannel = channels[1];
539 mInputManager.registerInputChannel(mServerChannel);
540 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
541 mH.getLooper().getQueue());
542 }
543 }
544
545 void unregister() {
546 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
547 if (mClientChannel == null) {
548 Slog.e(TAG, "Unregister of nonexistent drag input channel");
549 } else {
550 mInputManager.unregisterInputChannel(mServerChannel);
551 InputQueue.unregisterInputChannel(mClientChannel);
552 mClientChannel.dispose();
553 mClientChannel = null;
554 mServerChannel = null;
555 }
556 }
557
558 /* call out to each visible window/session informing it about the drag
559 */
560 void broadcastDragStartedLw() {
561 // Cache a base-class instance of the clip metadata so that parceling
562 // works correctly in calling out to the apps.
563 mDataDescription = new ClipDescription(mData);
564 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700565 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700566
567 if (DEBUG_DRAG) {
568 Slog.d(TAG, "broadcasting DRAG_STARTED of " + mDataDescription);
569 }
570
571 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED, 0, 0,
572 mDataDescription, null);
Christopher Tate2c095f32010-10-04 14:13:40 -0700573 final int N = mWindows.size();
574 for (int i = 0; i < N; i++) {
575 // sendDragStartedLw() clones evt for local-process dispatch
576 sendDragStartedLw(mWindows.get(i), evt);
Christopher Tatea53146c2010-09-07 11:57:52 -0700577 }
578 evt.recycle();
579 }
580
581 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
582 * designated window is potentially a drop recipient. There are race situations
583 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
584 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700585 *
586 * This method clones the 'event' parameter if it's being delivered to the same
587 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700588 */
Christopher Tate2c095f32010-10-04 14:13:40 -0700589 private void sendDragStartedLw(WindowState newWin, DragEvent event) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700590 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700591 try {
Christopher Tate2c095f32010-10-04 14:13:40 -0700592 // clone for local callees since dispatch will recycle the event
593 if (Process.myPid() == newWin.mSession.mPid) {
594 event = DragEvent.obtain(event);
595 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700596 newWin.mClient.dispatchDragEvent(event);
597 // track each window that we've notified that the drag is starting
598 mNotifiedWindows.add(newWin);
599 } catch (RemoteException e) {
600 Slog.w(TAG, "Unable to drag-start window " + newWin);
601 }
602 }
603 }
604
605 /* helper - construct and send a DRAG_STARTED event only if the window has not
606 * previously been notified, i.e. it became visible after the drag operation
607 * was begun. This is a rare case.
608 */
609 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700610 if (mDragInProgress) {
611 // If we have sent the drag-started, we needn't do so again
612 for (WindowState ws : mNotifiedWindows) {
613 if (ws == newWin) {
614 return;
615 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700616 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700617 if (DEBUG_DRAG) {
618 Slog.d(TAG, "sending DRAG_STARTED to new window " + newWin);
619 }
620 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED, 0, 0,
621 mDataDescription, null);
622 // sendDragStartedLw() clones 'event' if the window is process-local
623 sendDragStartedLw(newWin, event);
624 event.recycle();
Christopher Tatea53146c2010-09-07 11:57:52 -0700625 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700626 }
627
628 void broadcastDragEnded() {
629 if (DEBUG_DRAG) {
630 Slog.d(TAG, "broadcasting DRAG_ENDED");
631 }
632 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED, 0, 0, null, null);
633 synchronized (mWindowMap) {
634 for (WindowState ws: mNotifiedWindows) {
635 try {
636 ws.mClient.dispatchDragEvent(evt);
637 } catch (RemoteException e) {
638 Slog.w(TAG, "Unable to drag-end window " + ws);
639 }
640 }
641 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700642 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700643 }
644 evt.recycle();
645 }
646
647 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700648 final int myPid = Process.myPid();
649
650 // Move the surface to the given touch
651 mSurface.openTransaction();
652 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
653 mSurface.closeTransaction();
654
655 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700656 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
657 try {
658 // have we dragged over a new window?
659 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
660 if (DEBUG_DRAG) {
661 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
662 }
663 // force DRAG_EXITED_EVENT if appropriate
664 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
665 0, 0, null, null);
666 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700667 if (myPid != mTargetWindow.mSession.mPid) {
668 evt.recycle();
669 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700670 }
671 if (touchedWin != null) {
672 if (DEBUG_DRAG) {
673 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
674 }
675 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
676 x, y, null, null);
677 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700678 if (myPid != touchedWin.mSession.mPid) {
679 evt.recycle();
680 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700681 }
682 } catch (RemoteException e) {
683 Slog.w(TAG, "can't send drag notification to windows");
684 }
685 mTargetWindow = touchedWin;
686 }
687
688 // Tell the drop target about the data, and then broadcast the drag-ended notification
689 void notifyDropLw(float x, float y) {
690 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
691 if (touchedWin != null) {
692 if (DEBUG_DRAG) {
693 Slog.d(TAG, "sending DROP to " + touchedWin);
694 }
Christopher Tate2c095f32010-10-04 14:13:40 -0700695 final int myPid = Process.myPid();
Christopher Tatea53146c2010-09-07 11:57:52 -0700696 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP, x, y, null, mData);
697 try {
698 touchedWin.mClient.dispatchDragEvent(evt);
699 } catch (RemoteException e) {
700 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
701 }
Christopher Tate2c095f32010-10-04 14:13:40 -0700702 if (myPid != touchedWin.mSession.mPid) {
703 evt.recycle();
704 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700705 }
706 }
707
708 // Find the visible, touch-deliverable window under the given point
709 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
710 WindowState touchedWin = null;
711 final int x = (int) xf;
712 final int y = (int) yf;
713 final ArrayList<WindowState> windows = mWindows;
714 final int N = windows.size();
715 for (int i = N - 1; i >= 0; i--) {
716 WindowState child = windows.get(i);
717 final int flags = child.mAttrs.flags;
718 if (!child.isVisibleLw()) {
719 // not visible == don't tell about drags
720 continue;
721 }
722 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
723 // not touchable == don't tell about drags
724 continue;
725 }
726 // account for the window's decor etc
727 tmpRect.set(child.mFrame);
728 if (child.mTouchableInsets == ViewTreeObserver
729 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
730 // The point is inside of the window if it is
731 // inside the frame, AND the content part of that
732 // frame that was given by the application.
733 tmpRect.left += child.mGivenContentInsets.left;
734 tmpRect.top += child.mGivenContentInsets.top;
735 tmpRect.right -= child.mGivenContentInsets.right;
736 tmpRect.bottom -= child.mGivenContentInsets.bottom;
737 } else if (child.mTouchableInsets == ViewTreeObserver
738 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
739 // The point is inside of the window if it is
740 // inside the frame, AND the visible part of that
741 // frame that was given by the application.
742 tmpRect.left += child.mGivenVisibleInsets.left;
743 tmpRect.top += child.mGivenVisibleInsets.top;
744 tmpRect.right -= child.mGivenVisibleInsets.right;
745 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
746 }
747 final int touchFlags = flags &
748 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
749 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
750 if (tmpRect.contains(x, y) || touchFlags == 0) {
751 // Found it
752 touchedWin = child;
753 break;
754 }
755 }
756
757 return touchedWin;
758 }
759 }
760
761 DragState mDragState = null;
762 private final InputHandler mDragInputHandler = new BaseInputHandler() {
763 @Override
764 public void handleMotion(MotionEvent event, Runnable finishedCallback) {
765 boolean endDrag = false;
766 final float newX = event.getRawX();
767 final float newY = event.getRawY();
768
769 try {
770 if (mDragState != null) {
771 switch (event.getAction()) {
772 case MotionEvent.ACTION_DOWN: {
773 if (DEBUG_DRAG) {
774 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
775 }
776 } break;
777
778 case MotionEvent.ACTION_MOVE: {
779 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700780 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700781 mDragState.notifyMoveLw(newX, newY);
782 }
783 } break;
784
785 case MotionEvent.ACTION_UP: {
786 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
787 + newX + "," + newY);
788 synchronized (mWindowMap) {
789 mDragState.notifyDropLw(newX, newY);
790 }
791 endDrag = true;
792 } break;
793
794 case MotionEvent.ACTION_CANCEL: {
795 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
796 endDrag = true;
797 } break;
798 }
799
800 if (endDrag) {
801 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
802 // tell all the windows that the drag has ended
803 mDragState.broadcastDragEnded();
804
805 // stop intercepting input
806 mDragState.unregister();
Chris Tate59943592010-10-11 20:33:44 -0700807 synchronized (mWindowMap) {
808 mInputMonitor.updateInputWindowsLw();
809 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700810
811 // free our resources and drop all the object references
812 mDragState.reset();
813 mDragState = null;
814 }
815 }
816 } catch (Exception e) {
817 Slog.e(TAG, "Exception caught by drag handleMotion", e);
818 } finally {
819 finishedCallback.run();
820 }
821 }
822 };
823
824 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800825 * Whether the UI is currently running in touch mode (not showing
826 * navigational focus because the user is directly pressing the screen).
827 */
828 boolean mInTouchMode = false;
829
830 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700831 private ArrayList<WindowChangeListener> mWindowChangeListeners =
832 new ArrayList<WindowChangeListener>();
833 private boolean mWindowsChanged = false;
834
835 public interface WindowChangeListener {
836 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700837 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700838 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800839
Dianne Hackbornc485a602009-03-24 22:39:49 -0700840 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700841 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700842
843 // The frame use to limit the size of the app running in compatibility mode.
844 Rect mCompatibleScreenFrame = new Rect();
845 // The surface used to fill the outer rim of the app running in compatibility mode.
846 Surface mBackgroundFillerSurface = null;
847 boolean mBackgroundFillerShown = false;
848
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800849 public static WindowManagerService main(Context context,
850 PowerManagerService pm, boolean haveInputMethods) {
851 WMThread thr = new WMThread(context, pm, haveInputMethods);
852 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700853
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800854 synchronized (thr) {
855 while (thr.mService == null) {
856 try {
857 thr.wait();
858 } catch (InterruptedException e) {
859 }
860 }
861 }
Romain Guy06882f82009-06-10 13:36:04 -0700862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800863 return thr.mService;
864 }
Romain Guy06882f82009-06-10 13:36:04 -0700865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800866 static class WMThread extends Thread {
867 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700868
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800869 private final Context mContext;
870 private final PowerManagerService mPM;
871 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700872
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800873 public WMThread(Context context, PowerManagerService pm,
874 boolean haveInputMethods) {
875 super("WindowManager");
876 mContext = context;
877 mPM = pm;
878 mHaveInputMethods = haveInputMethods;
879 }
Romain Guy06882f82009-06-10 13:36:04 -0700880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800881 public void run() {
882 Looper.prepare();
883 WindowManagerService s = new WindowManagerService(mContext, mPM,
884 mHaveInputMethods);
885 android.os.Process.setThreadPriority(
886 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700887 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800889 synchronized (this) {
890 mService = s;
891 notifyAll();
892 }
Romain Guy06882f82009-06-10 13:36:04 -0700893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800894 Looper.loop();
895 }
896 }
897
898 static class PolicyThread extends Thread {
899 private final WindowManagerPolicy mPolicy;
900 private final WindowManagerService mService;
901 private final Context mContext;
902 private final PowerManagerService mPM;
903 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800905 public PolicyThread(WindowManagerPolicy policy,
906 WindowManagerService service, Context context,
907 PowerManagerService pm) {
908 super("WindowManagerPolicy");
909 mPolicy = policy;
910 mService = service;
911 mContext = context;
912 mPM = pm;
913 }
Romain Guy06882f82009-06-10 13:36:04 -0700914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800915 public void run() {
916 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800917 WindowManagerPolicyThread.set(this, Looper.myLooper());
918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800919 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800920 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800921 android.os.Process.setThreadPriority(
922 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700923 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 synchronized (this) {
927 mRunning = true;
928 notifyAll();
929 }
Romain Guy06882f82009-06-10 13:36:04 -0700930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 Looper.loop();
932 }
933 }
934
935 private WindowManagerService(Context context, PowerManagerService pm,
936 boolean haveInputMethods) {
937 mContext = context;
938 mHaveInputMethods = haveInputMethods;
939 mLimitedAlphaCompositing = context.getResources().getBoolean(
940 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800942 mPowerManager = pm;
943 mPowerManager.setPolicy(mPolicy);
944 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
945 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
946 "SCREEN_FROZEN");
947 mScreenFrozenLock.setReferenceCounted(false);
948
949 mActivityManager = ActivityManagerNative.getDefault();
950 mBatteryStats = BatteryStatsService.getService();
951
952 // Get persisted window scale setting
953 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
954 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
955 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
956 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700957
Jim Miller284b62e2010-06-08 14:27:42 -0700958 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
959 IntentFilter filter = new IntentFilter();
960 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
961 mContext.registerReceiver(mBroadcastReceiver, filter);
962
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700963 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
964 "KEEP_SCREEN_ON_FLAG");
965 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800966
Jeff Browne33348b2010-07-15 23:54:05 -0700967 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -0700968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800969 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
970 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800972 synchronized (thr) {
973 while (!thr.mRunning) {
974 try {
975 thr.wait();
976 } catch (InterruptedException e) {
977 }
978 }
979 }
Romain Guy06882f82009-06-10 13:36:04 -0700980
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700981 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -0700982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800983 // Add ourself to the Watchdog monitors.
984 Watchdog.getInstance().addMonitor(this);
985 }
986
987 @Override
988 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
989 throws RemoteException {
990 try {
991 return super.onTransact(code, data, reply, flags);
992 } catch (RuntimeException e) {
993 // The window manager only throws security exceptions, so let's
994 // log all others.
995 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800996 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800997 }
998 throw e;
999 }
1000 }
1001
Jeff Browne33348b2010-07-15 23:54:05 -07001002 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001003 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001004 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001005 TAG, "Adding window " + window + " at "
1006 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1007 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001008 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001009 }
1010
Jeff Browne33348b2010-07-15 23:54:05 -07001011 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001012 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001013 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001014 TAG, "Adding window " + window + " at "
1015 + i + " of " + mWindows.size() + " (before " + pos + ")");
1016 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001017 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001018 }
1019
1020 //This method finds out the index of a window that has the same app token as
1021 //win. used for z ordering the windows in mWindows
1022 private int findIdxBasedOnAppTokens(WindowState win) {
1023 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001024 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001025 int jmax = localmWindows.size();
1026 if(jmax == 0) {
1027 return -1;
1028 }
1029 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001030 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001031 if(wentry.mAppToken == win.mAppToken) {
1032 return j;
1033 }
1034 }
1035 return -1;
1036 }
Romain Guy06882f82009-06-10 13:36:04 -07001037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001038 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1039 final IWindow client = win.mClient;
1040 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001041 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001043 final int N = localmWindows.size();
1044 final WindowState attached = win.mAttachedWindow;
1045 int i;
1046 if (attached == null) {
1047 int tokenWindowsPos = token.windows.size();
1048 if (token.appWindowToken != null) {
1049 int index = tokenWindowsPos-1;
1050 if (index >= 0) {
1051 // If this application has existing windows, we
1052 // simply place the new window on top of them... but
1053 // keep the starting window on top.
1054 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1055 // Base windows go behind everything else.
1056 placeWindowBefore(token.windows.get(0), win);
1057 tokenWindowsPos = 0;
1058 } else {
1059 AppWindowToken atoken = win.mAppToken;
1060 if (atoken != null &&
1061 token.windows.get(index) == atoken.startingWindow) {
1062 placeWindowBefore(token.windows.get(index), win);
1063 tokenWindowsPos--;
1064 } else {
1065 int newIdx = findIdxBasedOnAppTokens(win);
1066 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001067 //there is a window above this one associated with the same
1068 //apptoken note that the window could be a floating window
1069 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001070 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001071 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001072 TAG, "Adding window " + win + " at "
1073 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001074 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001075 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001076 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001077 }
1078 }
1079 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001080 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 TAG, "Figuring out where to add app window "
1082 + client.asBinder() + " (token=" + token + ")");
1083 // Figure out where the window should go, based on the
1084 // order of applications.
1085 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001086 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001087 for (i=NA-1; i>=0; i--) {
1088 AppWindowToken t = mAppTokens.get(i);
1089 if (t == token) {
1090 i--;
1091 break;
1092 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001093
Dianne Hackborna8f60182009-09-01 19:01:50 -07001094 // We haven't reached the token yet; if this token
1095 // is not going to the bottom and has windows, we can
1096 // use it as an anchor for when we do reach the token.
1097 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001098 pos = t.windows.get(0);
1099 }
1100 }
1101 // We now know the index into the apps. If we found
1102 // an app window above, that gives us the position; else
1103 // we need to look some more.
1104 if (pos != null) {
1105 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001106 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001107 if (atoken != null) {
1108 final int NC = atoken.windows.size();
1109 if (NC > 0) {
1110 WindowState bottom = atoken.windows.get(0);
1111 if (bottom.mSubLayer < 0) {
1112 pos = bottom;
1113 }
1114 }
1115 }
1116 placeWindowBefore(pos, win);
1117 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001118 // Continue looking down until we find the first
1119 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120 while (i >= 0) {
1121 AppWindowToken t = mAppTokens.get(i);
1122 final int NW = t.windows.size();
1123 if (NW > 0) {
1124 pos = t.windows.get(NW-1);
1125 break;
1126 }
1127 i--;
1128 }
1129 if (pos != null) {
1130 // Move in front of any windows attached to this
1131 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001132 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001133 if (atoken != null) {
1134 final int NC = atoken.windows.size();
1135 if (NC > 0) {
1136 WindowState top = atoken.windows.get(NC-1);
1137 if (top.mSubLayer >= 0) {
1138 pos = top;
1139 }
1140 }
1141 }
1142 placeWindowAfter(pos, win);
1143 } else {
1144 // Just search for the start of this layer.
1145 final int myLayer = win.mBaseLayer;
1146 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001147 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 if (w.mBaseLayer > myLayer) {
1149 break;
1150 }
1151 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001152 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001153 TAG, "Adding window " + win + " at "
1154 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001156 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001157 }
1158 }
1159 }
1160 } else {
1161 // Figure out where window should go, based on layer.
1162 final int myLayer = win.mBaseLayer;
1163 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001164 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001165 i++;
1166 break;
1167 }
1168 }
1169 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001170 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001171 TAG, "Adding window " + win + " at "
1172 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001173 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001174 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 }
1176 if (addToToken) {
1177 token.windows.add(tokenWindowsPos, win);
1178 }
1179
1180 } else {
1181 // Figure out this window's ordering relative to the window
1182 // it is attached to.
1183 final int NA = token.windows.size();
1184 final int sublayer = win.mSubLayer;
1185 int largestSublayer = Integer.MIN_VALUE;
1186 WindowState windowWithLargestSublayer = null;
1187 for (i=0; i<NA; i++) {
1188 WindowState w = token.windows.get(i);
1189 final int wSublayer = w.mSubLayer;
1190 if (wSublayer >= largestSublayer) {
1191 largestSublayer = wSublayer;
1192 windowWithLargestSublayer = w;
1193 }
1194 if (sublayer < 0) {
1195 // For negative sublayers, we go below all windows
1196 // in the same sublayer.
1197 if (wSublayer >= sublayer) {
1198 if (addToToken) {
1199 token.windows.add(i, win);
1200 }
1201 placeWindowBefore(
1202 wSublayer >= 0 ? attached : w, win);
1203 break;
1204 }
1205 } else {
1206 // For positive sublayers, we go above all windows
1207 // in the same sublayer.
1208 if (wSublayer > sublayer) {
1209 if (addToToken) {
1210 token.windows.add(i, win);
1211 }
1212 placeWindowBefore(w, win);
1213 break;
1214 }
1215 }
1216 }
1217 if (i >= NA) {
1218 if (addToToken) {
1219 token.windows.add(win);
1220 }
1221 if (sublayer < 0) {
1222 placeWindowBefore(attached, win);
1223 } else {
1224 placeWindowAfter(largestSublayer >= 0
1225 ? windowWithLargestSublayer
1226 : attached,
1227 win);
1228 }
1229 }
1230 }
Romain Guy06882f82009-06-10 13:36:04 -07001231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001232 if (win.mAppToken != null && addToToken) {
1233 win.mAppToken.allAppWindows.add(win);
1234 }
1235 }
Romain Guy06882f82009-06-10 13:36:04 -07001236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001237 static boolean canBeImeTarget(WindowState w) {
1238 final int fl = w.mAttrs.flags
1239 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1240 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1241 return w.isVisibleOrAdding();
1242 }
1243 return false;
1244 }
Romain Guy06882f82009-06-10 13:36:04 -07001245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001246 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001247 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001248 final int N = localmWindows.size();
1249 WindowState w = null;
1250 int i = N;
1251 while (i > 0) {
1252 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001253 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001254
Joe Onorato8a9b2202010-02-26 18:56:32 -08001255 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001256 // + Integer.toHexString(w.mAttrs.flags));
1257 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001258 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001260 // Yet more tricksyness! If this window is a "starting"
1261 // window, we do actually want to be on top of it, but
1262 // it is not -really- where input will go. So if the caller
1263 // is not actually looking to move the IME, look down below
1264 // for a real window to target...
1265 if (!willMove
1266 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1267 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001268 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001269 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1270 i--;
1271 w = wb;
1272 }
1273 }
1274 break;
1275 }
1276 }
Romain Guy06882f82009-06-10 13:36:04 -07001277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001278 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -07001279
Joe Onorato8a9b2202010-02-26 18:56:32 -08001280 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001281 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001283 if (willMove && w != null) {
1284 final WindowState curTarget = mInputMethodTarget;
1285 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001287 // Now some fun for dealing with window animations that
1288 // modify the Z order. We need to look at all windows below
1289 // the current target that are in this app, finding the highest
1290 // visible one in layering.
1291 AppWindowToken token = curTarget.mAppToken;
1292 WindowState highestTarget = null;
1293 int highestPos = 0;
1294 if (token.animating || token.animation != null) {
1295 int pos = 0;
1296 pos = localmWindows.indexOf(curTarget);
1297 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001298 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001299 if (win.mAppToken != token) {
1300 break;
1301 }
1302 if (!win.mRemoved) {
1303 if (highestTarget == null || win.mAnimLayer >
1304 highestTarget.mAnimLayer) {
1305 highestTarget = win;
1306 highestPos = pos;
1307 }
1308 }
1309 pos--;
1310 }
1311 }
Romain Guy06882f82009-06-10 13:36:04 -07001312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001313 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001314 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001315 + mNextAppTransition + " " + highestTarget
1316 + " animating=" + highestTarget.isAnimating()
1317 + " layer=" + highestTarget.mAnimLayer
1318 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001319
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001320 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001321 // If we are currently setting up for an animation,
1322 // hold everything until we can find out what will happen.
1323 mInputMethodTargetWaitingAnim = true;
1324 mInputMethodTarget = highestTarget;
1325 return highestPos + 1;
1326 } else if (highestTarget.isAnimating() &&
1327 highestTarget.mAnimLayer > w.mAnimLayer) {
1328 // If the window we are currently targeting is involved
1329 // with an animation, and it is on top of the next target
1330 // we will be over, then hold off on moving until
1331 // that is done.
1332 mInputMethodTarget = highestTarget;
1333 return highestPos + 1;
1334 }
1335 }
1336 }
1337 }
Romain Guy06882f82009-06-10 13:36:04 -07001338
Joe Onorato8a9b2202010-02-26 18:56:32 -08001339 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001340 if (w != null) {
1341 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001342 if (DEBUG_INPUT_METHOD) {
1343 RuntimeException e = null;
1344 if (!HIDE_STACK_CRAWLS) {
1345 e = new RuntimeException();
1346 e.fillInStackTrace();
1347 }
1348 Slog.w(TAG, "Moving IM target from "
1349 + mInputMethodTarget + " to " + w, e);
1350 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001351 mInputMethodTarget = w;
1352 if (w.mAppToken != null) {
1353 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1354 } else {
1355 setInputMethodAnimLayerAdjustment(0);
1356 }
1357 }
1358 return i+1;
1359 }
1360 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001361 if (DEBUG_INPUT_METHOD) {
1362 RuntimeException e = null;
1363 if (!HIDE_STACK_CRAWLS) {
1364 e = new RuntimeException();
1365 e.fillInStackTrace();
1366 }
1367 Slog.w(TAG, "Moving IM target from "
1368 + mInputMethodTarget + " to null", e);
1369 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001370 mInputMethodTarget = null;
1371 setInputMethodAnimLayerAdjustment(0);
1372 }
1373 return -1;
1374 }
Romain Guy06882f82009-06-10 13:36:04 -07001375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001376 void addInputMethodWindowToListLocked(WindowState win) {
1377 int pos = findDesiredInputMethodWindowIndexLocked(true);
1378 if (pos >= 0) {
1379 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001380 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001381 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001382 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001383 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001384 moveInputMethodDialogsLocked(pos+1);
1385 return;
1386 }
1387 win.mTargetAppToken = null;
1388 addWindowToListInOrderLocked(win, true);
1389 moveInputMethodDialogsLocked(pos);
1390 }
Romain Guy06882f82009-06-10 13:36:04 -07001391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001392 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001393 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001394 mInputMethodAnimLayerAdjustment = adj;
1395 WindowState imw = mInputMethodWindow;
1396 if (imw != null) {
1397 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001398 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001399 + " anim layer: " + imw.mAnimLayer);
1400 int wi = imw.mChildWindows.size();
1401 while (wi > 0) {
1402 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001403 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001404 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001405 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001406 + " anim layer: " + cw.mAnimLayer);
1407 }
1408 }
1409 int di = mInputMethodDialogs.size();
1410 while (di > 0) {
1411 di --;
1412 imw = mInputMethodDialogs.get(di);
1413 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001414 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001415 + " anim layer: " + imw.mAnimLayer);
1416 }
1417 }
Romain Guy06882f82009-06-10 13:36:04 -07001418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001419 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1420 int wpos = mWindows.indexOf(win);
1421 if (wpos >= 0) {
1422 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001423 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001424 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001425 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001426 int NC = win.mChildWindows.size();
1427 while (NC > 0) {
1428 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001429 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001430 int cpos = mWindows.indexOf(cw);
1431 if (cpos >= 0) {
1432 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001433 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001434 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001435 mWindows.remove(cpos);
1436 }
1437 }
1438 }
1439 return interestingPos;
1440 }
Romain Guy06882f82009-06-10 13:36:04 -07001441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001442 private void reAddWindowToListInOrderLocked(WindowState win) {
1443 addWindowToListInOrderLocked(win, false);
1444 // This is a hack to get all of the child windows added as well
1445 // at the right position. Child windows should be rare and
1446 // this case should be rare, so it shouldn't be that big a deal.
1447 int wpos = mWindows.indexOf(win);
1448 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001449 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001450 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001451 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001452 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001453 reAddWindowLocked(wpos, win);
1454 }
1455 }
Romain Guy06882f82009-06-10 13:36:04 -07001456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001457 void logWindowList(String prefix) {
1458 int N = mWindows.size();
1459 while (N > 0) {
1460 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001461 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001462 }
1463 }
Romain Guy06882f82009-06-10 13:36:04 -07001464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001465 void moveInputMethodDialogsLocked(int pos) {
1466 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001468 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001469 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001470 for (int i=0; i<N; i++) {
1471 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1472 }
1473 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001474 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001475 logWindowList(" ");
1476 }
Romain Guy06882f82009-06-10 13:36:04 -07001477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001478 if (pos >= 0) {
1479 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1480 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001481 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001482 if (wp == mInputMethodWindow) {
1483 pos++;
1484 }
1485 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001486 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001487 for (int i=0; i<N; i++) {
1488 WindowState win = dialogs.get(i);
1489 win.mTargetAppToken = targetAppToken;
1490 pos = reAddWindowLocked(pos, win);
1491 }
1492 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001493 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001494 logWindowList(" ");
1495 }
1496 return;
1497 }
1498 for (int i=0; i<N; i++) {
1499 WindowState win = dialogs.get(i);
1500 win.mTargetAppToken = null;
1501 reAddWindowToListInOrderLocked(win);
1502 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001503 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001504 logWindowList(" ");
1505 }
1506 }
1507 }
Romain Guy06882f82009-06-10 13:36:04 -07001508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001509 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1510 final WindowState imWin = mInputMethodWindow;
1511 final int DN = mInputMethodDialogs.size();
1512 if (imWin == null && DN == 0) {
1513 return false;
1514 }
Romain Guy06882f82009-06-10 13:36:04 -07001515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001516 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1517 if (imPos >= 0) {
1518 // In this case, the input method windows are to be placed
1519 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001521 // First check to see if the input method windows are already
1522 // located here, and contiguous.
1523 final int N = mWindows.size();
1524 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001525 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001527 // Figure out the actual input method window that should be
1528 // at the bottom of their stack.
1529 WindowState baseImWin = imWin != null
1530 ? imWin : mInputMethodDialogs.get(0);
1531 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001532 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001533 if (cw.mSubLayer < 0) baseImWin = cw;
1534 }
Romain Guy06882f82009-06-10 13:36:04 -07001535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001536 if (firstImWin == baseImWin) {
1537 // The windows haven't moved... but are they still contiguous?
1538 // First find the top IM window.
1539 int pos = imPos+1;
1540 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001541 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001542 break;
1543 }
1544 pos++;
1545 }
1546 pos++;
1547 // Now there should be no more input method windows above.
1548 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001549 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001550 break;
1551 }
1552 pos++;
1553 }
1554 if (pos >= N) {
1555 // All is good!
1556 return false;
1557 }
1558 }
Romain Guy06882f82009-06-10 13:36:04 -07001559
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001560 if (imWin != null) {
1561 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001562 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001563 logWindowList(" ");
1564 }
1565 imPos = tmpRemoveWindowLocked(imPos, imWin);
1566 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001567 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001568 logWindowList(" ");
1569 }
1570 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1571 reAddWindowLocked(imPos, imWin);
1572 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001573 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001574 logWindowList(" ");
1575 }
1576 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1577 } else {
1578 moveInputMethodDialogsLocked(imPos);
1579 }
Romain Guy06882f82009-06-10 13:36:04 -07001580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001581 } else {
1582 // In this case, the input method windows go in a fixed layer,
1583 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001585 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001586 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001587 tmpRemoveWindowLocked(0, imWin);
1588 imWin.mTargetAppToken = null;
1589 reAddWindowToListInOrderLocked(imWin);
1590 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001591 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001592 logWindowList(" ");
1593 }
1594 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1595 } else {
1596 moveInputMethodDialogsLocked(-1);;
1597 }
Romain Guy06882f82009-06-10 13:36:04 -07001598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001599 }
Romain Guy06882f82009-06-10 13:36:04 -07001600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001601 if (needAssignLayers) {
1602 assignLayersLocked();
1603 }
Romain Guy06882f82009-06-10 13:36:04 -07001604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001605 return true;
1606 }
Romain Guy06882f82009-06-10 13:36:04 -07001607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001608 void adjustInputMethodDialogsLocked() {
1609 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1610 }
Romain Guy06882f82009-06-10 13:36:04 -07001611
Dianne Hackborn25994b42009-09-04 14:21:19 -07001612 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001613 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001614 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1615 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1616 ? wallpaperTarget.mAppToken.animation : null)
1617 + " upper=" + mUpperWallpaperTarget
1618 + " lower=" + mLowerWallpaperTarget);
1619 return (wallpaperTarget != null
1620 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1621 && wallpaperTarget.mAppToken.animation != null)))
1622 || mUpperWallpaperTarget != null
1623 || mLowerWallpaperTarget != null;
1624 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001625
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001626 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1627 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001628
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001629 int adjustWallpaperWindowsLocked() {
1630 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001631
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001632 final int dw = mDisplay.getWidth();
1633 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001634
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001635 // First find top-most window that has asked to be on top of the
1636 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001637 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001638 int N = localmWindows.size();
1639 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001640 WindowState foundW = null;
1641 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001642 WindowState topCurW = null;
1643 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001644 int i = N;
1645 while (i > 0) {
1646 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001647 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001648 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1649 if (topCurW == null) {
1650 topCurW = w;
1651 topCurI = i;
1652 }
1653 continue;
1654 }
1655 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001656 if (w.mAppToken != null) {
1657 // If this window's app token is hidden and not animating,
1658 // it is of no interest to us.
1659 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001660 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001661 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001662 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001663 continue;
1664 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001665 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001666 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001667 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1668 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001669 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001670 && (mWallpaperTarget == w
1671 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001672 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001673 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001674 foundW = w;
1675 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001676 if (w == mWallpaperTarget && ((w.mAppToken != null
1677 && w.mAppToken.animation != null)
1678 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001679 // The current wallpaper target is animating, so we'll
1680 // look behind it for another possible target and figure
1681 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001682 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001683 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001684 continue;
1685 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001686 break;
1687 }
1688 }
1689
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001690 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001691 // If we are currently waiting for an app transition, and either
1692 // the current target or the next target are involved with it,
1693 // then hold off on doing anything with the wallpaper.
1694 // Note that we are checking here for just whether the target
1695 // is part of an app token... which is potentially overly aggressive
1696 // (the app token may not be involved in the transition), but good
1697 // enough (we'll just wait until whatever transition is pending
1698 // executes).
1699 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001700 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001701 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001702 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001703 }
1704 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001705 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001706 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001707 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001708 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001709 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001710
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001711 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001712 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001713 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001714 + " oldTarget: " + mWallpaperTarget);
1715 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001716
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001717 mLowerWallpaperTarget = null;
1718 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001719
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001720 WindowState oldW = mWallpaperTarget;
1721 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001722
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001723 // Now what is happening... if the current and new targets are
1724 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001725 if (foundW != null && oldW != null) {
1726 boolean oldAnim = oldW.mAnimation != null
1727 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1728 boolean foundAnim = foundW.mAnimation != null
1729 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001730 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001731 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001732 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001733 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001734 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001735 int oldI = localmWindows.indexOf(oldW);
1736 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001737 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001738 }
1739 if (oldI >= 0) {
1740 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001741 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001742 + "=" + oldW + "; new#" + foundI
1743 + "=" + foundW);
1744 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001745
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001746 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001747 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001748 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001749 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001750 }
1751 mWallpaperTarget = oldW;
1752 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001753
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001754 // Now set the upper and lower wallpaper targets
1755 // correctly, and make sure that we are positioning
1756 // the wallpaper below the lower.
1757 if (foundI > oldI) {
1758 // The new target is on top of the old one.
1759 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001760 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001761 }
1762 mUpperWallpaperTarget = foundW;
1763 mLowerWallpaperTarget = oldW;
1764 foundW = oldW;
1765 foundI = oldI;
1766 } else {
1767 // The new target is below the old one.
1768 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001769 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001770 }
1771 mUpperWallpaperTarget = oldW;
1772 mLowerWallpaperTarget = foundW;
1773 }
1774 }
1775 }
1776 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001777
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001778 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001779 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001780 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1781 || (mLowerWallpaperTarget.mAppToken != null
1782 && mLowerWallpaperTarget.mAppToken.animation != null);
1783 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1784 || (mUpperWallpaperTarget.mAppToken != null
1785 && mUpperWallpaperTarget.mAppToken.animation != null);
1786 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001787 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001788 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001789 }
1790 mLowerWallpaperTarget = null;
1791 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001792 }
1793 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001794
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001795 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001796 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001797 // The window is visible to the compositor... but is it visible
1798 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001799 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001800 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001801
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001802 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001803 // its layer adjustment. Only do this if we are not transfering
1804 // between two wallpaper targets.
1805 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001806 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001807 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001808
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001809 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1810 * TYPE_LAYER_MULTIPLIER
1811 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001812
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001813 // Now w is the window we are supposed to be behind... but we
1814 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001815 // AND any starting window associated with it, AND below the
1816 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001817 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001818 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001819 if (wb.mBaseLayer < maxLayer &&
1820 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001821 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001822 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001823 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001824 // This window is not related to the previous one in any
1825 // interesting way, so stop here.
1826 break;
1827 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001828 foundW = wb;
1829 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001830 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001831 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001832 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001833 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001834
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001835 if (foundW == null && topCurW != null) {
1836 // There is no wallpaper target, so it goes at the bottom.
1837 // We will assume it is the same place as last time, if known.
1838 foundW = topCurW;
1839 foundI = topCurI+1;
1840 } else {
1841 // Okay i is the position immediately above the wallpaper. Look at
1842 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001843 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001844 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001845
Dianne Hackborn284ac932009-08-28 10:34:25 -07001846 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001847 if (mWallpaperTarget.mWallpaperX >= 0) {
1848 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001849 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001850 }
1851 if (mWallpaperTarget.mWallpaperY >= 0) {
1852 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001853 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001854 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001855 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001856
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001857 // Start stepping backwards from here, ensuring that our wallpaper windows
1858 // are correctly placed.
1859 int curTokenIndex = mWallpaperTokens.size();
1860 while (curTokenIndex > 0) {
1861 curTokenIndex--;
1862 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001863 if (token.hidden == visible) {
1864 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1865 token.hidden = !visible;
1866 // Need to do a layout to ensure the wallpaper now has the
1867 // correct size.
1868 mLayoutNeeded = true;
1869 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001870
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001871 int curWallpaperIndex = token.windows.size();
1872 while (curWallpaperIndex > 0) {
1873 curWallpaperIndex--;
1874 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001875
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001876 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001877 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001878 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001879
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001880 // First, make sure the client has the current visibility
1881 // state.
1882 if (wallpaper.mWallpaperVisible != visible) {
1883 wallpaper.mWallpaperVisible = visible;
1884 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001885 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001886 "Setting visibility of wallpaper " + wallpaper
1887 + ": " + visible);
1888 wallpaper.mClient.dispatchAppVisibility(visible);
1889 } catch (RemoteException e) {
1890 }
1891 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001892
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001893 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001894 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001895 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001896
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001897 // First, if this window is at the current index, then all
1898 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001899 if (wallpaper == foundW) {
1900 foundI--;
1901 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001902 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001903 continue;
1904 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001905
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001906 // The window didn't match... the current wallpaper window,
1907 // wherever it is, is in the wrong place, so make sure it is
1908 // not in the list.
1909 int oldIndex = localmWindows.indexOf(wallpaper);
1910 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001911 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001912 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001913 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001914 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001915 if (oldIndex < foundI) {
1916 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001917 }
1918 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001919
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001920 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001921 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001922 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001923 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001924
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001925 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001926 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001927 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001928 }
1929 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001930
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001931 return changed;
1932 }
1933
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001934 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001935 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001936 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001937 mWallpaperAnimLayerAdjustment = adj;
1938 int curTokenIndex = mWallpaperTokens.size();
1939 while (curTokenIndex > 0) {
1940 curTokenIndex--;
1941 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1942 int curWallpaperIndex = token.windows.size();
1943 while (curWallpaperIndex > 0) {
1944 curWallpaperIndex--;
1945 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1946 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001947 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001948 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001949 }
1950 }
1951 }
1952
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001953 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1954 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001955 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001956 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001957 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001958 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001959 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1960 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1961 changed = wallpaperWin.mXOffset != offset;
1962 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001963 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001964 + wallpaperWin + " x: " + offset);
1965 wallpaperWin.mXOffset = offset;
1966 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001967 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001968 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001969 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001970 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001971 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001972
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001973 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001974 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001975 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1976 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1977 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001978 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001979 + wallpaperWin + " y: " + offset);
1980 changed = true;
1981 wallpaperWin.mYOffset = offset;
1982 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001983 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001984 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001985 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001986 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001987 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001988
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001989 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001990 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001991 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001992 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1993 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001994 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001995 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001996 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001997 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001998 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1999 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002000 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002001 if (mWaitingOnWallpaper != null) {
2002 long start = SystemClock.uptimeMillis();
2003 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2004 < start) {
2005 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002006 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002007 "Waiting for offset complete...");
2008 mWindowMap.wait(WALLPAPER_TIMEOUT);
2009 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002010 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002011 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002012 if ((start+WALLPAPER_TIMEOUT)
2013 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002014 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002015 + wallpaperWin);
2016 mLastWallpaperTimeoutTime = start;
2017 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002018 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002019 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002020 }
2021 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002022 } catch (RemoteException e) {
2023 }
2024 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002025
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002026 return changed;
2027 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002028
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002029 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002030 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002031 if (mWaitingOnWallpaper != null &&
2032 mWaitingOnWallpaper.mClient.asBinder() == window) {
2033 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002034 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002035 }
2036 }
2037 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002038
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002039 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002040 final int dw = mDisplay.getWidth();
2041 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002042
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002043 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002044
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002045 WindowState target = mWallpaperTarget;
2046 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002047 if (target.mWallpaperX >= 0) {
2048 mLastWallpaperX = target.mWallpaperX;
2049 } else if (changingTarget.mWallpaperX >= 0) {
2050 mLastWallpaperX = changingTarget.mWallpaperX;
2051 }
2052 if (target.mWallpaperY >= 0) {
2053 mLastWallpaperY = target.mWallpaperY;
2054 } else if (changingTarget.mWallpaperY >= 0) {
2055 mLastWallpaperY = changingTarget.mWallpaperY;
2056 }
2057 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002058
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002059 int curTokenIndex = mWallpaperTokens.size();
2060 while (curTokenIndex > 0) {
2061 curTokenIndex--;
2062 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2063 int curWallpaperIndex = token.windows.size();
2064 while (curWallpaperIndex > 0) {
2065 curWallpaperIndex--;
2066 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2067 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2068 wallpaper.computeShownFrameLocked();
2069 changed = true;
2070 // We only want to be synchronous with one wallpaper.
2071 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002072 }
2073 }
2074 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002075
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002076 return changed;
2077 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002078
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002079 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002080 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002081 final int dw = mDisplay.getWidth();
2082 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002083
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002084 int curTokenIndex = mWallpaperTokens.size();
2085 while (curTokenIndex > 0) {
2086 curTokenIndex--;
2087 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002088 if (token.hidden == visible) {
2089 token.hidden = !visible;
2090 // Need to do a layout to ensure the wallpaper now has the
2091 // correct size.
2092 mLayoutNeeded = true;
2093 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002094
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002095 int curWallpaperIndex = token.windows.size();
2096 while (curWallpaperIndex > 0) {
2097 curWallpaperIndex--;
2098 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2099 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002100 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002101 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002102
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002103 if (wallpaper.mWallpaperVisible != visible) {
2104 wallpaper.mWallpaperVisible = visible;
2105 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002106 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002107 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002108 + ": " + visible);
2109 wallpaper.mClient.dispatchAppVisibility(visible);
2110 } catch (RemoteException e) {
2111 }
2112 }
2113 }
2114 }
2115 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002117 public int addWindow(Session session, IWindow client,
2118 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002119 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002120 int res = mPolicy.checkAddPermission(attrs);
2121 if (res != WindowManagerImpl.ADD_OKAY) {
2122 return res;
2123 }
Romain Guy06882f82009-06-10 13:36:04 -07002124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002125 boolean reportNewConfig = false;
2126 WindowState attachedWindow = null;
2127 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002128 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002130 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002131 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002132 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002133 }
Romain Guy06882f82009-06-10 13:36:04 -07002134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002135 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002136 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002137 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2138 }
2139
2140 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002141 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002142 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002143 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002144 + attrs.token + ". Aborting.");
2145 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2146 }
2147 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2148 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002149 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002150 + attrs.token + ". Aborting.");
2151 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2152 }
2153 }
2154
2155 boolean addToken = false;
2156 WindowToken token = mTokenMap.get(attrs.token);
2157 if (token == null) {
2158 if (attrs.type >= FIRST_APPLICATION_WINDOW
2159 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002160 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002161 + attrs.token + ". Aborting.");
2162 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2163 }
2164 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002165 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002166 + attrs.token + ". Aborting.");
2167 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2168 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002169 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002170 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002171 + attrs.token + ". Aborting.");
2172 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2173 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002174 token = new WindowToken(attrs.token, -1, false);
2175 addToken = true;
2176 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2177 && attrs.type <= LAST_APPLICATION_WINDOW) {
2178 AppWindowToken atoken = token.appWindowToken;
2179 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002180 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002181 + token + ". Aborting.");
2182 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2183 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002184 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002185 + token + ". Aborting.");
2186 return WindowManagerImpl.ADD_APP_EXITING;
2187 }
2188 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2189 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002190 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002191 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2192 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2193 }
2194 } else if (attrs.type == TYPE_INPUT_METHOD) {
2195 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002196 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002197 + attrs.token + ". Aborting.");
2198 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2199 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002200 } else if (attrs.type == TYPE_WALLPAPER) {
2201 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002202 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002203 + attrs.token + ". Aborting.");
2204 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2205 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002206 }
2207
2208 win = new WindowState(session, client, token,
2209 attachedWindow, attrs, viewVisibility);
2210 if (win.mDeathRecipient == null) {
2211 // Client has apparently died, so there is no reason to
2212 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002213 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002214 + " that is dead, aborting.");
2215 return WindowManagerImpl.ADD_APP_EXITING;
2216 }
2217
2218 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002220 res = mPolicy.prepareAddWindowLw(win, attrs);
2221 if (res != WindowManagerImpl.ADD_OKAY) {
2222 return res;
2223 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002224
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002225 if (outInputChannel != null) {
2226 String name = win.makeInputChannelName();
2227 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2228 win.mInputChannel = inputChannels[0];
2229 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2230
2231 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002232 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002233
2234 // From now on, no exceptions or errors allowed!
2235
2236 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002237
Dianne Hackborn5132b372010-07-29 12:51:35 -07002238 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002239
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002240 if (addToken) {
2241 mTokenMap.put(attrs.token, token);
2242 mTokenList.add(token);
2243 }
2244 win.attach();
2245 mWindowMap.put(client.asBinder(), win);
2246
2247 if (attrs.type == TYPE_APPLICATION_STARTING &&
2248 token.appWindowToken != null) {
2249 token.appWindowToken.startingWindow = win;
2250 }
2251
2252 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002254 if (attrs.type == TYPE_INPUT_METHOD) {
2255 mInputMethodWindow = win;
2256 addInputMethodWindowToListLocked(win);
2257 imMayMove = false;
2258 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2259 mInputMethodDialogs.add(win);
2260 addWindowToListInOrderLocked(win, true);
2261 adjustInputMethodDialogsLocked();
2262 imMayMove = false;
2263 } else {
2264 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002265 if (attrs.type == TYPE_WALLPAPER) {
2266 mLastWallpaperTimeoutTime = 0;
2267 adjustWallpaperWindowsLocked();
2268 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002269 adjustWallpaperWindowsLocked();
2270 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002271 }
Romain Guy06882f82009-06-10 13:36:04 -07002272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002273 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002275 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002277 if (mInTouchMode) {
2278 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2279 }
2280 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2281 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2282 }
Romain Guy06882f82009-06-10 13:36:04 -07002283
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002284 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002285 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07002286 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
2287 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002288 imMayMove = false;
2289 }
2290 }
Romain Guy06882f82009-06-10 13:36:04 -07002291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002292 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002293 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002294 }
Romain Guy06882f82009-06-10 13:36:04 -07002295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002296 assignLayersLocked();
2297 // Don't do layout here, the window must call
2298 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002300 //dump();
2301
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002302 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07002303 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002304 }
Jeff Brown349703e2010-06-22 01:27:15 -07002305
Joe Onorato8a9b2202010-02-26 18:56:32 -08002306 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002307 TAG, "New client " + client.asBinder()
2308 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002309
2310 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2311 reportNewConfig = true;
2312 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002313 }
2314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002315 if (reportNewConfig) {
2316 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002317 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002319 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002321 return res;
2322 }
Romain Guy06882f82009-06-10 13:36:04 -07002323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002324 public void removeWindow(Session session, IWindow client) {
2325 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002326 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002327 if (win == null) {
2328 return;
2329 }
2330 removeWindowLocked(session, win);
2331 }
2332 }
Romain Guy06882f82009-06-10 13:36:04 -07002333
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002334 public void removeWindowLocked(Session session, WindowState win) {
2335
Joe Onorato8a9b2202010-02-26 18:56:32 -08002336 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002337 TAG, "Remove " + win + " client="
2338 + Integer.toHexString(System.identityHashCode(
2339 win.mClient.asBinder()))
2340 + ", surface=" + win.mSurface);
2341
2342 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002343
2344 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002345
Joe Onorato8a9b2202010-02-26 18:56:32 -08002346 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002347 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2348 + " mExiting=" + win.mExiting
2349 + " isAnimating=" + win.isAnimating()
2350 + " app-animation="
2351 + (win.mAppToken != null ? win.mAppToken.animation : null)
2352 + " inPendingTransaction="
2353 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2354 + " mDisplayFrozen=" + mDisplayFrozen);
2355 // Visibility of the removed window. Will be used later to update orientation later on.
2356 boolean wasVisible = false;
2357 // First, see if we need to run an animation. If we do, we have
2358 // to hold off on removing the window until the animation is done.
2359 // If the display is frozen, just remove immediately, since the
2360 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002361 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002362 // If we are not currently running the exit animation, we
2363 // need to see about starting one.
2364 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002366 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2367 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2368 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2369 }
2370 // Try starting an animation.
2371 if (applyAnimationLocked(win, transit, false)) {
2372 win.mExiting = true;
2373 }
2374 }
2375 if (win.mExiting || win.isAnimating()) {
2376 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002377 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002378 win.mExiting = true;
2379 win.mRemoveOnExit = true;
2380 mLayoutNeeded = true;
2381 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2382 performLayoutAndPlaceSurfacesLocked();
2383 if (win.mAppToken != null) {
2384 win.mAppToken.updateReportedVisibilityLocked();
2385 }
2386 //dump();
2387 Binder.restoreCallingIdentity(origId);
2388 return;
2389 }
2390 }
2391
2392 removeWindowInnerLocked(session, win);
2393 // Removing a visible window will effect the computed orientation
2394 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002395 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002396 != mForcedAppOrientation
2397 && updateOrientationFromAppTokensLocked()) {
2398 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002399 }
2400 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2401 Binder.restoreCallingIdentity(origId);
2402 }
Romain Guy06882f82009-06-10 13:36:04 -07002403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002404 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002405 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002407 if (mInputMethodTarget == win) {
2408 moveInputMethodWindowsIfNeededLocked(false);
2409 }
Romain Guy06882f82009-06-10 13:36:04 -07002410
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002411 if (false) {
2412 RuntimeException e = new RuntimeException("here");
2413 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002414 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002415 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002417 mPolicy.removeWindowLw(win);
2418 win.removeLocked();
2419
2420 mWindowMap.remove(win.mClient.asBinder());
2421 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002422 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002423 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002424
2425 if (mInputMethodWindow == win) {
2426 mInputMethodWindow = null;
2427 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2428 mInputMethodDialogs.remove(win);
2429 }
Romain Guy06882f82009-06-10 13:36:04 -07002430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002431 final WindowToken token = win.mToken;
2432 final AppWindowToken atoken = win.mAppToken;
2433 token.windows.remove(win);
2434 if (atoken != null) {
2435 atoken.allAppWindows.remove(win);
2436 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002437 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002438 TAG, "**** Removing window " + win + ": count="
2439 + token.windows.size());
2440 if (token.windows.size() == 0) {
2441 if (!token.explicit) {
2442 mTokenMap.remove(token.token);
2443 mTokenList.remove(token);
2444 } else if (atoken != null) {
2445 atoken.firstWindowDrawn = false;
2446 }
2447 }
2448
2449 if (atoken != null) {
2450 if (atoken.startingWindow == win) {
2451 atoken.startingWindow = null;
2452 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2453 // If this is the last window and we had requested a starting
2454 // transition window, well there is no point now.
2455 atoken.startingData = null;
2456 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2457 // If this is the last window except for a starting transition
2458 // window, we need to get rid of the starting transition.
2459 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002460 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002461 + ": no more real windows");
2462 }
2463 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2464 mH.sendMessage(m);
2465 }
2466 }
Romain Guy06882f82009-06-10 13:36:04 -07002467
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002468 if (win.mAttrs.type == TYPE_WALLPAPER) {
2469 mLastWallpaperTimeoutTime = 0;
2470 adjustWallpaperWindowsLocked();
2471 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002472 adjustWallpaperWindowsLocked();
2473 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002475 if (!mInLayout) {
2476 assignLayersLocked();
2477 mLayoutNeeded = true;
2478 performLayoutAndPlaceSurfacesLocked();
2479 if (win.mAppToken != null) {
2480 win.mAppToken.updateReportedVisibilityLocked();
2481 }
2482 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002483
2484 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002485 }
2486
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002487 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2488 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2489 + ": " + msg + " / " + w.mAttrs.getTitle();
2490 if (where != null) {
2491 Slog.i(TAG, str, where);
2492 } else {
2493 Slog.i(TAG, str);
2494 }
2495 }
2496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002497 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2498 long origId = Binder.clearCallingIdentity();
2499 try {
2500 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002501 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002502 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002503 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002504 Surface.openTransaction();
2505 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002506 if (SHOW_TRANSACTIONS) logSurface(w,
2507 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002508 w.mSurface.setTransparentRegionHint(region);
2509 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002510 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002511 Surface.closeTransaction();
2512 }
2513 }
2514 }
2515 } finally {
2516 Binder.restoreCallingIdentity(origId);
2517 }
2518 }
2519
2520 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002521 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002522 Rect visibleInsets) {
2523 long origId = Binder.clearCallingIdentity();
2524 try {
2525 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002526 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002527 if (w != null) {
2528 w.mGivenInsetsPending = false;
2529 w.mGivenContentInsets.set(contentInsets);
2530 w.mGivenVisibleInsets.set(visibleInsets);
2531 w.mTouchableInsets = touchableInsets;
2532 mLayoutNeeded = true;
2533 performLayoutAndPlaceSurfacesLocked();
2534 }
2535 }
2536 } finally {
2537 Binder.restoreCallingIdentity(origId);
2538 }
2539 }
Romain Guy06882f82009-06-10 13:36:04 -07002540
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002541 public void getWindowDisplayFrame(Session session, IWindow client,
2542 Rect outDisplayFrame) {
2543 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002544 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002545 if (win == null) {
2546 outDisplayFrame.setEmpty();
2547 return;
2548 }
2549 outDisplayFrame.set(win.mDisplayFrame);
2550 }
2551 }
2552
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002553 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2554 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002555 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2556 window.mWallpaperX = x;
2557 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002558 window.mWallpaperXStep = xStep;
2559 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002560 if (updateWallpaperOffsetLocked(window, true)) {
2561 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002562 }
2563 }
2564 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002565
Dianne Hackborn75804932009-10-20 20:15:20 -07002566 void wallpaperCommandComplete(IBinder window, Bundle result) {
2567 synchronized (mWindowMap) {
2568 if (mWaitingOnWallpaper != null &&
2569 mWaitingOnWallpaper.mClient.asBinder() == window) {
2570 mWaitingOnWallpaper = null;
2571 mWindowMap.notifyAll();
2572 }
2573 }
2574 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002575
Dianne Hackborn75804932009-10-20 20:15:20 -07002576 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2577 String action, int x, int y, int z, Bundle extras, boolean sync) {
2578 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2579 || window == mUpperWallpaperTarget) {
2580 boolean doWait = sync;
2581 int curTokenIndex = mWallpaperTokens.size();
2582 while (curTokenIndex > 0) {
2583 curTokenIndex--;
2584 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2585 int curWallpaperIndex = token.windows.size();
2586 while (curWallpaperIndex > 0) {
2587 curWallpaperIndex--;
2588 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2589 try {
2590 wallpaper.mClient.dispatchWallpaperCommand(action,
2591 x, y, z, extras, sync);
2592 // We only want to be synchronous with one wallpaper.
2593 sync = false;
2594 } catch (RemoteException e) {
2595 }
2596 }
2597 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002598
Dianne Hackborn75804932009-10-20 20:15:20 -07002599 if (doWait) {
2600 // XXX Need to wait for result.
2601 }
2602 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002603
Dianne Hackborn75804932009-10-20 20:15:20 -07002604 return null;
2605 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002607 public int relayoutWindow(Session session, IWindow client,
2608 WindowManager.LayoutParams attrs, int requestedWidth,
2609 int requestedHeight, int viewVisibility, boolean insetsPending,
2610 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002611 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002612 boolean displayed = false;
2613 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002614 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002615 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002617 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002618 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002619 if (win == null) {
2620 return 0;
2621 }
2622 win.mRequestedWidth = requestedWidth;
2623 win.mRequestedHeight = requestedHeight;
2624
2625 if (attrs != null) {
2626 mPolicy.adjustWindowParamsLw(attrs);
2627 }
Romain Guy06882f82009-06-10 13:36:04 -07002628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002629 int attrChanges = 0;
2630 int flagChanges = 0;
2631 if (attrs != null) {
2632 flagChanges = win.mAttrs.flags ^= attrs.flags;
2633 attrChanges = win.mAttrs.copyFrom(attrs);
2634 }
2635
Joe Onorato8a9b2202010-02-26 18:56:32 -08002636 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002637
2638 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2639 win.mAlpha = attrs.alpha;
2640 }
2641
2642 final boolean scaledWindow =
2643 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2644
2645 if (scaledWindow) {
2646 // requested{Width|Height} Surface's physical size
2647 // attrs.{width|height} Size on screen
2648 win.mHScale = (attrs.width != requestedWidth) ?
2649 (attrs.width / (float)requestedWidth) : 1.0f;
2650 win.mVScale = (attrs.height != requestedHeight) ?
2651 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002652 } else {
2653 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002654 }
2655
2656 boolean imMayMove = (flagChanges&(
2657 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2658 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002660 boolean focusMayChange = win.mViewVisibility != viewVisibility
2661 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2662 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002663
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002664 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2665 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002667 win.mRelayoutCalled = true;
2668 final int oldVisibility = win.mViewVisibility;
2669 win.mViewVisibility = viewVisibility;
2670 if (viewVisibility == View.VISIBLE &&
2671 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2672 displayed = !win.isVisibleLw();
2673 if (win.mExiting) {
2674 win.mExiting = false;
2675 win.mAnimation = null;
2676 }
2677 if (win.mDestroying) {
2678 win.mDestroying = false;
2679 mDestroySurface.remove(win);
2680 }
2681 if (oldVisibility == View.GONE) {
2682 win.mEnterAnimationPending = true;
2683 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002684 if (displayed) {
2685 if (win.mSurface != null && !win.mDrawPending
2686 && !win.mCommitDrawPending && !mDisplayFrozen
2687 && mPolicy.isScreenOn()) {
2688 applyEnterAnimationLocked(win);
2689 }
2690 if ((win.mAttrs.flags
2691 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2692 if (DEBUG_VISIBILITY) Slog.v(TAG,
2693 "Relayout window turning screen on: " + win);
2694 win.mTurnOnScreen = true;
2695 }
2696 int diff = 0;
2697 if (win.mConfiguration != mCurConfiguration
2698 && (win.mConfiguration == null
2699 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2700 win.mConfiguration = mCurConfiguration;
2701 if (DEBUG_CONFIGURATION) {
2702 Slog.i(TAG, "Window " + win + " visible with new config: "
2703 + win.mConfiguration + " / 0x"
2704 + Integer.toHexString(diff));
2705 }
2706 outConfig.setTo(mCurConfiguration);
2707 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002708 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002709 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2710 // To change the format, we need to re-build the surface.
2711 win.destroySurfaceLocked();
2712 displayed = true;
2713 }
2714 try {
2715 Surface surface = win.createSurfaceLocked();
2716 if (surface != null) {
2717 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002718 win.mReportDestroySurface = false;
2719 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002720 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002721 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002722 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002723 // For some reason there isn't a surface. Clear the
2724 // caller's object so they see the same state.
2725 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002726 }
2727 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002728 mInputMonitor.updateInputWindowsLw();
2729
Joe Onorato8a9b2202010-02-26 18:56:32 -08002730 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002731 + client + " (" + win.mAttrs.getTitle() + ")",
2732 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002733 Binder.restoreCallingIdentity(origId);
2734 return 0;
2735 }
2736 if (displayed) {
2737 focusMayChange = true;
2738 }
2739 if (win.mAttrs.type == TYPE_INPUT_METHOD
2740 && mInputMethodWindow == null) {
2741 mInputMethodWindow = win;
2742 imMayMove = true;
2743 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002744 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2745 && win.mAppToken != null
2746 && win.mAppToken.startingWindow != null) {
2747 // Special handling of starting window over the base
2748 // window of the app: propagate lock screen flags to it,
2749 // to provide the correct semantics while starting.
2750 final int mask =
2751 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002752 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2753 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002754 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2755 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2756 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002757 } else {
2758 win.mEnterAnimationPending = false;
2759 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002760 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002761 + ": mExiting=" + win.mExiting
2762 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002763 // If we are not currently running the exit animation, we
2764 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002765 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002766 // Try starting an animation; if there isn't one, we
2767 // can destroy the surface right away.
2768 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2769 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2770 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2771 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002772 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002773 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002774 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002775 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002776 } else if (win.isAnimating()) {
2777 // Currently in a hide animation... turn this into
2778 // an exit.
2779 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002780 } else if (win == mWallpaperTarget) {
2781 // If the wallpaper is currently behind this
2782 // window, we need to change both of them inside
2783 // of a transaction to avoid artifacts.
2784 win.mExiting = true;
2785 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002786 } else {
2787 if (mInputMethodWindow == win) {
2788 mInputMethodWindow = null;
2789 }
2790 win.destroySurfaceLocked();
2791 }
2792 }
2793 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002794
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002795 if (win.mSurface == null || (win.getAttrs().flags
2796 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2797 || win.mSurfacePendingDestroy) {
2798 // We are being called from a local process, which
2799 // means outSurface holds its current surface. Ensure the
2800 // surface object is cleared, but we don't want it actually
2801 // destroyed at this point.
2802 win.mSurfacePendingDestroy = false;
2803 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002804 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002805 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002806 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002807 "Keeping surface, will report destroy: " + win);
2808 win.mReportDestroySurface = true;
2809 outSurface.copyFrom(win.mSurface);
2810 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002811 }
2812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002813 if (focusMayChange) {
2814 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2815 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002816 imMayMove = false;
2817 }
2818 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2819 }
Romain Guy06882f82009-06-10 13:36:04 -07002820
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002821 // updateFocusedWindowLocked() already assigned layers so we only need to
2822 // reassign them at this point if the IM window state gets shuffled
2823 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002825 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002826 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2827 // Little hack here -- we -should- be able to rely on the
2828 // function to return true if the IME has moved and needs
2829 // its layer recomputed. However, if the IME was hidden
2830 // and isn't actually moved in the list, its layer may be
2831 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002832 assignLayers = true;
2833 }
2834 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002835 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002836 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002837 assignLayers = true;
2838 }
2839 }
Romain Guy06882f82009-06-10 13:36:04 -07002840
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002841 mLayoutNeeded = true;
2842 win.mGivenInsetsPending = insetsPending;
2843 if (assignLayers) {
2844 assignLayersLocked();
2845 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002846 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002847 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002848 if (displayed && win.mIsWallpaper) {
2849 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002850 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002851 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852 if (win.mAppToken != null) {
2853 win.mAppToken.updateReportedVisibilityLocked();
2854 }
2855 outFrame.set(win.mFrame);
2856 outContentInsets.set(win.mContentInsets);
2857 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002858 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002859 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002860 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002861 + ", requestedHeight=" + requestedHeight
2862 + ", viewVisibility=" + viewVisibility
2863 + "\nRelayout returning frame=" + outFrame
2864 + ", surface=" + outSurface);
2865
Joe Onorato8a9b2202010-02-26 18:56:32 -08002866 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002867 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2868
2869 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002870
2871 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002872 }
2873
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002874 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002875 sendNewConfiguration();
2876 }
Romain Guy06882f82009-06-10 13:36:04 -07002877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002878 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002879
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002880 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2881 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2882 }
2883
2884 public void finishDrawingWindow(Session session, IWindow client) {
2885 final long origId = Binder.clearCallingIdentity();
2886 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002887 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002888 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002889 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2890 adjustWallpaperWindowsLocked();
2891 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002892 mLayoutNeeded = true;
2893 performLayoutAndPlaceSurfacesLocked();
2894 }
2895 }
2896 Binder.restoreCallingIdentity(origId);
2897 }
2898
2899 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002900 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002901 + (lp != null ? lp.packageName : null)
2902 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2903 if (lp != null && lp.windowAnimations != 0) {
2904 // If this is a system resource, don't try to load it from the
2905 // application resources. It is nice to avoid loading application
2906 // resources if we can.
2907 String packageName = lp.packageName != null ? lp.packageName : "android";
2908 int resId = lp.windowAnimations;
2909 if ((resId&0xFF000000) == 0x01000000) {
2910 packageName = "android";
2911 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002912 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002913 + packageName);
2914 return AttributeCache.instance().get(packageName, resId,
2915 com.android.internal.R.styleable.WindowAnimation);
2916 }
2917 return null;
2918 }
Romain Guy06882f82009-06-10 13:36:04 -07002919
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002920 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002921 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002922 + packageName + " resId=0x" + Integer.toHexString(resId));
2923 if (packageName != null) {
2924 if ((resId&0xFF000000) == 0x01000000) {
2925 packageName = "android";
2926 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002927 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002928 + packageName);
2929 return AttributeCache.instance().get(packageName, resId,
2930 com.android.internal.R.styleable.WindowAnimation);
2931 }
2932 return null;
2933 }
2934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002935 private void applyEnterAnimationLocked(WindowState win) {
2936 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2937 if (win.mEnterAnimationPending) {
2938 win.mEnterAnimationPending = false;
2939 transit = WindowManagerPolicy.TRANSIT_ENTER;
2940 }
2941
2942 applyAnimationLocked(win, transit, true);
2943 }
2944
2945 private boolean applyAnimationLocked(WindowState win,
2946 int transit, boolean isEntrance) {
2947 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2948 // If we are trying to apply an animation, but already running
2949 // an animation of the same type, then just leave that one alone.
2950 return true;
2951 }
Romain Guy06882f82009-06-10 13:36:04 -07002952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002953 // Only apply an animation if the display isn't frozen. If it is
2954 // frozen, there is no reason to animate and it can cause strange
2955 // artifacts when we unfreeze the display if some different animation
2956 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002957 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002958 int anim = mPolicy.selectAnimationLw(win, transit);
2959 int attr = -1;
2960 Animation a = null;
2961 if (anim != 0) {
2962 a = AnimationUtils.loadAnimation(mContext, anim);
2963 } else {
2964 switch (transit) {
2965 case WindowManagerPolicy.TRANSIT_ENTER:
2966 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2967 break;
2968 case WindowManagerPolicy.TRANSIT_EXIT:
2969 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2970 break;
2971 case WindowManagerPolicy.TRANSIT_SHOW:
2972 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2973 break;
2974 case WindowManagerPolicy.TRANSIT_HIDE:
2975 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2976 break;
2977 }
2978 if (attr >= 0) {
2979 a = loadAnimation(win.mAttrs, attr);
2980 }
2981 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002982 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002983 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2984 + " mAnimation=" + win.mAnimation
2985 + " isEntrance=" + isEntrance);
2986 if (a != null) {
2987 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002988 RuntimeException e = null;
2989 if (!HIDE_STACK_CRAWLS) {
2990 e = new RuntimeException();
2991 e.fillInStackTrace();
2992 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002993 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002994 }
2995 win.setAnimation(a);
2996 win.mAnimationIsEntrance = isEntrance;
2997 }
2998 } else {
2999 win.clearAnimation();
3000 }
3001
3002 return win.mAnimation != null;
3003 }
3004
3005 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3006 int anim = 0;
3007 Context context = mContext;
3008 if (animAttr >= 0) {
3009 AttributeCache.Entry ent = getCachedAnimations(lp);
3010 if (ent != null) {
3011 context = ent.context;
3012 anim = ent.array.getResourceId(animAttr, 0);
3013 }
3014 }
3015 if (anim != 0) {
3016 return AnimationUtils.loadAnimation(context, anim);
3017 }
3018 return null;
3019 }
Romain Guy06882f82009-06-10 13:36:04 -07003020
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003021 private Animation loadAnimation(String packageName, int resId) {
3022 int anim = 0;
3023 Context context = mContext;
3024 if (resId >= 0) {
3025 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3026 if (ent != null) {
3027 context = ent.context;
3028 anim = resId;
3029 }
3030 }
3031 if (anim != 0) {
3032 return AnimationUtils.loadAnimation(context, anim);
3033 }
3034 return null;
3035 }
3036
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003037 private boolean applyAnimationLocked(AppWindowToken wtoken,
3038 WindowManager.LayoutParams lp, int transit, boolean enter) {
3039 // Only apply an animation if the display isn't frozen. If it is
3040 // frozen, there is no reason to animate and it can cause strange
3041 // artifacts when we unfreeze the display if some different animation
3042 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003043 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003044 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003045 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003046 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003047 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003048 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003049 } else if (mNextAppTransitionPackage != null) {
3050 a = loadAnimation(mNextAppTransitionPackage, enter ?
3051 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003052 } else {
3053 int animAttr = 0;
3054 switch (transit) {
3055 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3056 animAttr = enter
3057 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3058 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3059 break;
3060 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3061 animAttr = enter
3062 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3063 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3064 break;
3065 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3066 animAttr = enter
3067 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3068 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3069 break;
3070 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3071 animAttr = enter
3072 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3073 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3074 break;
3075 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3076 animAttr = enter
3077 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3078 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3079 break;
3080 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3081 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003082 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003083 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3084 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003085 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003086 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003087 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3088 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003089 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003090 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003091 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003092 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3093 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3094 break;
3095 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3096 animAttr = enter
3097 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3098 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3099 break;
3100 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3101 animAttr = enter
3102 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3103 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003104 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003105 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003106 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003107 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003108 + " anim=" + a
3109 + " animAttr=0x" + Integer.toHexString(animAttr)
3110 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003111 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003112 if (a != null) {
3113 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003114 RuntimeException e = null;
3115 if (!HIDE_STACK_CRAWLS) {
3116 e = new RuntimeException();
3117 e.fillInStackTrace();
3118 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003119 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003120 }
3121 wtoken.setAnimation(a);
3122 }
3123 } else {
3124 wtoken.clearAnimation();
3125 }
3126
3127 return wtoken.animation != null;
3128 }
3129
3130 // -------------------------------------------------------------
3131 // Application Window Tokens
3132 // -------------------------------------------------------------
3133
3134 public void validateAppTokens(List tokens) {
3135 int v = tokens.size()-1;
3136 int m = mAppTokens.size()-1;
3137 while (v >= 0 && m >= 0) {
3138 AppWindowToken wtoken = mAppTokens.get(m);
3139 if (wtoken.removed) {
3140 m--;
3141 continue;
3142 }
3143 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003144 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003145 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3146 }
3147 v--;
3148 m--;
3149 }
3150 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003151 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003152 v--;
3153 }
3154 while (m >= 0) {
3155 AppWindowToken wtoken = mAppTokens.get(m);
3156 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003157 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003158 }
3159 m--;
3160 }
3161 }
3162
3163 boolean checkCallingPermission(String permission, String func) {
3164 // Quick check: if the calling permission is me, it's all okay.
3165 if (Binder.getCallingPid() == Process.myPid()) {
3166 return true;
3167 }
Romain Guy06882f82009-06-10 13:36:04 -07003168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003169 if (mContext.checkCallingPermission(permission)
3170 == PackageManager.PERMISSION_GRANTED) {
3171 return true;
3172 }
3173 String msg = "Permission Denial: " + func + " from pid="
3174 + Binder.getCallingPid()
3175 + ", uid=" + Binder.getCallingUid()
3176 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003177 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003178 return false;
3179 }
Romain Guy06882f82009-06-10 13:36:04 -07003180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003181 AppWindowToken findAppWindowToken(IBinder token) {
3182 WindowToken wtoken = mTokenMap.get(token);
3183 if (wtoken == null) {
3184 return null;
3185 }
3186 return wtoken.appWindowToken;
3187 }
Romain Guy06882f82009-06-10 13:36:04 -07003188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003189 public void addWindowToken(IBinder token, int type) {
3190 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3191 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003192 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003193 }
Romain Guy06882f82009-06-10 13:36:04 -07003194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003195 synchronized(mWindowMap) {
3196 WindowToken wtoken = mTokenMap.get(token);
3197 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003198 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003199 return;
3200 }
3201 wtoken = new WindowToken(token, type, true);
3202 mTokenMap.put(token, wtoken);
3203 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003204 if (type == TYPE_WALLPAPER) {
3205 mWallpaperTokens.add(wtoken);
3206 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003207 }
3208 }
Romain Guy06882f82009-06-10 13:36:04 -07003209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003210 public void removeWindowToken(IBinder token) {
3211 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3212 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003213 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003214 }
3215
3216 final long origId = Binder.clearCallingIdentity();
3217 synchronized(mWindowMap) {
3218 WindowToken wtoken = mTokenMap.remove(token);
3219 mTokenList.remove(wtoken);
3220 if (wtoken != null) {
3221 boolean delayed = false;
3222 if (!wtoken.hidden) {
3223 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003225 final int N = wtoken.windows.size();
3226 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003228 for (int i=0; i<N; i++) {
3229 WindowState win = wtoken.windows.get(i);
3230
3231 if (win.isAnimating()) {
3232 delayed = true;
3233 }
Romain Guy06882f82009-06-10 13:36:04 -07003234
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003235 if (win.isVisibleNow()) {
3236 applyAnimationLocked(win,
3237 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003238 changed = true;
3239 }
3240 }
3241
3242 if (changed) {
3243 mLayoutNeeded = true;
3244 performLayoutAndPlaceSurfacesLocked();
3245 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3246 }
Romain Guy06882f82009-06-10 13:36:04 -07003247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003248 if (delayed) {
3249 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003250 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3251 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003252 }
3253 }
Romain Guy06882f82009-06-10 13:36:04 -07003254
Jeff Brownc5ed5912010-07-14 18:48:53 -07003255 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003256 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003257 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003258 }
3259 }
3260 Binder.restoreCallingIdentity(origId);
3261 }
3262
3263 public void addAppToken(int addPos, IApplicationToken token,
3264 int groupId, int requestedOrientation, boolean fullscreen) {
3265 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3266 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003267 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003268 }
Jeff Brown349703e2010-06-22 01:27:15 -07003269
3270 // Get the dispatching timeout here while we are not holding any locks so that it
3271 // can be cached by the AppWindowToken. The timeout value is used later by the
3272 // input dispatcher in code that does hold locks. If we did not cache the value
3273 // here we would run the chance of introducing a deadlock between the window manager
3274 // (which holds locks while updating the input dispatcher state) and the activity manager
3275 // (which holds locks while querying the application token).
3276 long inputDispatchingTimeoutNanos;
3277 try {
3278 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3279 } catch (RemoteException ex) {
3280 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3281 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3282 }
Romain Guy06882f82009-06-10 13:36:04 -07003283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003284 synchronized(mWindowMap) {
3285 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3286 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003287 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003288 return;
3289 }
3290 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003291 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003292 wtoken.groupId = groupId;
3293 wtoken.appFullscreen = fullscreen;
3294 wtoken.requestedOrientation = requestedOrientation;
3295 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003296 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003297 mTokenMap.put(token.asBinder(), wtoken);
3298 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003300 // Application tokens start out hidden.
3301 wtoken.hidden = true;
3302 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003304 //dump();
3305 }
3306 }
Romain Guy06882f82009-06-10 13:36:04 -07003307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003308 public void setAppGroupId(IBinder token, int groupId) {
3309 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3310 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003311 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003312 }
3313
3314 synchronized(mWindowMap) {
3315 AppWindowToken wtoken = findAppWindowToken(token);
3316 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003317 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003318 return;
3319 }
3320 wtoken.groupId = groupId;
3321 }
3322 }
Romain Guy06882f82009-06-10 13:36:04 -07003323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003324 public int getOrientationFromWindowsLocked() {
3325 int pos = mWindows.size() - 1;
3326 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003327 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003328 pos--;
3329 if (wtoken.mAppToken != null) {
3330 // We hit an application window. so the orientation will be determined by the
3331 // app window. No point in continuing further.
3332 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3333 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003334 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003335 continue;
3336 }
3337 int req = wtoken.mAttrs.screenOrientation;
3338 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3339 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3340 continue;
3341 } else {
3342 return req;
3343 }
3344 }
3345 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3346 }
Romain Guy06882f82009-06-10 13:36:04 -07003347
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003348 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003349 int pos = mAppTokens.size() - 1;
3350 int curGroup = 0;
3351 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3352 boolean findingBehind = false;
3353 boolean haveGroup = false;
3354 boolean lastFullscreen = false;
3355 while (pos >= 0) {
3356 AppWindowToken wtoken = mAppTokens.get(pos);
3357 pos--;
3358 // if we're about to tear down this window and not seek for
3359 // the behind activity, don't use it for orientation
3360 if (!findingBehind
3361 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3362 continue;
3363 }
3364
3365 if (!haveGroup) {
3366 // We ignore any hidden applications on the top.
3367 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003368 continue;
3369 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003370 haveGroup = true;
3371 curGroup = wtoken.groupId;
3372 lastOrientation = wtoken.requestedOrientation;
3373 } else if (curGroup != wtoken.groupId) {
3374 // If we have hit a new application group, and the bottom
3375 // of the previous group didn't explicitly say to use
3376 // the orientation behind it, and the last app was
3377 // full screen, then we'll stick with the
3378 // user's orientation.
3379 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3380 && lastFullscreen) {
3381 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003382 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003383 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003384 int or = wtoken.requestedOrientation;
3385 // If this application is fullscreen, and didn't explicitly say
3386 // to use the orientation behind it, then just take whatever
3387 // orientation it has and ignores whatever is under it.
3388 lastFullscreen = wtoken.appFullscreen;
3389 if (lastFullscreen
3390 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3391 return or;
3392 }
3393 // If this application has requested an explicit orientation,
3394 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003395 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3396 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003397 return or;
3398 }
3399 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3400 }
3401 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003402 }
Romain Guy06882f82009-06-10 13:36:04 -07003403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003404 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003405 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003406 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3407 "updateOrientationFromAppTokens()")) {
3408 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3409 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003410
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003411 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003412 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003413
3414 synchronized(mWindowMap) {
3415 if (updateOrientationFromAppTokensLocked()) {
3416 if (freezeThisOneIfNeeded != null) {
3417 AppWindowToken wtoken = findAppWindowToken(
3418 freezeThisOneIfNeeded);
3419 if (wtoken != null) {
3420 startAppFreezingScreenLocked(wtoken,
3421 ActivityInfo.CONFIG_ORIENTATION);
3422 }
3423 }
3424 config = computeNewConfigurationLocked();
3425
3426 } else if (currentConfig != null) {
3427 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003428 // state mismatches the activity manager's, update it,
3429 // disregarding font scale, which should remain set to
3430 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003431 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003432 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003433 if (computeNewConfigurationLocked(mTempConfiguration)) {
3434 if (currentConfig.diff(mTempConfiguration) != 0) {
3435 mWaitingForConfig = true;
3436 mLayoutNeeded = true;
3437 startFreezingDisplayLocked();
3438 config = new Configuration(mTempConfiguration);
3439 }
3440 }
3441 }
3442 }
3443
Dianne Hackborncfaef692009-06-15 14:24:44 -07003444 Binder.restoreCallingIdentity(ident);
3445 return config;
3446 }
3447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003448 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003449 * Determine the new desired orientation of the display, returning
3450 * a non-null new Configuration if it has changed from the current
3451 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3452 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3453 * SCREEN. This will typically be done for you if you call
3454 * sendNewConfiguration().
3455 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003456 * The orientation is computed from non-application windows first. If none of
3457 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003458 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003459 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3460 * android.os.IBinder)
3461 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003462 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003463 if (mDisplayFrozen) {
3464 // If the display is frozen, some activities may be in the middle
3465 // of restarting, and thus have removed their old window. If the
3466 // window has the flag to hide the lock screen, then the lock screen
3467 // can re-appear and inflict its own orientation on us. Keep the
3468 // orientation stable until this all settles down.
3469 return false;
3470 }
3471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003472 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003473 long ident = Binder.clearCallingIdentity();
3474 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003475 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003477 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003478 mForcedAppOrientation = req;
3479 //send a message to Policy indicating orientation change to take
3480 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003481 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003482 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3483 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3484 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003485 }
3486 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003487
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003488 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003489 } finally {
3490 Binder.restoreCallingIdentity(ident);
3491 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003492 }
Romain Guy06882f82009-06-10 13:36:04 -07003493
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003494 int computeForcedAppOrientationLocked() {
3495 int req = getOrientationFromWindowsLocked();
3496 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3497 req = getOrientationFromAppTokensLocked();
3498 }
3499 return req;
3500 }
Romain Guy06882f82009-06-10 13:36:04 -07003501
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003502 public void setNewConfiguration(Configuration config) {
3503 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3504 "setNewConfiguration()")) {
3505 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3506 }
3507
3508 synchronized(mWindowMap) {
3509 mCurConfiguration = new Configuration(config);
3510 mWaitingForConfig = false;
3511 performLayoutAndPlaceSurfacesLocked();
3512 }
3513 }
3514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003515 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3516 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3517 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003518 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003519 }
Romain Guy06882f82009-06-10 13:36:04 -07003520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003521 synchronized(mWindowMap) {
3522 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3523 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003524 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003525 return;
3526 }
Romain Guy06882f82009-06-10 13:36:04 -07003527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003528 wtoken.requestedOrientation = requestedOrientation;
3529 }
3530 }
Romain Guy06882f82009-06-10 13:36:04 -07003531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003532 public int getAppOrientation(IApplicationToken token) {
3533 synchronized(mWindowMap) {
3534 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3535 if (wtoken == null) {
3536 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3537 }
Romain Guy06882f82009-06-10 13:36:04 -07003538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003539 return wtoken.requestedOrientation;
3540 }
3541 }
Romain Guy06882f82009-06-10 13:36:04 -07003542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003543 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3544 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3545 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003546 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003547 }
3548
3549 synchronized(mWindowMap) {
3550 boolean changed = false;
3551 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003552 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003553 changed = mFocusedApp != null;
3554 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003555 if (changed) {
3556 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003557 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003558 } else {
3559 AppWindowToken newFocus = findAppWindowToken(token);
3560 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003561 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003562 return;
3563 }
3564 changed = mFocusedApp != newFocus;
3565 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003566 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003567 if (changed) {
3568 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003569 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003570 }
3571
3572 if (moveFocusNow && changed) {
3573 final long origId = Binder.clearCallingIdentity();
3574 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3575 Binder.restoreCallingIdentity(origId);
3576 }
3577 }
3578 }
3579
3580 public void prepareAppTransition(int transit) {
3581 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3582 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003583 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003584 }
Romain Guy06882f82009-06-10 13:36:04 -07003585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003586 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003587 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003588 TAG, "Prepare app transition: transit=" + transit
3589 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003590 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003591 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3592 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003593 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003594 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3595 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3596 // Opening a new task always supersedes a close for the anim.
3597 mNextAppTransition = transit;
3598 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3599 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3600 // Opening a new activity always supersedes a close for the anim.
3601 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003602 }
3603 mAppTransitionReady = false;
3604 mAppTransitionTimeout = false;
3605 mStartingIconInTransition = false;
3606 mSkipAppTransitionAnimation = false;
3607 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3608 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3609 5000);
3610 }
3611 }
3612 }
3613
3614 public int getPendingAppTransition() {
3615 return mNextAppTransition;
3616 }
Romain Guy06882f82009-06-10 13:36:04 -07003617
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003618 public void overridePendingAppTransition(String packageName,
3619 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003620 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003621 mNextAppTransitionPackage = packageName;
3622 mNextAppTransitionEnter = enterAnim;
3623 mNextAppTransitionExit = exitAnim;
3624 }
3625 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003627 public void executeAppTransition() {
3628 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3629 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003630 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003631 }
Romain Guy06882f82009-06-10 13:36:04 -07003632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003633 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003634 if (DEBUG_APP_TRANSITIONS) {
3635 RuntimeException e = new RuntimeException("here");
3636 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003637 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003638 + mNextAppTransition, e);
3639 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003640 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003641 mAppTransitionReady = true;
3642 final long origId = Binder.clearCallingIdentity();
3643 performLayoutAndPlaceSurfacesLocked();
3644 Binder.restoreCallingIdentity(origId);
3645 }
3646 }
3647 }
3648
3649 public void setAppStartingWindow(IBinder token, String pkg,
3650 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3651 IBinder transferFrom, boolean createIfNeeded) {
3652 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3653 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003654 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003655 }
3656
3657 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003658 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003659 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3660 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003662 AppWindowToken wtoken = findAppWindowToken(token);
3663 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003664 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003665 return;
3666 }
3667
3668 // If the display is frozen, we won't do anything until the
3669 // actual window is displayed so there is no reason to put in
3670 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003671 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003672 return;
3673 }
Romain Guy06882f82009-06-10 13:36:04 -07003674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003675 if (wtoken.startingData != null) {
3676 return;
3677 }
Romain Guy06882f82009-06-10 13:36:04 -07003678
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003679 if (transferFrom != null) {
3680 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3681 if (ttoken != null) {
3682 WindowState startingWindow = ttoken.startingWindow;
3683 if (startingWindow != null) {
3684 if (mStartingIconInTransition) {
3685 // In this case, the starting icon has already
3686 // been displayed, so start letting windows get
3687 // shown immediately without any more transitions.
3688 mSkipAppTransitionAnimation = true;
3689 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003690 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003691 "Moving existing starting from " + ttoken
3692 + " to " + wtoken);
3693 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003695 // Transfer the starting window over to the new
3696 // token.
3697 wtoken.startingData = ttoken.startingData;
3698 wtoken.startingView = ttoken.startingView;
3699 wtoken.startingWindow = startingWindow;
3700 ttoken.startingData = null;
3701 ttoken.startingView = null;
3702 ttoken.startingWindow = null;
3703 ttoken.startingMoved = true;
3704 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003705 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003706 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003707 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003708 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003709 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003710 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003711 ttoken.windows.remove(startingWindow);
3712 ttoken.allAppWindows.remove(startingWindow);
3713 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003715 // Propagate other interesting state between the
3716 // tokens. If the old token is displayed, we should
3717 // immediately force the new one to be displayed. If
3718 // it is animating, we need to move that animation to
3719 // the new one.
3720 if (ttoken.allDrawn) {
3721 wtoken.allDrawn = true;
3722 }
3723 if (ttoken.firstWindowDrawn) {
3724 wtoken.firstWindowDrawn = true;
3725 }
3726 if (!ttoken.hidden) {
3727 wtoken.hidden = false;
3728 wtoken.hiddenRequested = false;
3729 wtoken.willBeHidden = false;
3730 }
3731 if (wtoken.clientHidden != ttoken.clientHidden) {
3732 wtoken.clientHidden = ttoken.clientHidden;
3733 wtoken.sendAppVisibilityToClients();
3734 }
3735 if (ttoken.animation != null) {
3736 wtoken.animation = ttoken.animation;
3737 wtoken.animating = ttoken.animating;
3738 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3739 ttoken.animation = null;
3740 ttoken.animLayerAdjustment = 0;
3741 wtoken.updateLayers();
3742 ttoken.updateLayers();
3743 }
Romain Guy06882f82009-06-10 13:36:04 -07003744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003745 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003746 mLayoutNeeded = true;
3747 performLayoutAndPlaceSurfacesLocked();
3748 Binder.restoreCallingIdentity(origId);
3749 return;
3750 } else if (ttoken.startingData != null) {
3751 // The previous app was getting ready to show a
3752 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003753 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003754 "Moving pending starting from " + ttoken
3755 + " to " + wtoken);
3756 wtoken.startingData = ttoken.startingData;
3757 ttoken.startingData = null;
3758 ttoken.startingMoved = true;
3759 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3760 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3761 // want to process the message ASAP, before any other queued
3762 // messages.
3763 mH.sendMessageAtFrontOfQueue(m);
3764 return;
3765 }
3766 }
3767 }
3768
3769 // There is no existing starting window, and the caller doesn't
3770 // want us to create one, so that's it!
3771 if (!createIfNeeded) {
3772 return;
3773 }
Romain Guy06882f82009-06-10 13:36:04 -07003774
Dianne Hackborn284ac932009-08-28 10:34:25 -07003775 // If this is a translucent or wallpaper window, then don't
3776 // show a starting window -- the current effect (a full-screen
3777 // opaque starting window that fades away to the real contents
3778 // when it is ready) does not work for this.
3779 if (theme != 0) {
3780 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3781 com.android.internal.R.styleable.Window);
3782 if (ent.array.getBoolean(
3783 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3784 return;
3785 }
3786 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003787 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3788 return;
3789 }
3790 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003791 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3792 return;
3793 }
3794 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003796 mStartingIconInTransition = true;
3797 wtoken.startingData = new StartingData(
3798 pkg, theme, nonLocalizedLabel,
3799 labelRes, icon);
3800 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3801 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3802 // want to process the message ASAP, before any other queued
3803 // messages.
3804 mH.sendMessageAtFrontOfQueue(m);
3805 }
3806 }
3807
3808 public void setAppWillBeHidden(IBinder token) {
3809 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3810 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003811 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003812 }
3813
3814 AppWindowToken wtoken;
3815
3816 synchronized(mWindowMap) {
3817 wtoken = findAppWindowToken(token);
3818 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003819 Slog.w(TAG, "Attempted to set will be hidden of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003820 return;
3821 }
3822 wtoken.willBeHidden = true;
3823 }
3824 }
Romain Guy06882f82009-06-10 13:36:04 -07003825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003826 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3827 boolean visible, int transit, boolean performLayout) {
3828 boolean delayed = false;
3829
3830 if (wtoken.clientHidden == visible) {
3831 wtoken.clientHidden = !visible;
3832 wtoken.sendAppVisibilityToClients();
3833 }
Romain Guy06882f82009-06-10 13:36:04 -07003834
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003835 wtoken.willBeHidden = false;
3836 if (wtoken.hidden == visible) {
3837 final int N = wtoken.allAppWindows.size();
3838 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003839 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003840 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3841 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003843 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003844
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003845 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003846 if (wtoken.animation == sDummyAnimation) {
3847 wtoken.animation = null;
3848 }
3849 applyAnimationLocked(wtoken, lp, transit, visible);
3850 changed = true;
3851 if (wtoken.animation != null) {
3852 delayed = runningAppAnimation = true;
3853 }
3854 }
Romain Guy06882f82009-06-10 13:36:04 -07003855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003856 for (int i=0; i<N; i++) {
3857 WindowState win = wtoken.allAppWindows.get(i);
3858 if (win == wtoken.startingWindow) {
3859 continue;
3860 }
3861
3862 if (win.isAnimating()) {
3863 delayed = true;
3864 }
Romain Guy06882f82009-06-10 13:36:04 -07003865
Joe Onorato8a9b2202010-02-26 18:56:32 -08003866 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003867 //win.dump(" ");
3868 if (visible) {
3869 if (!win.isVisibleNow()) {
3870 if (!runningAppAnimation) {
3871 applyAnimationLocked(win,
3872 WindowManagerPolicy.TRANSIT_ENTER, true);
3873 }
3874 changed = true;
3875 }
3876 } else if (win.isVisibleNow()) {
3877 if (!runningAppAnimation) {
3878 applyAnimationLocked(win,
3879 WindowManagerPolicy.TRANSIT_EXIT, false);
3880 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003881 changed = true;
3882 }
3883 }
3884
3885 wtoken.hidden = wtoken.hiddenRequested = !visible;
3886 if (!visible) {
3887 unsetAppFreezingScreenLocked(wtoken, true, true);
3888 } else {
3889 // If we are being set visible, and the starting window is
3890 // not yet displayed, then make sure it doesn't get displayed.
3891 WindowState swin = wtoken.startingWindow;
3892 if (swin != null && (swin.mDrawPending
3893 || swin.mCommitDrawPending)) {
3894 swin.mPolicyVisibility = false;
3895 swin.mPolicyVisibilityAfterAnim = false;
3896 }
3897 }
Romain Guy06882f82009-06-10 13:36:04 -07003898
Joe Onorato8a9b2202010-02-26 18:56:32 -08003899 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003900 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3901 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003902
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003903 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003904 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003905 if (performLayout) {
3906 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3907 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003908 } else {
3909 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003910 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003911 }
3912 }
3913
3914 if (wtoken.animation != null) {
3915 delayed = true;
3916 }
Romain Guy06882f82009-06-10 13:36:04 -07003917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003918 return delayed;
3919 }
3920
3921 public void setAppVisibility(IBinder token, boolean visible) {
3922 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3923 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003924 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003925 }
3926
3927 AppWindowToken wtoken;
3928
3929 synchronized(mWindowMap) {
3930 wtoken = findAppWindowToken(token);
3931 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003932 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003933 return;
3934 }
3935
3936 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003937 RuntimeException e = null;
3938 if (!HIDE_STACK_CRAWLS) {
3939 e = new RuntimeException();
3940 e.fillInStackTrace();
3941 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003942 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003943 + "): mNextAppTransition=" + mNextAppTransition
3944 + " hidden=" + wtoken.hidden
3945 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3946 }
Romain Guy06882f82009-06-10 13:36:04 -07003947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003948 // If we are preparing an app transition, then delay changing
3949 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003950 if (!mDisplayFrozen && mPolicy.isScreenOn()
3951 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003952 // Already in requested state, don't do anything more.
3953 if (wtoken.hiddenRequested != visible) {
3954 return;
3955 }
3956 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003957
Joe Onorato8a9b2202010-02-26 18:56:32 -08003958 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003959 TAG, "Setting dummy animation on: " + wtoken);
3960 wtoken.setDummyAnimation();
3961 mOpeningApps.remove(wtoken);
3962 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003963 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003964 wtoken.inPendingTransaction = true;
3965 if (visible) {
3966 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003967 wtoken.startingDisplayed = false;
3968 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003969
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003970 // If the token is currently hidden (should be the
3971 // common case), then we need to set up to wait for
3972 // its windows to be ready.
3973 if (wtoken.hidden) {
3974 wtoken.allDrawn = false;
3975 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003976
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003977 if (wtoken.clientHidden) {
3978 // In the case where we are making an app visible
3979 // but holding off for a transition, we still need
3980 // to tell the client to make its windows visible so
3981 // they get drawn. Otherwise, we will wait on
3982 // performing the transition until all windows have
3983 // been drawn, they never will be, and we are sad.
3984 wtoken.clientHidden = false;
3985 wtoken.sendAppVisibilityToClients();
3986 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003987 }
3988 } else {
3989 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003990
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003991 // If the token is currently visible (should be the
3992 // common case), then set up to wait for it to be hidden.
3993 if (!wtoken.hidden) {
3994 wtoken.waitingToHide = true;
3995 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003996 }
3997 return;
3998 }
Romain Guy06882f82009-06-10 13:36:04 -07003999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004000 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004001 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004002 wtoken.updateReportedVisibilityLocked();
4003 Binder.restoreCallingIdentity(origId);
4004 }
4005 }
4006
4007 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4008 boolean unfreezeSurfaceNow, boolean force) {
4009 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004010 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004011 + " force=" + force);
4012 final int N = wtoken.allAppWindows.size();
4013 boolean unfrozeWindows = false;
4014 for (int i=0; i<N; i++) {
4015 WindowState w = wtoken.allAppWindows.get(i);
4016 if (w.mAppFreezing) {
4017 w.mAppFreezing = false;
4018 if (w.mSurface != null && !w.mOrientationChanging) {
4019 w.mOrientationChanging = true;
4020 }
4021 unfrozeWindows = true;
4022 }
4023 }
4024 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004025 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004026 wtoken.freezingScreen = false;
4027 mAppsFreezingScreen--;
4028 }
4029 if (unfreezeSurfaceNow) {
4030 if (unfrozeWindows) {
4031 mLayoutNeeded = true;
4032 performLayoutAndPlaceSurfacesLocked();
4033 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004034 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004035 }
4036 }
4037 }
Romain Guy06882f82009-06-10 13:36:04 -07004038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004039 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4040 int configChanges) {
4041 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004042 RuntimeException e = null;
4043 if (!HIDE_STACK_CRAWLS) {
4044 e = new RuntimeException();
4045 e.fillInStackTrace();
4046 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004047 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004048 + ": hidden=" + wtoken.hidden + " freezing="
4049 + wtoken.freezingScreen, e);
4050 }
4051 if (!wtoken.hiddenRequested) {
4052 if (!wtoken.freezingScreen) {
4053 wtoken.freezingScreen = true;
4054 mAppsFreezingScreen++;
4055 if (mAppsFreezingScreen == 1) {
4056 startFreezingDisplayLocked();
4057 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4058 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4059 5000);
4060 }
4061 }
4062 final int N = wtoken.allAppWindows.size();
4063 for (int i=0; i<N; i++) {
4064 WindowState w = wtoken.allAppWindows.get(i);
4065 w.mAppFreezing = true;
4066 }
4067 }
4068 }
Romain Guy06882f82009-06-10 13:36:04 -07004069
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004070 public void startAppFreezingScreen(IBinder token, int configChanges) {
4071 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4072 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004073 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004074 }
4075
4076 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004077 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004078 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004079 return;
4080 }
Romain Guy06882f82009-06-10 13:36:04 -07004081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004082 AppWindowToken wtoken = findAppWindowToken(token);
4083 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004084 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004085 return;
4086 }
4087 final long origId = Binder.clearCallingIdentity();
4088 startAppFreezingScreenLocked(wtoken, configChanges);
4089 Binder.restoreCallingIdentity(origId);
4090 }
4091 }
Romain Guy06882f82009-06-10 13:36:04 -07004092
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004093 public void stopAppFreezingScreen(IBinder token, boolean force) {
4094 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4095 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004096 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004097 }
4098
4099 synchronized(mWindowMap) {
4100 AppWindowToken wtoken = findAppWindowToken(token);
4101 if (wtoken == null || wtoken.appToken == null) {
4102 return;
4103 }
4104 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004105 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004106 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4107 unsetAppFreezingScreenLocked(wtoken, true, force);
4108 Binder.restoreCallingIdentity(origId);
4109 }
4110 }
Romain Guy06882f82009-06-10 13:36:04 -07004111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004112 public void removeAppToken(IBinder token) {
4113 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4114 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004115 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004116 }
4117
4118 AppWindowToken wtoken = null;
4119 AppWindowToken startingToken = null;
4120 boolean delayed = false;
4121
4122 final long origId = Binder.clearCallingIdentity();
4123 synchronized(mWindowMap) {
4124 WindowToken basewtoken = mTokenMap.remove(token);
4125 mTokenList.remove(basewtoken);
4126 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004127 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004128 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004129 wtoken.inPendingTransaction = false;
4130 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004131 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004132 if (mClosingApps.contains(wtoken)) {
4133 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004134 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004135 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004136 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004137 delayed = true;
4138 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004139 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004140 TAG, "Removing app " + wtoken + " delayed=" + delayed
4141 + " animation=" + wtoken.animation
4142 + " animating=" + wtoken.animating);
4143 if (delayed) {
4144 // set the token aside because it has an active animation to be finished
4145 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004146 } else {
4147 // Make sure there is no animation running on this token,
4148 // so any windows associated with it will be removed as
4149 // soon as their animations are complete
4150 wtoken.animation = null;
4151 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004152 }
4153 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07004154 if (mLastEnterAnimToken == wtoken) {
4155 mLastEnterAnimToken = null;
4156 mLastEnterAnimParams = null;
4157 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004158 wtoken.removed = true;
4159 if (wtoken.startingData != null) {
4160 startingToken = wtoken;
4161 }
4162 unsetAppFreezingScreenLocked(wtoken, true, true);
4163 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004164 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004165 mFocusedApp = null;
4166 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004167 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004168 }
4169 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004170 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004171 }
Romain Guy06882f82009-06-10 13:36:04 -07004172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004173 if (!delayed && wtoken != null) {
4174 wtoken.updateReportedVisibilityLocked();
4175 }
4176 }
4177 Binder.restoreCallingIdentity(origId);
4178
4179 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004180 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004181 + startingToken + ": app token removed");
4182 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4183 mH.sendMessage(m);
4184 }
4185 }
4186
4187 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4188 final int NW = token.windows.size();
4189 for (int i=0; i<NW; i++) {
4190 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004191 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004192 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004193 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004194 int j = win.mChildWindows.size();
4195 while (j > 0) {
4196 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004197 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004198 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004199 "Tmp removing child window " + cwin);
4200 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004201 }
4202 }
4203 return NW > 0;
4204 }
4205
4206 void dumpAppTokensLocked() {
4207 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004208 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004209 }
4210 }
Romain Guy06882f82009-06-10 13:36:04 -07004211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004212 void dumpWindowsLocked() {
4213 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004214 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004215 }
4216 }
Romain Guy06882f82009-06-10 13:36:04 -07004217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004218 private int findWindowOffsetLocked(int tokenPos) {
4219 final int NW = mWindows.size();
4220
4221 if (tokenPos >= mAppTokens.size()) {
4222 int i = NW;
4223 while (i > 0) {
4224 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004225 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004226 if (win.getAppToken() != null) {
4227 return i+1;
4228 }
4229 }
4230 }
4231
4232 while (tokenPos > 0) {
4233 // Find the first app token below the new position that has
4234 // a window displayed.
4235 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004236 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004237 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004238 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004239 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004240 "Skipping token -- currently sending to bottom");
4241 tokenPos--;
4242 continue;
4243 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004244 int i = wtoken.windows.size();
4245 while (i > 0) {
4246 i--;
4247 WindowState win = wtoken.windows.get(i);
4248 int j = win.mChildWindows.size();
4249 while (j > 0) {
4250 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004251 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004252 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004253 for (int pos=NW-1; pos>=0; pos--) {
4254 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004255 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004256 "Found child win @" + (pos+1));
4257 return pos+1;
4258 }
4259 }
4260 }
4261 }
4262 for (int pos=NW-1; pos>=0; pos--) {
4263 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004264 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004265 return pos+1;
4266 }
4267 }
4268 }
4269 tokenPos--;
4270 }
4271
4272 return 0;
4273 }
4274
4275 private final int reAddWindowLocked(int index, WindowState win) {
4276 final int NCW = win.mChildWindows.size();
4277 boolean added = false;
4278 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004279 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004280 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004281 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004282 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004283 mWindows.add(index, win);
4284 index++;
4285 added = true;
4286 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004287 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004288 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004289 mWindows.add(index, cwin);
4290 index++;
4291 }
4292 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004293 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004294 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004295 mWindows.add(index, win);
4296 index++;
4297 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004298 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004299 return index;
4300 }
Romain Guy06882f82009-06-10 13:36:04 -07004301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004302 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4303 final int NW = token.windows.size();
4304 for (int i=0; i<NW; i++) {
4305 index = reAddWindowLocked(index, token.windows.get(i));
4306 }
4307 return index;
4308 }
4309
4310 public void moveAppToken(int index, IBinder token) {
4311 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4312 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004313 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004314 }
4315
4316 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004317 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004318 if (DEBUG_REORDER) dumpAppTokensLocked();
4319 final AppWindowToken wtoken = findAppWindowToken(token);
4320 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004321 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004322 + token + " (" + wtoken + ")");
4323 return;
4324 }
4325 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004326 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004327 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004329 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004330 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004331 if (DEBUG_REORDER) dumpWindowsLocked();
4332 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004333 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004334 if (DEBUG_REORDER) dumpWindowsLocked();
4335 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004336 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004337 if (DEBUG_REORDER) dumpWindowsLocked();
4338 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004339 mLayoutNeeded = true;
4340 performLayoutAndPlaceSurfacesLocked();
4341 }
4342 Binder.restoreCallingIdentity(origId);
4343 }
4344 }
4345
4346 private void removeAppTokensLocked(List<IBinder> tokens) {
4347 // XXX This should be done more efficiently!
4348 // (take advantage of the fact that both lists should be
4349 // ordered in the same way.)
4350 int N = tokens.size();
4351 for (int i=0; i<N; i++) {
4352 IBinder token = tokens.get(i);
4353 final AppWindowToken wtoken = findAppWindowToken(token);
4354 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004355 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004356 + token + " (" + wtoken + ")");
4357 i--;
4358 N--;
4359 }
4360 }
4361 }
4362
Dianne Hackborna8f60182009-09-01 19:01:50 -07004363 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4364 boolean updateFocusAndLayout) {
4365 // First remove all of the windows from the list.
4366 tmpRemoveAppWindowsLocked(wtoken);
4367
4368 // Where to start adding?
4369 int pos = findWindowOffsetLocked(tokenPos);
4370
4371 // And now add them back at the correct place.
4372 pos = reAddAppWindowsLocked(pos, wtoken);
4373
4374 if (updateFocusAndLayout) {
4375 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4376 assignLayersLocked();
4377 }
4378 mLayoutNeeded = true;
4379 performLayoutAndPlaceSurfacesLocked();
4380 }
4381 }
4382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004383 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4384 // First remove all of the windows from the list.
4385 final int N = tokens.size();
4386 int i;
4387 for (i=0; i<N; i++) {
4388 WindowToken token = mTokenMap.get(tokens.get(i));
4389 if (token != null) {
4390 tmpRemoveAppWindowsLocked(token);
4391 }
4392 }
4393
4394 // Where to start adding?
4395 int pos = findWindowOffsetLocked(tokenPos);
4396
4397 // And now add them back at the correct place.
4398 for (i=0; i<N; i++) {
4399 WindowToken token = mTokenMap.get(tokens.get(i));
4400 if (token != null) {
4401 pos = reAddAppWindowsLocked(pos, token);
4402 }
4403 }
4404
Dianne Hackborna8f60182009-09-01 19:01:50 -07004405 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4406 assignLayersLocked();
4407 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004408 mLayoutNeeded = true;
4409 performLayoutAndPlaceSurfacesLocked();
4410
4411 //dump();
4412 }
4413
4414 public void moveAppTokensToTop(List<IBinder> tokens) {
4415 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4416 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004417 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004418 }
4419
4420 final long origId = Binder.clearCallingIdentity();
4421 synchronized(mWindowMap) {
4422 removeAppTokensLocked(tokens);
4423 final int N = tokens.size();
4424 for (int i=0; i<N; i++) {
4425 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4426 if (wt != null) {
4427 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004428 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004429 mToTopApps.remove(wt);
4430 mToBottomApps.remove(wt);
4431 mToTopApps.add(wt);
4432 wt.sendingToBottom = false;
4433 wt.sendingToTop = true;
4434 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004435 }
4436 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004437
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004438 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004439 moveAppWindowsLocked(tokens, mAppTokens.size());
4440 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004441 }
4442 Binder.restoreCallingIdentity(origId);
4443 }
4444
4445 public void moveAppTokensToBottom(List<IBinder> tokens) {
4446 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4447 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004448 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004449 }
4450
4451 final long origId = Binder.clearCallingIdentity();
4452 synchronized(mWindowMap) {
4453 removeAppTokensLocked(tokens);
4454 final int N = tokens.size();
4455 int pos = 0;
4456 for (int i=0; i<N; i++) {
4457 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4458 if (wt != null) {
4459 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004460 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004461 mToTopApps.remove(wt);
4462 mToBottomApps.remove(wt);
4463 mToBottomApps.add(i, wt);
4464 wt.sendingToTop = false;
4465 wt.sendingToBottom = true;
4466 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004467 pos++;
4468 }
4469 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004470
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004471 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004472 moveAppWindowsLocked(tokens, 0);
4473 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004474 }
4475 Binder.restoreCallingIdentity(origId);
4476 }
4477
4478 // -------------------------------------------------------------
4479 // Misc IWindowSession methods
4480 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004481
Jim Miller284b62e2010-06-08 14:27:42 -07004482 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004483 {
Jim Miller284b62e2010-06-08 14:27:42 -07004484 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4485 // called before DevicePolicyManagerService has started.
4486 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4487 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4488 Context.DEVICE_POLICY_SERVICE);
4489 if (dpm != null) {
4490 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4491 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4492 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4493 }
Jim Millerd6b57052010-06-07 17:52:42 -07004494 }
Jim Miller284b62e2010-06-08 14:27:42 -07004495 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004496 }
4497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004498 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004499 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004500 != PackageManager.PERMISSION_GRANTED) {
4501 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4502 }
Jim Millerd6b57052010-06-07 17:52:42 -07004503
Jim Miller284b62e2010-06-08 14:27:42 -07004504 synchronized (mKeyguardTokenWatcher) {
4505 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004506 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004507 }
4508
4509 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004510 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004511 != PackageManager.PERMISSION_GRANTED) {
4512 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4513 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004514
Jim Miller284b62e2010-06-08 14:27:42 -07004515 synchronized (mKeyguardTokenWatcher) {
4516 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004517
Jim Miller284b62e2010-06-08 14:27:42 -07004518 if (!mKeyguardTokenWatcher.isAcquired()) {
4519 // If we are the last one to reenable the keyguard wait until
4520 // we have actually finished reenabling until returning.
4521 // It is possible that reenableKeyguard() can be called before
4522 // the previous disableKeyguard() is handled, in which case
4523 // neither mKeyguardTokenWatcher.acquired() or released() would
4524 // be called. In that case mKeyguardDisabled will be false here
4525 // and we have nothing to wait for.
4526 while (mKeyguardDisabled) {
4527 try {
4528 mKeyguardTokenWatcher.wait();
4529 } catch (InterruptedException e) {
4530 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004531 }
4532 }
4533 }
4534 }
4535 }
4536
4537 /**
4538 * @see android.app.KeyguardManager#exitKeyguardSecurely
4539 */
4540 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004541 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004542 != PackageManager.PERMISSION_GRANTED) {
4543 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4544 }
4545 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4546 public void onKeyguardExitResult(boolean success) {
4547 try {
4548 callback.onKeyguardExitResult(success);
4549 } catch (RemoteException e) {
4550 // Client has died, we don't care.
4551 }
4552 }
4553 });
4554 }
4555
4556 public boolean inKeyguardRestrictedInputMode() {
4557 return mPolicy.inKeyguardRestrictedKeyInputMode();
4558 }
Romain Guy06882f82009-06-10 13:36:04 -07004559
Dianne Hackbornffa42482009-09-23 22:20:11 -07004560 public void closeSystemDialogs(String reason) {
4561 synchronized(mWindowMap) {
4562 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004563 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004564 if (w.mSurface != null) {
4565 try {
4566 w.mClient.closeSystemDialogs(reason);
4567 } catch (RemoteException e) {
4568 }
4569 }
4570 }
4571 }
4572 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004574 static float fixScale(float scale) {
4575 if (scale < 0) scale = 0;
4576 else if (scale > 20) scale = 20;
4577 return Math.abs(scale);
4578 }
Romain Guy06882f82009-06-10 13:36:04 -07004579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004580 public void setAnimationScale(int which, float scale) {
4581 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4582 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004583 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004584 }
4585
4586 if (scale < 0) scale = 0;
4587 else if (scale > 20) scale = 20;
4588 scale = Math.abs(scale);
4589 switch (which) {
4590 case 0: mWindowAnimationScale = fixScale(scale); break;
4591 case 1: mTransitionAnimationScale = fixScale(scale); break;
4592 }
Romain Guy06882f82009-06-10 13:36:04 -07004593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004594 // Persist setting
4595 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4596 }
Romain Guy06882f82009-06-10 13:36:04 -07004597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004598 public void setAnimationScales(float[] scales) {
4599 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4600 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004601 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004602 }
4603
4604 if (scales != null) {
4605 if (scales.length >= 1) {
4606 mWindowAnimationScale = fixScale(scales[0]);
4607 }
4608 if (scales.length >= 2) {
4609 mTransitionAnimationScale = fixScale(scales[1]);
4610 }
4611 }
Romain Guy06882f82009-06-10 13:36:04 -07004612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004613 // Persist setting
4614 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4615 }
Romain Guy06882f82009-06-10 13:36:04 -07004616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004617 public float getAnimationScale(int which) {
4618 switch (which) {
4619 case 0: return mWindowAnimationScale;
4620 case 1: return mTransitionAnimationScale;
4621 }
4622 return 0;
4623 }
Romain Guy06882f82009-06-10 13:36:04 -07004624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004625 public float[] getAnimationScales() {
4626 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4627 }
Romain Guy06882f82009-06-10 13:36:04 -07004628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004629 public int getSwitchState(int sw) {
4630 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4631 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004632 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004633 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004634 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004635 }
Romain Guy06882f82009-06-10 13:36:04 -07004636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004637 public int getSwitchStateForDevice(int devid, int sw) {
4638 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4639 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004640 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004641 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004642 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004643 }
Romain Guy06882f82009-06-10 13:36:04 -07004644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004645 public int getScancodeState(int sw) {
4646 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4647 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004648 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004649 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004650 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004651 }
Romain Guy06882f82009-06-10 13:36:04 -07004652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004653 public int getScancodeStateForDevice(int devid, int sw) {
4654 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4655 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004656 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004657 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004658 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004659 }
Romain Guy06882f82009-06-10 13:36:04 -07004660
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004661 public int getTrackballScancodeState(int sw) {
4662 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4663 "getTrackballScancodeState()")) {
4664 throw new SecurityException("Requires READ_INPUT_STATE permission");
4665 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004666 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004667 }
4668
4669 public int getDPadScancodeState(int sw) {
4670 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4671 "getDPadScancodeState()")) {
4672 throw new SecurityException("Requires READ_INPUT_STATE permission");
4673 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004674 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004675 }
4676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004677 public int getKeycodeState(int sw) {
4678 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4679 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004680 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004681 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004682 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004683 }
Romain Guy06882f82009-06-10 13:36:04 -07004684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004685 public int getKeycodeStateForDevice(int devid, int sw) {
4686 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4687 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004688 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004689 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004690 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004691 }
Romain Guy06882f82009-06-10 13:36:04 -07004692
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004693 public int getTrackballKeycodeState(int sw) {
4694 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4695 "getTrackballKeycodeState()")) {
4696 throw new SecurityException("Requires READ_INPUT_STATE permission");
4697 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004698 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004699 }
4700
4701 public int getDPadKeycodeState(int sw) {
4702 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4703 "getDPadKeycodeState()")) {
4704 throw new SecurityException("Requires READ_INPUT_STATE permission");
4705 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004706 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004707 }
Jeff Browna41ca772010-08-11 14:46:32 -07004708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004709 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004710 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004711 }
Romain Guy06882f82009-06-10 13:36:04 -07004712
Jeff Browna41ca772010-08-11 14:46:32 -07004713 public InputChannel monitorInput(String inputChannelName) {
4714 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4715 "monitorInput()")) {
4716 throw new SecurityException("Requires READ_INPUT_STATE permission");
4717 }
4718 return mInputManager.monitorInput(inputChannelName);
4719 }
4720
Jeff Brown8d608662010-08-30 03:02:23 -07004721 public InputDevice getInputDevice(int deviceId) {
4722 return mInputManager.getInputDevice(deviceId);
4723 }
4724
4725 public int[] getInputDeviceIds() {
4726 return mInputManager.getInputDeviceIds();
4727 }
4728
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004729 public void enableScreenAfterBoot() {
4730 synchronized(mWindowMap) {
4731 if (mSystemBooted) {
4732 return;
4733 }
4734 mSystemBooted = true;
4735 }
Romain Guy06882f82009-06-10 13:36:04 -07004736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004737 performEnableScreen();
4738 }
Romain Guy06882f82009-06-10 13:36:04 -07004739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004740 public void enableScreenIfNeededLocked() {
4741 if (mDisplayEnabled) {
4742 return;
4743 }
4744 if (!mSystemBooted) {
4745 return;
4746 }
4747 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4748 }
Romain Guy06882f82009-06-10 13:36:04 -07004749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004750 public void performEnableScreen() {
4751 synchronized(mWindowMap) {
4752 if (mDisplayEnabled) {
4753 return;
4754 }
4755 if (!mSystemBooted) {
4756 return;
4757 }
Romain Guy06882f82009-06-10 13:36:04 -07004758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004759 // Don't enable the screen until all existing windows
4760 // have been drawn.
4761 final int N = mWindows.size();
4762 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004763 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004764 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004765 return;
4766 }
4767 }
Romain Guy06882f82009-06-10 13:36:04 -07004768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004769 mDisplayEnabled = true;
4770 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004771 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004772 StringWriter sw = new StringWriter();
4773 PrintWriter pw = new PrintWriter(sw);
4774 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004775 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004776 }
4777 try {
4778 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4779 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004780 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004781 Parcel data = Parcel.obtain();
4782 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4783 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4784 data, null, 0);
4785 data.recycle();
4786 }
4787 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004788 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004789 }
4790 }
Romain Guy06882f82009-06-10 13:36:04 -07004791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004792 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004794 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004795 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4796 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004797 }
Romain Guy06882f82009-06-10 13:36:04 -07004798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004799 public void setInTouchMode(boolean mode) {
4800 synchronized(mWindowMap) {
4801 mInTouchMode = mode;
4802 }
4803 }
4804
Romain Guy06882f82009-06-10 13:36:04 -07004805 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004806 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004807 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004808 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004809 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004810 }
4811
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004812 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004813 }
Romain Guy06882f82009-06-10 13:36:04 -07004814
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004815 public void setRotationUnchecked(int rotation,
4816 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004817 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004818 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004819
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004820 long origId = Binder.clearCallingIdentity();
4821 boolean changed;
4822 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004823 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004824 }
Romain Guy06882f82009-06-10 13:36:04 -07004825
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004826 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004827 sendNewConfiguration();
4828 }
Romain Guy06882f82009-06-10 13:36:04 -07004829
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004830 Binder.restoreCallingIdentity(origId);
4831 }
Romain Guy06882f82009-06-10 13:36:04 -07004832
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004833 /**
4834 * Apply a new rotation to the screen, respecting the requests of
4835 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4836 * re-evaluate the desired rotation.
4837 *
4838 * Returns null if the rotation has been changed. In this case YOU
4839 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4840 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004841 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004842 boolean changed;
4843 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4844 rotation = mRequestedRotation;
4845 } else {
4846 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004847 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004848 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004849 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004850 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004851 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004852 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004853 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004855 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004856 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004857 "Rotation changed to " + rotation
4858 + " from " + mRotation
4859 + " (forceApp=" + mForcedAppOrientation
4860 + ", req=" + mRequestedRotation + ")");
4861 mRotation = rotation;
4862 mWindowsFreezingScreen = true;
4863 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4864 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4865 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004866 mWaitingForConfig = true;
4867 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004868 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004869 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004870 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004871 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004872 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004873 }
4874 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004875 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004876 if (w.mSurface != null) {
4877 w.mOrientationChanging = true;
4878 }
4879 }
4880 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4881 try {
4882 mRotationWatchers.get(i).onRotationChanged(rotation);
4883 } catch (RemoteException e) {
4884 }
4885 }
4886 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004888 return changed;
4889 }
Romain Guy06882f82009-06-10 13:36:04 -07004890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004891 public int getRotation() {
4892 return mRotation;
4893 }
4894
4895 public int watchRotation(IRotationWatcher watcher) {
4896 final IBinder watcherBinder = watcher.asBinder();
4897 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4898 public void binderDied() {
4899 synchronized (mWindowMap) {
4900 for (int i=0; i<mRotationWatchers.size(); i++) {
4901 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004902 IRotationWatcher removed = mRotationWatchers.remove(i);
4903 if (removed != null) {
4904 removed.asBinder().unlinkToDeath(this, 0);
4905 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004906 i--;
4907 }
4908 }
4909 }
4910 }
4911 };
Romain Guy06882f82009-06-10 13:36:04 -07004912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004913 synchronized (mWindowMap) {
4914 try {
4915 watcher.asBinder().linkToDeath(dr, 0);
4916 mRotationWatchers.add(watcher);
4917 } catch (RemoteException e) {
4918 // Client died, no cleanup needed.
4919 }
Romain Guy06882f82009-06-10 13:36:04 -07004920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004921 return mRotation;
4922 }
4923 }
4924
4925 /**
4926 * Starts the view server on the specified port.
4927 *
4928 * @param port The port to listener to.
4929 *
4930 * @return True if the server was successfully started, false otherwise.
4931 *
4932 * @see com.android.server.ViewServer
4933 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4934 */
4935 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004936 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004937 return false;
4938 }
4939
4940 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4941 return false;
4942 }
4943
4944 if (port < 1024) {
4945 return false;
4946 }
4947
4948 if (mViewServer != null) {
4949 if (!mViewServer.isRunning()) {
4950 try {
4951 return mViewServer.start();
4952 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004953 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004954 }
4955 }
4956 return false;
4957 }
4958
4959 try {
4960 mViewServer = new ViewServer(this, port);
4961 return mViewServer.start();
4962 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004963 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004964 }
4965 return false;
4966 }
4967
Romain Guy06882f82009-06-10 13:36:04 -07004968 private boolean isSystemSecure() {
4969 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4970 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4971 }
4972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004973 /**
4974 * Stops the view server if it exists.
4975 *
4976 * @return True if the server stopped, false if it wasn't started or
4977 * couldn't be stopped.
4978 *
4979 * @see com.android.server.ViewServer
4980 */
4981 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004982 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004983 return false;
4984 }
4985
4986 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4987 return false;
4988 }
4989
4990 if (mViewServer != null) {
4991 return mViewServer.stop();
4992 }
4993 return false;
4994 }
4995
4996 /**
4997 * Indicates whether the view server is running.
4998 *
4999 * @return True if the server is running, false otherwise.
5000 *
5001 * @see com.android.server.ViewServer
5002 */
5003 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005004 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005005 return false;
5006 }
5007
5008 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5009 return false;
5010 }
5011
5012 return mViewServer != null && mViewServer.isRunning();
5013 }
5014
5015 /**
5016 * Lists all availble windows in the system. The listing is written in the
5017 * specified Socket's output stream with the following syntax:
5018 * windowHashCodeInHexadecimal windowName
5019 * Each line of the ouput represents a different window.
5020 *
5021 * @param client The remote client to send the listing to.
5022 * @return False if an error occured, true otherwise.
5023 */
5024 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005025 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005026 return false;
5027 }
5028
5029 boolean result = true;
5030
Jeff Browne33348b2010-07-15 23:54:05 -07005031 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005032 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005033 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005034 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005035 }
5036
5037 BufferedWriter out = null;
5038
5039 // Any uncaught exception will crash the system process
5040 try {
5041 OutputStream clientStream = client.getOutputStream();
5042 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5043
5044 final int count = windows.length;
5045 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005046 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005047 out.write(Integer.toHexString(System.identityHashCode(w)));
5048 out.write(' ');
5049 out.append(w.mAttrs.getTitle());
5050 out.write('\n');
5051 }
5052
5053 out.write("DONE.\n");
5054 out.flush();
5055 } catch (Exception e) {
5056 result = false;
5057 } finally {
5058 if (out != null) {
5059 try {
5060 out.close();
5061 } catch (IOException e) {
5062 result = false;
5063 }
5064 }
5065 }
5066
5067 return result;
5068 }
5069
5070 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005071 * Returns the focused window in the following format:
5072 * windowHashCodeInHexadecimal windowName
5073 *
5074 * @param client The remote client to send the listing to.
5075 * @return False if an error occurred, true otherwise.
5076 */
5077 boolean viewServerGetFocusedWindow(Socket client) {
5078 if (isSystemSecure()) {
5079 return false;
5080 }
5081
5082 boolean result = true;
5083
5084 WindowState focusedWindow = getFocusedWindow();
5085
5086 BufferedWriter out = null;
5087
5088 // Any uncaught exception will crash the system process
5089 try {
5090 OutputStream clientStream = client.getOutputStream();
5091 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5092
5093 if(focusedWindow != null) {
5094 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5095 out.write(' ');
5096 out.append(focusedWindow.mAttrs.getTitle());
5097 }
5098 out.write('\n');
5099 out.flush();
5100 } catch (Exception e) {
5101 result = false;
5102 } finally {
5103 if (out != null) {
5104 try {
5105 out.close();
5106 } catch (IOException e) {
5107 result = false;
5108 }
5109 }
5110 }
5111
5112 return result;
5113 }
5114
5115 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005116 * Sends a command to a target window. The result of the command, if any, will be
5117 * written in the output stream of the specified socket.
5118 *
5119 * The parameters must follow this syntax:
5120 * windowHashcode extra
5121 *
5122 * Where XX is the length in characeters of the windowTitle.
5123 *
5124 * The first parameter is the target window. The window with the specified hashcode
5125 * will be the target. If no target can be found, nothing happens. The extra parameters
5126 * will be delivered to the target window and as parameters to the command itself.
5127 *
5128 * @param client The remote client to sent the result, if any, to.
5129 * @param command The command to execute.
5130 * @param parameters The command parameters.
5131 *
5132 * @return True if the command was successfully delivered, false otherwise. This does
5133 * not indicate whether the command itself was successful.
5134 */
5135 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005136 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005137 return false;
5138 }
5139
5140 boolean success = true;
5141 Parcel data = null;
5142 Parcel reply = null;
5143
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005144 BufferedWriter out = null;
5145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005146 // Any uncaught exception will crash the system process
5147 try {
5148 // Find the hashcode of the window
5149 int index = parameters.indexOf(' ');
5150 if (index == -1) {
5151 index = parameters.length();
5152 }
5153 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005154 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005155
5156 // Extract the command's parameter after the window description
5157 if (index < parameters.length()) {
5158 parameters = parameters.substring(index + 1);
5159 } else {
5160 parameters = "";
5161 }
5162
5163 final WindowManagerService.WindowState window = findWindow(hashCode);
5164 if (window == null) {
5165 return false;
5166 }
5167
5168 data = Parcel.obtain();
5169 data.writeInterfaceToken("android.view.IWindow");
5170 data.writeString(command);
5171 data.writeString(parameters);
5172 data.writeInt(1);
5173 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5174
5175 reply = Parcel.obtain();
5176
5177 final IBinder binder = window.mClient.asBinder();
5178 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5179 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5180
5181 reply.readException();
5182
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005183 if (!client.isOutputShutdown()) {
5184 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5185 out.write("DONE\n");
5186 out.flush();
5187 }
5188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005189 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005190 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005191 success = false;
5192 } finally {
5193 if (data != null) {
5194 data.recycle();
5195 }
5196 if (reply != null) {
5197 reply.recycle();
5198 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005199 if (out != null) {
5200 try {
5201 out.close();
5202 } catch (IOException e) {
5203
5204 }
5205 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005206 }
5207
5208 return success;
5209 }
5210
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005211 public void addWindowChangeListener(WindowChangeListener listener) {
5212 synchronized(mWindowMap) {
5213 mWindowChangeListeners.add(listener);
5214 }
5215 }
5216
5217 public void removeWindowChangeListener(WindowChangeListener listener) {
5218 synchronized(mWindowMap) {
5219 mWindowChangeListeners.remove(listener);
5220 }
5221 }
5222
5223 private void notifyWindowsChanged() {
5224 WindowChangeListener[] windowChangeListeners;
5225 synchronized(mWindowMap) {
5226 if(mWindowChangeListeners.isEmpty()) {
5227 return;
5228 }
5229 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5230 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5231 }
5232 int N = windowChangeListeners.length;
5233 for(int i = 0; i < N; i++) {
5234 windowChangeListeners[i].windowsChanged();
5235 }
5236 }
5237
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005238 private void notifyFocusChanged() {
5239 WindowChangeListener[] windowChangeListeners;
5240 synchronized(mWindowMap) {
5241 if(mWindowChangeListeners.isEmpty()) {
5242 return;
5243 }
5244 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5245 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5246 }
5247 int N = windowChangeListeners.length;
5248 for(int i = 0; i < N; i++) {
5249 windowChangeListeners[i].focusChanged();
5250 }
5251 }
5252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005253 private WindowState findWindow(int hashCode) {
5254 if (hashCode == -1) {
5255 return getFocusedWindow();
5256 }
5257
5258 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005259 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005260 final int count = windows.size();
5261
5262 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005263 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005264 if (System.identityHashCode(w) == hashCode) {
5265 return w;
5266 }
5267 }
5268 }
5269
5270 return null;
5271 }
5272
5273 /*
5274 * Instruct the Activity Manager to fetch the current configuration and broadcast
5275 * that to config-changed listeners if appropriate.
5276 */
5277 void sendNewConfiguration() {
5278 try {
5279 mActivityManager.updateConfiguration(null);
5280 } catch (RemoteException e) {
5281 }
5282 }
Romain Guy06882f82009-06-10 13:36:04 -07005283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005284 public Configuration computeNewConfiguration() {
5285 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07005286 return computeNewConfigurationLocked();
5287 }
5288 }
Romain Guy06882f82009-06-10 13:36:04 -07005289
Dianne Hackbornc485a602009-03-24 22:39:49 -07005290 Configuration computeNewConfigurationLocked() {
5291 Configuration config = new Configuration();
5292 if (!computeNewConfigurationLocked(config)) {
5293 return null;
5294 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005295 return config;
5296 }
Romain Guy06882f82009-06-10 13:36:04 -07005297
Dianne Hackbornc485a602009-03-24 22:39:49 -07005298 boolean computeNewConfigurationLocked(Configuration config) {
5299 if (mDisplay == null) {
5300 return false;
5301 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005302
5303 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005304
5305 // Use the effective "visual" dimensions based on current rotation
5306 final boolean rotated = (mRotation == Surface.ROTATION_90
5307 || mRotation == Surface.ROTATION_270);
5308 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5309 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5310
Dianne Hackbornc485a602009-03-24 22:39:49 -07005311 int orientation = Configuration.ORIENTATION_SQUARE;
5312 if (dw < dh) {
5313 orientation = Configuration.ORIENTATION_PORTRAIT;
5314 } else if (dw > dh) {
5315 orientation = Configuration.ORIENTATION_LANDSCAPE;
5316 }
5317 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005318
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005319 DisplayMetrics dm = new DisplayMetrics();
5320 mDisplay.getMetrics(dm);
5321 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5322
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005323 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005324 // Note we only do this once because at this point we don't
5325 // expect the screen to change in this way at runtime, and want
5326 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005327 int longSize = dw;
5328 int shortSize = dh;
5329 if (longSize < shortSize) {
5330 int tmp = longSize;
5331 longSize = shortSize;
5332 shortSize = tmp;
5333 }
5334 longSize = (int)(longSize/dm.density);
5335 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005336
Dianne Hackborn723738c2009-06-25 19:48:04 -07005337 // These semi-magic numbers define our compatibility modes for
5338 // applications with different screens. Don't change unless you
5339 // make sure to test lots and lots of apps!
5340 if (longSize < 470) {
5341 // This is shorter than an HVGA normal density screen (which
5342 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005343 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5344 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005345 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005346 // What size is this screen screen?
5347 if (longSize >= 800 && shortSize >= 600) {
5348 // SVGA or larger screens at medium density are the point
5349 // at which we consider it to be an extra large screen.
5350 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
5351 } else if (longSize >= 640 && shortSize >= 480) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005352 // VGA or larger screens at medium density are the point
5353 // at which we consider it to be a large screen.
5354 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5355 } else {
5356 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005357
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005358 // If this screen is wider than normal HVGA, or taller
5359 // than FWVGA, then for old apps we want to run in size
5360 // compatibility mode.
5361 if (shortSize > 321 || longSize > 570) {
5362 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5363 }
5364 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005365
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005366 // Is this a long screen?
5367 if (((longSize*3)/5) >= (shortSize-1)) {
5368 // Anything wider than WVGA (5:3) is considering to be long.
5369 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5370 } else {
5371 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5372 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005373 }
5374 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005375 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005376
Dianne Hackbornc485a602009-03-24 22:39:49 -07005377 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5378 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5379 mPolicy.adjustConfigurationLw(config);
5380 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005381 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005382
5383 // -------------------------------------------------------------
5384 // Drag and drop
5385 // -------------------------------------------------------------
5386
5387 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
5388 boolean localOnly, int width, int height, Surface outSurface) {
5389 if (DEBUG_DRAG) {
5390 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
5391 + " local=" + localOnly + " win=" + window
5392 + " asbinder=" + window.asBinder());
5393 }
5394
5395 final int callerPid = Binder.getCallingPid();
5396 final long origId = Binder.clearCallingIdentity();
5397 IBinder token = null;
5398
5399 try {
5400 synchronized (mWindowMap) {
5401 try {
5402 // !!! TODO: fail if the given window does not currently have touch focus?
5403
5404 if (mDragState == null) {
5405 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5406 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5407 outSurface.copyFrom(surface);
5408 token = new Binder();
5409 mDragState = new DragState(token, surface, localOnly);
5410 mDragState.mSurface = surface;
5411 mDragState.mLocalOnly = localOnly;
5412 token = mDragState.mToken = new Binder();
5413
5414 // 5 second timeout for this window to actually begin the drag
5415 mH.removeMessages(H.DRAG_START_TIMEOUT, window);
5416 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, window.asBinder());
5417 mH.sendMessageDelayed(msg, 5000);
5418 } else {
5419 Slog.w(TAG, "Drag already in progress");
5420 }
5421 } catch (Surface.OutOfResourcesException e) {
5422 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5423 if (mDragState != null) {
5424 mDragState.reset();
5425 mDragState = null;
5426 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005427 }
5428 }
5429 } finally {
5430 Binder.restoreCallingIdentity(origId);
5431 }
5432
5433 return token;
5434 }
5435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005436 // -------------------------------------------------------------
5437 // Input Events and Focus Management
5438 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005439
Jeff Brown349703e2010-06-22 01:27:15 -07005440 InputMonitor mInputMonitor = new InputMonitor();
5441
5442 /* Tracks the progress of input dispatch and ensures that input dispatch state
5443 * is kept in sync with changes in window focus, visibility, registration, and
5444 * other relevant Window Manager state transitions. */
5445 final class InputMonitor {
5446 // Current window with input focus for keys and other non-touch events. May be null.
5447 private WindowState mInputFocus;
5448
5449 // When true, prevents input dispatch from proceeding until set to false again.
5450 private boolean mInputDispatchFrozen;
5451
5452 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5453 private boolean mInputDispatchEnabled = true;
5454
5455 // Temporary list of windows information to provide to the input dispatcher.
5456 private InputWindowList mTempInputWindows = new InputWindowList();
5457
5458 // Temporary input application object to provide to the input dispatcher.
5459 private InputApplication mTempInputApplication = new InputApplication();
5460
5461 /* Notifies the window manager about a broken input channel.
5462 *
5463 * Called by the InputManager.
5464 */
5465 public void notifyInputChannelBroken(InputChannel inputChannel) {
5466 synchronized (mWindowMap) {
5467 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5468 if (windowState == null) {
5469 return; // irrelevant
5470 }
5471
5472 Slog.i(TAG, "WINDOW DIED " + windowState);
5473 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005474 }
5475 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005476
Jeff Brown519e0242010-09-15 15:18:56 -07005477 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005478 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005479 *
5480 * Called by the InputManager.
5481 */
Jeff Brown519e0242010-09-15 15:18:56 -07005482 public long notifyANR(Object token, InputChannel inputChannel) {
5483 AppWindowToken appWindowToken = null;
5484 if (inputChannel != null) {
5485 synchronized (mWindowMap) {
5486 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5487 if (windowState != null) {
5488 Slog.i(TAG, "Input event dispatching timed out sending to "
5489 + windowState.mAttrs.getTitle());
5490 appWindowToken = windowState.mAppToken;
5491 }
Jeff Brown349703e2010-06-22 01:27:15 -07005492 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005493 }
5494
Jeff Brown519e0242010-09-15 15:18:56 -07005495 if (appWindowToken == null && token != null) {
5496 appWindowToken = (AppWindowToken) token;
5497 Slog.i(TAG, "Input event dispatching timed out sending to application "
5498 + appWindowToken.stringName);
5499 }
Jeff Brown349703e2010-06-22 01:27:15 -07005500
Jeff Brown519e0242010-09-15 15:18:56 -07005501 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005502 try {
5503 // Notify the activity manager about the timeout and let it decide whether
5504 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005505 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005506 if (! abort) {
5507 // The activity manager declined to abort dispatching.
5508 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005509 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005510 }
Jeff Brown349703e2010-06-22 01:27:15 -07005511 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005512 }
5513 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005514 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005515 }
5516
Jeff Brown349703e2010-06-22 01:27:15 -07005517 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5518 synchronized (mWindowMap) {
5519 return getWindowStateForInputChannelLocked(inputChannel);
5520 }
5521 }
5522
5523 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5524 int windowCount = mWindows.size();
5525 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005526 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005527 if (windowState.mInputChannel == inputChannel) {
5528 return windowState;
5529 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005530 }
5531
Jeff Brown349703e2010-06-22 01:27:15 -07005532 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005533 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005534
5535 private void addDragInputWindow(InputWindowList windowList) {
5536 final InputWindow inputWindow = windowList.add();
5537 inputWindow.inputChannel = mDragState.mServerChannel;
5538 inputWindow.name = "drag";
5539 inputWindow.layoutParamsFlags = 0;
5540 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5541 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5542 inputWindow.visible = true;
5543 inputWindow.canReceiveKeys = false;
5544 inputWindow.hasFocus = true;
5545 inputWindow.hasWallpaper = false;
5546 inputWindow.paused = false;
5547 inputWindow.layer = mPolicy.windowTypeToLayerLw(inputWindow.layoutParamsType)
5548 * TYPE_LAYER_MULTIPLIER
5549 + TYPE_LAYER_OFFSET;
5550 inputWindow.ownerPid = Process.myPid();
5551 inputWindow.ownerUid = Process.myUid();
5552
5553 // The drag window covers the entire display
5554 inputWindow.frameLeft = 0;
5555 inputWindow.frameTop = 0;
5556 inputWindow.frameRight = mDisplay.getWidth();
5557 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005558
Christopher Tatea53146c2010-09-07 11:57:52 -07005559 inputWindow.visibleFrameLeft = inputWindow.frameLeft;
5560 inputWindow.visibleFrameTop = inputWindow.frameTop;
5561 inputWindow.visibleFrameRight = inputWindow.frameRight;
5562 inputWindow.visibleFrameBottom = inputWindow.frameBottom;
5563
5564 inputWindow.touchableAreaLeft = inputWindow.frameLeft;
5565 inputWindow.touchableAreaTop = inputWindow.frameTop;
5566 inputWindow.touchableAreaRight = inputWindow.frameRight;
5567 inputWindow.touchableAreaBottom = inputWindow.frameBottom;
5568 }
5569
Jeff Brown349703e2010-06-22 01:27:15 -07005570 /* Updates the cached window information provided to the input dispatcher. */
5571 public void updateInputWindowsLw() {
5572 // Populate the input window list with information about all of the windows that
5573 // could potentially receive input.
5574 // As an optimization, we could try to prune the list of windows but this turns
5575 // out to be difficult because only the native code knows for sure which window
5576 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005577 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005578
5579 // If there's a drag in flight, provide a pseudowindow to catch drag input
5580 final boolean inDrag = (mDragState != null);
5581 if (inDrag) {
5582 if (DEBUG_DRAG) {
5583 Log.d(TAG, "Inserting drag window");
5584 }
5585 addDragInputWindow(mTempInputWindows);
5586 }
5587
Jeff Brown7fbdc842010-06-17 20:52:56 -07005588 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005589 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005590 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005591 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005592 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005593 continue;
5594 }
5595
Jeff Brown349703e2010-06-22 01:27:15 -07005596 final int flags = child.mAttrs.flags;
5597 final int type = child.mAttrs.type;
5598
5599 final boolean hasFocus = (child == mInputFocus);
5600 final boolean isVisible = child.isVisibleLw();
5601 final boolean hasWallpaper = (child == mWallpaperTarget)
5602 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005603
5604 // If there's a drag in progress and 'child' is a potential drop target,
5605 // make sure it's been told about the drag
5606 if (inDrag && isVisible) {
5607 mDragState.sendDragStartedIfNeededLw(child);
5608 }
5609
Jeff Brown349703e2010-06-22 01:27:15 -07005610 // Add a window to our list of input windows.
5611 final InputWindow inputWindow = mTempInputWindows.add();
5612 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005613 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005614 inputWindow.layoutParamsFlags = flags;
5615 inputWindow.layoutParamsType = type;
5616 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5617 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005618 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005619 inputWindow.hasFocus = hasFocus;
5620 inputWindow.hasWallpaper = hasWallpaper;
5621 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005622 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005623 inputWindow.ownerPid = child.mSession.mPid;
5624 inputWindow.ownerUid = child.mSession.mUid;
5625
5626 final Rect frame = child.mFrame;
5627 inputWindow.frameLeft = frame.left;
5628 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005629 inputWindow.frameRight = frame.right;
5630 inputWindow.frameBottom = frame.bottom;
5631
5632 final Rect visibleFrame = child.mVisibleFrame;
5633 inputWindow.visibleFrameLeft = visibleFrame.left;
5634 inputWindow.visibleFrameTop = visibleFrame.top;
5635 inputWindow.visibleFrameRight = visibleFrame.right;
5636 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005637
5638 switch (child.mTouchableInsets) {
5639 default:
5640 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5641 inputWindow.touchableAreaLeft = frame.left;
5642 inputWindow.touchableAreaTop = frame.top;
5643 inputWindow.touchableAreaRight = frame.right;
5644 inputWindow.touchableAreaBottom = frame.bottom;
5645 break;
5646
5647 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5648 Rect inset = child.mGivenContentInsets;
5649 inputWindow.touchableAreaLeft = frame.left + inset.left;
5650 inputWindow.touchableAreaTop = frame.top + inset.top;
5651 inputWindow.touchableAreaRight = frame.right - inset.right;
5652 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5653 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005654 }
Jeff Brown349703e2010-06-22 01:27:15 -07005655
5656 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5657 Rect inset = child.mGivenVisibleInsets;
5658 inputWindow.touchableAreaLeft = frame.left + inset.left;
5659 inputWindow.touchableAreaTop = frame.top + inset.top;
5660 inputWindow.touchableAreaRight = frame.right - inset.right;
5661 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005662 break;
5663 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005664 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005665 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005666
Jeff Brown349703e2010-06-22 01:27:15 -07005667 // Send windows to native code.
5668 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005669
Jeff Brown349703e2010-06-22 01:27:15 -07005670 // Clear the list in preparation for the next round.
5671 // Also avoids keeping InputChannel objects referenced unnecessarily.
5672 mTempInputWindows.clear();
5673 }
5674
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005675 /* Notifies that the lid switch changed state. */
5676 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5677 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5678 }
5679
Jeff Brown349703e2010-06-22 01:27:15 -07005680 /* Provides an opportunity for the window manager policy to intercept early key
5681 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005682 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5683 int policyFlags, boolean isScreenOn) {
5684 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5685 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005686 }
5687
5688 /* Provides an opportunity for the window manager policy to process a key before
5689 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005690 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5691 int action, int flags, int keyCode, int metaState, int repeatCount,
5692 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005693 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005694 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5695 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005696 }
5697
5698 /* Called when the current input focus changes.
5699 * Layer assignment is assumed to be complete by the time this is called.
5700 */
5701 public void setInputFocusLw(WindowState newWindow) {
5702 if (DEBUG_INPUT) {
5703 Slog.d(TAG, "Input focus has changed to " + newWindow);
5704 }
5705
5706 if (newWindow != mInputFocus) {
5707 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005708 // Displaying a window implicitly causes dispatching to be unpaused.
5709 // This is to protect against bugs if someone pauses dispatching but
5710 // forgets to resume.
5711 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005712 }
Jeff Brown349703e2010-06-22 01:27:15 -07005713
5714 mInputFocus = newWindow;
5715 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005716 }
5717 }
5718
Jeff Brown349703e2010-06-22 01:27:15 -07005719 public void setFocusedAppLw(AppWindowToken newApp) {
5720 // Focused app has changed.
5721 if (newApp == null) {
5722 mInputManager.setFocusedApplication(null);
5723 } else {
5724 mTempInputApplication.name = newApp.toString();
5725 mTempInputApplication.dispatchingTimeoutNanos =
5726 newApp.inputDispatchingTimeoutNanos;
5727 mTempInputApplication.token = newApp;
5728
5729 mInputManager.setFocusedApplication(mTempInputApplication);
5730 }
5731 }
5732
Jeff Brown349703e2010-06-22 01:27:15 -07005733 public void pauseDispatchingLw(WindowToken window) {
5734 if (! window.paused) {
5735 if (DEBUG_INPUT) {
5736 Slog.v(TAG, "Pausing WindowToken " + window);
5737 }
5738
5739 window.paused = true;
5740 updateInputWindowsLw();
5741 }
5742 }
5743
5744 public void resumeDispatchingLw(WindowToken window) {
5745 if (window.paused) {
5746 if (DEBUG_INPUT) {
5747 Slog.v(TAG, "Resuming WindowToken " + window);
5748 }
5749
5750 window.paused = false;
5751 updateInputWindowsLw();
5752 }
5753 }
5754
5755 public void freezeInputDispatchingLw() {
5756 if (! mInputDispatchFrozen) {
5757 if (DEBUG_INPUT) {
5758 Slog.v(TAG, "Freezing input dispatching");
5759 }
5760
5761 mInputDispatchFrozen = true;
5762 updateInputDispatchModeLw();
5763 }
5764 }
5765
5766 public void thawInputDispatchingLw() {
5767 if (mInputDispatchFrozen) {
5768 if (DEBUG_INPUT) {
5769 Slog.v(TAG, "Thawing input dispatching");
5770 }
5771
5772 mInputDispatchFrozen = false;
5773 updateInputDispatchModeLw();
5774 }
5775 }
5776
5777 public void setEventDispatchingLw(boolean enabled) {
5778 if (mInputDispatchEnabled != enabled) {
5779 if (DEBUG_INPUT) {
5780 Slog.v(TAG, "Setting event dispatching to " + enabled);
5781 }
5782
5783 mInputDispatchEnabled = enabled;
5784 updateInputDispatchModeLw();
5785 }
5786 }
5787
5788 private void updateInputDispatchModeLw() {
5789 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5790 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005791 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005793 public void pauseKeyDispatching(IBinder _token) {
5794 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5795 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005796 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005797 }
5798
5799 synchronized (mWindowMap) {
5800 WindowToken token = mTokenMap.get(_token);
5801 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005802 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005803 }
5804 }
5805 }
5806
5807 public void resumeKeyDispatching(IBinder _token) {
5808 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5809 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005810 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005811 }
5812
5813 synchronized (mWindowMap) {
5814 WindowToken token = mTokenMap.get(_token);
5815 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005816 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005817 }
5818 }
5819 }
5820
5821 public void setEventDispatching(boolean enabled) {
5822 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5823 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005824 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005825 }
5826
5827 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005828 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005829 }
5830 }
Romain Guy06882f82009-06-10 13:36:04 -07005831
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005832 /**
5833 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005834 * Even when sync is false, this method may block while waiting for current
5835 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005836 *
5837 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005838 * {@link SystemClock#uptimeMillis()} as the timebase.)
5839 * @param sync If true, wait for the event to be completed before returning to the caller.
5840 * @return Returns true if event was dispatched, false if it was dropped for any reason
5841 */
5842 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5843 long downTime = ev.getDownTime();
5844 long eventTime = ev.getEventTime();
5845
5846 int action = ev.getAction();
5847 int code = ev.getKeyCode();
5848 int repeatCount = ev.getRepeatCount();
5849 int metaState = ev.getMetaState();
5850 int deviceId = ev.getDeviceId();
5851 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005852 int source = ev.getSource();
5853
5854 if (source == InputDevice.SOURCE_UNKNOWN) {
5855 source = InputDevice.SOURCE_KEYBOARD;
5856 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005857
5858 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5859 if (downTime == 0) downTime = eventTime;
5860
5861 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005862 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005863
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005864 final int pid = Binder.getCallingPid();
5865 final int uid = Binder.getCallingUid();
5866 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005867
Jeff Brownbbda99d2010-07-28 15:48:59 -07005868 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5869 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5870 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5871 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005872
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005873 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005874 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005875 }
5876
5877 /**
5878 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005879 * Even when sync is false, this method may block while waiting for current
5880 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005881 *
5882 * @param ev A motion event describing the pointer (touch) action. (As noted in
5883 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005884 * {@link SystemClock#uptimeMillis()} as the timebase.)
5885 * @param sync If true, wait for the event to be completed before returning to the caller.
5886 * @return Returns true if event was dispatched, false if it was dropped for any reason
5887 */
5888 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005889 final int pid = Binder.getCallingPid();
5890 final int uid = Binder.getCallingUid();
5891 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005892
Jeff Brownc5ed5912010-07-14 18:48:53 -07005893 MotionEvent newEvent = MotionEvent.obtain(ev);
5894 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5895 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5896 }
5897
Jeff Brownbbda99d2010-07-28 15:48:59 -07005898 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5899 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5900 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5901 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005902
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005903 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005904 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005905 }
Romain Guy06882f82009-06-10 13:36:04 -07005906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005907 /**
5908 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005909 * Even when sync is false, this method may block while waiting for current
5910 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005911 *
5912 * @param ev A motion event describing the trackball action. (As noted in
5913 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005914 * {@link SystemClock#uptimeMillis()} as the timebase.)
5915 * @param sync If true, wait for the event to be completed before returning to the caller.
5916 * @return Returns true if event was dispatched, false if it was dropped for any reason
5917 */
5918 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005919 final int pid = Binder.getCallingPid();
5920 final int uid = Binder.getCallingUid();
5921 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005922
Jeff Brownc5ed5912010-07-14 18:48:53 -07005923 MotionEvent newEvent = MotionEvent.obtain(ev);
5924 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5925 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5926 }
5927
Jeff Brownbbda99d2010-07-28 15:48:59 -07005928 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5929 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5930 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5931 INJECTION_TIMEOUT_MILLIS);
5932
5933 Binder.restoreCallingIdentity(ident);
5934 return reportInjectionResult(result);
5935 }
5936
5937 /**
5938 * Inject an input event into the UI without waiting for dispatch to commence.
5939 * This variant is useful for fire-and-forget input event injection. It does not
5940 * block any longer than it takes to enqueue the input event.
5941 *
5942 * @param ev An input event. (Be sure to set the input source correctly.)
5943 * @return Returns true if event was dispatched, false if it was dropped for any reason
5944 */
5945 public boolean injectInputEventNoWait(InputEvent ev) {
5946 final int pid = Binder.getCallingPid();
5947 final int uid = Binder.getCallingUid();
5948 final long ident = Binder.clearCallingIdentity();
5949
5950 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5951 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5952 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005953
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005954 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005955 return reportInjectionResult(result);
5956 }
5957
5958 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005959 switch (result) {
5960 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5961 Slog.w(TAG, "Input event injection permission denied.");
5962 throw new SecurityException(
5963 "Injecting to another application requires INJECT_EVENTS permission");
5964 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07005965 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005966 return true;
5967 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5968 Slog.w(TAG, "Input event injection timed out.");
5969 return false;
5970 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5971 default:
5972 Slog.w(TAG, "Input event injection failed.");
5973 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005974 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005975 }
Romain Guy06882f82009-06-10 13:36:04 -07005976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005977 private WindowState getFocusedWindow() {
5978 synchronized (mWindowMap) {
5979 return getFocusedWindowLocked();
5980 }
5981 }
5982
5983 private WindowState getFocusedWindowLocked() {
5984 return mCurrentFocus;
5985 }
Romain Guy06882f82009-06-10 13:36:04 -07005986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005987 public boolean detectSafeMode() {
5988 mSafeMode = mPolicy.detectSafeMode();
5989 return mSafeMode;
5990 }
Romain Guy06882f82009-06-10 13:36:04 -07005991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005992 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07005993 synchronized(mWindowMap) {
5994 if (mDisplay != null) {
5995 throw new IllegalStateException("Display already initialized");
5996 }
5997 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
5998 mDisplay = wm.getDefaultDisplay();
5999 mInitialDisplayWidth = mDisplay.getWidth();
6000 mInitialDisplayHeight = mDisplay.getHeight();
6001 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
6002 }
6003
6004 try {
6005 mActivityManager.updateConfiguration(null);
6006 } catch (RemoteException e) {
6007 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006008
6009 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006010 }
6011
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006012 // -------------------------------------------------------------
6013 // Client Session State
6014 // -------------------------------------------------------------
6015
6016 private final class Session extends IWindowSession.Stub
6017 implements IBinder.DeathRecipient {
6018 final IInputMethodClient mClient;
6019 final IInputContext mInputContext;
6020 final int mUid;
6021 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006022 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006023 SurfaceSession mSurfaceSession;
6024 int mNumWindow = 0;
6025 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006026
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006027 public Session(IInputMethodClient client, IInputContext inputContext) {
6028 mClient = client;
6029 mInputContext = inputContext;
6030 mUid = Binder.getCallingUid();
6031 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006032 StringBuilder sb = new StringBuilder();
6033 sb.append("Session{");
6034 sb.append(Integer.toHexString(System.identityHashCode(this)));
6035 sb.append(" uid ");
6036 sb.append(mUid);
6037 sb.append("}");
6038 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006040 synchronized (mWindowMap) {
6041 if (mInputMethodManager == null && mHaveInputMethods) {
6042 IBinder b = ServiceManager.getService(
6043 Context.INPUT_METHOD_SERVICE);
6044 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6045 }
6046 }
6047 long ident = Binder.clearCallingIdentity();
6048 try {
6049 // Note: it is safe to call in to the input method manager
6050 // here because we are not holding our lock.
6051 if (mInputMethodManager != null) {
6052 mInputMethodManager.addClient(client, inputContext,
6053 mUid, mPid);
6054 } else {
6055 client.setUsingInputMethod(false);
6056 }
6057 client.asBinder().linkToDeath(this, 0);
6058 } catch (RemoteException e) {
6059 // The caller has died, so we can just forget about this.
6060 try {
6061 if (mInputMethodManager != null) {
6062 mInputMethodManager.removeClient(client);
6063 }
6064 } catch (RemoteException ee) {
6065 }
6066 } finally {
6067 Binder.restoreCallingIdentity(ident);
6068 }
6069 }
Romain Guy06882f82009-06-10 13:36:04 -07006070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006071 @Override
6072 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6073 throws RemoteException {
6074 try {
6075 return super.onTransact(code, data, reply, flags);
6076 } catch (RuntimeException e) {
6077 // Log all 'real' exceptions thrown to the caller
6078 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006079 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006080 }
6081 throw e;
6082 }
6083 }
6084
6085 public void binderDied() {
6086 // Note: it is safe to call in to the input method manager
6087 // here because we are not holding our lock.
6088 try {
6089 if (mInputMethodManager != null) {
6090 mInputMethodManager.removeClient(mClient);
6091 }
6092 } catch (RemoteException e) {
6093 }
6094 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006095 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006096 mClientDead = true;
6097 killSessionLocked();
6098 }
6099 }
6100
6101 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006102 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6103 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6104 outInputChannel);
6105 }
6106
6107 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006108 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006109 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006110 }
Romain Guy06882f82009-06-10 13:36:04 -07006111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006112 public void remove(IWindow window) {
6113 removeWindow(this, window);
6114 }
Romain Guy06882f82009-06-10 13:36:04 -07006115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006116 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6117 int requestedWidth, int requestedHeight, int viewFlags,
6118 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006119 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006120 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6121 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006122 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006123 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006124 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6125 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006126 }
Romain Guy06882f82009-06-10 13:36:04 -07006127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006128 public void setTransparentRegion(IWindow window, Region region) {
6129 setTransparentRegionWindow(this, window, region);
6130 }
Romain Guy06882f82009-06-10 13:36:04 -07006131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006132 public void setInsets(IWindow window, int touchableInsets,
6133 Rect contentInsets, Rect visibleInsets) {
6134 setInsetsWindow(this, window, touchableInsets, contentInsets,
6135 visibleInsets);
6136 }
Romain Guy06882f82009-06-10 13:36:04 -07006137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006138 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6139 getWindowDisplayFrame(this, window, outDisplayFrame);
6140 }
Romain Guy06882f82009-06-10 13:36:04 -07006141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006142 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006143 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006144 TAG, "IWindow finishDrawing called for " + window);
6145 finishDrawingWindow(this, window);
6146 }
6147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006148 public void setInTouchMode(boolean mode) {
6149 synchronized(mWindowMap) {
6150 mInTouchMode = mode;
6151 }
6152 }
6153
6154 public boolean getInTouchMode() {
6155 synchronized(mWindowMap) {
6156 return mInTouchMode;
6157 }
6158 }
6159
6160 public boolean performHapticFeedback(IWindow window, int effectId,
6161 boolean always) {
6162 synchronized(mWindowMap) {
6163 long ident = Binder.clearCallingIdentity();
6164 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006165 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006166 windowForClientLocked(this, window, true),
6167 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006168 } finally {
6169 Binder.restoreCallingIdentity(ident);
6170 }
6171 }
6172 }
Romain Guy06882f82009-06-10 13:36:04 -07006173
Christopher Tatea53146c2010-09-07 11:57:52 -07006174 /* Drag/drop */
6175 public IBinder prepareDrag(IWindow window, boolean localOnly,
6176 int width, int height, Surface outSurface) {
6177 return prepareDragSurface(window, mSurfaceSession, localOnly,
6178 width, height, outSurface);
6179 }
6180
6181 public boolean performDrag(IWindow window, IBinder dragToken,
6182 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6183 ClipData data) {
6184 if (DEBUG_DRAG) {
6185 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6186 }
6187
6188 synchronized (mWindowMap) {
6189 if (mDragState == null) {
6190 Slog.w(TAG, "No drag prepared");
6191 throw new IllegalStateException("performDrag() without prepareDrag()");
6192 }
6193
6194 if (dragToken != mDragState.mToken) {
6195 Slog.w(TAG, "Performing mismatched drag");
6196 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6197 }
6198
6199 WindowState callingWin = windowForClientLocked(null, window, false);
6200 if (callingWin == null) {
6201 Slog.w(TAG, "Bad requesting window " + window);
6202 return false; // !!! TODO: throw here?
6203 }
6204
6205 // !!! TODO: if input is not still focused on the initiating window, fail
6206 // the drag initiation (e.g. an alarm window popped up just as the application
6207 // called performDrag()
6208
6209 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6210
Christopher Tate2c095f32010-10-04 14:13:40 -07006211 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6212 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006213
6214 mDragState.register();
6215 mInputMonitor.updateInputWindowsLw();
6216 mInputManager.transferTouchFocus(callingWin.mInputChannel,
6217 mDragState.mServerChannel);
6218
6219 mDragState.mData = data;
6220 mDragState.broadcastDragStartedLw();
6221
6222 // remember the thumb offsets for later
6223 mDragState.mThumbOffsetX = thumbCenterX;
6224 mDragState.mThumbOffsetY = thumbCenterY;
6225
6226 // Make the surface visible at the proper location
6227 final Surface surface = mDragState.mSurface;
6228 surface.openTransaction();
6229 try {
6230 surface.setPosition((int)(touchX - thumbCenterX),
6231 (int)(touchY - thumbCenterY));
6232 surface.setAlpha(.5f);
6233 surface.show();
6234 } finally {
6235 surface.closeTransaction();
6236 }
6237 }
6238
6239 return true; // success!
6240 }
6241
6242 public void dragRecipientEntered(IWindow window) {
6243 if (DEBUG_DRAG) {
6244 Slog.d(TAG, "Drag into new candidate view @ " + window);
6245 }
6246 }
6247
6248 public void dragRecipientExited(IWindow window) {
6249 if (DEBUG_DRAG) {
6250 Slog.d(TAG, "Drag from old candidate view @ " + window);
6251 }
6252 }
6253
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006254 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006255 synchronized(mWindowMap) {
6256 long ident = Binder.clearCallingIdentity();
6257 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006258 setWindowWallpaperPositionLocked(
6259 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006260 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006261 } finally {
6262 Binder.restoreCallingIdentity(ident);
6263 }
6264 }
6265 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006266
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006267 public void wallpaperOffsetsComplete(IBinder window) {
6268 WindowManagerService.this.wallpaperOffsetsComplete(window);
6269 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006270
Dianne Hackborn75804932009-10-20 20:15:20 -07006271 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6272 int z, Bundle extras, boolean sync) {
6273 synchronized(mWindowMap) {
6274 long ident = Binder.clearCallingIdentity();
6275 try {
6276 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006277 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006278 action, x, y, z, extras, sync);
6279 } finally {
6280 Binder.restoreCallingIdentity(ident);
6281 }
6282 }
6283 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006284
Dianne Hackborn75804932009-10-20 20:15:20 -07006285 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6286 WindowManagerService.this.wallpaperCommandComplete(window, result);
6287 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006289 void windowAddedLocked() {
6290 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006291 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006292 TAG, "First window added to " + this + ", creating SurfaceSession");
6293 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006294 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006295 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006296 mSessions.add(this);
6297 }
6298 mNumWindow++;
6299 }
6300
6301 void windowRemovedLocked() {
6302 mNumWindow--;
6303 killSessionLocked();
6304 }
Romain Guy06882f82009-06-10 13:36:04 -07006305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006306 void killSessionLocked() {
6307 if (mNumWindow <= 0 && mClientDead) {
6308 mSessions.remove(this);
6309 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006310 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006311 TAG, "Last window removed from " + this
6312 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006313 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006314 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006315 try {
6316 mSurfaceSession.kill();
6317 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006318 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006319 + mSurfaceSession + " in session " + this
6320 + ": " + e.toString());
6321 }
6322 mSurfaceSession = null;
6323 }
6324 }
6325 }
Romain Guy06882f82009-06-10 13:36:04 -07006326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006327 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006328 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6329 pw.print(" mClientDead="); pw.print(mClientDead);
6330 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006331 }
6332
6333 @Override
6334 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006335 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006336 }
6337 }
6338
6339 // -------------------------------------------------------------
6340 // Client Window State
6341 // -------------------------------------------------------------
6342
6343 private final class WindowState implements WindowManagerPolicy.WindowState {
6344 final Session mSession;
6345 final IWindow mClient;
6346 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006347 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006348 AppWindowToken mAppToken;
6349 AppWindowToken mTargetAppToken;
6350 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6351 final DeathRecipient mDeathRecipient;
6352 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006353 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006354 final int mBaseLayer;
6355 final int mSubLayer;
6356 final boolean mLayoutAttached;
6357 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006358 final boolean mIsWallpaper;
6359 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006360 int mViewVisibility;
6361 boolean mPolicyVisibility = true;
6362 boolean mPolicyVisibilityAfterAnim = true;
6363 boolean mAppFreezing;
6364 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006365 boolean mReportDestroySurface;
6366 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006367 boolean mAttachedHidden; // is our parent window hidden?
6368 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006369 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006370 int mRequestedWidth;
6371 int mRequestedHeight;
6372 int mLastRequestedWidth;
6373 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006374 int mLayer;
6375 int mAnimLayer;
6376 int mLastLayer;
6377 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006378 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006379 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006380
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006381 int mLayoutSeq = -1;
6382
6383 Configuration mConfiguration = null;
6384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006385 // Actual frame shown on-screen (may be modified by animation)
6386 final Rect mShownFrame = new Rect();
6387 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006389 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006390 * Set when we have changed the size of the surface, to know that
6391 * we must tell them application to resize (and thus redraw itself).
6392 */
6393 boolean mSurfaceResized;
6394
6395 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006396 * Insets that determine the actually visible area
6397 */
6398 final Rect mVisibleInsets = new Rect();
6399 final Rect mLastVisibleInsets = new Rect();
6400 boolean mVisibleInsetsChanged;
6401
6402 /**
6403 * Insets that are covered by system windows
6404 */
6405 final Rect mContentInsets = new Rect();
6406 final Rect mLastContentInsets = new Rect();
6407 boolean mContentInsetsChanged;
6408
6409 /**
6410 * Set to true if we are waiting for this window to receive its
6411 * given internal insets before laying out other windows based on it.
6412 */
6413 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006415 /**
6416 * These are the content insets that were given during layout for
6417 * this window, to be applied to windows behind it.
6418 */
6419 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006421 /**
6422 * These are the visible insets that were given during layout for
6423 * this window, to be applied to windows behind it.
6424 */
6425 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006427 /**
6428 * Flag indicating whether the touchable region should be adjusted by
6429 * the visible insets; if false the area outside the visible insets is
6430 * NOT touchable, so we must use those to adjust the frame during hit
6431 * tests.
6432 */
6433 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006435 // Current transformation being applied.
6436 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6437 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6438 float mHScale=1, mVScale=1;
6439 float mLastHScale=1, mLastVScale=1;
6440 final Matrix mTmpMatrix = new Matrix();
6441
6442 // "Real" frame that the application sees.
6443 final Rect mFrame = new Rect();
6444 final Rect mLastFrame = new Rect();
6445
6446 final Rect mContainingFrame = new Rect();
6447 final Rect mDisplayFrame = new Rect();
6448 final Rect mContentFrame = new Rect();
6449 final Rect mVisibleFrame = new Rect();
6450
6451 float mShownAlpha = 1;
6452 float mAlpha = 1;
6453 float mLastAlpha = 1;
6454
6455 // Set to true if, when the window gets displayed, it should perform
6456 // an enter animation.
6457 boolean mEnterAnimationPending;
6458
6459 // Currently running animation.
6460 boolean mAnimating;
6461 boolean mLocalAnimating;
6462 Animation mAnimation;
6463 boolean mAnimationIsEntrance;
6464 boolean mHasTransformation;
6465 boolean mHasLocalTransformation;
6466 final Transformation mTransformation = new Transformation();
6467
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006468 // If a window showing a wallpaper: the requested offset for the
6469 // wallpaper; if a wallpaper window: the currently applied offset.
6470 float mWallpaperX = -1;
6471 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006472
6473 // If a window showing a wallpaper: what fraction of the offset
6474 // range corresponds to a full virtual screen.
6475 float mWallpaperXStep = -1;
6476 float mWallpaperYStep = -1;
6477
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006478 // Wallpaper windows: pixels offset based on above variables.
6479 int mXOffset;
6480 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006482 // This is set after IWindowSession.relayout() has been called at
6483 // least once for the window. It allows us to detect the situation
6484 // where we don't yet have a surface, but should have one soon, so
6485 // we can give the window focus before waiting for the relayout.
6486 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006488 // This is set after the Surface has been created but before the
6489 // window has been drawn. During this time the surface is hidden.
6490 boolean mDrawPending;
6491
6492 // This is set after the window has finished drawing for the first
6493 // time but before its surface is shown. The surface will be
6494 // displayed when the next layout is run.
6495 boolean mCommitDrawPending;
6496
6497 // This is set during the time after the window's drawing has been
6498 // committed, and before its surface is actually shown. It is used
6499 // to delay showing the surface until all windows in a token are ready
6500 // to be shown.
6501 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006503 // Set when the window has been shown in the screen the first time.
6504 boolean mHasDrawn;
6505
6506 // Currently running an exit animation?
6507 boolean mExiting;
6508
6509 // Currently on the mDestroySurface list?
6510 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006512 // Completely remove from window manager after exit animation?
6513 boolean mRemoveOnExit;
6514
6515 // Set when the orientation is changing and this window has not yet
6516 // been updated for the new orientation.
6517 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006519 // Is this window now (or just being) removed?
6520 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006521
Dianne Hackborn16064f92010-03-25 00:47:24 -07006522 // For debugging, this is the last information given to the surface flinger.
6523 boolean mSurfaceShown;
6524 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6525 int mSurfaceLayer;
6526 float mSurfaceAlpha;
6527
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006528 // Input channel
6529 InputChannel mInputChannel;
6530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006531 WindowState(Session s, IWindow c, WindowToken token,
6532 WindowState attachedWindow, WindowManager.LayoutParams a,
6533 int viewVisibility) {
6534 mSession = s;
6535 mClient = c;
6536 mToken = token;
6537 mAttrs.copyFrom(a);
6538 mViewVisibility = viewVisibility;
6539 DeathRecipient deathRecipient = new DeathRecipient();
6540 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006541 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006542 TAG, "Window " + this + " client=" + c.asBinder()
6543 + " token=" + token + " (" + mAttrs.token + ")");
6544 try {
6545 c.asBinder().linkToDeath(deathRecipient, 0);
6546 } catch (RemoteException e) {
6547 mDeathRecipient = null;
6548 mAttachedWindow = null;
6549 mLayoutAttached = false;
6550 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006551 mIsWallpaper = false;
6552 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006553 mBaseLayer = 0;
6554 mSubLayer = 0;
6555 return;
6556 }
6557 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006559 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6560 mAttrs.type <= LAST_SUB_WINDOW)) {
6561 // The multiplier here is to reserve space for multiple
6562 // windows in the same type layer.
6563 mBaseLayer = mPolicy.windowTypeToLayerLw(
6564 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6565 + TYPE_LAYER_OFFSET;
6566 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6567 mAttachedWindow = attachedWindow;
6568 mAttachedWindow.mChildWindows.add(this);
6569 mLayoutAttached = mAttrs.type !=
6570 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6571 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6572 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006573 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6574 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006575 } else {
6576 // The multiplier here is to reserve space for multiple
6577 // windows in the same type layer.
6578 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6579 * TYPE_LAYER_MULTIPLIER
6580 + TYPE_LAYER_OFFSET;
6581 mSubLayer = 0;
6582 mAttachedWindow = null;
6583 mLayoutAttached = false;
6584 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6585 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006586 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6587 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006588 }
6589
6590 WindowState appWin = this;
6591 while (appWin.mAttachedWindow != null) {
6592 appWin = mAttachedWindow;
6593 }
6594 WindowToken appToken = appWin.mToken;
6595 while (appToken.appWindowToken == null) {
6596 WindowToken parent = mTokenMap.get(appToken.token);
6597 if (parent == null || appToken == parent) {
6598 break;
6599 }
6600 appToken = parent;
6601 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006602 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006603 mAppToken = appToken.appWindowToken;
6604
6605 mSurface = null;
6606 mRequestedWidth = 0;
6607 mRequestedHeight = 0;
6608 mLastRequestedWidth = 0;
6609 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006610 mXOffset = 0;
6611 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006612 mLayer = 0;
6613 mAnimLayer = 0;
6614 mLastLayer = 0;
6615 }
6616
6617 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006618 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006619 TAG, "Attaching " + this + " token=" + mToken
6620 + ", list=" + mToken.windows);
6621 mSession.windowAddedLocked();
6622 }
6623
6624 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6625 mHaveFrame = true;
6626
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006627 final Rect container = mContainingFrame;
6628 container.set(pf);
6629
6630 final Rect display = mDisplayFrame;
6631 display.set(df);
6632
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006633 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006634 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006635 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6636 display.intersect(mCompatibleScreenFrame);
6637 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006638 }
6639
6640 final int pw = container.right - container.left;
6641 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006642
6643 int w,h;
6644 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6645 w = mAttrs.width < 0 ? pw : mAttrs.width;
6646 h = mAttrs.height< 0 ? ph : mAttrs.height;
6647 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006648 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6649 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006650 }
Romain Guy06882f82009-06-10 13:36:04 -07006651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006652 final Rect content = mContentFrame;
6653 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006655 final Rect visible = mVisibleFrame;
6656 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006657
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006658 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006659 final int fw = frame.width();
6660 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006662 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6663 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6664
6665 Gravity.apply(mAttrs.gravity, w, h, container,
6666 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6667 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6668
6669 //System.out.println("Out: " + mFrame);
6670
6671 // Now make sure the window fits in the overall display.
6672 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006674 // Make sure the content and visible frames are inside of the
6675 // final window frame.
6676 if (content.left < frame.left) content.left = frame.left;
6677 if (content.top < frame.top) content.top = frame.top;
6678 if (content.right > frame.right) content.right = frame.right;
6679 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6680 if (visible.left < frame.left) visible.left = frame.left;
6681 if (visible.top < frame.top) visible.top = frame.top;
6682 if (visible.right > frame.right) visible.right = frame.right;
6683 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006685 final Rect contentInsets = mContentInsets;
6686 contentInsets.left = content.left-frame.left;
6687 contentInsets.top = content.top-frame.top;
6688 contentInsets.right = frame.right-content.right;
6689 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006691 final Rect visibleInsets = mVisibleInsets;
6692 visibleInsets.left = visible.left-frame.left;
6693 visibleInsets.top = visible.top-frame.top;
6694 visibleInsets.right = frame.right-visible.right;
6695 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006696
Dianne Hackborn284ac932009-08-28 10:34:25 -07006697 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6698 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006699 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006700 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006702 if (localLOGV) {
6703 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6704 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006705 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006706 + mRequestedWidth + ", mRequestedheight="
6707 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6708 + "): frame=" + mFrame.toShortString()
6709 + " ci=" + contentInsets.toShortString()
6710 + " vi=" + visibleInsets.toShortString());
6711 //}
6712 }
6713 }
Romain Guy06882f82009-06-10 13:36:04 -07006714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006715 public Rect getFrameLw() {
6716 return mFrame;
6717 }
6718
6719 public Rect getShownFrameLw() {
6720 return mShownFrame;
6721 }
6722
6723 public Rect getDisplayFrameLw() {
6724 return mDisplayFrame;
6725 }
6726
6727 public Rect getContentFrameLw() {
6728 return mContentFrame;
6729 }
6730
6731 public Rect getVisibleFrameLw() {
6732 return mVisibleFrame;
6733 }
6734
6735 public boolean getGivenInsetsPendingLw() {
6736 return mGivenInsetsPending;
6737 }
6738
6739 public Rect getGivenContentInsetsLw() {
6740 return mGivenContentInsets;
6741 }
Romain Guy06882f82009-06-10 13:36:04 -07006742
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006743 public Rect getGivenVisibleInsetsLw() {
6744 return mGivenVisibleInsets;
6745 }
Romain Guy06882f82009-06-10 13:36:04 -07006746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006747 public WindowManager.LayoutParams getAttrs() {
6748 return mAttrs;
6749 }
6750
6751 public int getSurfaceLayer() {
6752 return mLayer;
6753 }
Romain Guy06882f82009-06-10 13:36:04 -07006754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006755 public IApplicationToken getAppToken() {
6756 return mAppToken != null ? mAppToken.appToken : null;
6757 }
Jeff Brown349703e2010-06-22 01:27:15 -07006758
6759 public long getInputDispatchingTimeoutNanos() {
6760 return mAppToken != null
6761 ? mAppToken.inputDispatchingTimeoutNanos
6762 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6763 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006764
6765 public boolean hasAppShownWindows() {
6766 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6767 }
6768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006769 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006770 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006771 TAG, "Setting animation in " + this + ": " + anim);
6772 mAnimating = false;
6773 mLocalAnimating = false;
6774 mAnimation = anim;
6775 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6776 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6777 }
6778
6779 public void clearAnimation() {
6780 if (mAnimation != null) {
6781 mAnimating = true;
6782 mLocalAnimating = false;
6783 mAnimation = null;
6784 }
6785 }
Romain Guy06882f82009-06-10 13:36:04 -07006786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006787 Surface createSurfaceLocked() {
6788 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006789 mReportDestroySurface = false;
6790 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006791 mDrawPending = true;
6792 mCommitDrawPending = false;
6793 mReadyToShow = false;
6794 if (mAppToken != null) {
6795 mAppToken.allDrawn = false;
6796 }
6797
6798 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006799 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006800 flags |= Surface.PUSH_BUFFERS;
6801 }
6802
6803 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6804 flags |= Surface.SECURE;
6805 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006806 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006807 TAG, "Creating surface in session "
6808 + mSession.mSurfaceSession + " window " + this
6809 + " w=" + mFrame.width()
6810 + " h=" + mFrame.height() + " format="
6811 + mAttrs.format + " flags=" + flags);
6812
6813 int w = mFrame.width();
6814 int h = mFrame.height();
6815 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6816 // for a scaled surface, we always want the requested
6817 // size.
6818 w = mRequestedWidth;
6819 h = mRequestedHeight;
6820 }
6821
Romain Guy9825ec62009-10-01 00:58:09 -07006822 // Something is wrong and SurfaceFlinger will not like this,
6823 // try to revert to sane values
6824 if (w <= 0) w = 1;
6825 if (h <= 0) h = 1;
6826
Dianne Hackborn16064f92010-03-25 00:47:24 -07006827 mSurfaceShown = false;
6828 mSurfaceLayer = 0;
6829 mSurfaceAlpha = 1;
6830 mSurfaceX = 0;
6831 mSurfaceY = 0;
6832 mSurfaceW = w;
6833 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006834 try {
Romain Guyd10cd572010-10-10 13:33:22 -07006835 final boolean isHwAccelerated = (mAttrs.flags &
6836 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
6837 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
6838 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
6839 flags |= Surface.OPAQUE;
6840 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006841 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006842 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006843 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07006844 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006845 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006846 + mSurface + " IN SESSION "
6847 + mSession.mSurfaceSession
6848 + ": pid=" + mSession.mPid + " format="
6849 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006850 + Integer.toHexString(flags)
6851 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006852 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006853 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006854 reclaimSomeSurfaceMemoryLocked(this, "create");
6855 return null;
6856 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006857 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006858 return null;
6859 }
Romain Guy06882f82009-06-10 13:36:04 -07006860
Joe Onorato8a9b2202010-02-26 18:56:32 -08006861 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006862 TAG, "Got surface: " + mSurface
6863 + ", set left=" + mFrame.left + " top=" + mFrame.top
6864 + ", animLayer=" + mAnimLayer);
6865 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006866 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006867 if (SHOW_TRANSACTIONS) logSurface(this,
6868 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6869 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6870 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006871 }
6872 Surface.openTransaction();
6873 try {
6874 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006875 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006876 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006877 mSurface.setPosition(mSurfaceX, mSurfaceY);
6878 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006879 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006880 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006881 mSurface.hide();
6882 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006883 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006884 mSurface.setFlags(Surface.SURFACE_DITHER,
6885 Surface.SURFACE_DITHER);
6886 }
6887 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006888 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006889 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6890 }
6891 mLastHidden = true;
6892 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006893 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006894 Surface.closeTransaction();
6895 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006896 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006897 TAG, "Created surface " + this);
6898 }
6899 return mSurface;
6900 }
Romain Guy06882f82009-06-10 13:36:04 -07006901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006902 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006903 if (mAppToken != null && this == mAppToken.startingWindow) {
6904 mAppToken.startingDisplayed = false;
6905 }
Romain Guy06882f82009-06-10 13:36:04 -07006906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006907 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006908 mDrawPending = false;
6909 mCommitDrawPending = false;
6910 mReadyToShow = false;
6911
6912 int i = mChildWindows.size();
6913 while (i > 0) {
6914 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006915 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006916 c.mAttachedHidden = true;
6917 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006918
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006919 if (mReportDestroySurface) {
6920 mReportDestroySurface = false;
6921 mSurfacePendingDestroy = true;
6922 try {
6923 mClient.dispatchGetNewSurface();
6924 // We'll really destroy on the next time around.
6925 return;
6926 } catch (RemoteException e) {
6927 }
6928 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006930 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006931 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006932 RuntimeException e = null;
6933 if (!HIDE_STACK_CRAWLS) {
6934 e = new RuntimeException();
6935 e.fillInStackTrace();
6936 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006937 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006938 + mSurface + ", session " + mSession, e);
6939 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006940 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006941 RuntimeException e = null;
6942 if (!HIDE_STACK_CRAWLS) {
6943 e = new RuntimeException();
6944 e.fillInStackTrace();
6945 }
6946 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006947 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006948 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006949 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006950 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006951 + " surface " + mSurface + " session " + mSession
6952 + ": " + e.toString());
6953 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006954
Dianne Hackborn16064f92010-03-25 00:47:24 -07006955 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006956 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006957 }
6958 }
6959
6960 boolean finishDrawingLocked() {
6961 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006962 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006963 TAG, "finishDrawingLocked: " + mSurface);
6964 mCommitDrawPending = true;
6965 mDrawPending = false;
6966 return true;
6967 }
6968 return false;
6969 }
6970
6971 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006972 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006973 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006974 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006975 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006976 }
6977 mCommitDrawPending = false;
6978 mReadyToShow = true;
6979 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6980 final AppWindowToken atoken = mAppToken;
6981 if (atoken == null || atoken.allDrawn || starting) {
6982 performShowLocked();
6983 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006984 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006985 }
6986
6987 // This must be called while inside a transaction.
6988 boolean performShowLocked() {
6989 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006990 RuntimeException e = null;
6991 if (!HIDE_STACK_CRAWLS) {
6992 e = new RuntimeException();
6993 e.fillInStackTrace();
6994 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006995 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006996 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
6997 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
6998 }
6999 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007000 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7001 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007002 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007003 + " during animation: policyVis=" + mPolicyVisibility
7004 + " attHidden=" + mAttachedHidden
7005 + " tok.hiddenRequested="
7006 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007007 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007008 + (mAppToken != null ? mAppToken.hidden : false)
7009 + " animating=" + mAnimating
7010 + " tok animating="
7011 + (mAppToken != null ? mAppToken.animating : false));
7012 if (!showSurfaceRobustlyLocked(this)) {
7013 return false;
7014 }
7015 mLastAlpha = -1;
7016 mHasDrawn = true;
7017 mLastHidden = false;
7018 mReadyToShow = false;
7019 enableScreenIfNeededLocked();
7020
7021 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007023 int i = mChildWindows.size();
7024 while (i > 0) {
7025 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007026 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007027 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007028 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007029 if (c.mSurface != null) {
7030 c.performShowLocked();
7031 // It hadn't been shown, which means layout not
7032 // performed on it, so now we want to make sure to
7033 // do a layout. If called from within the transaction
7034 // loop, this will cause it to restart with a new
7035 // layout.
7036 mLayoutNeeded = true;
7037 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007038 }
7039 }
Romain Guy06882f82009-06-10 13:36:04 -07007040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007041 if (mAttrs.type != TYPE_APPLICATION_STARTING
7042 && mAppToken != null) {
7043 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007044
Dianne Hackborn248b1882009-09-16 16:46:44 -07007045 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007046 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007047 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007048 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007049 // If this initial window is animating, stop it -- we
7050 // will do an animation to reveal it from behind the
7051 // starting window, so there is no need for it to also
7052 // be doing its own stuff.
7053 if (mAnimation != null) {
7054 mAnimation = null;
7055 // Make sure we clean up the animation.
7056 mAnimating = true;
7057 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007058 mFinishedStarting.add(mAppToken);
7059 mH.sendEmptyMessage(H.FINISHED_STARTING);
7060 }
7061 mAppToken.updateReportedVisibilityLocked();
7062 }
7063 }
7064 return true;
7065 }
Romain Guy06882f82009-06-10 13:36:04 -07007066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007067 // This must be called while inside a transaction. Returns true if
7068 // there is more animation to run.
7069 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007070 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007071 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007073 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7074 mHasTransformation = true;
7075 mHasLocalTransformation = true;
7076 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007077 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007078 TAG, "Starting animation in " + this +
7079 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7080 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7081 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7082 mAnimation.setStartTime(currentTime);
7083 mLocalAnimating = true;
7084 mAnimating = true;
7085 }
7086 mTransformation.clear();
7087 final boolean more = mAnimation.getTransformation(
7088 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007089 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007090 TAG, "Stepped animation in " + this +
7091 ": more=" + more + ", xform=" + mTransformation);
7092 if (more) {
7093 // we're not done!
7094 return true;
7095 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007096 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007097 TAG, "Finished animation in " + this +
7098 " @ " + currentTime);
7099 mAnimation = null;
7100 //WindowManagerService.this.dump();
7101 }
7102 mHasLocalTransformation = false;
7103 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007104 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007105 // When our app token is animating, we kind-of pretend like
7106 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7107 // part of this check means that we will only do this if
7108 // our window is not currently exiting, or it is not
7109 // locally animating itself. The idea being that one that
7110 // is exiting and doing a local animation should be removed
7111 // once that animation is done.
7112 mAnimating = true;
7113 mHasTransformation = true;
7114 mTransformation.clear();
7115 return false;
7116 } else if (mHasTransformation) {
7117 // Little trick to get through the path below to act like
7118 // we have finished an animation.
7119 mAnimating = true;
7120 } else if (isAnimating()) {
7121 mAnimating = true;
7122 }
7123 } else if (mAnimation != null) {
7124 // If the display is frozen, and there is a pending animation,
7125 // clear it and make sure we run the cleanup code.
7126 mAnimating = true;
7127 mLocalAnimating = true;
7128 mAnimation = null;
7129 }
Romain Guy06882f82009-06-10 13:36:04 -07007130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007131 if (!mAnimating && !mLocalAnimating) {
7132 return false;
7133 }
7134
Joe Onorato8a9b2202010-02-26 18:56:32 -08007135 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007136 TAG, "Animation done in " + this + ": exiting=" + mExiting
7137 + ", reportedVisible="
7138 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007140 mAnimating = false;
7141 mLocalAnimating = false;
7142 mAnimation = null;
7143 mAnimLayer = mLayer;
7144 if (mIsImWindow) {
7145 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007146 } else if (mIsWallpaper) {
7147 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007148 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007149 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007150 + " anim layer: " + mAnimLayer);
7151 mHasTransformation = false;
7152 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007153 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7154 if (DEBUG_VISIBILITY) {
7155 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7156 + mPolicyVisibilityAfterAnim);
7157 }
7158 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7159 if (!mPolicyVisibility) {
7160 if (mCurrentFocus == this) {
7161 mFocusMayChange = true;
7162 }
7163 // Window is no longer visible -- make sure if we were waiting
7164 // for it to be displayed before enabling the display, that
7165 // we allow the display to be enabled now.
7166 enableScreenIfNeededLocked();
7167 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007168 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007169 mTransformation.clear();
7170 if (mHasDrawn
7171 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7172 && mAppToken != null
7173 && mAppToken.firstWindowDrawn
7174 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007175 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007176 + mToken + ": first real window done animating");
7177 mFinishedStarting.add(mAppToken);
7178 mH.sendEmptyMessage(H.FINISHED_STARTING);
7179 }
Romain Guy06882f82009-06-10 13:36:04 -07007180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007181 finishExit();
7182
7183 if (mAppToken != null) {
7184 mAppToken.updateReportedVisibilityLocked();
7185 }
7186
7187 return false;
7188 }
7189
7190 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007191 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007192 TAG, "finishExit in " + this
7193 + ": exiting=" + mExiting
7194 + " remove=" + mRemoveOnExit
7195 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007197 final int N = mChildWindows.size();
7198 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007199 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007200 }
Romain Guy06882f82009-06-10 13:36:04 -07007201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007202 if (!mExiting) {
7203 return;
7204 }
Romain Guy06882f82009-06-10 13:36:04 -07007205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007206 if (isWindowAnimating()) {
7207 return;
7208 }
7209
Joe Onorato8a9b2202010-02-26 18:56:32 -08007210 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007211 TAG, "Exit animation finished in " + this
7212 + ": remove=" + mRemoveOnExit);
7213 if (mSurface != null) {
7214 mDestroySurface.add(this);
7215 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007216 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007217 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007218 try {
7219 mSurface.hide();
7220 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007221 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007222 }
7223 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007224 }
7225 mExiting = false;
7226 if (mRemoveOnExit) {
7227 mPendingRemove.add(this);
7228 mRemoveOnExit = false;
7229 }
7230 }
Romain Guy06882f82009-06-10 13:36:04 -07007231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007232 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7233 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7234 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7235 if (dtdx < -.000001f || dtdx > .000001f) return false;
7236 if (dsdy < -.000001f || dsdy > .000001f) return false;
7237 return true;
7238 }
Romain Guy06882f82009-06-10 13:36:04 -07007239
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007240 void computeShownFrameLocked() {
7241 final boolean selfTransformation = mHasLocalTransformation;
7242 Transformation attachedTransformation =
7243 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7244 ? mAttachedWindow.mTransformation : null;
7245 Transformation appTransformation =
7246 (mAppToken != null && mAppToken.hasTransformation)
7247 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007248
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007249 // Wallpapers are animated based on the "real" window they
7250 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007251 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007252 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007253 if (mWallpaperTarget.mHasLocalTransformation &&
7254 mWallpaperTarget.mAnimation != null &&
7255 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007256 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007257 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007258 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007259 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007260 }
7261 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007262 mWallpaperTarget.mAppToken.hasTransformation &&
7263 mWallpaperTarget.mAppToken.animation != null &&
7264 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007265 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007266 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007267 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007268 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007269 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007270 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007272 if (selfTransformation || attachedTransformation != null
7273 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007274 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007275 final Rect frame = mFrame;
7276 final float tmpFloats[] = mTmpFloats;
7277 final Matrix tmpMatrix = mTmpMatrix;
7278
7279 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007280 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007281 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007282 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007283 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007284 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007285 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007286 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007287 }
7288 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007289 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007290 }
7291
7292 // "convert" it into SurfaceFlinger's format
7293 // (a 2x2 matrix + an offset)
7294 // Here we must not transform the position of the surface
7295 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007296 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007298 tmpMatrix.getValues(tmpFloats);
7299 mDsDx = tmpFloats[Matrix.MSCALE_X];
7300 mDtDx = tmpFloats[Matrix.MSKEW_X];
7301 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7302 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007303 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7304 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007305 int w = frame.width();
7306 int h = frame.height();
7307 mShownFrame.set(x, y, x+w, y+h);
7308
7309 // Now set the alpha... but because our current hardware
7310 // can't do alpha transformation on a non-opaque surface,
7311 // turn it off if we are running an animation that is also
7312 // transforming since it is more important to have that
7313 // animation be smooth.
7314 mShownAlpha = mAlpha;
7315 if (!mLimitedAlphaCompositing
7316 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7317 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7318 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007319 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007320 if (selfTransformation) {
7321 mShownAlpha *= mTransformation.getAlpha();
7322 }
7323 if (attachedTransformation != null) {
7324 mShownAlpha *= attachedTransformation.getAlpha();
7325 }
7326 if (appTransformation != null) {
7327 mShownAlpha *= appTransformation.getAlpha();
7328 }
7329 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007330 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007331 }
Romain Guy06882f82009-06-10 13:36:04 -07007332
Joe Onorato8a9b2202010-02-26 18:56:32 -08007333 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007334 TAG, "Continuing animation in " + this +
7335 ": " + mShownFrame +
7336 ", alpha=" + mTransformation.getAlpha());
7337 return;
7338 }
Romain Guy06882f82009-06-10 13:36:04 -07007339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007340 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007341 if (mXOffset != 0 || mYOffset != 0) {
7342 mShownFrame.offset(mXOffset, mYOffset);
7343 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007344 mShownAlpha = mAlpha;
7345 mDsDx = 1;
7346 mDtDx = 0;
7347 mDsDy = 0;
7348 mDtDy = 1;
7349 }
Romain Guy06882f82009-06-10 13:36:04 -07007350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007351 /**
7352 * Is this window visible? It is not visible if there is no
7353 * surface, or we are in the process of running an exit animation
7354 * that will remove the surface, or its app token has been hidden.
7355 */
7356 public boolean isVisibleLw() {
7357 final AppWindowToken atoken = mAppToken;
7358 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7359 && (atoken == null || !atoken.hiddenRequested)
7360 && !mExiting && !mDestroying;
7361 }
7362
7363 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007364 * Like {@link #isVisibleLw}, but also counts a window that is currently
7365 * "hidden" behind the keyguard as visible. This allows us to apply
7366 * things like window flags that impact the keyguard.
7367 * XXX I am starting to think we need to have ANOTHER visibility flag
7368 * for this "hidden behind keyguard" state rather than overloading
7369 * mPolicyVisibility. Ungh.
7370 */
7371 public boolean isVisibleOrBehindKeyguardLw() {
7372 final AppWindowToken atoken = mAppToken;
7373 return mSurface != null && !mAttachedHidden
7374 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007375 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007376 && !mExiting && !mDestroying;
7377 }
7378
7379 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007380 * Is this window visible, ignoring its app token? It is not visible
7381 * if there is no surface, or we are in the process of running an exit animation
7382 * that will remove the surface.
7383 */
7384 public boolean isWinVisibleLw() {
7385 final AppWindowToken atoken = mAppToken;
7386 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7387 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7388 && !mExiting && !mDestroying;
7389 }
7390
7391 /**
7392 * The same as isVisible(), but follows the current hidden state of
7393 * the associated app token, not the pending requested hidden state.
7394 */
7395 boolean isVisibleNow() {
7396 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007397 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007398 }
7399
7400 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007401 * Can this window possibly be a drag/drop target? The test here is
7402 * a combination of the above "visible now" with the check that the
7403 * Input Manager uses when discarding windows from input consideration.
7404 */
7405 boolean isPotentialDragTarget() {
7406 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7407 }
7408
7409 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007410 * Same as isVisible(), but we also count it as visible between the
7411 * call to IWindowSession.add() and the first relayout().
7412 */
7413 boolean isVisibleOrAdding() {
7414 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007415 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007416 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7417 && mPolicyVisibility && !mAttachedHidden
7418 && (atoken == null || !atoken.hiddenRequested)
7419 && !mExiting && !mDestroying;
7420 }
7421
7422 /**
7423 * Is this window currently on-screen? It is on-screen either if it
7424 * is visible or it is currently running an animation before no longer
7425 * being visible.
7426 */
7427 boolean isOnScreen() {
7428 final AppWindowToken atoken = mAppToken;
7429 if (atoken != null) {
7430 return mSurface != null && mPolicyVisibility && !mDestroying
7431 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007432 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007433 } else {
7434 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007435 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007436 }
7437 }
Romain Guy06882f82009-06-10 13:36:04 -07007438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007439 /**
7440 * Like isOnScreen(), but we don't return true if the window is part
7441 * of a transition that has not yet been started.
7442 */
7443 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007444 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007445 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007446 return false;
7447 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007448 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007449 final boolean animating = atoken != null
7450 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007451 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007452 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7453 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007454 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007455 }
7456
7457 /** Is the window or its container currently animating? */
7458 boolean isAnimating() {
7459 final WindowState attached = mAttachedWindow;
7460 final AppWindowToken atoken = mAppToken;
7461 return mAnimation != null
7462 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007463 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007464 (atoken.animation != null
7465 || atoken.inPendingTransaction));
7466 }
7467
7468 /** Is this window currently animating? */
7469 boolean isWindowAnimating() {
7470 return mAnimation != null;
7471 }
7472
7473 /**
7474 * Like isOnScreen, but returns false if the surface hasn't yet
7475 * been drawn.
7476 */
7477 public boolean isDisplayedLw() {
7478 final AppWindowToken atoken = mAppToken;
7479 return mSurface != null && mPolicyVisibility && !mDestroying
7480 && !mDrawPending && !mCommitDrawPending
7481 && ((!mAttachedHidden &&
7482 (atoken == null || !atoken.hiddenRequested))
7483 || mAnimating);
7484 }
7485
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007486 /**
7487 * Returns true if the window has a surface that it has drawn a
7488 * complete UI in to.
7489 */
7490 public boolean isDrawnLw() {
7491 final AppWindowToken atoken = mAppToken;
7492 return mSurface != null && !mDestroying
7493 && !mDrawPending && !mCommitDrawPending;
7494 }
7495
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007496 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007497 * Return true if the window is opaque and fully drawn. This indicates
7498 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007499 */
7500 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007501 return (mAttrs.format == PixelFormat.OPAQUE
7502 || mAttrs.type == TYPE_WALLPAPER)
7503 && mSurface != null && mAnimation == null
7504 && (mAppToken == null || mAppToken.animation == null)
7505 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007506 }
7507
7508 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7509 return
7510 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007511 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7512 // only if it's visible
7513 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007514 // and only if the application fills the compatible screen
7515 mFrame.left <= mCompatibleScreenFrame.left &&
7516 mFrame.top <= mCompatibleScreenFrame.top &&
7517 mFrame.right >= mCompatibleScreenFrame.right &&
7518 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007519 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007520 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007521 }
7522
7523 boolean isFullscreen(int screenWidth, int screenHeight) {
7524 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007525 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007526 }
7527
7528 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007529 disposeInputChannel();
7530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007531 if (mAttachedWindow != null) {
7532 mAttachedWindow.mChildWindows.remove(this);
7533 }
7534 destroySurfaceLocked();
7535 mSession.windowRemovedLocked();
7536 try {
7537 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7538 } catch (RuntimeException e) {
7539 // Ignore if it has already been removed (usually because
7540 // we are doing this as part of processing a death note.)
7541 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007542 }
7543
7544 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007545 if (mInputChannel != null) {
7546 mInputManager.unregisterInputChannel(mInputChannel);
7547
7548 mInputChannel.dispose();
7549 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007550 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007551 }
7552
7553 private class DeathRecipient implements IBinder.DeathRecipient {
7554 public void binderDied() {
7555 try {
7556 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007557 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007558 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007559 if (win != null) {
7560 removeWindowLocked(mSession, win);
7561 }
7562 }
7563 } catch (IllegalArgumentException ex) {
7564 // This will happen if the window has already been
7565 // removed.
7566 }
7567 }
7568 }
7569
7570 /** Returns true if this window desires key events. */
7571 public final boolean canReceiveKeys() {
7572 return isVisibleOrAdding()
7573 && (mViewVisibility == View.VISIBLE)
7574 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7575 }
7576
7577 public boolean hasDrawnLw() {
7578 return mHasDrawn;
7579 }
7580
7581 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007582 return showLw(doAnimation, true);
7583 }
7584
7585 boolean showLw(boolean doAnimation, boolean requestAnim) {
7586 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7587 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007588 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007589 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007590 if (doAnimation) {
7591 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7592 + mPolicyVisibility + " mAnimation=" + mAnimation);
7593 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7594 doAnimation = false;
7595 } else if (mPolicyVisibility && mAnimation == null) {
7596 // Check for the case where we are currently visible and
7597 // not animating; we do not want to do animation at such a
7598 // point to become visible when we already are.
7599 doAnimation = false;
7600 }
7601 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007602 mPolicyVisibility = true;
7603 mPolicyVisibilityAfterAnim = true;
7604 if (doAnimation) {
7605 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7606 }
7607 if (requestAnim) {
7608 requestAnimationLocked(0);
7609 }
7610 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007611 }
7612
7613 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007614 return hideLw(doAnimation, true);
7615 }
7616
7617 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007618 if (doAnimation) {
7619 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7620 doAnimation = false;
7621 }
7622 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007623 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7624 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007625 if (!current) {
7626 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007627 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007628 if (doAnimation) {
7629 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7630 if (mAnimation == null) {
7631 doAnimation = false;
7632 }
7633 }
7634 if (doAnimation) {
7635 mPolicyVisibilityAfterAnim = false;
7636 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007637 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007638 mPolicyVisibilityAfterAnim = false;
7639 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007640 // Window is no longer visible -- make sure if we were waiting
7641 // for it to be displayed before enabling the display, that
7642 // we allow the display to be enabled now.
7643 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007644 if (mCurrentFocus == this) {
7645 mFocusMayChange = true;
7646 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007647 }
7648 if (requestAnim) {
7649 requestAnimationLocked(0);
7650 }
7651 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007652 }
7653
7654 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007655 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7656 pw.print(" mClient="); pw.println(mClient.asBinder());
7657 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7658 if (mAttachedWindow != null || mLayoutAttached) {
7659 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7660 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7661 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007662 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7663 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7664 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007665 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7666 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007667 }
7668 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7669 pw.print(" mSubLayer="); pw.print(mSubLayer);
7670 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7671 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7672 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7673 pw.print("="); pw.print(mAnimLayer);
7674 pw.print(" mLastLayer="); pw.println(mLastLayer);
7675 if (mSurface != null) {
7676 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007677 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7678 pw.print(" layer="); pw.print(mSurfaceLayer);
7679 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7680 pw.print(" rect=("); pw.print(mSurfaceX);
7681 pw.print(","); pw.print(mSurfaceY);
7682 pw.print(") "); pw.print(mSurfaceW);
7683 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007684 }
7685 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7686 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7687 if (mAppToken != null) {
7688 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7689 }
7690 if (mTargetAppToken != null) {
7691 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7692 }
7693 pw.print(prefix); pw.print("mViewVisibility=0x");
7694 pw.print(Integer.toHexString(mViewVisibility));
7695 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007696 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7697 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007698 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7699 pw.print(prefix); pw.print("mPolicyVisibility=");
7700 pw.print(mPolicyVisibility);
7701 pw.print(" mPolicyVisibilityAfterAnim=");
7702 pw.print(mPolicyVisibilityAfterAnim);
7703 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7704 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007705 if (!mRelayoutCalled) {
7706 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7707 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007708 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007709 pw.print(" h="); pw.print(mRequestedHeight);
7710 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007711 if (mXOffset != 0 || mYOffset != 0) {
7712 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7713 pw.print(" y="); pw.println(mYOffset);
7714 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007715 pw.print(prefix); pw.print("mGivenContentInsets=");
7716 mGivenContentInsets.printShortString(pw);
7717 pw.print(" mGivenVisibleInsets=");
7718 mGivenVisibleInsets.printShortString(pw);
7719 pw.println();
7720 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7721 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7722 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7723 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007724 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007725 pw.print(prefix); pw.print("mShownFrame=");
7726 mShownFrame.printShortString(pw);
7727 pw.print(" last="); mLastShownFrame.printShortString(pw);
7728 pw.println();
7729 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7730 pw.print(" last="); mLastFrame.printShortString(pw);
7731 pw.println();
7732 pw.print(prefix); pw.print("mContainingFrame=");
7733 mContainingFrame.printShortString(pw);
7734 pw.print(" mDisplayFrame=");
7735 mDisplayFrame.printShortString(pw);
7736 pw.println();
7737 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7738 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7739 pw.println();
7740 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7741 pw.print(" last="); mLastContentInsets.printShortString(pw);
7742 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7743 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7744 pw.println();
7745 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7746 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7747 pw.print(" mAlpha="); pw.print(mAlpha);
7748 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7749 }
7750 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7751 || mAnimation != null) {
7752 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7753 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7754 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7755 pw.print(" mAnimation="); pw.println(mAnimation);
7756 }
7757 if (mHasTransformation || mHasLocalTransformation) {
7758 pw.print(prefix); pw.print("XForm: has=");
7759 pw.print(mHasTransformation);
7760 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7761 pw.print(" "); mTransformation.printShortString(pw);
7762 pw.println();
7763 }
7764 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7765 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7766 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7767 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7768 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7769 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7770 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7771 pw.print(" mDestroying="); pw.print(mDestroying);
7772 pw.print(" mRemoved="); pw.println(mRemoved);
7773 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007774 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007775 pw.print(prefix); pw.print("mOrientationChanging=");
7776 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007777 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7778 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007779 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007780 if (mHScale != 1 || mVScale != 1) {
7781 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7782 pw.print(" mVScale="); pw.println(mVScale);
7783 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007784 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007785 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7786 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7787 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007788 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7789 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7790 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7791 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007792 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007793
7794 String makeInputChannelName() {
7795 return Integer.toHexString(System.identityHashCode(this))
7796 + " " + mAttrs.getTitle();
7797 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007798
7799 @Override
7800 public String toString() {
7801 return "Window{"
7802 + Integer.toHexString(System.identityHashCode(this))
7803 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7804 }
7805 }
Romain Guy06882f82009-06-10 13:36:04 -07007806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007807 // -------------------------------------------------------------
7808 // Window Token State
7809 // -------------------------------------------------------------
7810
7811 class WindowToken {
7812 // The actual token.
7813 final IBinder token;
7814
7815 // The type of window this token is for, as per WindowManager.LayoutParams.
7816 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007818 // Set if this token was explicitly added by a client, so should
7819 // not be removed when all windows are removed.
7820 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007821
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007822 // For printing.
7823 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007825 // If this is an AppWindowToken, this is non-null.
7826 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007827
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007828 // All of the windows associated with this token.
7829 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7830
7831 // Is key dispatching paused for this token?
7832 boolean paused = false;
7833
7834 // Should this token's windows be hidden?
7835 boolean hidden;
7836
7837 // Temporary for finding which tokens no longer have visible windows.
7838 boolean hasVisible;
7839
Dianne Hackborna8f60182009-09-01 19:01:50 -07007840 // Set to true when this token is in a pending transaction where it
7841 // will be shown.
7842 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007843
Dianne Hackborna8f60182009-09-01 19:01:50 -07007844 // Set to true when this token is in a pending transaction where it
7845 // will be hidden.
7846 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007847
Dianne Hackborna8f60182009-09-01 19:01:50 -07007848 // Set to true when this token is in a pending transaction where its
7849 // windows will be put to the bottom of the list.
7850 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007851
Dianne Hackborna8f60182009-09-01 19:01:50 -07007852 // Set to true when this token is in a pending transaction where its
7853 // windows will be put to the top of the list.
7854 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007856 WindowToken(IBinder _token, int type, boolean _explicit) {
7857 token = _token;
7858 windowType = type;
7859 explicit = _explicit;
7860 }
7861
7862 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007863 pw.print(prefix); pw.print("token="); pw.println(token);
7864 pw.print(prefix); pw.print("windows="); pw.println(windows);
7865 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7866 pw.print(" hidden="); pw.print(hidden);
7867 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007868 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7869 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7870 pw.print(" waitingToHide="); pw.print(waitingToHide);
7871 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7872 pw.print(" sendingToTop="); pw.println(sendingToTop);
7873 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007874 }
7875
7876 @Override
7877 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007878 if (stringName == null) {
7879 StringBuilder sb = new StringBuilder();
7880 sb.append("WindowToken{");
7881 sb.append(Integer.toHexString(System.identityHashCode(this)));
7882 sb.append(" token="); sb.append(token); sb.append('}');
7883 stringName = sb.toString();
7884 }
7885 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007886 }
7887 };
7888
7889 class AppWindowToken extends WindowToken {
7890 // Non-null only for application tokens.
7891 final IApplicationToken appToken;
7892
7893 // All of the windows and child windows that are included in this
7894 // application token. Note this list is NOT sorted!
7895 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7896
7897 int groupId = -1;
7898 boolean appFullscreen;
7899 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007900
7901 // The input dispatching timeout for this application token in nanoseconds.
7902 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007904 // These are used for determining when all windows associated with
7905 // an activity have been drawn, so they can be made visible together
7906 // at the same time.
7907 int lastTransactionSequence = mTransactionSequence-1;
7908 int numInterestingWindows;
7909 int numDrawnWindows;
7910 boolean inPendingTransaction;
7911 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007913 // Is this token going to be hidden in a little while? If so, it
7914 // won't be taken into account for setting the screen orientation.
7915 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007917 // Is this window's surface needed? This is almost like hidden, except
7918 // it will sometimes be true a little earlier: when the token has
7919 // been shown, but is still waiting for its app transition to execute
7920 // before making its windows shown.
7921 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007923 // Have we told the window clients to hide themselves?
7924 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007926 // Last visibility state we reported to the app token.
7927 boolean reportedVisible;
7928
7929 // Set to true when the token has been removed from the window mgr.
7930 boolean removed;
7931
7932 // Have we been asked to have this token keep the screen frozen?
7933 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007935 boolean animating;
7936 Animation animation;
7937 boolean hasTransformation;
7938 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007940 // Offset to the window of all layers in the token, for use by
7941 // AppWindowToken animations.
7942 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007943
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007944 // Information about an application starting window if displayed.
7945 StartingData startingData;
7946 WindowState startingWindow;
7947 View startingView;
7948 boolean startingDisplayed;
7949 boolean startingMoved;
7950 boolean firstWindowDrawn;
7951
7952 AppWindowToken(IApplicationToken _token) {
7953 super(_token.asBinder(),
7954 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7955 appWindowToken = this;
7956 appToken = _token;
7957 }
Romain Guy06882f82009-06-10 13:36:04 -07007958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007959 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007960 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007961 TAG, "Setting animation in " + this + ": " + anim);
7962 animation = anim;
7963 animating = false;
7964 anim.restrictDuration(MAX_ANIMATION_DURATION);
7965 anim.scaleCurrentDuration(mTransitionAnimationScale);
7966 int zorder = anim.getZAdjustment();
7967 int adj = 0;
7968 if (zorder == Animation.ZORDER_TOP) {
7969 adj = TYPE_LAYER_OFFSET;
7970 } else if (zorder == Animation.ZORDER_BOTTOM) {
7971 adj = -TYPE_LAYER_OFFSET;
7972 }
Romain Guy06882f82009-06-10 13:36:04 -07007973
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007974 if (animLayerAdjustment != adj) {
7975 animLayerAdjustment = adj;
7976 updateLayers();
7977 }
7978 }
Romain Guy06882f82009-06-10 13:36:04 -07007979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007980 public void setDummyAnimation() {
7981 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007982 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007983 TAG, "Setting dummy animation in " + this);
7984 animation = sDummyAnimation;
7985 }
7986 }
7987
7988 public void clearAnimation() {
7989 if (animation != null) {
7990 animation = null;
7991 animating = true;
7992 }
7993 }
Romain Guy06882f82009-06-10 13:36:04 -07007994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007995 void updateLayers() {
7996 final int N = allAppWindows.size();
7997 final int adj = animLayerAdjustment;
7998 for (int i=0; i<N; i++) {
7999 WindowState w = allAppWindows.get(i);
8000 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008001 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008002 + w.mAnimLayer);
8003 if (w == mInputMethodTarget) {
8004 setInputMethodAnimLayerAdjustment(adj);
8005 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008006 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008007 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008008 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008009 }
8010 }
Romain Guy06882f82009-06-10 13:36:04 -07008011
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008012 void sendAppVisibilityToClients() {
8013 final int N = allAppWindows.size();
8014 for (int i=0; i<N; i++) {
8015 WindowState win = allAppWindows.get(i);
8016 if (win == startingWindow && clientHidden) {
8017 // Don't hide the starting window.
8018 continue;
8019 }
8020 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008021 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008022 "Setting visibility of " + win + ": " + (!clientHidden));
8023 win.mClient.dispatchAppVisibility(!clientHidden);
8024 } catch (RemoteException e) {
8025 }
8026 }
8027 }
Romain Guy06882f82009-06-10 13:36:04 -07008028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008029 void showAllWindowsLocked() {
8030 final int NW = allAppWindows.size();
8031 for (int i=0; i<NW; i++) {
8032 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008033 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008034 "performing show on: " + w);
8035 w.performShowLocked();
8036 }
8037 }
Romain Guy06882f82009-06-10 13:36:04 -07008038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008039 // This must be called while inside a transaction.
8040 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008041 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008042 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008044 if (animation == sDummyAnimation) {
8045 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008046 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008047 // when it is really time to animate, this will be set to
8048 // a real animation and the next call will execute normally.
8049 return false;
8050 }
Romain Guy06882f82009-06-10 13:36:04 -07008051
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008052 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8053 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008054 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008055 TAG, "Starting animation in " + this +
8056 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8057 + " scale=" + mTransitionAnimationScale
8058 + " allDrawn=" + allDrawn + " animating=" + animating);
8059 animation.initialize(dw, dh, dw, dh);
8060 animation.setStartTime(currentTime);
8061 animating = true;
8062 }
8063 transformation.clear();
8064 final boolean more = animation.getTransformation(
8065 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008066 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008067 TAG, "Stepped animation in " + this +
8068 ": more=" + more + ", xform=" + transformation);
8069 if (more) {
8070 // we're done!
8071 hasTransformation = true;
8072 return true;
8073 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008074 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008075 TAG, "Finished animation in " + this +
8076 " @ " + currentTime);
8077 animation = null;
8078 }
8079 } else if (animation != null) {
8080 // If the display is frozen, and there is a pending animation,
8081 // clear it and make sure we run the cleanup code.
8082 animating = true;
8083 animation = null;
8084 }
8085
8086 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008087
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008088 if (!animating) {
8089 return false;
8090 }
8091
8092 clearAnimation();
8093 animating = false;
8094 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8095 moveInputMethodWindowsIfNeededLocked(true);
8096 }
Romain Guy06882f82009-06-10 13:36:04 -07008097
Joe Onorato8a9b2202010-02-26 18:56:32 -08008098 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008099 TAG, "Animation done in " + this
8100 + ": reportedVisible=" + reportedVisible);
8101
8102 transformation.clear();
8103 if (animLayerAdjustment != 0) {
8104 animLayerAdjustment = 0;
8105 updateLayers();
8106 }
Romain Guy06882f82009-06-10 13:36:04 -07008107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008108 final int N = windows.size();
8109 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008110 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008111 }
8112 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008114 return false;
8115 }
8116
8117 void updateReportedVisibilityLocked() {
8118 if (appToken == null) {
8119 return;
8120 }
Romain Guy06882f82009-06-10 13:36:04 -07008121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008122 int numInteresting = 0;
8123 int numVisible = 0;
8124 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008125
Joe Onorato8a9b2202010-02-26 18:56:32 -08008126 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008127 final int N = allAppWindows.size();
8128 for (int i=0; i<N; i++) {
8129 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008130 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008131 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008132 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8133 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008134 continue;
8135 }
8136 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008137 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008138 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008139 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008140 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008141 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008142 + " pv=" + win.mPolicyVisibility
8143 + " dp=" + win.mDrawPending
8144 + " cdp=" + win.mCommitDrawPending
8145 + " ah=" + win.mAttachedHidden
8146 + " th="
8147 + (win.mAppToken != null
8148 ? win.mAppToken.hiddenRequested : false)
8149 + " a=" + win.mAnimating);
8150 }
8151 }
8152 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008153 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008154 if (!win.isAnimating()) {
8155 numVisible++;
8156 }
8157 nowGone = false;
8158 } else if (win.isAnimating()) {
8159 nowGone = false;
8160 }
8161 }
Romain Guy06882f82009-06-10 13:36:04 -07008162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008163 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008164 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008165 + numInteresting + " visible=" + numVisible);
8166 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008167 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008168 TAG, "Visibility changed in " + this
8169 + ": vis=" + nowVisible);
8170 reportedVisible = nowVisible;
8171 Message m = mH.obtainMessage(
8172 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8173 nowVisible ? 1 : 0,
8174 nowGone ? 1 : 0,
8175 this);
8176 mH.sendMessage(m);
8177 }
8178 }
Romain Guy06882f82009-06-10 13:36:04 -07008179
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008180 WindowState findMainWindow() {
8181 int j = windows.size();
8182 while (j > 0) {
8183 j--;
8184 WindowState win = windows.get(j);
8185 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8186 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8187 return win;
8188 }
8189 }
8190 return null;
8191 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008193 void dump(PrintWriter pw, String prefix) {
8194 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008195 if (appToken != null) {
8196 pw.print(prefix); pw.println("app=true");
8197 }
8198 if (allAppWindows.size() > 0) {
8199 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8200 }
8201 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008202 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008203 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8204 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8205 pw.print(" clientHidden="); pw.print(clientHidden);
8206 pw.print(" willBeHidden="); pw.print(willBeHidden);
8207 pw.print(" reportedVisible="); pw.println(reportedVisible);
8208 if (paused || freezingScreen) {
8209 pw.print(prefix); pw.print("paused="); pw.print(paused);
8210 pw.print(" freezingScreen="); pw.println(freezingScreen);
8211 }
8212 if (numInterestingWindows != 0 || numDrawnWindows != 0
8213 || inPendingTransaction || allDrawn) {
8214 pw.print(prefix); pw.print("numInterestingWindows=");
8215 pw.print(numInterestingWindows);
8216 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8217 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8218 pw.print(" allDrawn="); pw.println(allDrawn);
8219 }
8220 if (animating || animation != null) {
8221 pw.print(prefix); pw.print("animating="); pw.print(animating);
8222 pw.print(" animation="); pw.println(animation);
8223 }
8224 if (animLayerAdjustment != 0) {
8225 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8226 }
8227 if (hasTransformation) {
8228 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8229 pw.print(" transformation="); transformation.printShortString(pw);
8230 pw.println();
8231 }
8232 if (startingData != null || removed || firstWindowDrawn) {
8233 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8234 pw.print(" removed="); pw.print(removed);
8235 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8236 }
8237 if (startingWindow != null || startingView != null
8238 || startingDisplayed || startingMoved) {
8239 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8240 pw.print(" startingView="); pw.print(startingView);
8241 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8242 pw.print(" startingMoved"); pw.println(startingMoved);
8243 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008244 }
8245
8246 @Override
8247 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008248 if (stringName == null) {
8249 StringBuilder sb = new StringBuilder();
8250 sb.append("AppWindowToken{");
8251 sb.append(Integer.toHexString(System.identityHashCode(this)));
8252 sb.append(" token="); sb.append(token); sb.append('}');
8253 stringName = sb.toString();
8254 }
8255 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008256 }
8257 }
Romain Guy06882f82009-06-10 13:36:04 -07008258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008259 // -------------------------------------------------------------
8260 // DummyAnimation
8261 // -------------------------------------------------------------
8262
8263 // This is an animation that does nothing: it just immediately finishes
8264 // itself every time it is called. It is used as a stub animation in cases
8265 // where we want to synchronize multiple things that may be animating.
8266 static final class DummyAnimation extends Animation {
8267 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8268 return false;
8269 }
8270 }
8271 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008273 // -------------------------------------------------------------
8274 // Async Handler
8275 // -------------------------------------------------------------
8276
8277 static final class StartingData {
8278 final String pkg;
8279 final int theme;
8280 final CharSequence nonLocalizedLabel;
8281 final int labelRes;
8282 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008284 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8285 int _labelRes, int _icon) {
8286 pkg = _pkg;
8287 theme = _theme;
8288 nonLocalizedLabel = _nonLocalizedLabel;
8289 labelRes = _labelRes;
8290 icon = _icon;
8291 }
8292 }
8293
8294 private final class H extends Handler {
8295 public static final int REPORT_FOCUS_CHANGE = 2;
8296 public static final int REPORT_LOSING_FOCUS = 3;
8297 public static final int ANIMATE = 4;
8298 public static final int ADD_STARTING = 5;
8299 public static final int REMOVE_STARTING = 6;
8300 public static final int FINISHED_STARTING = 7;
8301 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008302 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8303 public static final int HOLD_SCREEN_CHANGED = 12;
8304 public static final int APP_TRANSITION_TIMEOUT = 13;
8305 public static final int PERSIST_ANIMATION_SCALE = 14;
8306 public static final int FORCE_GC = 15;
8307 public static final int ENABLE_SCREEN = 16;
8308 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008309 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008310 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008311 public static final int DRAG_START_TIMEOUT = 20;
Romain Guy06882f82009-06-10 13:36:04 -07008312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008313 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008315 public H() {
8316 }
Romain Guy06882f82009-06-10 13:36:04 -07008317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008318 @Override
8319 public void handleMessage(Message msg) {
8320 switch (msg.what) {
8321 case REPORT_FOCUS_CHANGE: {
8322 WindowState lastFocus;
8323 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008325 synchronized(mWindowMap) {
8326 lastFocus = mLastFocus;
8327 newFocus = mCurrentFocus;
8328 if (lastFocus == newFocus) {
8329 // Focus is not changing, so nothing to do.
8330 return;
8331 }
8332 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008333 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008334 // + " to " + newFocus);
8335 if (newFocus != null && lastFocus != null
8336 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008337 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008338 mLosingFocus.add(lastFocus);
8339 lastFocus = null;
8340 }
8341 }
8342
8343 if (lastFocus != newFocus) {
8344 //System.out.println("Changing focus from " + lastFocus
8345 // + " to " + newFocus);
8346 if (newFocus != null) {
8347 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008348 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008349 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8350 } catch (RemoteException e) {
8351 // Ignore if process has died.
8352 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008353 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008354 }
8355
8356 if (lastFocus != null) {
8357 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008358 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008359 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8360 } catch (RemoteException e) {
8361 // Ignore if process has died.
8362 }
8363 }
8364 }
8365 } break;
8366
8367 case REPORT_LOSING_FOCUS: {
8368 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008370 synchronized(mWindowMap) {
8371 losers = mLosingFocus;
8372 mLosingFocus = new ArrayList<WindowState>();
8373 }
8374
8375 final int N = losers.size();
8376 for (int i=0; i<N; i++) {
8377 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008378 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008379 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8380 } catch (RemoteException e) {
8381 // Ignore if process has died.
8382 }
8383 }
8384 } break;
8385
8386 case ANIMATE: {
8387 synchronized(mWindowMap) {
8388 mAnimationPending = false;
8389 performLayoutAndPlaceSurfacesLocked();
8390 }
8391 } break;
8392
8393 case ADD_STARTING: {
8394 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8395 final StartingData sd = wtoken.startingData;
8396
8397 if (sd == null) {
8398 // Animation has been canceled... do nothing.
8399 return;
8400 }
Romain Guy06882f82009-06-10 13:36:04 -07008401
Joe Onorato8a9b2202010-02-26 18:56:32 -08008402 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008403 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008405 View view = null;
8406 try {
8407 view = mPolicy.addStartingWindow(
8408 wtoken.token, sd.pkg,
8409 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8410 sd.icon);
8411 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008412 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008413 }
8414
8415 if (view != null) {
8416 boolean abort = false;
8417
8418 synchronized(mWindowMap) {
8419 if (wtoken.removed || wtoken.startingData == null) {
8420 // If the window was successfully added, then
8421 // we need to remove it.
8422 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008423 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008424 "Aborted starting " + wtoken
8425 + ": removed=" + wtoken.removed
8426 + " startingData=" + wtoken.startingData);
8427 wtoken.startingWindow = null;
8428 wtoken.startingData = null;
8429 abort = true;
8430 }
8431 } else {
8432 wtoken.startingView = view;
8433 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008434 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008435 "Added starting " + wtoken
8436 + ": startingWindow="
8437 + wtoken.startingWindow + " startingView="
8438 + wtoken.startingView);
8439 }
8440
8441 if (abort) {
8442 try {
8443 mPolicy.removeStartingWindow(wtoken.token, view);
8444 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008445 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008446 }
8447 }
8448 }
8449 } break;
8450
8451 case REMOVE_STARTING: {
8452 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8453 IBinder token = null;
8454 View view = null;
8455 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008456 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008457 + wtoken + ": startingWindow="
8458 + wtoken.startingWindow + " startingView="
8459 + wtoken.startingView);
8460 if (wtoken.startingWindow != null) {
8461 view = wtoken.startingView;
8462 token = wtoken.token;
8463 wtoken.startingData = null;
8464 wtoken.startingView = null;
8465 wtoken.startingWindow = null;
8466 }
8467 }
8468 if (view != null) {
8469 try {
8470 mPolicy.removeStartingWindow(token, view);
8471 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008472 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008473 }
8474 }
8475 } break;
8476
8477 case FINISHED_STARTING: {
8478 IBinder token = null;
8479 View view = null;
8480 while (true) {
8481 synchronized (mWindowMap) {
8482 final int N = mFinishedStarting.size();
8483 if (N <= 0) {
8484 break;
8485 }
8486 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8487
Joe Onorato8a9b2202010-02-26 18:56:32 -08008488 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008489 "Finished starting " + wtoken
8490 + ": startingWindow=" + wtoken.startingWindow
8491 + " startingView=" + wtoken.startingView);
8492
8493 if (wtoken.startingWindow == null) {
8494 continue;
8495 }
8496
8497 view = wtoken.startingView;
8498 token = wtoken.token;
8499 wtoken.startingData = null;
8500 wtoken.startingView = null;
8501 wtoken.startingWindow = null;
8502 }
8503
8504 try {
8505 mPolicy.removeStartingWindow(token, view);
8506 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008507 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008508 }
8509 }
8510 } break;
8511
8512 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8513 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8514
8515 boolean nowVisible = msg.arg1 != 0;
8516 boolean nowGone = msg.arg2 != 0;
8517
8518 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008519 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008520 TAG, "Reporting visible in " + wtoken
8521 + " visible=" + nowVisible
8522 + " gone=" + nowGone);
8523 if (nowVisible) {
8524 wtoken.appToken.windowsVisible();
8525 } else {
8526 wtoken.appToken.windowsGone();
8527 }
8528 } catch (RemoteException ex) {
8529 }
8530 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008532 case WINDOW_FREEZE_TIMEOUT: {
8533 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008534 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008535 int i = mWindows.size();
8536 while (i > 0) {
8537 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008538 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008539 if (w.mOrientationChanging) {
8540 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008541 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008542 }
8543 }
8544 performLayoutAndPlaceSurfacesLocked();
8545 }
8546 break;
8547 }
Romain Guy06882f82009-06-10 13:36:04 -07008548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008549 case HOLD_SCREEN_CHANGED: {
8550 Session oldHold;
8551 Session newHold;
8552 synchronized (mWindowMap) {
8553 oldHold = mLastReportedHold;
8554 newHold = (Session)msg.obj;
8555 mLastReportedHold = newHold;
8556 }
Romain Guy06882f82009-06-10 13:36:04 -07008557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008558 if (oldHold != newHold) {
8559 try {
8560 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008561 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008562 "window",
8563 BatteryStats.WAKE_TYPE_WINDOW);
8564 }
8565 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008566 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008567 "window",
8568 BatteryStats.WAKE_TYPE_WINDOW);
8569 }
8570 } catch (RemoteException e) {
8571 }
8572 }
8573 break;
8574 }
Romain Guy06882f82009-06-10 13:36:04 -07008575
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008576 case APP_TRANSITION_TIMEOUT: {
8577 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008578 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008579 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008580 "*** APP TRANSITION TIMEOUT");
8581 mAppTransitionReady = true;
8582 mAppTransitionTimeout = true;
8583 performLayoutAndPlaceSurfacesLocked();
8584 }
8585 }
8586 break;
8587 }
Romain Guy06882f82009-06-10 13:36:04 -07008588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008589 case PERSIST_ANIMATION_SCALE: {
8590 Settings.System.putFloat(mContext.getContentResolver(),
8591 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8592 Settings.System.putFloat(mContext.getContentResolver(),
8593 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8594 break;
8595 }
Romain Guy06882f82009-06-10 13:36:04 -07008596
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008597 case FORCE_GC: {
8598 synchronized(mWindowMap) {
8599 if (mAnimationPending) {
8600 // If we are animating, don't do the gc now but
8601 // delay a bit so we don't interrupt the animation.
8602 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8603 2000);
8604 return;
8605 }
8606 // If we are currently rotating the display, it will
8607 // schedule a new message when done.
8608 if (mDisplayFrozen) {
8609 return;
8610 }
8611 mFreezeGcPending = 0;
8612 }
8613 Runtime.getRuntime().gc();
8614 break;
8615 }
Romain Guy06882f82009-06-10 13:36:04 -07008616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008617 case ENABLE_SCREEN: {
8618 performEnableScreen();
8619 break;
8620 }
Romain Guy06882f82009-06-10 13:36:04 -07008621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008622 case APP_FREEZE_TIMEOUT: {
8623 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008624 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008625 int i = mAppTokens.size();
8626 while (i > 0) {
8627 i--;
8628 AppWindowToken tok = mAppTokens.get(i);
8629 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008630 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008631 unsetAppFreezingScreenLocked(tok, true, true);
8632 }
8633 }
8634 }
8635 break;
8636 }
Romain Guy06882f82009-06-10 13:36:04 -07008637
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008638 case SEND_NEW_CONFIGURATION: {
8639 removeMessages(SEND_NEW_CONFIGURATION);
8640 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008641 break;
8642 }
Romain Guy06882f82009-06-10 13:36:04 -07008643
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008644 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008645 if (mWindowsChanged) {
8646 synchronized (mWindowMap) {
8647 mWindowsChanged = false;
8648 }
8649 notifyWindowsChanged();
8650 }
8651 break;
8652 }
8653
Christopher Tatea53146c2010-09-07 11:57:52 -07008654 case DRAG_START_TIMEOUT: {
8655 IBinder win = (IBinder)msg.obj;
8656 if (DEBUG_DRAG) {
8657 Slog.w(TAG, "Timeout starting drag by win " + win);
8658 }
8659 synchronized (mWindowMap) {
8660 // !!! TODO: ANR the app that has failed to start the drag in time
8661 if (mDragState != null) {
8662 mDragState.reset();
8663 mDragState = null;
8664 }
8665 }
8666 }
8667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008668 }
8669 }
8670 }
8671
8672 // -------------------------------------------------------------
8673 // IWindowManager API
8674 // -------------------------------------------------------------
8675
8676 public IWindowSession openSession(IInputMethodClient client,
8677 IInputContext inputContext) {
8678 if (client == null) throw new IllegalArgumentException("null client");
8679 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008680 Session session = new Session(client, inputContext);
8681 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008682 }
8683
8684 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8685 synchronized (mWindowMap) {
8686 // The focus for the client is the window immediately below
8687 // where we would place the input method window.
8688 int idx = findDesiredInputMethodWindowIndexLocked(false);
8689 WindowState imFocus;
8690 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008691 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008692 if (imFocus != null) {
8693 if (imFocus.mSession.mClient != null &&
8694 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8695 return true;
8696 }
8697 }
8698 }
8699 }
8700 return false;
8701 }
Romain Guy06882f82009-06-10 13:36:04 -07008702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008703 // -------------------------------------------------------------
8704 // Internals
8705 // -------------------------------------------------------------
8706
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008707 final WindowState windowForClientLocked(Session session, IWindow client,
8708 boolean throwOnError) {
8709 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008710 }
Romain Guy06882f82009-06-10 13:36:04 -07008711
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008712 final WindowState windowForClientLocked(Session session, IBinder client,
8713 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008714 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008715 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008716 TAG, "Looking up client " + client + ": " + win);
8717 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008718 RuntimeException ex = new IllegalArgumentException(
8719 "Requested window " + client + " does not exist");
8720 if (throwOnError) {
8721 throw ex;
8722 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008723 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008724 return null;
8725 }
8726 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008727 RuntimeException ex = new IllegalArgumentException(
8728 "Requested window " + client + " is in session " +
8729 win.mSession + ", not " + session);
8730 if (throwOnError) {
8731 throw ex;
8732 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008733 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008734 return null;
8735 }
8736
8737 return win;
8738 }
8739
Dianne Hackborna8f60182009-09-01 19:01:50 -07008740 final void rebuildAppWindowListLocked() {
8741 int NW = mWindows.size();
8742 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008743 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008744 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008745
Dianne Hackborna8f60182009-09-01 19:01:50 -07008746 // First remove all existing app windows.
8747 i=0;
8748 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008749 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008750 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008751 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008752 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008753 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008754 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008755 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008756 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008757 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008758 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8759 && lastWallpaper == i-1) {
8760 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008761 }
8762 i++;
8763 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008764
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008765 // The wallpaper window(s) typically live at the bottom of the stack,
8766 // so skip them before adding app tokens.
8767 lastWallpaper++;
8768 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008769
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008770 // First add all of the exiting app tokens... these are no longer
8771 // in the main app list, but still have windows shown. We put them
8772 // in the back because now that the animation is over we no longer
8773 // will care about them.
8774 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008775 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008776 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8777 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008778
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008779 // And add in the still active app tokens in Z order.
8780 NT = mAppTokens.size();
8781 for (int j=0; j<NT; j++) {
8782 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008783 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008784
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008785 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008786 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008787 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008788 + " windows but added " + i);
8789 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008790 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008792 private final void assignLayersLocked() {
8793 int N = mWindows.size();
8794 int curBaseLayer = 0;
8795 int curLayer = 0;
8796 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008798 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008799 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008800 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8801 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008802 curLayer += WINDOW_LAYER_MULTIPLIER;
8803 w.mLayer = curLayer;
8804 } else {
8805 curBaseLayer = curLayer = w.mBaseLayer;
8806 w.mLayer = curLayer;
8807 }
8808 if (w.mTargetAppToken != null) {
8809 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8810 } else if (w.mAppToken != null) {
8811 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8812 } else {
8813 w.mAnimLayer = w.mLayer;
8814 }
8815 if (w.mIsImWindow) {
8816 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008817 } else if (w.mIsWallpaper) {
8818 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008819 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008820 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008821 + w.mAnimLayer);
8822 //System.out.println(
8823 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8824 }
8825 }
8826
8827 private boolean mInLayout = false;
8828 private final void performLayoutAndPlaceSurfacesLocked() {
8829 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008830 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008831 throw new RuntimeException("Recursive call!");
8832 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008833 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008834 return;
8835 }
8836
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008837 if (mWaitingForConfig) {
8838 // Our configuration has changed (most likely rotation), but we
8839 // don't yet have the complete configuration to report to
8840 // applications. Don't do any window layout until we have it.
8841 return;
8842 }
8843
Dianne Hackbornce2ef762010-09-20 11:39:14 -07008844 if (mDisplay == null) {
8845 // Not yet initialized, nothing to do.
8846 return;
8847 }
8848
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008849 boolean recoveringMemory = false;
8850 if (mForceRemoves != null) {
8851 recoveringMemory = true;
8852 // Wait a little it for things to settle down, and off we go.
8853 for (int i=0; i<mForceRemoves.size(); i++) {
8854 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008855 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008856 removeWindowInnerLocked(ws.mSession, ws);
8857 }
8858 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008859 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008860 Object tmp = new Object();
8861 synchronized (tmp) {
8862 try {
8863 tmp.wait(250);
8864 } catch (InterruptedException e) {
8865 }
8866 }
8867 }
Romain Guy06882f82009-06-10 13:36:04 -07008868
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008869 mInLayout = true;
8870 try {
8871 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008872
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008873 int i = mPendingRemove.size()-1;
8874 if (i >= 0) {
8875 while (i >= 0) {
8876 WindowState w = mPendingRemove.get(i);
8877 removeWindowInnerLocked(w.mSession, w);
8878 i--;
8879 }
8880 mPendingRemove.clear();
8881
8882 mInLayout = false;
8883 assignLayersLocked();
8884 mLayoutNeeded = true;
8885 performLayoutAndPlaceSurfacesLocked();
8886
8887 } else {
8888 mInLayout = false;
8889 if (mLayoutNeeded) {
8890 requestAnimationLocked(0);
8891 }
8892 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008893 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008894 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8895 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008896 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008897 } catch (RuntimeException e) {
8898 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008899 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008900 }
8901 }
8902
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008903 private final int performLayoutLockedInner() {
8904 if (!mLayoutNeeded) {
8905 return 0;
8906 }
8907
8908 mLayoutNeeded = false;
8909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008910 final int dw = mDisplay.getWidth();
8911 final int dh = mDisplay.getHeight();
8912
8913 final int N = mWindows.size();
8914 int i;
8915
Joe Onorato8a9b2202010-02-26 18:56:32 -08008916 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008917 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8918
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008919 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008920
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008921 int seq = mLayoutSeq+1;
8922 if (seq < 0) seq = 0;
8923 mLayoutSeq = seq;
8924
8925 // First perform layout of any root windows (not attached
8926 // to another window).
8927 int topAttached = -1;
8928 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008929 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008930
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008931 // Don't do layout of a window if it is not visible, or
8932 // soon won't be visible, to avoid wasting time and funky
8933 // changes while a window is animating away.
8934 final AppWindowToken atoken = win.mAppToken;
8935 final boolean gone = win.mViewVisibility == View.GONE
8936 || !win.mRelayoutCalled
8937 || win.mRootToken.hidden
8938 || (atoken != null && atoken.hiddenRequested)
8939 || win.mAttachedHidden
8940 || win.mExiting || win.mDestroying;
8941
8942 if (!win.mLayoutAttached) {
8943 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
8944 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
8945 + " mLayoutAttached=" + win.mLayoutAttached);
8946 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
8947 + win.mViewVisibility + " mRelayoutCalled="
8948 + win.mRelayoutCalled + " hidden="
8949 + win.mRootToken.hidden + " hiddenRequested="
8950 + (atoken != null && atoken.hiddenRequested)
8951 + " mAttachedHidden=" + win.mAttachedHidden);
8952 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008953
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008954 // If this view is GONE, then skip it -- keep the current
8955 // frame, and let the caller know so they can ignore it
8956 // if they want. (We do the normal layout for INVISIBLE
8957 // windows, since that means "perform layout as normal,
8958 // just don't display").
8959 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008960 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008961 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8962 win.mLayoutSeq = seq;
8963 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8964 + win.mFrame + " mContainingFrame="
8965 + win.mContainingFrame + " mDisplayFrame="
8966 + win.mDisplayFrame);
8967 } else {
8968 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008969 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008970 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008971 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008972
8973 // Now perform layout of attached windows, which usually
8974 // depend on the position of the window they are attached to.
8975 // XXX does not deal with windows that are attached to windows
8976 // that are themselves attached.
8977 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008978 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008979
8980 // If this view is GONE, then skip it -- keep the current
8981 // frame, and let the caller know so they can ignore it
8982 // if they want. (We do the normal layout for INVISIBLE
8983 // windows, since that means "perform layout as normal,
8984 // just don't display").
8985 if (win.mLayoutAttached) {
8986 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
8987 + " mHaveFrame=" + win.mHaveFrame
8988 + " mViewVisibility=" + win.mViewVisibility
8989 + " mRelayoutCalled=" + win.mRelayoutCalled);
8990 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
8991 || !win.mHaveFrame) {
8992 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
8993 win.mLayoutSeq = seq;
8994 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8995 + win.mFrame + " mContainingFrame="
8996 + win.mContainingFrame + " mDisplayFrame="
8997 + win.mDisplayFrame);
8998 }
8999 }
9000 }
Jeff Brown349703e2010-06-22 01:27:15 -07009001
9002 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009003 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009004
9005 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009006 }
Romain Guy06882f82009-06-10 13:36:04 -07009007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009008 private final void performLayoutAndPlaceSurfacesLockedInner(
9009 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009010 if (mDisplay == null) {
9011 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9012 return;
9013 }
9014
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009015 final long currentTime = SystemClock.uptimeMillis();
9016 final int dw = mDisplay.getWidth();
9017 final int dh = mDisplay.getHeight();
9018
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009019 int i;
9020
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009021 if (mFocusMayChange) {
9022 mFocusMayChange = false;
9023 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9024 }
9025
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009026 // Initialize state of exiting tokens.
9027 for (i=mExitingTokens.size()-1; i>=0; i--) {
9028 mExitingTokens.get(i).hasVisible = false;
9029 }
9030
9031 // Initialize state of exiting applications.
9032 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9033 mExitingAppTokens.get(i).hasVisible = false;
9034 }
9035
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009036 boolean orientationChangeComplete = true;
9037 Session holdScreen = null;
9038 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009039 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009040 boolean focusDisplayed = false;
9041 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009042 boolean createWatermark = false;
9043
9044 if (mFxSession == null) {
9045 mFxSession = new SurfaceSession();
9046 createWatermark = true;
9047 }
9048
9049 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009050
9051 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009052
9053 if (createWatermark) {
9054 createWatermark();
9055 }
9056 if (mWatermark != null) {
9057 mWatermark.positionSurface(dw, dh);
9058 }
9059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009060 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009061 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009062 int repeats = 0;
9063 int changes = 0;
9064
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009065 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009066 repeats++;
9067 if (repeats > 6) {
9068 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9069 mLayoutNeeded = false;
9070 break;
9071 }
9072
9073 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9074 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9075 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9076 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9077 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9078 assignLayersLocked();
9079 mLayoutNeeded = true;
9080 }
9081 }
9082 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9083 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9084 if (updateOrientationFromAppTokensLocked()) {
9085 mLayoutNeeded = true;
9086 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9087 }
9088 }
9089 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9090 mLayoutNeeded = true;
9091 }
9092 }
9093
9094 // FIRST LOOP: Perform a layout, if needed.
9095 if (repeats < 4) {
9096 changes = performLayoutLockedInner();
9097 if (changes != 0) {
9098 continue;
9099 }
9100 } else {
9101 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9102 changes = 0;
9103 }
9104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009105 final int transactionSequence = ++mTransactionSequence;
9106
9107 // Update animations of all applications, including those
9108 // associated with exiting/removed apps
9109 boolean tokensAnimating = false;
9110 final int NAT = mAppTokens.size();
9111 for (i=0; i<NAT; i++) {
9112 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9113 tokensAnimating = true;
9114 }
9115 }
9116 final int NEAT = mExitingAppTokens.size();
9117 for (i=0; i<NEAT; i++) {
9118 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9119 tokensAnimating = true;
9120 }
9121 }
9122
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009123 // SECOND LOOP: Execute animations and update visibility of windows.
9124
Joe Onorato8a9b2202010-02-26 18:56:32 -08009125 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009126 + transactionSequence + " tokensAnimating="
9127 + tokensAnimating);
9128
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009129 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009130
9131 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009132 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009133 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009134
9135 mPolicy.beginAnimationLw(dw, dh);
9136
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009137 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009139 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009140 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009141
9142 final WindowManager.LayoutParams attrs = w.mAttrs;
9143
9144 if (w.mSurface != null) {
9145 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009146 if (w.commitFinishDrawingLocked(currentTime)) {
9147 if ((w.mAttrs.flags
9148 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009149 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009150 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009151 wallpaperMayChange = true;
9152 }
9153 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009154
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009155 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009156 if (w.stepAnimationLocked(currentTime, dw, dh)) {
9157 animating = true;
9158 //w.dump(" ");
9159 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009160 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9161 wallpaperMayChange = true;
9162 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009163
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009164 if (mPolicy.doesForceHide(w, attrs)) {
9165 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009166 if (DEBUG_VISIBILITY) Slog.v(TAG,
9167 "Animation done that could impact force hide: "
9168 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009169 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009170 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009171 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9172 forceHiding = true;
9173 }
9174 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9175 boolean changed;
9176 if (forceHiding) {
9177 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009178 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9179 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009180 } else {
9181 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009182 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9183 "Now policy shown: " + w);
9184 if (changed) {
9185 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009186 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009187 // Assume we will need to animate. If
9188 // we don't (because the wallpaper will
9189 // stay with the lock screen), then we will
9190 // clean up later.
9191 Animation a = mPolicy.createForceHideEnterAnimation();
9192 if (a != null) {
9193 w.setAnimation(a);
9194 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009195 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009196 if (mCurrentFocus == null ||
9197 mCurrentFocus.mLayer < w.mLayer) {
9198 // We are showing on to of the current
9199 // focus, so re-evaluate focus to make
9200 // sure it is correct.
9201 mFocusMayChange = true;
9202 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009203 }
9204 }
9205 if (changed && (attrs.flags
9206 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9207 wallpaperMayChange = true;
9208 }
9209 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009211 mPolicy.animatingWindowLw(w, attrs);
9212 }
9213
9214 final AppWindowToken atoken = w.mAppToken;
9215 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9216 if (atoken.lastTransactionSequence != transactionSequence) {
9217 atoken.lastTransactionSequence = transactionSequence;
9218 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9219 atoken.startingDisplayed = false;
9220 }
9221 if ((w.isOnScreen() || w.mAttrs.type
9222 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9223 && !w.mExiting && !w.mDestroying) {
9224 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009225 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009226 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009227 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009228 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009229 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009230 + " pv=" + w.mPolicyVisibility
9231 + " dp=" + w.mDrawPending
9232 + " cdp=" + w.mCommitDrawPending
9233 + " ah=" + w.mAttachedHidden
9234 + " th=" + atoken.hiddenRequested
9235 + " a=" + w.mAnimating);
9236 }
9237 }
9238 if (w != atoken.startingWindow) {
9239 if (!atoken.freezingScreen || !w.mAppFreezing) {
9240 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009241 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009242 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009243 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009244 "tokenMayBeDrawn: " + atoken
9245 + " freezingScreen=" + atoken.freezingScreen
9246 + " mAppFreezing=" + w.mAppFreezing);
9247 tokenMayBeDrawn = true;
9248 }
9249 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009250 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009251 atoken.startingDisplayed = true;
9252 }
9253 }
9254 } else if (w.mReadyToShow) {
9255 w.performShowLocked();
9256 }
9257 }
9258
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009259 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009260
9261 if (tokenMayBeDrawn) {
9262 // See if any windows have been drawn, so they (and others
9263 // associated with them) can now be shown.
9264 final int NT = mTokenList.size();
9265 for (i=0; i<NT; i++) {
9266 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9267 if (wtoken == null) {
9268 continue;
9269 }
9270 if (wtoken.freezingScreen) {
9271 int numInteresting = wtoken.numInterestingWindows;
9272 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009273 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009274 "allDrawn: " + wtoken
9275 + " interesting=" + numInteresting
9276 + " drawn=" + wtoken.numDrawnWindows);
9277 wtoken.showAllWindowsLocked();
9278 unsetAppFreezingScreenLocked(wtoken, false, true);
9279 orientationChangeComplete = true;
9280 }
9281 } else if (!wtoken.allDrawn) {
9282 int numInteresting = wtoken.numInterestingWindows;
9283 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009284 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009285 "allDrawn: " + wtoken
9286 + " interesting=" + numInteresting
9287 + " drawn=" + wtoken.numDrawnWindows);
9288 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009289 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009290
9291 // We can now show all of the drawn windows!
9292 if (!mOpeningApps.contains(wtoken)) {
9293 wtoken.showAllWindowsLocked();
9294 }
9295 }
9296 }
9297 }
9298 }
9299
9300 // If we are ready to perform an app transition, check through
9301 // all of the app tokens to be shown and see if they are ready
9302 // to go.
9303 if (mAppTransitionReady) {
9304 int NN = mOpeningApps.size();
9305 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009306 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009307 "Checking " + NN + " opening apps (frozen="
9308 + mDisplayFrozen + " timeout="
9309 + mAppTransitionTimeout + ")...");
9310 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9311 // If the display isn't frozen, wait to do anything until
9312 // all of the apps are ready. Otherwise just go because
9313 // we'll unfreeze the display when everyone is ready.
9314 for (i=0; i<NN && goodToGo; i++) {
9315 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009316 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009317 "Check opening app" + wtoken + ": allDrawn="
9318 + wtoken.allDrawn + " startingDisplayed="
9319 + wtoken.startingDisplayed);
9320 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9321 && !wtoken.startingMoved) {
9322 goodToGo = false;
9323 }
9324 }
9325 }
9326 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009327 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009328 int transit = mNextAppTransition;
9329 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009330 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009331 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009332 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009333 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009334 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009335 mAppTransitionTimeout = false;
9336 mStartingIconInTransition = false;
9337 mSkipAppTransitionAnimation = false;
9338
9339 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9340
Dianne Hackborna8f60182009-09-01 19:01:50 -07009341 // If there are applications waiting to come to the
9342 // top of the stack, now is the time to move their windows.
9343 // (Note that we don't do apps going to the bottom
9344 // here -- we want to keep their windows in the old
9345 // Z-order until the animation completes.)
9346 if (mToTopApps.size() > 0) {
9347 NN = mAppTokens.size();
9348 for (i=0; i<NN; i++) {
9349 AppWindowToken wtoken = mAppTokens.get(i);
9350 if (wtoken.sendingToTop) {
9351 wtoken.sendingToTop = false;
9352 moveAppWindowsLocked(wtoken, NN, false);
9353 }
9354 }
9355 mToTopApps.clear();
9356 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009357
Dianne Hackborn25994b42009-09-04 14:21:19 -07009358 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009359
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009360 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009361 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009362
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009363 // The top-most window will supply the layout params,
9364 // and we will determine it below.
9365 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009366 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009367 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009368
Joe Onorato8a9b2202010-02-26 18:56:32 -08009369 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009370 "New wallpaper target=" + mWallpaperTarget
9371 + ", lower target=" + mLowerWallpaperTarget
9372 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009373 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009374 // Do a first pass through the tokens for two
9375 // things:
9376 // (1) Determine if both the closing and opening
9377 // app token sets are wallpaper targets, in which
9378 // case special animations are needed
9379 // (since the wallpaper needs to stay static
9380 // behind them).
9381 // (2) Find the layout params of the top-most
9382 // application window in the tokens, which is
9383 // what will control the animation theme.
9384 final int NC = mClosingApps.size();
9385 NN = NC + mOpeningApps.size();
9386 for (i=0; i<NN; i++) {
9387 AppWindowToken wtoken;
9388 int mode;
9389 if (i < NC) {
9390 wtoken = mClosingApps.get(i);
9391 mode = 1;
9392 } else {
9393 wtoken = mOpeningApps.get(i-NC);
9394 mode = 2;
9395 }
9396 if (mLowerWallpaperTarget != null) {
9397 if (mLowerWallpaperTarget.mAppToken == wtoken
9398 || mUpperWallpaperTarget.mAppToken == wtoken) {
9399 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009400 }
9401 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009402 if (wtoken.appFullscreen) {
9403 WindowState ws = wtoken.findMainWindow();
9404 if (ws != null) {
9405 // If this is a compatibility mode
9406 // window, we will always use its anim.
9407 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9408 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009409 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009410 bestAnimLayer = Integer.MAX_VALUE;
9411 } else if (ws.mLayer > bestAnimLayer) {
9412 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009413 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009414 bestAnimLayer = ws.mLayer;
9415 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009416 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009417 }
9418 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009419
Dianne Hackborn25994b42009-09-04 14:21:19 -07009420 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009421 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009422 "Wallpaper animation!");
9423 switch (transit) {
9424 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9425 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9426 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9427 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9428 break;
9429 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9430 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9431 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9432 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9433 break;
9434 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009435 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009436 "New transit: " + transit);
9437 } else if (oldWallpaper != null) {
9438 // We are transitioning from an activity with
9439 // a wallpaper to one without.
9440 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009441 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009442 "New transit away from wallpaper: " + transit);
9443 } else if (mWallpaperTarget != null) {
9444 // We are transitioning from an activity without
9445 // a wallpaper to now showing the wallpaper
9446 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009447 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009448 "New transit into wallpaper: " + transit);
9449 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009450
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009451 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9452 mLastEnterAnimToken = animToken;
9453 mLastEnterAnimParams = animLp;
9454 } else if (mLastEnterAnimParams != null) {
9455 animLp = mLastEnterAnimParams;
9456 mLastEnterAnimToken = null;
9457 mLastEnterAnimParams = null;
9458 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009459
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009460 // If all closing windows are obscured, then there is
9461 // no need to do an animation. This is the case, for
9462 // example, when this transition is being done behind
9463 // the lock screen.
9464 if (!mPolicy.allowAppAnimationsLw()) {
9465 animLp = null;
9466 }
9467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009468 NN = mOpeningApps.size();
9469 for (i=0; i<NN; i++) {
9470 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009471 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009472 "Now opening app" + wtoken);
9473 wtoken.reportedVisible = false;
9474 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009475 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009476 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009477 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009478 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009479 wtoken.showAllWindowsLocked();
9480 }
9481 NN = mClosingApps.size();
9482 for (i=0; i<NN; i++) {
9483 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009484 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009485 "Now closing app" + wtoken);
9486 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009487 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009488 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009489 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009490 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009491 // Force the allDrawn flag, because we want to start
9492 // this guy's animations regardless of whether it's
9493 // gotten drawn.
9494 wtoken.allDrawn = true;
9495 }
9496
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009497 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009499 mOpeningApps.clear();
9500 mClosingApps.clear();
9501
9502 // This has changed the visibility of windows, so perform
9503 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009504 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009505 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009506 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9507 assignLayersLocked();
9508 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009509 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009510 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009511 }
9512 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009513
Dianne Hackborn16064f92010-03-25 00:47:24 -07009514 int adjResult = 0;
9515
Dianne Hackborna8f60182009-09-01 19:01:50 -07009516 if (!animating && mAppTransitionRunning) {
9517 // We have finished the animation of an app transition. To do
9518 // this, we have delayed a lot of operations like showing and
9519 // hiding apps, moving apps in Z-order, etc. The app token list
9520 // reflects the correct Z-order, but the window list may now
9521 // be out of sync with it. So here we will just rebuild the
9522 // entire app window list. Fun!
9523 mAppTransitionRunning = false;
9524 // Clear information about apps that were moving.
9525 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009526
Dianne Hackborna8f60182009-09-01 19:01:50 -07009527 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009528 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009529 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009530 moveInputMethodWindowsIfNeededLocked(false);
9531 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009532 // Since the window list has been rebuilt, focus might
9533 // have to be recomputed since the actual order of windows
9534 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009535 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009536 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009537
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009538 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009539 // At this point, there was a window with a wallpaper that
9540 // was force hiding other windows behind it, but now it
9541 // is going away. This may be simple -- just animate
9542 // away the wallpaper and its window -- or it may be
9543 // hard -- the wallpaper now needs to be shown behind
9544 // something that was hidden.
9545 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009546 if (mLowerWallpaperTarget != null
9547 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009548 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009549 "wallpaperForceHiding changed with lower="
9550 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009551 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009552 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9553 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9554 if (mLowerWallpaperTarget.mAppToken.hidden) {
9555 // The lower target has become hidden before we
9556 // actually started the animation... let's completely
9557 // re-evaluate everything.
9558 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009559 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009560 }
9561 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009562 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009563 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009564 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009565 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009566 + " NEW: " + mWallpaperTarget
9567 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009568 if (mLowerWallpaperTarget == null) {
9569 // Whoops, we don't need a special wallpaper animation.
9570 // Clear them out.
9571 forceHiding = false;
9572 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009573 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009574 if (w.mSurface != null) {
9575 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009576 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009577 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009578 forceHiding = true;
9579 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9580 if (!w.mAnimating) {
9581 // We set the animation above so it
9582 // is not yet running.
9583 w.clearAnimation();
9584 }
9585 }
9586 }
9587 }
9588 }
9589 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009590
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009591 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009592 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009593 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009594 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009595 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009596
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009597 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009598 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009599 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009600 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009601 assignLayersLocked();
9602 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009603 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009604 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009605 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009606 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009607
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009608 if (mFocusMayChange) {
9609 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009610 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009611 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009612 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009613 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009614 }
9615
9616 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009617 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009618 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009619
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009620 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9621 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009622
Jeff Browne33348b2010-07-15 23:54:05 -07009623 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009624 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009625
9626 // THIRD LOOP: Update the surfaces of all windows.
9627
9628 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9629
9630 boolean obscured = false;
9631 boolean blurring = false;
9632 boolean dimming = false;
9633 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009634 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009635 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009636
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009637 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009639 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009640 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009641
9642 boolean displayed = false;
9643 final WindowManager.LayoutParams attrs = w.mAttrs;
9644 final int attrFlags = attrs.flags;
9645
9646 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009647 // XXX NOTE: The logic here could be improved. We have
9648 // the decision about whether to resize a window separated
9649 // from whether to hide the surface. This can cause us to
9650 // resize a surface even if we are going to hide it. You
9651 // can see this by (1) holding device in landscape mode on
9652 // home screen; (2) tapping browser icon (device will rotate
9653 // to landscape; (3) tap home. The wallpaper will be resized
9654 // in step 2 but then immediately hidden, causing us to
9655 // have to resize and then redraw it again in step 3. It
9656 // would be nice to figure out how to avoid this, but it is
9657 // difficult because we do need to resize surfaces in some
9658 // cases while they are hidden such as when first showing a
9659 // window.
9660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009661 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009662 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009663 TAG, "Placing surface #" + i + " " + w.mSurface
9664 + ": new=" + w.mShownFrame + ", old="
9665 + w.mLastShownFrame);
9666
9667 boolean resize;
9668 int width, height;
9669 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9670 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9671 w.mLastRequestedHeight != w.mRequestedHeight;
9672 // for a scaled surface, we just want to use
9673 // the requested size.
9674 width = w.mRequestedWidth;
9675 height = w.mRequestedHeight;
9676 w.mLastRequestedWidth = width;
9677 w.mLastRequestedHeight = height;
9678 w.mLastShownFrame.set(w.mShownFrame);
9679 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009680 if (SHOW_TRANSACTIONS) logSurface(w,
9681 "POS " + w.mShownFrame.left
9682 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009683 w.mSurfaceX = w.mShownFrame.left;
9684 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009685 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9686 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009687 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009688 if (!recoveringMemory) {
9689 reclaimSomeSurfaceMemoryLocked(w, "position");
9690 }
9691 }
9692 } else {
9693 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9694 width = w.mShownFrame.width();
9695 height = w.mShownFrame.height();
9696 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009697 }
9698
9699 if (resize) {
9700 if (width < 1) width = 1;
9701 if (height < 1) height = 1;
9702 if (w.mSurface != null) {
9703 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009704 if (SHOW_TRANSACTIONS) logSurface(w,
9705 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009706 + w.mShownFrame.top + " SIZE "
9707 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009708 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009709 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009710 w.mSurfaceW = width;
9711 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009712 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009713 w.mSurfaceX = w.mShownFrame.left;
9714 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009715 w.mSurface.setPosition(w.mShownFrame.left,
9716 w.mShownFrame.top);
9717 } catch (RuntimeException e) {
9718 // If something goes wrong with the surface (such
9719 // as running out of memory), don't take down the
9720 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009721 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009722 + "size=(" + width + "x" + height
9723 + "), pos=(" + w.mShownFrame.left
9724 + "," + w.mShownFrame.top + ")", e);
9725 if (!recoveringMemory) {
9726 reclaimSomeSurfaceMemoryLocked(w, "size");
9727 }
9728 }
9729 }
9730 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009731 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009732 w.mContentInsetsChanged =
9733 !w.mLastContentInsets.equals(w.mContentInsets);
9734 w.mVisibleInsetsChanged =
9735 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009736 boolean configChanged =
9737 w.mConfiguration != mCurConfiguration
9738 && (w.mConfiguration == null
9739 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009740 if (DEBUG_CONFIGURATION && configChanged) {
9741 Slog.v(TAG, "Win " + w + " config changed: "
9742 + mCurConfiguration);
9743 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009744 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009745 + ": configChanged=" + configChanged
9746 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009747 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009748 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009749 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009750 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009751 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009752 w.mLastFrame.set(w.mFrame);
9753 w.mLastContentInsets.set(w.mContentInsets);
9754 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009755 // If the screen is currently frozen, then keep
9756 // it frozen until this window draws at its new
9757 // orientation.
9758 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009759 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009760 "Resizing while display frozen: " + w);
9761 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009762 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009763 mWindowsFreezingScreen = true;
9764 // XXX should probably keep timeout from
9765 // when we first froze the display.
9766 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9767 mH.sendMessageDelayed(mH.obtainMessage(
9768 H.WINDOW_FREEZE_TIMEOUT), 2000);
9769 }
9770 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009771 // If the orientation is changing, then we need to
9772 // hold off on unfreezing the display until this
9773 // window has been redrawn; to do that, we need
9774 // to go through the process of getting informed
9775 // by the application when it has finished drawing.
9776 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009777 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009778 "Orientation start waiting for draw in "
9779 + w + ", surface " + w.mSurface);
9780 w.mDrawPending = true;
9781 w.mCommitDrawPending = false;
9782 w.mReadyToShow = false;
9783 if (w.mAppToken != null) {
9784 w.mAppToken.allDrawn = false;
9785 }
9786 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009787 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009788 "Resizing window " + w + " to " + w.mFrame);
9789 mResizingWindows.add(w);
9790 } else if (w.mOrientationChanging) {
9791 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009792 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009793 "Orientation not waiting for draw in "
9794 + w + ", surface " + w.mSurface);
9795 w.mOrientationChanging = false;
9796 }
9797 }
9798 }
9799
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009800 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009801 if (!w.mLastHidden) {
9802 //dump();
9803 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009804 if (SHOW_TRANSACTIONS) logSurface(w,
9805 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009806 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009807 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009808 try {
9809 w.mSurface.hide();
9810 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009811 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009812 }
9813 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009814 }
9815 // If we are waiting for this window to handle an
9816 // orientation change, well, it is hidden, so
9817 // doesn't really matter. Note that this does
9818 // introduce a potential glitch if the window
9819 // becomes unhidden before it has drawn for the
9820 // new orientation.
9821 if (w.mOrientationChanging) {
9822 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009823 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009824 "Orientation change skips hidden " + w);
9825 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009826 } else if (w.mLastLayer != w.mAnimLayer
9827 || w.mLastAlpha != w.mShownAlpha
9828 || w.mLastDsDx != w.mDsDx
9829 || w.mLastDtDx != w.mDtDx
9830 || w.mLastDsDy != w.mDsDy
9831 || w.mLastDtDy != w.mDtDy
9832 || w.mLastHScale != w.mHScale
9833 || w.mLastVScale != w.mVScale
9834 || w.mLastHidden) {
9835 displayed = true;
9836 w.mLastAlpha = w.mShownAlpha;
9837 w.mLastLayer = w.mAnimLayer;
9838 w.mLastDsDx = w.mDsDx;
9839 w.mLastDtDx = w.mDtDx;
9840 w.mLastDsDy = w.mDsDy;
9841 w.mLastDtDy = w.mDtDy;
9842 w.mLastHScale = w.mHScale;
9843 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009844 if (SHOW_TRANSACTIONS) logSurface(w,
9845 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009846 + " matrix=[" + (w.mDsDx*w.mHScale)
9847 + "," + (w.mDtDx*w.mVScale)
9848 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009849 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009850 if (w.mSurface != null) {
9851 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009852 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009853 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009854 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009855 w.mSurface.setLayer(w.mAnimLayer);
9856 w.mSurface.setMatrix(
9857 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9858 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9859 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009860 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009861 if (!recoveringMemory) {
9862 reclaimSomeSurfaceMemoryLocked(w, "update");
9863 }
9864 }
9865 }
9866
9867 if (w.mLastHidden && !w.mDrawPending
9868 && !w.mCommitDrawPending
9869 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009870 if (SHOW_TRANSACTIONS) logSurface(w,
9871 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009872 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009873 + " during relayout");
9874 if (showSurfaceRobustlyLocked(w)) {
9875 w.mHasDrawn = true;
9876 w.mLastHidden = false;
9877 } else {
9878 w.mOrientationChanging = false;
9879 }
9880 }
9881 if (w.mSurface != null) {
9882 w.mToken.hasVisible = true;
9883 }
9884 } else {
9885 displayed = true;
9886 }
9887
9888 if (displayed) {
9889 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009890 if (attrs.width == LayoutParams.MATCH_PARENT
9891 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009892 covered = true;
9893 }
9894 }
9895 if (w.mOrientationChanging) {
9896 if (w.mDrawPending || w.mCommitDrawPending) {
9897 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009898 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009899 "Orientation continue waiting for draw in " + w);
9900 } else {
9901 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009902 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009903 "Orientation change complete in " + w);
9904 }
9905 }
9906 w.mToken.hasVisible = true;
9907 }
9908 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009909 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009910 "Orientation change skips hidden " + w);
9911 w.mOrientationChanging = false;
9912 }
9913
9914 final boolean canBeSeen = w.isDisplayedLw();
9915
9916 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9917 focusDisplayed = true;
9918 }
9919
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009920 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009922 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009923 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009924 if (w.mSurface != null) {
9925 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9926 holdScreen = w.mSession;
9927 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009928 if (!syswin && w.mAttrs.screenBrightness >= 0
9929 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009930 screenBrightness = w.mAttrs.screenBrightness;
9931 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009932 if (!syswin && w.mAttrs.buttonBrightness >= 0
9933 && buttonBrightness < 0) {
9934 buttonBrightness = w.mAttrs.buttonBrightness;
9935 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05009936 if (canBeSeen
9937 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9938 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9939 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009940 syswin = true;
9941 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009942 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009943
Dianne Hackborn25994b42009-09-04 14:21:19 -07009944 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
9945 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009946 // This window completely covers everything behind it,
9947 // so we want to leave all of them as unblurred (for
9948 // performance reasons).
9949 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009950 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009951 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009952 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009953 obscured = true;
9954 if (mBackgroundFillerSurface == null) {
9955 try {
9956 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009957 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009958 0, dw, dh,
9959 PixelFormat.OPAQUE,
9960 Surface.FX_SURFACE_NORMAL);
9961 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009962 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009963 }
9964 }
9965 try {
9966 mBackgroundFillerSurface.setPosition(0, 0);
9967 mBackgroundFillerSurface.setSize(dw, dh);
9968 // Using the same layer as Dim because they will never be shown at the
9969 // same time.
9970 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9971 mBackgroundFillerSurface.show();
9972 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009973 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009974 }
9975 backgroundFillerShown = true;
9976 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009977 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009978 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009979 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009980 + ": blurring=" + blurring
9981 + " obscured=" + obscured
9982 + " displayed=" + displayed);
9983 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9984 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009985 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009986 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009987 if (mDimAnimator == null) {
9988 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009989 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009990 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009991 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009992 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009993 }
9994 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
9995 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009996 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009997 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009998 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009999 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010000 + mBlurSurface + ": CREATE");
10001 try {
Romain Guy06882f82009-06-10 13:36:04 -070010002 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010003 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010004 -1, 16, 16,
10005 PixelFormat.OPAQUE,
10006 Surface.FX_SURFACE_BLUR);
10007 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010008 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010009 }
10010 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010011 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010012 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10013 + mBlurSurface + ": pos=(0,0) (" +
10014 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010015 mBlurSurface.setPosition(0, 0);
10016 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010017 mBlurSurface.setLayer(w.mAnimLayer-2);
10018 if (!mBlurShown) {
10019 try {
10020 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10021 + mBlurSurface + ": SHOW");
10022 mBlurSurface.show();
10023 } catch (RuntimeException e) {
10024 Slog.w(TAG, "Failure showing blur surface", e);
10025 }
10026 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010027 }
10028 }
10029 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010030 }
10031 }
10032 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010033
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010034 if (obscuredChanged && mWallpaperTarget == w) {
10035 // This is the wallpaper target and its obscured state
10036 // changed... make sure the current wallaper's visibility
10037 // has been updated accordingly.
10038 updateWallpaperVisibilityLocked();
10039 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010040 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010041
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010042 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10043 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010044 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010045 try {
10046 mBackgroundFillerSurface.hide();
10047 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010048 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010049 }
10050 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010051
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010052 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010053 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10054 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010055 }
Romain Guy06882f82009-06-10 13:36:04 -070010056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010057 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010058 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010059 + ": HIDE");
10060 try {
10061 mBlurSurface.hide();
10062 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010063 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010064 }
10065 mBlurShown = false;
10066 }
10067
Joe Onorato8a9b2202010-02-26 18:56:32 -080010068 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010069 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010070 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010071 }
10072
Jeff Browne33348b2010-07-15 23:54:05 -070010073 mInputMonitor.updateInputWindowsLw();
10074
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010075 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010076
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010077 if (mWatermark != null) {
10078 mWatermark.drawIfNeeded();
10079 }
10080
Joe Onorato8a9b2202010-02-26 18:56:32 -080010081 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010082 "With display frozen, orientationChangeComplete="
10083 + orientationChangeComplete);
10084 if (orientationChangeComplete) {
10085 if (mWindowsFreezingScreen) {
10086 mWindowsFreezingScreen = false;
10087 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10088 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010089 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010090 }
Romain Guy06882f82009-06-10 13:36:04 -070010091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010092 i = mResizingWindows.size();
10093 if (i > 0) {
10094 do {
10095 i--;
10096 WindowState win = mResizingWindows.get(i);
10097 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010098 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10099 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010100 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010101 boolean configChanged =
10102 win.mConfiguration != mCurConfiguration
10103 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010104 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10105 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10106 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010107 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010108 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010109 + " / " + mCurConfiguration + " / 0x"
10110 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010111 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010112 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010113 win.mClient.resized(win.mFrame.width(),
10114 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010115 win.mLastVisibleInsets, win.mDrawPending,
10116 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010117 win.mContentInsetsChanged = false;
10118 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010119 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010120 } catch (RemoteException e) {
10121 win.mOrientationChanging = false;
10122 }
10123 } while (i > 0);
10124 mResizingWindows.clear();
10125 }
Romain Guy06882f82009-06-10 13:36:04 -070010126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010127 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010128 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010129 i = mDestroySurface.size();
10130 if (i > 0) {
10131 do {
10132 i--;
10133 WindowState win = mDestroySurface.get(i);
10134 win.mDestroying = false;
10135 if (mInputMethodWindow == win) {
10136 mInputMethodWindow = null;
10137 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010138 if (win == mWallpaperTarget) {
10139 wallpaperDestroyed = true;
10140 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010141 win.destroySurfaceLocked();
10142 } while (i > 0);
10143 mDestroySurface.clear();
10144 }
10145
10146 // Time to remove any exiting tokens?
10147 for (i=mExitingTokens.size()-1; i>=0; i--) {
10148 WindowToken token = mExitingTokens.get(i);
10149 if (!token.hasVisible) {
10150 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010151 if (token.windowType == TYPE_WALLPAPER) {
10152 mWallpaperTokens.remove(token);
10153 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010154 }
10155 }
10156
10157 // Time to remove any exiting applications?
10158 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10159 AppWindowToken token = mExitingAppTokens.get(i);
10160 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010161 // Make sure there is no animation running on this token,
10162 // so any windows associated with it will be removed as
10163 // soon as their animations are complete
10164 token.animation = null;
10165 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010166 mAppTokens.remove(token);
10167 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010168 if (mLastEnterAnimToken == token) {
10169 mLastEnterAnimToken = null;
10170 mLastEnterAnimParams = null;
10171 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010172 }
10173 }
10174
Dianne Hackborna8f60182009-09-01 19:01:50 -070010175 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010176
Dianne Hackborna8f60182009-09-01 19:01:50 -070010177 if (!animating && mAppTransitionRunning) {
10178 // We have finished the animation of an app transition. To do
10179 // this, we have delayed a lot of operations like showing and
10180 // hiding apps, moving apps in Z-order, etc. The app token list
10181 // reflects the correct Z-order, but the window list may now
10182 // be out of sync with it. So here we will just rebuild the
10183 // entire app window list. Fun!
10184 mAppTransitionRunning = false;
10185 needRelayout = true;
10186 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010187 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010188 // Clear information about apps that were moving.
10189 mToBottomApps.clear();
10190 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010192 if (focusDisplayed) {
10193 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10194 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010195 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010196 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010197 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010198 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010199 requestAnimationLocked(0);
10200 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010201 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10202 }
Jeff Browneb857f12010-07-16 10:06:33 -070010203
Jeff Browne33348b2010-07-15 23:54:05 -070010204 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010205
Jeff Brown8e03b752010-06-13 19:16:55 -070010206 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010207 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10208 mPowerManager.setScreenBrightnessOverride(-1);
10209 } else {
10210 mPowerManager.setScreenBrightnessOverride((int)
10211 (screenBrightness * Power.BRIGHTNESS_ON));
10212 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010213 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10214 mPowerManager.setButtonBrightnessOverride(-1);
10215 } else {
10216 mPowerManager.setButtonBrightnessOverride((int)
10217 (buttonBrightness * Power.BRIGHTNESS_ON));
10218 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010219 if (holdScreen != mHoldingScreenOn) {
10220 mHoldingScreenOn = holdScreen;
10221 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10222 mH.sendMessage(m);
10223 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010224
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010225 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010226 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010227 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10228 LocalPowerManager.BUTTON_EVENT, true);
10229 mTurnOnScreen = false;
10230 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010231
10232 // Check to see if we are now in a state where the screen should
10233 // be enabled, because the window obscured flags have changed.
10234 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010235 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070010236
10237 /**
10238 * Must be called with the main window manager lock held.
10239 */
10240 void setHoldScreenLocked(boolean holding) {
10241 boolean state = mHoldingScreenWakeLock.isHeld();
10242 if (holding != state) {
10243 if (holding) {
10244 mHoldingScreenWakeLock.acquire();
10245 } else {
10246 mPolicy.screenOnStoppedLw();
10247 mHoldingScreenWakeLock.release();
10248 }
10249 }
10250 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010251
10252 void requestAnimationLocked(long delay) {
10253 if (!mAnimationPending) {
10254 mAnimationPending = true;
10255 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10256 }
10257 }
Romain Guy06882f82009-06-10 13:36:04 -070010258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010259 /**
10260 * Have the surface flinger show a surface, robustly dealing with
10261 * error conditions. In particular, if there is not enough memory
10262 * to show the surface, then we will try to get rid of other surfaces
10263 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010264 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010265 * @return Returns true if the surface was successfully shown.
10266 */
10267 boolean showSurfaceRobustlyLocked(WindowState win) {
10268 try {
10269 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010270 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010271 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010272 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010273 if (DEBUG_VISIBILITY) Slog.v(TAG,
10274 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010275 win.mTurnOnScreen = false;
10276 mTurnOnScreen = true;
10277 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010278 }
10279 return true;
10280 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010281 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010282 }
Romain Guy06882f82009-06-10 13:36:04 -070010283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010284 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010286 return false;
10287 }
Romain Guy06882f82009-06-10 13:36:04 -070010288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010289 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10290 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010291
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010292 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010293 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010295 if (mForceRemoves == null) {
10296 mForceRemoves = new ArrayList<WindowState>();
10297 }
Romain Guy06882f82009-06-10 13:36:04 -070010298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010299 long callingIdentity = Binder.clearCallingIdentity();
10300 try {
10301 // There was some problem... first, do a sanity check of the
10302 // window list to make sure we haven't left any dangling surfaces
10303 // around.
10304 int N = mWindows.size();
10305 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010306 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010307 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010308 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010309 if (ws.mSurface != null) {
10310 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010311 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010312 + ws + " surface=" + ws.mSurface
10313 + " token=" + win.mToken
10314 + " pid=" + ws.mSession.mPid
10315 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010316 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010317 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010318 ws.mSurface = null;
10319 mForceRemoves.add(ws);
10320 i--;
10321 N--;
10322 leakedSurface = true;
10323 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010324 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010325 + ws + " surface=" + ws.mSurface
10326 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010327 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010328 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010329 ws.mSurface = null;
10330 leakedSurface = true;
10331 }
10332 }
10333 }
Romain Guy06882f82009-06-10 13:36:04 -070010334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010335 boolean killedApps = false;
10336 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010337 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010338 SparseIntArray pidCandidates = new SparseIntArray();
10339 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010340 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010341 if (ws.mSurface != null) {
10342 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10343 }
10344 }
10345 if (pidCandidates.size() > 0) {
10346 int[] pids = new int[pidCandidates.size()];
10347 for (int i=0; i<pids.length; i++) {
10348 pids[i] = pidCandidates.keyAt(i);
10349 }
10350 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010351 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010352 killedApps = true;
10353 }
10354 } catch (RemoteException e) {
10355 }
10356 }
10357 }
Romain Guy06882f82009-06-10 13:36:04 -070010358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010359 if (leakedSurface || killedApps) {
10360 // We managed to reclaim some memory, so get rid of the trouble
10361 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010362 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010363 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010364 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010365 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010366 win.mSurface = null;
10367 }
Romain Guy06882f82009-06-10 13:36:04 -070010368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010369 try {
10370 win.mClient.dispatchGetNewSurface();
10371 } catch (RemoteException e) {
10372 }
10373 }
10374 } finally {
10375 Binder.restoreCallingIdentity(callingIdentity);
10376 }
10377 }
Romain Guy06882f82009-06-10 13:36:04 -070010378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010379 private boolean updateFocusedWindowLocked(int mode) {
10380 WindowState newFocus = computeFocusedWindowLocked();
10381 if (mCurrentFocus != newFocus) {
10382 // This check makes sure that we don't already have the focus
10383 // change message pending.
10384 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10385 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010386 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010387 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10388 final WindowState oldFocus = mCurrentFocus;
10389 mCurrentFocus = newFocus;
10390 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010392 final WindowState imWindow = mInputMethodWindow;
10393 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010394 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010395 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010396 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10397 mLayoutNeeded = true;
10398 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010399 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
10400 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010401 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10402 // Client will do the layout, but we need to assign layers
10403 // for handleNewWindowLocked() below.
10404 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010405 }
10406 }
Jeff Brown349703e2010-06-22 01:27:15 -070010407
10408 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10409 // If we defer assigning layers, then the caller is responsible for
10410 // doing this part.
10411 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010412 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010413 return true;
10414 }
10415 return false;
10416 }
Jeff Brown349703e2010-06-22 01:27:15 -070010417
10418 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010419 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070010420 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010421
10422 private WindowState computeFocusedWindowLocked() {
10423 WindowState result = null;
10424 WindowState win;
10425
10426 int i = mWindows.size() - 1;
10427 int nextAppIndex = mAppTokens.size()-1;
10428 WindowToken nextApp = nextAppIndex >= 0
10429 ? mAppTokens.get(nextAppIndex) : null;
10430
10431 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070010432 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010433
Joe Onorato8a9b2202010-02-26 18:56:32 -080010434 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010435 TAG, "Looking for focus: " + i
10436 + " = " + win
10437 + ", flags=" + win.mAttrs.flags
10438 + ", canReceive=" + win.canReceiveKeys());
10439
10440 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010442 // If this window's application has been removed, just skip it.
10443 if (thisApp != null && thisApp.removed) {
10444 i--;
10445 continue;
10446 }
Romain Guy06882f82009-06-10 13:36:04 -070010447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010448 // If there is a focused app, don't allow focus to go to any
10449 // windows below it. If this is an application window, step
10450 // through the app tokens until we find its app.
10451 if (thisApp != null && nextApp != null && thisApp != nextApp
10452 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10453 int origAppIndex = nextAppIndex;
10454 while (nextAppIndex > 0) {
10455 if (nextApp == mFocusedApp) {
10456 // Whoops, we are below the focused app... no focus
10457 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010458 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010459 TAG, "Reached focused app: " + mFocusedApp);
10460 return null;
10461 }
10462 nextAppIndex--;
10463 nextApp = mAppTokens.get(nextAppIndex);
10464 if (nextApp == thisApp) {
10465 break;
10466 }
10467 }
10468 if (thisApp != nextApp) {
10469 // Uh oh, the app token doesn't exist! This shouldn't
10470 // happen, but if it does we can get totally hosed...
10471 // so restart at the original app.
10472 nextAppIndex = origAppIndex;
10473 nextApp = mAppTokens.get(nextAppIndex);
10474 }
10475 }
10476
10477 // Dispatch to this window if it is wants key events.
10478 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010479 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010480 TAG, "Found focus @ " + i + " = " + win);
10481 result = win;
10482 break;
10483 }
10484
10485 i--;
10486 }
10487
10488 return result;
10489 }
10490
10491 private void startFreezingDisplayLocked() {
10492 if (mDisplayFrozen) {
10493 return;
10494 }
Romain Guy06882f82009-06-10 13:36:04 -070010495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010496 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010498 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010499 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010500 if (mFreezeGcPending != 0) {
10501 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010502 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010503 mH.removeMessages(H.FORCE_GC);
10504 Runtime.getRuntime().gc();
10505 mFreezeGcPending = now;
10506 }
10507 } else {
10508 mFreezeGcPending = now;
10509 }
Romain Guy06882f82009-06-10 13:36:04 -070010510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010511 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010512
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010513 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010514
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010515 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10516 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010517 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010518 mAppTransitionReady = true;
10519 }
Romain Guy06882f82009-06-10 13:36:04 -070010520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010521 if (PROFILE_ORIENTATION) {
10522 File file = new File("/data/system/frozen");
10523 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10524 }
10525 Surface.freezeDisplay(0);
10526 }
Romain Guy06882f82009-06-10 13:36:04 -070010527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010528 private void stopFreezingDisplayLocked() {
10529 if (!mDisplayFrozen) {
10530 return;
10531 }
Romain Guy06882f82009-06-10 13:36:04 -070010532
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010533 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10534 return;
10535 }
10536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010537 mDisplayFrozen = false;
10538 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10539 if (PROFILE_ORIENTATION) {
10540 Debug.stopMethodTracing();
10541 }
10542 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010543
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010544 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010545
Christopher Tateb696aee2010-04-02 19:08:30 -070010546 // While the display is frozen we don't re-compute the orientation
10547 // to avoid inconsistent states. However, something interesting
10548 // could have actually changed during that time so re-evaluate it
10549 // now to catch that.
10550 if (updateOrientationFromAppTokensLocked()) {
10551 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10552 }
10553
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010554 // A little kludge: a lot could have happened while the
10555 // display was frozen, so now that we are coming back we
10556 // do a gc so that any remote references the system
10557 // processes holds on others can be released if they are
10558 // no longer needed.
10559 mH.removeMessages(H.FORCE_GC);
10560 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10561 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010563 mScreenFrozenLock.release();
10564 }
Romain Guy06882f82009-06-10 13:36:04 -070010565
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010566 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10567 DisplayMetrics dm) {
10568 if (index < tokens.length) {
10569 String str = tokens[index];
10570 if (str != null && str.length() > 0) {
10571 try {
10572 int val = Integer.parseInt(str);
10573 return val;
10574 } catch (Exception e) {
10575 }
10576 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010577 }
10578 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10579 return defDps;
10580 }
10581 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10582 return val;
10583 }
10584
10585 class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010586 final String[] mTokens;
10587 final String mText;
10588 final Paint mTextPaint;
10589 final int mTextWidth;
10590 final int mTextHeight;
10591 final int mTextAscent;
10592 final int mTextDescent;
10593 final int mDeltaX;
10594 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010595
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010596 Surface mSurface;
10597 int mLastDW;
10598 int mLastDH;
10599 boolean mDrawNeeded;
10600
10601 Watermark(SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010602 final DisplayMetrics dm = new DisplayMetrics();
10603 mDisplay.getMetrics(dm);
10604
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010605 if (false) {
10606 Log.i(TAG, "*********************** WATERMARK");
10607 for (int i=0; i<tokens.length; i++) {
10608 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10609 }
10610 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010611
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010612 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010613
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010614 StringBuilder builder = new StringBuilder(32);
10615 int len = mTokens[0].length();
10616 len = len & ~1;
10617 for (int i=0; i<len; i+=2) {
10618 int c1 = mTokens[0].charAt(i);
10619 int c2 = mTokens[0].charAt(i+1);
10620 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10621 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10622 else c1 -= '0';
10623 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10624 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10625 else c2 -= '0';
10626 builder.append((char)(255-((c1*16)+c2)));
10627 }
10628 mText = builder.toString();
10629 if (false) {
10630 Log.i(TAG, "Final text: " + mText);
10631 }
10632
10633 int fontSize = getPropertyInt(tokens, 1,
10634 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10635
10636 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10637 mTextPaint.setTextSize(fontSize);
10638 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10639
10640 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
10641 mTextWidth = (int)mTextPaint.measureText(mText);
10642 mTextAscent = fm.ascent;
10643 mTextDescent = fm.descent;
10644 mTextHeight = fm.descent - fm.ascent;
10645
10646 mDeltaX = getPropertyInt(tokens, 2,
10647 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
10648 mDeltaY = getPropertyInt(tokens, 3,
10649 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
10650 int shadowColor = getPropertyInt(tokens, 4,
10651 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
10652 int color = getPropertyInt(tokens, 5,
10653 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
10654 int shadowRadius = getPropertyInt(tokens, 6,
10655 TypedValue.COMPLEX_UNIT_PX, 7, dm);
10656 int shadowDx = getPropertyInt(tokens, 8,
10657 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10658 int shadowDy = getPropertyInt(tokens, 9,
10659 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10660
10661 mTextPaint.setColor(color);
10662 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010663
10664 try {
10665 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010666 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010667 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010668 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010669 mSurface.show();
10670 } catch (OutOfResourcesException e) {
10671 }
10672 }
10673
10674 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010675 if (mLastDW != dw || mLastDH != dh) {
10676 mLastDW = dw;
10677 mLastDH = dh;
10678 mSurface.setSize(dw, dh);
10679 mDrawNeeded = true;
10680 }
10681 }
10682
10683 void drawIfNeeded() {
10684 if (mDrawNeeded) {
10685 final int dw = mLastDW;
10686 final int dh = mLastDH;
10687
10688 mDrawNeeded = false;
10689 Rect dirty = new Rect(0, 0, dw, dh);
10690 Canvas c = null;
10691 try {
10692 c = mSurface.lockCanvas(dirty);
10693 } catch (IllegalArgumentException e) {
10694 } catch (OutOfResourcesException e) {
10695 }
10696 if (c != null) {
10697 int deltaX = mDeltaX;
10698 int deltaY = mDeltaY;
10699
10700 // deltaX shouldn't be close to a round fraction of our
10701 // x step, or else things will line up too much.
10702 int div = (dw+mTextWidth)/deltaX;
10703 int rem = (dw+mTextWidth) - (div*deltaX);
10704 int qdelta = deltaX/4;
10705 if (rem < qdelta || rem > (deltaX-qdelta)) {
10706 deltaX += deltaX/3;
10707 }
10708
10709 int y = -mTextHeight;
10710 int x = -mTextWidth;
10711 while (y < (dh+mTextHeight)) {
10712 c.drawText(mText, x, y, mTextPaint);
10713 x += deltaX;
10714 if (x >= dw) {
10715 x -= (dw+mTextWidth);
10716 y += deltaY;
10717 }
10718 }
10719 mSurface.unlockCanvasAndPost(c);
10720 }
10721 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010722 }
10723 }
10724
10725 void createWatermark() {
10726 if (mWatermark != null) {
10727 return;
10728 }
10729
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010730 File file = new File("/system/etc/setup.conf");
10731 FileInputStream in = null;
10732 try {
10733 in = new FileInputStream(file);
10734 DataInputStream ind = new DataInputStream(in);
10735 String line = ind.readLine();
10736 if (line != null) {
10737 String[] toks = line.split("%");
10738 if (toks != null && toks.length > 0) {
10739 mWatermark = new Watermark(mFxSession, toks);
10740 }
10741 }
10742 } catch (FileNotFoundException e) {
10743 } catch (IOException e) {
10744 } finally {
10745 if (in != null) {
10746 try {
10747 in.close();
10748 } catch (IOException e) {
10749 }
10750 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010751 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010752 }
10753
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010754 @Override
10755 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10756 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10757 != PackageManager.PERMISSION_GRANTED) {
10758 pw.println("Permission Denial: can't dump WindowManager from from pid="
10759 + Binder.getCallingPid()
10760 + ", uid=" + Binder.getCallingUid());
10761 return;
10762 }
Romain Guy06882f82009-06-10 13:36:04 -070010763
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010764 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010765 pw.println(" ");
10766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010767 synchronized(mWindowMap) {
10768 pw.println("Current Window Manager state:");
10769 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010770 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010771 pw.print(" Window #"); pw.print(i); pw.print(' ');
10772 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010773 w.dump(pw, " ");
10774 }
10775 if (mInputMethodDialogs.size() > 0) {
10776 pw.println(" ");
10777 pw.println(" Input method dialogs:");
10778 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10779 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010780 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010781 }
10782 }
10783 if (mPendingRemove.size() > 0) {
10784 pw.println(" ");
10785 pw.println(" Remove pending for:");
10786 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10787 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010788 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10789 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010790 w.dump(pw, " ");
10791 }
10792 }
10793 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10794 pw.println(" ");
10795 pw.println(" Windows force removing:");
10796 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10797 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010798 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10799 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010800 w.dump(pw, " ");
10801 }
10802 }
10803 if (mDestroySurface.size() > 0) {
10804 pw.println(" ");
10805 pw.println(" Windows waiting to destroy their surface:");
10806 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10807 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010808 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10809 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010810 w.dump(pw, " ");
10811 }
10812 }
10813 if (mLosingFocus.size() > 0) {
10814 pw.println(" ");
10815 pw.println(" Windows losing focus:");
10816 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10817 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010818 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10819 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010820 w.dump(pw, " ");
10821 }
10822 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010823 if (mResizingWindows.size() > 0) {
10824 pw.println(" ");
10825 pw.println(" Windows waiting to resize:");
10826 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10827 WindowState w = mResizingWindows.get(i);
10828 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10829 pw.print(w); pw.println(":");
10830 w.dump(pw, " ");
10831 }
10832 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010833 if (mSessions.size() > 0) {
10834 pw.println(" ");
10835 pw.println(" All active sessions:");
10836 Iterator<Session> it = mSessions.iterator();
10837 while (it.hasNext()) {
10838 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010839 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010840 s.dump(pw, " ");
10841 }
10842 }
10843 if (mTokenMap.size() > 0) {
10844 pw.println(" ");
10845 pw.println(" All tokens:");
10846 Iterator<WindowToken> it = mTokenMap.values().iterator();
10847 while (it.hasNext()) {
10848 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010849 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010850 token.dump(pw, " ");
10851 }
10852 }
10853 if (mTokenList.size() > 0) {
10854 pw.println(" ");
10855 pw.println(" Window token list:");
10856 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010857 pw.print(" #"); pw.print(i); pw.print(": ");
10858 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010859 }
10860 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010861 if (mWallpaperTokens.size() > 0) {
10862 pw.println(" ");
10863 pw.println(" Wallpaper tokens:");
10864 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10865 WindowToken token = mWallpaperTokens.get(i);
10866 pw.print(" Wallpaper #"); pw.print(i);
10867 pw.print(' '); pw.print(token); pw.println(':');
10868 token.dump(pw, " ");
10869 }
10870 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010871 if (mAppTokens.size() > 0) {
10872 pw.println(" ");
10873 pw.println(" Application tokens in Z order:");
10874 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010875 pw.print(" App #"); pw.print(i); pw.print(": ");
10876 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010877 }
10878 }
10879 if (mFinishedStarting.size() > 0) {
10880 pw.println(" ");
10881 pw.println(" Finishing start of application tokens:");
10882 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10883 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010884 pw.print(" Finished Starting #"); pw.print(i);
10885 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010886 token.dump(pw, " ");
10887 }
10888 }
10889 if (mExitingTokens.size() > 0) {
10890 pw.println(" ");
10891 pw.println(" Exiting tokens:");
10892 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10893 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010894 pw.print(" Exiting #"); pw.print(i);
10895 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010896 token.dump(pw, " ");
10897 }
10898 }
10899 if (mExitingAppTokens.size() > 0) {
10900 pw.println(" ");
10901 pw.println(" Exiting application tokens:");
10902 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10903 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010904 pw.print(" Exiting App #"); pw.print(i);
10905 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010906 token.dump(pw, " ");
10907 }
10908 }
10909 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010910 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10911 pw.print(" mLastFocus="); pw.println(mLastFocus);
10912 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10913 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10914 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010915 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010916 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10917 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10918 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10919 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010920 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10921 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10922 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010923 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10924 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10925 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10926 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010927 if (mDimAnimator != null) {
10928 mDimAnimator.printTo(pw);
10929 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080010930 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010931 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010932 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010933 pw.print(mInputMethodAnimLayerAdjustment);
10934 pw.print(" mWallpaperAnimLayerAdjustment=");
10935 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010936 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10937 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010938 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10939 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010940 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
10941 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010942 pw.print(" mRotation="); pw.print(mRotation);
10943 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10944 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10945 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10946 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10947 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10948 pw.print(" mNextAppTransition=0x");
10949 pw.print(Integer.toHexString(mNextAppTransition));
10950 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010951 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010952 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010953 if (mNextAppTransitionPackage != null) {
10954 pw.print(" mNextAppTransitionPackage=");
10955 pw.print(mNextAppTransitionPackage);
10956 pw.print(", mNextAppTransitionEnter=0x");
10957 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10958 pw.print(", mNextAppTransitionExit=0x");
10959 pw.print(Integer.toHexString(mNextAppTransitionExit));
10960 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010961 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10962 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010963 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10964 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10965 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10966 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010967 if (mOpeningApps.size() > 0) {
10968 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10969 }
10970 if (mClosingApps.size() > 0) {
10971 pw.print(" mClosingApps="); pw.println(mClosingApps);
10972 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010973 if (mToTopApps.size() > 0) {
10974 pw.print(" mToTopApps="); pw.println(mToTopApps);
10975 }
10976 if (mToBottomApps.size() > 0) {
10977 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10978 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010979 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10980 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010981 }
10982 }
10983
Jeff Brown349703e2010-06-22 01:27:15 -070010984 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010985 public void monitor() {
10986 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010987 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070010988 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010989
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010990 /**
10991 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010992 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010993 */
10994 private static class DimAnimator {
10995 Surface mDimSurface;
10996 boolean mDimShown = false;
10997 float mDimCurrentAlpha;
10998 float mDimTargetAlpha;
10999 float mDimDeltaPerMs;
11000 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011001
11002 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011003
11004 DimAnimator (SurfaceSession session) {
11005 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011006 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011007 + mDimSurface + ": CREATE");
11008 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011009 mDimSurface = new Surface(session, 0,
11010 "DimSurface",
11011 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011012 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011013 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011014 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011015 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011016 }
11017 }
11018 }
11019
11020 /**
11021 * Show the dim surface.
11022 */
11023 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011024 if (!mDimShown) {
11025 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11026 dw + "x" + dh + ")");
11027 mDimShown = true;
11028 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011029 mLastDimWidth = dw;
11030 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011031 mDimSurface.setPosition(0, 0);
11032 mDimSurface.setSize(dw, dh);
11033 mDimSurface.show();
11034 } catch (RuntimeException e) {
11035 Slog.w(TAG, "Failure showing dim surface", e);
11036 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011037 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11038 mLastDimWidth = dw;
11039 mLastDimHeight = dh;
11040 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011041 }
11042 }
11043
11044 /**
11045 * Set's the dim surface's layer and update dim parameters that will be used in
11046 * {@link updateSurface} after all windows are examined.
11047 */
11048 void updateParameters(WindowState w, long currentTime) {
11049 mDimSurface.setLayer(w.mAnimLayer-1);
11050
11051 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011052 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011053 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011054 if (mDimTargetAlpha != target) {
11055 // If the desired dim level has changed, then
11056 // start an animation to it.
11057 mLastDimAnimTime = currentTime;
11058 long duration = (w.mAnimating && w.mAnimation != null)
11059 ? w.mAnimation.computeDurationHint()
11060 : DEFAULT_DIM_DURATION;
11061 if (target > mDimTargetAlpha) {
11062 // This is happening behind the activity UI,
11063 // so we can make it run a little longer to
11064 // give a stronger impression without disrupting
11065 // the user.
11066 duration *= DIM_DURATION_MULTIPLIER;
11067 }
11068 if (duration < 1) {
11069 // Don't divide by zero
11070 duration = 1;
11071 }
11072 mDimTargetAlpha = target;
11073 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11074 }
11075 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011076
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011077 /**
11078 * Updating the surface's alpha. Returns true if the animation continues, or returns
11079 * false when the animation is finished and the dim surface is hidden.
11080 */
11081 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11082 if (!dimming) {
11083 if (mDimTargetAlpha != 0) {
11084 mLastDimAnimTime = currentTime;
11085 mDimTargetAlpha = 0;
11086 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11087 }
11088 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011089
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011090 boolean animating = false;
11091 if (mLastDimAnimTime != 0) {
11092 mDimCurrentAlpha += mDimDeltaPerMs
11093 * (currentTime-mLastDimAnimTime);
11094 boolean more = true;
11095 if (displayFrozen) {
11096 // If the display is frozen, there is no reason to animate.
11097 more = false;
11098 } else if (mDimDeltaPerMs > 0) {
11099 if (mDimCurrentAlpha > mDimTargetAlpha) {
11100 more = false;
11101 }
11102 } else if (mDimDeltaPerMs < 0) {
11103 if (mDimCurrentAlpha < mDimTargetAlpha) {
11104 more = false;
11105 }
11106 } else {
11107 more = false;
11108 }
11109
11110 // Do we need to continue animating?
11111 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011112 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011113 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11114 mLastDimAnimTime = currentTime;
11115 mDimSurface.setAlpha(mDimCurrentAlpha);
11116 animating = true;
11117 } else {
11118 mDimCurrentAlpha = mDimTargetAlpha;
11119 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011120 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011121 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11122 mDimSurface.setAlpha(mDimCurrentAlpha);
11123 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011124 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011125 + ": HIDE");
11126 try {
11127 mDimSurface.hide();
11128 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011129 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011130 }
11131 mDimShown = false;
11132 }
11133 }
11134 }
11135 return animating;
11136 }
11137
11138 public void printTo(PrintWriter pw) {
11139 pw.print(" mDimShown="); pw.print(mDimShown);
11140 pw.print(" current="); pw.print(mDimCurrentAlpha);
11141 pw.print(" target="); pw.print(mDimTargetAlpha);
11142 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11143 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11144 }
11145 }
11146
11147 /**
11148 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11149 * This is used for opening/closing transition for apps in compatible mode.
11150 */
11151 private static class FadeInOutAnimation extends Animation {
11152 int mWidth;
11153 boolean mFadeIn;
11154
11155 public FadeInOutAnimation(boolean fadeIn) {
11156 setInterpolator(new AccelerateInterpolator());
11157 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11158 mFadeIn = fadeIn;
11159 }
11160
11161 @Override
11162 protected void applyTransformation(float interpolatedTime, Transformation t) {
11163 float x = interpolatedTime;
11164 if (!mFadeIn) {
11165 x = 1.0f - x; // reverse the interpolation for fade out
11166 }
11167 if (x < 0.5) {
11168 // move the window out of the screen.
11169 t.getMatrix().setTranslate(mWidth, 0);
11170 } else {
11171 t.getMatrix().setTranslate(0, 0);// show
11172 t.setAlpha((x - 0.5f) * 2);
11173 }
11174 }
11175
11176 @Override
11177 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11178 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11179 mWidth = width;
11180 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011181
11182 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011183 public int getZAdjustment() {
11184 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011185 }
11186 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011187}