blob: 7100cc58d783ef27e03589d40a783365fa4b2e26 [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;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043import com.android.internal.view.IInputContext;
44import com.android.internal.view.IInputMethodClient;
45import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080046import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import com.android.server.am.BatteryStatsService;
48
49import android.Manifest;
50import android.app.ActivityManagerNative;
51import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070052import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070053import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070055import android.content.Intent;
56import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import android.content.pm.ActivityInfo;
58import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070059import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.content.res.Configuration;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070061import android.graphics.Canvas;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062import android.graphics.Matrix;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070063import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import android.graphics.PixelFormat;
65import android.graphics.Rect;
66import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070067import android.graphics.Typeface;
68import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069import android.os.BatteryStats;
70import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070071import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072import android.os.Debug;
73import android.os.Handler;
74import android.os.IBinder;
75import android.os.LocalPowerManager;
76import android.os.Looper;
77import android.os.Message;
78import android.os.Parcel;
79import android.os.ParcelFileDescriptor;
80import android.os.Power;
81import android.os.PowerManager;
82import android.os.Process;
83import android.os.RemoteException;
84import android.os.ServiceManager;
85import android.os.SystemClock;
86import android.os.SystemProperties;
87import android.os.TokenWatcher;
88import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070089import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070091import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080092import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070094import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095import android.view.Display;
96import android.view.Gravity;
Jeff Brown00fa7bd2010-07-02 15:37:36 -070097import android.view.HapticFeedbackConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098import android.view.IApplicationToken;
99import android.view.IOnKeyguardExitResult;
100import android.view.IRotationWatcher;
101import android.view.IWindow;
102import android.view.IWindowManager;
103import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700104import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700105import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700106import android.view.InputEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107import android.view.KeyEvent;
108import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109import android.view.Surface;
110import android.view.SurfaceSession;
111import android.view.View;
112import android.view.ViewTreeObserver;
113import android.view.WindowManager;
114import android.view.WindowManagerImpl;
115import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700116import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700118import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119import android.view.animation.Animation;
120import android.view.animation.AnimationUtils;
121import android.view.animation.Transformation;
122
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700123import java.io.BufferedReader;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700125import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126import java.io.File;
127import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700128import java.io.FileInputStream;
129import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130import java.io.IOException;
131import java.io.OutputStream;
132import java.io.OutputStreamWriter;
133import java.io.PrintWriter;
134import java.io.StringWriter;
135import java.net.Socket;
136import java.util.ArrayList;
137import java.util.HashMap;
138import java.util.HashSet;
139import java.util.Iterator;
140import java.util.List;
141
142/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700143public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700144 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 static final String TAG = "WindowManager";
146 static final boolean DEBUG = false;
147 static final boolean DEBUG_FOCUS = false;
148 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800149 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800150 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 static final boolean DEBUG_LAYERS = false;
152 static final boolean DEBUG_INPUT = false;
153 static final boolean DEBUG_INPUT_METHOD = false;
154 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700155 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700157 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 static final boolean DEBUG_APP_TRANSITIONS = false;
159 static final boolean DEBUG_STARTING_WINDOW = false;
160 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700161 static final boolean DEBUG_WALLPAPER = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700163 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 static final boolean PROFILE_ORIENTATION = false;
166 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700167 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 /** How much to multiply the policy's type layer, to reserve room
170 * for multiple windows of the same type and Z-ordering adjustment
171 * with TYPE_LAYER_OFFSET. */
172 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
175 * or below others in the same layer. */
176 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 /** How much to increment the layer for each window, to reserve room
179 * for effect surfaces between them.
180 */
181 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 /** The maximum length we will accept for a loaded animation duration:
184 * this is 10 seconds.
185 */
186 static final int MAX_ANIMATION_DURATION = 10*1000;
187
188 /** Amount of time (in milliseconds) to animate the dim surface from one
189 * value to another, when no window animation is driving it.
190 */
191 static final int DEFAULT_DIM_DURATION = 200;
192
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700193 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
194 * compatible windows.
195 */
196 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198 /** Adjustment to time to perform a dim, to make it more dramatic.
199 */
200 static final int DIM_DURATION_MULTIPLIER = 6;
Jeff Brown7fbdc842010-06-17 20:52:56 -0700201
202 // Maximum number of milliseconds to wait for input event injection.
203 // FIXME is this value reasonable?
204 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700205
206 // Default input dispatching timeout in nanoseconds.
207 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 static final int UPDATE_FOCUS_NORMAL = 0;
210 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
211 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
212 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700215 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216
217 /**
218 * Condition waited on by {@link #reenableKeyguard} to know the call to
219 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500220 * This is set to true only if mKeyguardTokenWatcher.acquired() has
221 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500223 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224
Jim Miller284b62e2010-06-08 14:27:42 -0700225 private static final int ALLOW_DISABLE_YES = 1;
226 private static final int ALLOW_DISABLE_NO = 0;
227 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
228 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
229
Mike Lockwood983ee092009-11-22 01:42:24 -0500230 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
231 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700233 if (shouldAllowDisableKeyguard()) {
234 mPolicy.enableKeyguard(false);
235 mKeyguardDisabled = true;
236 } else {
237 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
238 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 }
240 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700241 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500242 synchronized (mKeyguardTokenWatcher) {
243 mKeyguardDisabled = false;
244 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800245 }
246 }
247 };
248
Jim Miller284b62e2010-06-08 14:27:42 -0700249 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
250 @Override
251 public void onReceive(Context context, Intent intent) {
252 mPolicy.enableKeyguard(true);
253 synchronized(mKeyguardTokenWatcher) {
254 // lazily evaluate this next time we're asked to disable keyguard
255 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
256 mKeyguardDisabled = false;
257 }
258 }
259 };
260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261 final Context mContext;
262
263 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
268
269 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 /**
274 * All currently active sessions with clients.
275 */
276 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 /**
279 * Mapping from an IWindow IBinder to the server's Window object.
280 * This is also used as the lock for all of our state.
281 */
282 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
283
284 /**
285 * Mapping from a token IBinder to a WindowToken object.
286 */
287 final HashMap<IBinder, WindowToken> mTokenMap =
288 new HashMap<IBinder, WindowToken>();
289
290 /**
291 * The same tokens as mTokenMap, stored in a list for efficient iteration
292 * over them.
293 */
294 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 /**
297 * Window tokens that are in the process of exiting, but still
298 * on screen for animations.
299 */
300 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
301
302 /**
303 * Z-ordered (bottom-most first) list of all application tokens, for
304 * controlling the ordering of windows in different applications. This
305 * contains WindowToken objects.
306 */
307 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
308
309 /**
310 * Application tokens that are in the process of exiting, but still
311 * on screen for animations.
312 */
313 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
314
315 /**
316 * List of window tokens that have finished starting their application,
317 * and now need to have the policy remove their windows.
318 */
319 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
320
321 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700322 * This was the app token that was used to retrieve the last enter
323 * animation. It will be used for the next exit animation.
324 */
325 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800326
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700327 /**
328 * These were the layout params used to retrieve the last enter animation.
329 * They will be used for the next exit animation.
330 */
331 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800332
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700333 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334 * Z-ordered (bottom-most first) list of all Window objects.
335 */
Jeff Browne33348b2010-07-15 23:54:05 -0700336 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337
338 /**
339 * Windows that are being resized. Used so we can tell the client about
340 * the resize after closing the transaction in which we resized the
341 * underlying surface.
342 */
343 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
344
345 /**
346 * Windows whose animations have ended and now must be removed.
347 */
348 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
349
350 /**
351 * Windows whose surface should be destroyed.
352 */
353 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
354
355 /**
356 * Windows that have lost input focus and are waiting for the new
357 * focus window to be displayed before they are told about this.
358 */
359 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
360
361 /**
362 * This is set when we have run out of memory, and will either be an empty
363 * list or contain windows that need to be force removed.
364 */
365 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800369 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700370 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 Surface mBlurSurface;
372 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700373 Watermark mWatermark;
Romain Guy06882f82009-06-10 13:36:04 -0700374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 final float[] mTmpFloats = new float[9];
378
379 boolean mSafeMode;
380 boolean mDisplayEnabled = false;
381 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700382 int mInitialDisplayWidth = 0;
383 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 int mRotation = 0;
385 int mRequestedRotation = 0;
386 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700387 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 ArrayList<IRotationWatcher> mRotationWatchers
389 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 boolean mLayoutNeeded = true;
392 boolean mAnimationPending = false;
393 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800394 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 boolean mWindowsFreezingScreen = false;
396 long mFreezeGcPending = 0;
397 int mAppsFreezingScreen = 0;
398
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800399 int mLayoutSeq = 0;
400
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800401 // State while inside of layoutAndPlaceSurfacesLocked().
402 boolean mFocusMayChange;
403
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800404 Configuration mCurConfiguration = new Configuration();
405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 // This is held as long as we have the screen frozen, to give us time to
407 // perform a rotation animation when turning off shows the lock screen which
408 // changes the orientation.
409 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411 // State management of app transitions. When we are preparing for a
412 // transition, mNextAppTransition will be the kind of transition to
413 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
414 // mOpeningApps and mClosingApps are the lists of tokens that will be
415 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700416 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700417 String mNextAppTransitionPackage;
418 int mNextAppTransitionEnter;
419 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700421 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 boolean mAppTransitionTimeout = false;
423 boolean mStartingIconInTransition = false;
424 boolean mSkipAppTransitionAnimation = false;
425 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
426 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700427 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
428 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700429
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800430 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 H mH = new H();
433
434 WindowState mCurrentFocus = null;
435 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 // This just indicates the window the input method is on top of, not
438 // necessarily the window its input is going to.
439 WindowState mInputMethodTarget = null;
440 WindowState mUpcomingInputMethodTarget = null;
441 boolean mInputMethodTargetWaitingAnim;
442 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 WindowState mInputMethodWindow = null;
445 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
446
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700447 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800448
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700449 // If non-null, this is the currently visible window that is associated
450 // with the wallpaper.
451 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700452 // If non-null, we are in the middle of animating from one wallpaper target
453 // to another, and this is the lower one in Z-order.
454 WindowState mLowerWallpaperTarget = null;
455 // If non-null, we are in the middle of animating from one wallpaper target
456 // to another, and this is the higher one in Z-order.
457 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700458 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700459 float mLastWallpaperX = -1;
460 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800461 float mLastWallpaperXStep = -1;
462 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700463 // This is set when we are waiting for a wallpaper to tell us it is done
464 // changing its scroll position.
465 WindowState mWaitingOnWallpaper;
466 // The last time we had a timeout when waiting for a wallpaper.
467 long mLastWallpaperTimeoutTime;
468 // We give a wallpaper up to 150ms to finish scrolling.
469 static final long WALLPAPER_TIMEOUT = 150;
470 // Time we wait after a timeout before trying to wait again.
471 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800473 AppWindowToken mFocusedApp = null;
474
475 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800477 float mWindowAnimationScale = 1.0f;
478 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700479
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700480 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800481
482 // Who is holding the screen on.
483 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700484 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700485
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700486 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488 /**
489 * Whether the UI is currently running in touch mode (not showing
490 * navigational focus because the user is directly pressing the screen).
491 */
492 boolean mInTouchMode = false;
493
494 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700495 private ArrayList<WindowChangeListener> mWindowChangeListeners =
496 new ArrayList<WindowChangeListener>();
497 private boolean mWindowsChanged = false;
498
499 public interface WindowChangeListener {
500 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700501 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700502 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503
Dianne Hackbornc485a602009-03-24 22:39:49 -0700504 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700505 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700506
507 // The frame use to limit the size of the app running in compatibility mode.
508 Rect mCompatibleScreenFrame = new Rect();
509 // The surface used to fill the outer rim of the app running in compatibility mode.
510 Surface mBackgroundFillerSurface = null;
511 boolean mBackgroundFillerShown = false;
512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800513 public static WindowManagerService main(Context context,
514 PowerManagerService pm, boolean haveInputMethods) {
515 WMThread thr = new WMThread(context, pm, haveInputMethods);
516 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800518 synchronized (thr) {
519 while (thr.mService == null) {
520 try {
521 thr.wait();
522 } catch (InterruptedException e) {
523 }
524 }
525 }
Romain Guy06882f82009-06-10 13:36:04 -0700526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800527 return thr.mService;
528 }
Romain Guy06882f82009-06-10 13:36:04 -0700529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530 static class WMThread extends Thread {
531 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 private final Context mContext;
534 private final PowerManagerService mPM;
535 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800537 public WMThread(Context context, PowerManagerService pm,
538 boolean haveInputMethods) {
539 super("WindowManager");
540 mContext = context;
541 mPM = pm;
542 mHaveInputMethods = haveInputMethods;
543 }
Romain Guy06882f82009-06-10 13:36:04 -0700544
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800545 public void run() {
546 Looper.prepare();
547 WindowManagerService s = new WindowManagerService(mContext, mPM,
548 mHaveInputMethods);
549 android.os.Process.setThreadPriority(
550 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700551 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800553 synchronized (this) {
554 mService = s;
555 notifyAll();
556 }
Romain Guy06882f82009-06-10 13:36:04 -0700557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558 Looper.loop();
559 }
560 }
561
562 static class PolicyThread extends Thread {
563 private final WindowManagerPolicy mPolicy;
564 private final WindowManagerService mService;
565 private final Context mContext;
566 private final PowerManagerService mPM;
567 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 public PolicyThread(WindowManagerPolicy policy,
570 WindowManagerService service, Context context,
571 PowerManagerService pm) {
572 super("WindowManagerPolicy");
573 mPolicy = policy;
574 mService = service;
575 mContext = context;
576 mPM = pm;
577 }
Romain Guy06882f82009-06-10 13:36:04 -0700578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 public void run() {
580 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800581 WindowManagerPolicyThread.set(this, Looper.myLooper());
582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800584 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585 android.os.Process.setThreadPriority(
586 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700587 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 synchronized (this) {
591 mRunning = true;
592 notifyAll();
593 }
Romain Guy06882f82009-06-10 13:36:04 -0700594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595 Looper.loop();
596 }
597 }
598
599 private WindowManagerService(Context context, PowerManagerService pm,
600 boolean haveInputMethods) {
601 mContext = context;
602 mHaveInputMethods = haveInputMethods;
603 mLimitedAlphaCompositing = context.getResources().getBoolean(
604 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800606 mPowerManager = pm;
607 mPowerManager.setPolicy(mPolicy);
608 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
609 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
610 "SCREEN_FROZEN");
611 mScreenFrozenLock.setReferenceCounted(false);
612
613 mActivityManager = ActivityManagerNative.getDefault();
614 mBatteryStats = BatteryStatsService.getService();
615
616 // Get persisted window scale setting
617 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
618 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
619 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
620 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700621
Jim Miller284b62e2010-06-08 14:27:42 -0700622 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
623 IntentFilter filter = new IntentFilter();
624 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
625 mContext.registerReceiver(mBroadcastReceiver, filter);
626
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700627 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
628 "KEEP_SCREEN_ON_FLAG");
629 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800630
Jeff Browne33348b2010-07-15 23:54:05 -0700631 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -0700632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
634 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700635
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800636 synchronized (thr) {
637 while (!thr.mRunning) {
638 try {
639 thr.wait();
640 } catch (InterruptedException e) {
641 }
642 }
643 }
Romain Guy06882f82009-06-10 13:36:04 -0700644
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700645 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -0700646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800647 // Add ourself to the Watchdog monitors.
648 Watchdog.getInstance().addMonitor(this);
649 }
650
651 @Override
652 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
653 throws RemoteException {
654 try {
655 return super.onTransact(code, data, reply, flags);
656 } catch (RuntimeException e) {
657 // The window manager only throws security exceptions, so let's
658 // log all others.
659 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800660 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800661 }
662 throw e;
663 }
664 }
665
Jeff Browne33348b2010-07-15 23:54:05 -0700666 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800668 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800669 TAG, "Adding window " + window + " at "
670 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
671 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700672 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 }
674
Jeff Browne33348b2010-07-15 23:54:05 -0700675 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800676 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800677 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678 TAG, "Adding window " + window + " at "
679 + i + " of " + mWindows.size() + " (before " + pos + ")");
680 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700681 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800682 }
683
684 //This method finds out the index of a window that has the same app token as
685 //win. used for z ordering the windows in mWindows
686 private int findIdxBasedOnAppTokens(WindowState win) {
687 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -0700688 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800689 int jmax = localmWindows.size();
690 if(jmax == 0) {
691 return -1;
692 }
693 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700694 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800695 if(wentry.mAppToken == win.mAppToken) {
696 return j;
697 }
698 }
699 return -1;
700 }
Romain Guy06882f82009-06-10 13:36:04 -0700701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800702 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
703 final IWindow client = win.mClient;
704 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -0700705 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -0700706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800707 final int N = localmWindows.size();
708 final WindowState attached = win.mAttachedWindow;
709 int i;
710 if (attached == null) {
711 int tokenWindowsPos = token.windows.size();
712 if (token.appWindowToken != null) {
713 int index = tokenWindowsPos-1;
714 if (index >= 0) {
715 // If this application has existing windows, we
716 // simply place the new window on top of them... but
717 // keep the starting window on top.
718 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
719 // Base windows go behind everything else.
720 placeWindowBefore(token.windows.get(0), win);
721 tokenWindowsPos = 0;
722 } else {
723 AppWindowToken atoken = win.mAppToken;
724 if (atoken != null &&
725 token.windows.get(index) == atoken.startingWindow) {
726 placeWindowBefore(token.windows.get(index), win);
727 tokenWindowsPos--;
728 } else {
729 int newIdx = findIdxBasedOnAppTokens(win);
730 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -0700731 //there is a window above this one associated with the same
732 //apptoken note that the window could be a floating window
733 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800734 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -0800735 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700736 TAG, "Adding window " + win + " at "
737 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800738 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700739 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -0700740 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800741 }
742 }
743 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800744 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800745 TAG, "Figuring out where to add app window "
746 + client.asBinder() + " (token=" + token + ")");
747 // Figure out where the window should go, based on the
748 // order of applications.
749 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -0700750 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800751 for (i=NA-1; i>=0; i--) {
752 AppWindowToken t = mAppTokens.get(i);
753 if (t == token) {
754 i--;
755 break;
756 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800757
Dianne Hackborna8f60182009-09-01 19:01:50 -0700758 // We haven't reached the token yet; if this token
759 // is not going to the bottom and has windows, we can
760 // use it as an anchor for when we do reach the token.
761 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800762 pos = t.windows.get(0);
763 }
764 }
765 // We now know the index into the apps. If we found
766 // an app window above, that gives us the position; else
767 // we need to look some more.
768 if (pos != null) {
769 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -0700770 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800771 if (atoken != null) {
772 final int NC = atoken.windows.size();
773 if (NC > 0) {
774 WindowState bottom = atoken.windows.get(0);
775 if (bottom.mSubLayer < 0) {
776 pos = bottom;
777 }
778 }
779 }
780 placeWindowBefore(pos, win);
781 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700782 // Continue looking down until we find the first
783 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800784 while (i >= 0) {
785 AppWindowToken t = mAppTokens.get(i);
786 final int NW = t.windows.size();
787 if (NW > 0) {
788 pos = t.windows.get(NW-1);
789 break;
790 }
791 i--;
792 }
793 if (pos != null) {
794 // Move in front of any windows attached to this
795 // one.
Jeff Browne33348b2010-07-15 23:54:05 -0700796 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800797 if (atoken != null) {
798 final int NC = atoken.windows.size();
799 if (NC > 0) {
800 WindowState top = atoken.windows.get(NC-1);
801 if (top.mSubLayer >= 0) {
802 pos = top;
803 }
804 }
805 }
806 placeWindowAfter(pos, win);
807 } else {
808 // Just search for the start of this layer.
809 final int myLayer = win.mBaseLayer;
810 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -0700811 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800812 if (w.mBaseLayer > myLayer) {
813 break;
814 }
815 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800816 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700817 TAG, "Adding window " + win + " at "
818 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800819 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700820 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800821 }
822 }
823 }
824 } else {
825 // Figure out where window should go, based on layer.
826 final int myLayer = win.mBaseLayer;
827 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700828 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800829 i++;
830 break;
831 }
832 }
833 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800834 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700835 TAG, "Adding window " + win + " at "
836 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800837 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700838 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800839 }
840 if (addToToken) {
841 token.windows.add(tokenWindowsPos, win);
842 }
843
844 } else {
845 // Figure out this window's ordering relative to the window
846 // it is attached to.
847 final int NA = token.windows.size();
848 final int sublayer = win.mSubLayer;
849 int largestSublayer = Integer.MIN_VALUE;
850 WindowState windowWithLargestSublayer = null;
851 for (i=0; i<NA; i++) {
852 WindowState w = token.windows.get(i);
853 final int wSublayer = w.mSubLayer;
854 if (wSublayer >= largestSublayer) {
855 largestSublayer = wSublayer;
856 windowWithLargestSublayer = w;
857 }
858 if (sublayer < 0) {
859 // For negative sublayers, we go below all windows
860 // in the same sublayer.
861 if (wSublayer >= sublayer) {
862 if (addToToken) {
863 token.windows.add(i, win);
864 }
865 placeWindowBefore(
866 wSublayer >= 0 ? attached : w, win);
867 break;
868 }
869 } else {
870 // For positive sublayers, we go above all windows
871 // in the same sublayer.
872 if (wSublayer > sublayer) {
873 if (addToToken) {
874 token.windows.add(i, win);
875 }
876 placeWindowBefore(w, win);
877 break;
878 }
879 }
880 }
881 if (i >= NA) {
882 if (addToToken) {
883 token.windows.add(win);
884 }
885 if (sublayer < 0) {
886 placeWindowBefore(attached, win);
887 } else {
888 placeWindowAfter(largestSublayer >= 0
889 ? windowWithLargestSublayer
890 : attached,
891 win);
892 }
893 }
894 }
Romain Guy06882f82009-06-10 13:36:04 -0700895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800896 if (win.mAppToken != null && addToToken) {
897 win.mAppToken.allAppWindows.add(win);
898 }
899 }
Romain Guy06882f82009-06-10 13:36:04 -0700900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800901 static boolean canBeImeTarget(WindowState w) {
902 final int fl = w.mAttrs.flags
903 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
904 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
905 return w.isVisibleOrAdding();
906 }
907 return false;
908 }
Romain Guy06882f82009-06-10 13:36:04 -0700909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800910 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -0700911 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800912 final int N = localmWindows.size();
913 WindowState w = null;
914 int i = N;
915 while (i > 0) {
916 i--;
Jeff Browne33348b2010-07-15 23:54:05 -0700917 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -0700918
Joe Onorato8a9b2202010-02-26 18:56:32 -0800919 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800920 // + Integer.toHexString(w.mAttrs.flags));
921 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800922 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -0700923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 // Yet more tricksyness! If this window is a "starting"
925 // window, we do actually want to be on top of it, but
926 // it is not -really- where input will go. So if the caller
927 // is not actually looking to move the IME, look down below
928 // for a real window to target...
929 if (!willMove
930 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
931 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -0700932 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
934 i--;
935 w = wb;
936 }
937 }
938 break;
939 }
940 }
Romain Guy06882f82009-06-10 13:36:04 -0700941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800942 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -0700943
Joe Onorato8a9b2202010-02-26 18:56:32 -0800944 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800945 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -0700946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800947 if (willMove && w != null) {
948 final WindowState curTarget = mInputMethodTarget;
949 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -0700950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800951 // Now some fun for dealing with window animations that
952 // modify the Z order. We need to look at all windows below
953 // the current target that are in this app, finding the highest
954 // visible one in layering.
955 AppWindowToken token = curTarget.mAppToken;
956 WindowState highestTarget = null;
957 int highestPos = 0;
958 if (token.animating || token.animation != null) {
959 int pos = 0;
960 pos = localmWindows.indexOf(curTarget);
961 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -0700962 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800963 if (win.mAppToken != token) {
964 break;
965 }
966 if (!win.mRemoved) {
967 if (highestTarget == null || win.mAnimLayer >
968 highestTarget.mAnimLayer) {
969 highestTarget = win;
970 highestPos = pos;
971 }
972 }
973 pos--;
974 }
975 }
Romain Guy06882f82009-06-10 13:36:04 -0700976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800977 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800978 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800979 + mNextAppTransition + " " + highestTarget
980 + " animating=" + highestTarget.isAnimating()
981 + " layer=" + highestTarget.mAnimLayer
982 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -0700983
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700984 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800985 // If we are currently setting up for an animation,
986 // hold everything until we can find out what will happen.
987 mInputMethodTargetWaitingAnim = true;
988 mInputMethodTarget = highestTarget;
989 return highestPos + 1;
990 } else if (highestTarget.isAnimating() &&
991 highestTarget.mAnimLayer > w.mAnimLayer) {
992 // If the window we are currently targeting is involved
993 // with an animation, and it is on top of the next target
994 // we will be over, then hold off on moving until
995 // that is done.
996 mInputMethodTarget = highestTarget;
997 return highestPos + 1;
998 }
999 }
1000 }
1001 }
Romain Guy06882f82009-06-10 13:36:04 -07001002
Joe Onorato8a9b2202010-02-26 18:56:32 -08001003 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001004 if (w != null) {
1005 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001006 if (DEBUG_INPUT_METHOD) {
1007 RuntimeException e = null;
1008 if (!HIDE_STACK_CRAWLS) {
1009 e = new RuntimeException();
1010 e.fillInStackTrace();
1011 }
1012 Slog.w(TAG, "Moving IM target from "
1013 + mInputMethodTarget + " to " + w, e);
1014 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001015 mInputMethodTarget = w;
1016 if (w.mAppToken != null) {
1017 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1018 } else {
1019 setInputMethodAnimLayerAdjustment(0);
1020 }
1021 }
1022 return i+1;
1023 }
1024 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001025 if (DEBUG_INPUT_METHOD) {
1026 RuntimeException e = null;
1027 if (!HIDE_STACK_CRAWLS) {
1028 e = new RuntimeException();
1029 e.fillInStackTrace();
1030 }
1031 Slog.w(TAG, "Moving IM target from "
1032 + mInputMethodTarget + " to null", e);
1033 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001034 mInputMethodTarget = null;
1035 setInputMethodAnimLayerAdjustment(0);
1036 }
1037 return -1;
1038 }
Romain Guy06882f82009-06-10 13:36:04 -07001039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001040 void addInputMethodWindowToListLocked(WindowState win) {
1041 int pos = findDesiredInputMethodWindowIndexLocked(true);
1042 if (pos >= 0) {
1043 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001044 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001045 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001046 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001047 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001048 moveInputMethodDialogsLocked(pos+1);
1049 return;
1050 }
1051 win.mTargetAppToken = null;
1052 addWindowToListInOrderLocked(win, true);
1053 moveInputMethodDialogsLocked(pos);
1054 }
Romain Guy06882f82009-06-10 13:36:04 -07001055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001056 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001057 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001058 mInputMethodAnimLayerAdjustment = adj;
1059 WindowState imw = mInputMethodWindow;
1060 if (imw != null) {
1061 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001062 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001063 + " anim layer: " + imw.mAnimLayer);
1064 int wi = imw.mChildWindows.size();
1065 while (wi > 0) {
1066 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001067 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001069 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001070 + " anim layer: " + cw.mAnimLayer);
1071 }
1072 }
1073 int di = mInputMethodDialogs.size();
1074 while (di > 0) {
1075 di --;
1076 imw = mInputMethodDialogs.get(di);
1077 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001078 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001079 + " anim layer: " + imw.mAnimLayer);
1080 }
1081 }
Romain Guy06882f82009-06-10 13:36:04 -07001082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001083 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1084 int wpos = mWindows.indexOf(win);
1085 if (wpos >= 0) {
1086 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001087 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001088 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001089 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001090 int NC = win.mChildWindows.size();
1091 while (NC > 0) {
1092 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001093 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001094 int cpos = mWindows.indexOf(cw);
1095 if (cpos >= 0) {
1096 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001097 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001098 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 mWindows.remove(cpos);
1100 }
1101 }
1102 }
1103 return interestingPos;
1104 }
Romain Guy06882f82009-06-10 13:36:04 -07001105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 private void reAddWindowToListInOrderLocked(WindowState win) {
1107 addWindowToListInOrderLocked(win, false);
1108 // This is a hack to get all of the child windows added as well
1109 // at the right position. Child windows should be rare and
1110 // this case should be rare, so it shouldn't be that big a deal.
1111 int wpos = mWindows.indexOf(win);
1112 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001113 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001114 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001116 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001117 reAddWindowLocked(wpos, win);
1118 }
1119 }
Romain Guy06882f82009-06-10 13:36:04 -07001120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001121 void logWindowList(String prefix) {
1122 int N = mWindows.size();
1123 while (N > 0) {
1124 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001125 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001126 }
1127 }
Romain Guy06882f82009-06-10 13:36:04 -07001128
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001129 void moveInputMethodDialogsLocked(int pos) {
1130 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001133 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001134 for (int i=0; i<N; i++) {
1135 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1136 }
1137 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001138 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001139 logWindowList(" ");
1140 }
Romain Guy06882f82009-06-10 13:36:04 -07001141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 if (pos >= 0) {
1143 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1144 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001145 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001146 if (wp == mInputMethodWindow) {
1147 pos++;
1148 }
1149 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001150 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151 for (int i=0; i<N; i++) {
1152 WindowState win = dialogs.get(i);
1153 win.mTargetAppToken = targetAppToken;
1154 pos = reAddWindowLocked(pos, win);
1155 }
1156 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001157 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001158 logWindowList(" ");
1159 }
1160 return;
1161 }
1162 for (int i=0; i<N; i++) {
1163 WindowState win = dialogs.get(i);
1164 win.mTargetAppToken = null;
1165 reAddWindowToListInOrderLocked(win);
1166 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001167 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001168 logWindowList(" ");
1169 }
1170 }
1171 }
Romain Guy06882f82009-06-10 13:36:04 -07001172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001173 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1174 final WindowState imWin = mInputMethodWindow;
1175 final int DN = mInputMethodDialogs.size();
1176 if (imWin == null && DN == 0) {
1177 return false;
1178 }
Romain Guy06882f82009-06-10 13:36:04 -07001179
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001180 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1181 if (imPos >= 0) {
1182 // In this case, the input method windows are to be placed
1183 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001185 // First check to see if the input method windows are already
1186 // located here, and contiguous.
1187 final int N = mWindows.size();
1188 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001189 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001191 // Figure out the actual input method window that should be
1192 // at the bottom of their stack.
1193 WindowState baseImWin = imWin != null
1194 ? imWin : mInputMethodDialogs.get(0);
1195 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001196 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001197 if (cw.mSubLayer < 0) baseImWin = cw;
1198 }
Romain Guy06882f82009-06-10 13:36:04 -07001199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001200 if (firstImWin == baseImWin) {
1201 // The windows haven't moved... but are they still contiguous?
1202 // First find the top IM window.
1203 int pos = imPos+1;
1204 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001205 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001206 break;
1207 }
1208 pos++;
1209 }
1210 pos++;
1211 // Now there should be no more input method windows above.
1212 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001213 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001214 break;
1215 }
1216 pos++;
1217 }
1218 if (pos >= N) {
1219 // All is good!
1220 return false;
1221 }
1222 }
Romain Guy06882f82009-06-10 13:36:04 -07001223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 if (imWin != null) {
1225 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001226 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001227 logWindowList(" ");
1228 }
1229 imPos = tmpRemoveWindowLocked(imPos, imWin);
1230 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001231 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001232 logWindowList(" ");
1233 }
1234 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1235 reAddWindowLocked(imPos, imWin);
1236 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001237 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001238 logWindowList(" ");
1239 }
1240 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1241 } else {
1242 moveInputMethodDialogsLocked(imPos);
1243 }
Romain Guy06882f82009-06-10 13:36:04 -07001244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001245 } else {
1246 // In this case, the input method windows go in a fixed layer,
1247 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001249 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001250 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001251 tmpRemoveWindowLocked(0, imWin);
1252 imWin.mTargetAppToken = null;
1253 reAddWindowToListInOrderLocked(imWin);
1254 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001255 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001256 logWindowList(" ");
1257 }
1258 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1259 } else {
1260 moveInputMethodDialogsLocked(-1);;
1261 }
Romain Guy06882f82009-06-10 13:36:04 -07001262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001263 }
Romain Guy06882f82009-06-10 13:36:04 -07001264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 if (needAssignLayers) {
1266 assignLayersLocked();
1267 }
Romain Guy06882f82009-06-10 13:36:04 -07001268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001269 return true;
1270 }
Romain Guy06882f82009-06-10 13:36:04 -07001271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001272 void adjustInputMethodDialogsLocked() {
1273 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1274 }
Romain Guy06882f82009-06-10 13:36:04 -07001275
Dianne Hackborn25994b42009-09-04 14:21:19 -07001276 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001277 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001278 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1279 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1280 ? wallpaperTarget.mAppToken.animation : null)
1281 + " upper=" + mUpperWallpaperTarget
1282 + " lower=" + mLowerWallpaperTarget);
1283 return (wallpaperTarget != null
1284 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1285 && wallpaperTarget.mAppToken.animation != null)))
1286 || mUpperWallpaperTarget != null
1287 || mLowerWallpaperTarget != null;
1288 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001289
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001290 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1291 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001292
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001293 int adjustWallpaperWindowsLocked() {
1294 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001295
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001296 final int dw = mDisplay.getWidth();
1297 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001298
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001299 // First find top-most window that has asked to be on top of the
1300 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001301 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001302 int N = localmWindows.size();
1303 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001304 WindowState foundW = null;
1305 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001306 WindowState topCurW = null;
1307 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001308 int i = N;
1309 while (i > 0) {
1310 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001311 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001312 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1313 if (topCurW == null) {
1314 topCurW = w;
1315 topCurI = i;
1316 }
1317 continue;
1318 }
1319 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001320 if (w.mAppToken != null) {
1321 // If this window's app token is hidden and not animating,
1322 // it is of no interest to us.
1323 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001324 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001325 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001326 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001327 continue;
1328 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001329 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001330 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001331 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1332 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001333 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001334 && (mWallpaperTarget == w
1335 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001336 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001337 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001338 foundW = w;
1339 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001340 if (w == mWallpaperTarget && ((w.mAppToken != null
1341 && w.mAppToken.animation != null)
1342 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001343 // The current wallpaper target is animating, so we'll
1344 // look behind it for another possible target and figure
1345 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001346 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001347 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001348 continue;
1349 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001350 break;
1351 }
1352 }
1353
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001354 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001355 // If we are currently waiting for an app transition, and either
1356 // the current target or the next target are involved with it,
1357 // then hold off on doing anything with the wallpaper.
1358 // Note that we are checking here for just whether the target
1359 // is part of an app token... which is potentially overly aggressive
1360 // (the app token may not be involved in the transition), but good
1361 // enough (we'll just wait until whatever transition is pending
1362 // executes).
1363 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001364 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001365 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001366 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001367 }
1368 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001369 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001370 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001371 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001372 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001373 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001374
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001375 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001376 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001377 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001378 + " oldTarget: " + mWallpaperTarget);
1379 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001380
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001381 mLowerWallpaperTarget = null;
1382 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001383
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001384 WindowState oldW = mWallpaperTarget;
1385 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001386
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001387 // Now what is happening... if the current and new targets are
1388 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001389 if (foundW != null && oldW != null) {
1390 boolean oldAnim = oldW.mAnimation != null
1391 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1392 boolean foundAnim = foundW.mAnimation != null
1393 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001394 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001395 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001396 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001397 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001398 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001399 int oldI = localmWindows.indexOf(oldW);
1400 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001401 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001402 }
1403 if (oldI >= 0) {
1404 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001405 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001406 + "=" + oldW + "; new#" + foundI
1407 + "=" + foundW);
1408 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001409
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001410 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001411 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001412 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001413 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001414 }
1415 mWallpaperTarget = oldW;
1416 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001417
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001418 // Now set the upper and lower wallpaper targets
1419 // correctly, and make sure that we are positioning
1420 // the wallpaper below the lower.
1421 if (foundI > oldI) {
1422 // The new target is on top of the old one.
1423 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001424 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001425 }
1426 mUpperWallpaperTarget = foundW;
1427 mLowerWallpaperTarget = oldW;
1428 foundW = oldW;
1429 foundI = oldI;
1430 } else {
1431 // The new target is below the old one.
1432 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001433 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001434 }
1435 mUpperWallpaperTarget = oldW;
1436 mLowerWallpaperTarget = foundW;
1437 }
1438 }
1439 }
1440 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001441
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001442 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001443 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001444 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1445 || (mLowerWallpaperTarget.mAppToken != null
1446 && mLowerWallpaperTarget.mAppToken.animation != null);
1447 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1448 || (mUpperWallpaperTarget.mAppToken != null
1449 && mUpperWallpaperTarget.mAppToken.animation != null);
1450 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001451 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001452 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001453 }
1454 mLowerWallpaperTarget = null;
1455 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001456 }
1457 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001458
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001459 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001460 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001461 // The window is visible to the compositor... but is it visible
1462 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001463 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001464 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001465
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001466 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001467 // its layer adjustment. Only do this if we are not transfering
1468 // between two wallpaper targets.
1469 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001470 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001471 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001472
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001473 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1474 * TYPE_LAYER_MULTIPLIER
1475 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001476
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001477 // Now w is the window we are supposed to be behind... but we
1478 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001479 // AND any starting window associated with it, AND below the
1480 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001481 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001482 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001483 if (wb.mBaseLayer < maxLayer &&
1484 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001485 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001486 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001487 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001488 // This window is not related to the previous one in any
1489 // interesting way, so stop here.
1490 break;
1491 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001492 foundW = wb;
1493 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001494 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001495 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001496 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001497 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001498
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001499 if (foundW == null && topCurW != null) {
1500 // There is no wallpaper target, so it goes at the bottom.
1501 // We will assume it is the same place as last time, if known.
1502 foundW = topCurW;
1503 foundI = topCurI+1;
1504 } else {
1505 // Okay i is the position immediately above the wallpaper. Look at
1506 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001507 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001508 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001509
Dianne Hackborn284ac932009-08-28 10:34:25 -07001510 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001511 if (mWallpaperTarget.mWallpaperX >= 0) {
1512 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001513 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001514 }
1515 if (mWallpaperTarget.mWallpaperY >= 0) {
1516 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001517 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001518 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001519 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001520
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001521 // Start stepping backwards from here, ensuring that our wallpaper windows
1522 // are correctly placed.
1523 int curTokenIndex = mWallpaperTokens.size();
1524 while (curTokenIndex > 0) {
1525 curTokenIndex--;
1526 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001527 if (token.hidden == visible) {
1528 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1529 token.hidden = !visible;
1530 // Need to do a layout to ensure the wallpaper now has the
1531 // correct size.
1532 mLayoutNeeded = true;
1533 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001534
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001535 int curWallpaperIndex = token.windows.size();
1536 while (curWallpaperIndex > 0) {
1537 curWallpaperIndex--;
1538 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001539
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001540 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001541 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001542 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001543
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001544 // First, make sure the client has the current visibility
1545 // state.
1546 if (wallpaper.mWallpaperVisible != visible) {
1547 wallpaper.mWallpaperVisible = visible;
1548 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001549 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001550 "Setting visibility of wallpaper " + wallpaper
1551 + ": " + visible);
1552 wallpaper.mClient.dispatchAppVisibility(visible);
1553 } catch (RemoteException e) {
1554 }
1555 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001556
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001557 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001558 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001559 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001560
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001561 // First, if this window is at the current index, then all
1562 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001563 if (wallpaper == foundW) {
1564 foundI--;
1565 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001566 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001567 continue;
1568 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001569
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001570 // The window didn't match... the current wallpaper window,
1571 // wherever it is, is in the wrong place, so make sure it is
1572 // not in the list.
1573 int oldIndex = localmWindows.indexOf(wallpaper);
1574 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001575 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001576 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001577 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001578 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001579 if (oldIndex < foundI) {
1580 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001581 }
1582 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001583
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001584 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001585 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001586 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001587 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001588
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001589 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001590 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001591 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001592 }
1593 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001594
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001595 return changed;
1596 }
1597
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001598 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001599 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001600 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001601 mWallpaperAnimLayerAdjustment = adj;
1602 int curTokenIndex = mWallpaperTokens.size();
1603 while (curTokenIndex > 0) {
1604 curTokenIndex--;
1605 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1606 int curWallpaperIndex = token.windows.size();
1607 while (curWallpaperIndex > 0) {
1608 curWallpaperIndex--;
1609 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1610 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001611 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001612 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001613 }
1614 }
1615 }
1616
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001617 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1618 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001619 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001620 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001621 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001622 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001623 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1624 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1625 changed = wallpaperWin.mXOffset != offset;
1626 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001627 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001628 + wallpaperWin + " x: " + offset);
1629 wallpaperWin.mXOffset = offset;
1630 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001631 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001632 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001633 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001634 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001635 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001636
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001637 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001638 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001639 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1640 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1641 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001642 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001643 + wallpaperWin + " y: " + offset);
1644 changed = true;
1645 wallpaperWin.mYOffset = offset;
1646 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001647 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001648 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001649 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001650 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001651 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001652
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001653 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001654 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001655 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001656 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1657 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001658 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001659 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001660 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001661 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001662 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1663 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001664 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001665 if (mWaitingOnWallpaper != null) {
1666 long start = SystemClock.uptimeMillis();
1667 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1668 < start) {
1669 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001670 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001671 "Waiting for offset complete...");
1672 mWindowMap.wait(WALLPAPER_TIMEOUT);
1673 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001674 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001675 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001676 if ((start+WALLPAPER_TIMEOUT)
1677 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001678 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001679 + wallpaperWin);
1680 mLastWallpaperTimeoutTime = start;
1681 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001682 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001683 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001684 }
1685 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001686 } catch (RemoteException e) {
1687 }
1688 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001689
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001690 return changed;
1691 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001692
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001693 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001694 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001695 if (mWaitingOnWallpaper != null &&
1696 mWaitingOnWallpaper.mClient.asBinder() == window) {
1697 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001698 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001699 }
1700 }
1701 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001702
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001703 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001704 final int dw = mDisplay.getWidth();
1705 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001706
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001707 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001708
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001709 WindowState target = mWallpaperTarget;
1710 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001711 if (target.mWallpaperX >= 0) {
1712 mLastWallpaperX = target.mWallpaperX;
1713 } else if (changingTarget.mWallpaperX >= 0) {
1714 mLastWallpaperX = changingTarget.mWallpaperX;
1715 }
1716 if (target.mWallpaperY >= 0) {
1717 mLastWallpaperY = target.mWallpaperY;
1718 } else if (changingTarget.mWallpaperY >= 0) {
1719 mLastWallpaperY = changingTarget.mWallpaperY;
1720 }
1721 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001722
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001723 int curTokenIndex = mWallpaperTokens.size();
1724 while (curTokenIndex > 0) {
1725 curTokenIndex--;
1726 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1727 int curWallpaperIndex = token.windows.size();
1728 while (curWallpaperIndex > 0) {
1729 curWallpaperIndex--;
1730 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1731 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1732 wallpaper.computeShownFrameLocked();
1733 changed = true;
1734 // We only want to be synchronous with one wallpaper.
1735 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001736 }
1737 }
1738 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001739
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001740 return changed;
1741 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001742
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001743 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001744 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001745 final int dw = mDisplay.getWidth();
1746 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001747
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001748 int curTokenIndex = mWallpaperTokens.size();
1749 while (curTokenIndex > 0) {
1750 curTokenIndex--;
1751 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001752 if (token.hidden == visible) {
1753 token.hidden = !visible;
1754 // Need to do a layout to ensure the wallpaper now has the
1755 // correct size.
1756 mLayoutNeeded = true;
1757 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001758
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001759 int curWallpaperIndex = token.windows.size();
1760 while (curWallpaperIndex > 0) {
1761 curWallpaperIndex--;
1762 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1763 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001764 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001765 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001766
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001767 if (wallpaper.mWallpaperVisible != visible) {
1768 wallpaper.mWallpaperVisible = visible;
1769 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001770 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001771 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001772 + ": " + visible);
1773 wallpaper.mClient.dispatchAppVisibility(visible);
1774 } catch (RemoteException e) {
1775 }
1776 }
1777 }
1778 }
1779 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001780
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001781 public int addWindow(Session session, IWindow client,
1782 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001783 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001784 int res = mPolicy.checkAddPermission(attrs);
1785 if (res != WindowManagerImpl.ADD_OKAY) {
1786 return res;
1787 }
Romain Guy06882f82009-06-10 13:36:04 -07001788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001789 boolean reportNewConfig = false;
1790 WindowState attachedWindow = null;
1791 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07001792 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07001793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001794 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001795 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07001796 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001797 }
Romain Guy06882f82009-06-10 13:36:04 -07001798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001799 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001800 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001801 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1802 }
1803
1804 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001805 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001806 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001807 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001808 + attrs.token + ". Aborting.");
1809 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1810 }
1811 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1812 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001813 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001814 + attrs.token + ". Aborting.");
1815 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1816 }
1817 }
1818
1819 boolean addToken = false;
1820 WindowToken token = mTokenMap.get(attrs.token);
1821 if (token == null) {
1822 if (attrs.type >= FIRST_APPLICATION_WINDOW
1823 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001824 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001825 + attrs.token + ". Aborting.");
1826 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1827 }
1828 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001829 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001830 + attrs.token + ". Aborting.");
1831 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1832 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001833 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001834 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001835 + attrs.token + ". Aborting.");
1836 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1837 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001838 token = new WindowToken(attrs.token, -1, false);
1839 addToken = true;
1840 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1841 && attrs.type <= LAST_APPLICATION_WINDOW) {
1842 AppWindowToken atoken = token.appWindowToken;
1843 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001844 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001845 + token + ". Aborting.");
1846 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1847 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001848 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001849 + token + ". Aborting.");
1850 return WindowManagerImpl.ADD_APP_EXITING;
1851 }
1852 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1853 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001854 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001855 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1856 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1857 }
1858 } else if (attrs.type == TYPE_INPUT_METHOD) {
1859 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001860 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001861 + attrs.token + ". Aborting.");
1862 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1863 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001864 } else if (attrs.type == TYPE_WALLPAPER) {
1865 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001866 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001867 + attrs.token + ". Aborting.");
1868 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1869 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001870 }
1871
1872 win = new WindowState(session, client, token,
1873 attachedWindow, attrs, viewVisibility);
1874 if (win.mDeathRecipient == null) {
1875 // Client has apparently died, so there is no reason to
1876 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001877 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001878 + " that is dead, aborting.");
1879 return WindowManagerImpl.ADD_APP_EXITING;
1880 }
1881
1882 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001883
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001884 res = mPolicy.prepareAddWindowLw(win, attrs);
1885 if (res != WindowManagerImpl.ADD_OKAY) {
1886 return res;
1887 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001888
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001889 if (outInputChannel != null) {
1890 String name = win.makeInputChannelName();
1891 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1892 win.mInputChannel = inputChannels[0];
1893 inputChannels[1].transferToBinderOutParameter(outInputChannel);
1894
1895 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001896 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001897
1898 // From now on, no exceptions or errors allowed!
1899
1900 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001901
Dianne Hackborn5132b372010-07-29 12:51:35 -07001902 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001904 if (addToken) {
1905 mTokenMap.put(attrs.token, token);
1906 mTokenList.add(token);
1907 }
1908 win.attach();
1909 mWindowMap.put(client.asBinder(), win);
1910
1911 if (attrs.type == TYPE_APPLICATION_STARTING &&
1912 token.appWindowToken != null) {
1913 token.appWindowToken.startingWindow = win;
1914 }
1915
1916 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001918 if (attrs.type == TYPE_INPUT_METHOD) {
1919 mInputMethodWindow = win;
1920 addInputMethodWindowToListLocked(win);
1921 imMayMove = false;
1922 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1923 mInputMethodDialogs.add(win);
1924 addWindowToListInOrderLocked(win, true);
1925 adjustInputMethodDialogsLocked();
1926 imMayMove = false;
1927 } else {
1928 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001929 if (attrs.type == TYPE_WALLPAPER) {
1930 mLastWallpaperTimeoutTime = 0;
1931 adjustWallpaperWindowsLocked();
1932 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001933 adjustWallpaperWindowsLocked();
1934 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001935 }
Romain Guy06882f82009-06-10 13:36:04 -07001936
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001937 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001939 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001940
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001941 if (mInTouchMode) {
1942 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1943 }
1944 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1945 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1946 }
Romain Guy06882f82009-06-10 13:36:04 -07001947
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001948 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001949 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07001950 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
1951 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001952 imMayMove = false;
1953 }
1954 }
Romain Guy06882f82009-06-10 13:36:04 -07001955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001956 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07001957 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001958 }
Romain Guy06882f82009-06-10 13:36:04 -07001959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001960 assignLayersLocked();
1961 // Don't do layout here, the window must call
1962 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07001963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001964 //dump();
1965
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001966 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07001967 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001968 }
Jeff Brown349703e2010-06-22 01:27:15 -07001969
Joe Onorato8a9b2202010-02-26 18:56:32 -08001970 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001971 TAG, "New client " + client.asBinder()
1972 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001973
1974 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
1975 reportNewConfig = true;
1976 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001977 }
1978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001979 if (reportNewConfig) {
1980 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001981 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07001982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001983 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07001984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001985 return res;
1986 }
Romain Guy06882f82009-06-10 13:36:04 -07001987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001988 public void removeWindow(Session session, IWindow client) {
1989 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001990 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001991 if (win == null) {
1992 return;
1993 }
1994 removeWindowLocked(session, win);
1995 }
1996 }
Romain Guy06882f82009-06-10 13:36:04 -07001997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001998 public void removeWindowLocked(Session session, WindowState win) {
1999
Joe Onorato8a9b2202010-02-26 18:56:32 -08002000 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002001 TAG, "Remove " + win + " client="
2002 + Integer.toHexString(System.identityHashCode(
2003 win.mClient.asBinder()))
2004 + ", surface=" + win.mSurface);
2005
2006 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002007
2008 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002009
Joe Onorato8a9b2202010-02-26 18:56:32 -08002010 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002011 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2012 + " mExiting=" + win.mExiting
2013 + " isAnimating=" + win.isAnimating()
2014 + " app-animation="
2015 + (win.mAppToken != null ? win.mAppToken.animation : null)
2016 + " inPendingTransaction="
2017 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2018 + " mDisplayFrozen=" + mDisplayFrozen);
2019 // Visibility of the removed window. Will be used later to update orientation later on.
2020 boolean wasVisible = false;
2021 // First, see if we need to run an animation. If we do, we have
2022 // to hold off on removing the window until the animation is done.
2023 // If the display is frozen, just remove immediately, since the
2024 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002025 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002026 // If we are not currently running the exit animation, we
2027 // need to see about starting one.
2028 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002030 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2031 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2032 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2033 }
2034 // Try starting an animation.
2035 if (applyAnimationLocked(win, transit, false)) {
2036 win.mExiting = true;
2037 }
2038 }
2039 if (win.mExiting || win.isAnimating()) {
2040 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002041 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002042 win.mExiting = true;
2043 win.mRemoveOnExit = true;
2044 mLayoutNeeded = true;
2045 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2046 performLayoutAndPlaceSurfacesLocked();
2047 if (win.mAppToken != null) {
2048 win.mAppToken.updateReportedVisibilityLocked();
2049 }
2050 //dump();
2051 Binder.restoreCallingIdentity(origId);
2052 return;
2053 }
2054 }
2055
2056 removeWindowInnerLocked(session, win);
2057 // Removing a visible window will effect the computed orientation
2058 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002059 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002060 != mForcedAppOrientation
2061 && updateOrientationFromAppTokensLocked()) {
2062 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002063 }
2064 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2065 Binder.restoreCallingIdentity(origId);
2066 }
Romain Guy06882f82009-06-10 13:36:04 -07002067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002068 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002069 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002071 if (mInputMethodTarget == win) {
2072 moveInputMethodWindowsIfNeededLocked(false);
2073 }
Romain Guy06882f82009-06-10 13:36:04 -07002074
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002075 if (false) {
2076 RuntimeException e = new RuntimeException("here");
2077 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002078 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002079 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002081 mPolicy.removeWindowLw(win);
2082 win.removeLocked();
2083
2084 mWindowMap.remove(win.mClient.asBinder());
2085 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002086 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002087 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002088
2089 if (mInputMethodWindow == win) {
2090 mInputMethodWindow = null;
2091 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2092 mInputMethodDialogs.remove(win);
2093 }
Romain Guy06882f82009-06-10 13:36:04 -07002094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002095 final WindowToken token = win.mToken;
2096 final AppWindowToken atoken = win.mAppToken;
2097 token.windows.remove(win);
2098 if (atoken != null) {
2099 atoken.allAppWindows.remove(win);
2100 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002101 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002102 TAG, "**** Removing window " + win + ": count="
2103 + token.windows.size());
2104 if (token.windows.size() == 0) {
2105 if (!token.explicit) {
2106 mTokenMap.remove(token.token);
2107 mTokenList.remove(token);
2108 } else if (atoken != null) {
2109 atoken.firstWindowDrawn = false;
2110 }
2111 }
2112
2113 if (atoken != null) {
2114 if (atoken.startingWindow == win) {
2115 atoken.startingWindow = null;
2116 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2117 // If this is the last window and we had requested a starting
2118 // transition window, well there is no point now.
2119 atoken.startingData = null;
2120 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2121 // If this is the last window except for a starting transition
2122 // window, we need to get rid of the starting transition.
2123 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002124 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002125 + ": no more real windows");
2126 }
2127 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2128 mH.sendMessage(m);
2129 }
2130 }
Romain Guy06882f82009-06-10 13:36:04 -07002131
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002132 if (win.mAttrs.type == TYPE_WALLPAPER) {
2133 mLastWallpaperTimeoutTime = 0;
2134 adjustWallpaperWindowsLocked();
2135 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002136 adjustWallpaperWindowsLocked();
2137 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002139 if (!mInLayout) {
2140 assignLayersLocked();
2141 mLayoutNeeded = true;
2142 performLayoutAndPlaceSurfacesLocked();
2143 if (win.mAppToken != null) {
2144 win.mAppToken.updateReportedVisibilityLocked();
2145 }
2146 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002147
2148 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002149 }
2150
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002151 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2152 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2153 + ": " + msg + " / " + w.mAttrs.getTitle();
2154 if (where != null) {
2155 Slog.i(TAG, str, where);
2156 } else {
2157 Slog.i(TAG, str);
2158 }
2159 }
2160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002161 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2162 long origId = Binder.clearCallingIdentity();
2163 try {
2164 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002165 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002166 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002167 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002168 Surface.openTransaction();
2169 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002170 if (SHOW_TRANSACTIONS) logSurface(w,
2171 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002172 w.mSurface.setTransparentRegionHint(region);
2173 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002174 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002175 Surface.closeTransaction();
2176 }
2177 }
2178 }
2179 } finally {
2180 Binder.restoreCallingIdentity(origId);
2181 }
2182 }
2183
2184 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002185 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002186 Rect visibleInsets) {
2187 long origId = Binder.clearCallingIdentity();
2188 try {
2189 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002190 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002191 if (w != null) {
2192 w.mGivenInsetsPending = false;
2193 w.mGivenContentInsets.set(contentInsets);
2194 w.mGivenVisibleInsets.set(visibleInsets);
2195 w.mTouchableInsets = touchableInsets;
2196 mLayoutNeeded = true;
2197 performLayoutAndPlaceSurfacesLocked();
2198 }
2199 }
2200 } finally {
2201 Binder.restoreCallingIdentity(origId);
2202 }
2203 }
Romain Guy06882f82009-06-10 13:36:04 -07002204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002205 public void getWindowDisplayFrame(Session session, IWindow client,
2206 Rect outDisplayFrame) {
2207 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002208 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002209 if (win == null) {
2210 outDisplayFrame.setEmpty();
2211 return;
2212 }
2213 outDisplayFrame.set(win.mDisplayFrame);
2214 }
2215 }
2216
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002217 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2218 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002219 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2220 window.mWallpaperX = x;
2221 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002222 window.mWallpaperXStep = xStep;
2223 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002224 if (updateWallpaperOffsetLocked(window, true)) {
2225 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002226 }
2227 }
2228 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002229
Dianne Hackborn75804932009-10-20 20:15:20 -07002230 void wallpaperCommandComplete(IBinder window, Bundle result) {
2231 synchronized (mWindowMap) {
2232 if (mWaitingOnWallpaper != null &&
2233 mWaitingOnWallpaper.mClient.asBinder() == window) {
2234 mWaitingOnWallpaper = null;
2235 mWindowMap.notifyAll();
2236 }
2237 }
2238 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002239
Dianne Hackborn75804932009-10-20 20:15:20 -07002240 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2241 String action, int x, int y, int z, Bundle extras, boolean sync) {
2242 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2243 || window == mUpperWallpaperTarget) {
2244 boolean doWait = sync;
2245 int curTokenIndex = mWallpaperTokens.size();
2246 while (curTokenIndex > 0) {
2247 curTokenIndex--;
2248 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2249 int curWallpaperIndex = token.windows.size();
2250 while (curWallpaperIndex > 0) {
2251 curWallpaperIndex--;
2252 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2253 try {
2254 wallpaper.mClient.dispatchWallpaperCommand(action,
2255 x, y, z, extras, sync);
2256 // We only want to be synchronous with one wallpaper.
2257 sync = false;
2258 } catch (RemoteException e) {
2259 }
2260 }
2261 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002262
Dianne Hackborn75804932009-10-20 20:15:20 -07002263 if (doWait) {
2264 // XXX Need to wait for result.
2265 }
2266 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002267
Dianne Hackborn75804932009-10-20 20:15:20 -07002268 return null;
2269 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002271 public int relayoutWindow(Session session, IWindow client,
2272 WindowManager.LayoutParams attrs, int requestedWidth,
2273 int requestedHeight, int viewVisibility, boolean insetsPending,
2274 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002275 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002276 boolean displayed = false;
2277 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002278 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002279 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002281 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002282 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002283 if (win == null) {
2284 return 0;
2285 }
2286 win.mRequestedWidth = requestedWidth;
2287 win.mRequestedHeight = requestedHeight;
2288
2289 if (attrs != null) {
2290 mPolicy.adjustWindowParamsLw(attrs);
2291 }
Romain Guy06882f82009-06-10 13:36:04 -07002292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002293 int attrChanges = 0;
2294 int flagChanges = 0;
2295 if (attrs != null) {
2296 flagChanges = win.mAttrs.flags ^= attrs.flags;
2297 attrChanges = win.mAttrs.copyFrom(attrs);
2298 }
2299
Joe Onorato8a9b2202010-02-26 18:56:32 -08002300 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002301
2302 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2303 win.mAlpha = attrs.alpha;
2304 }
2305
2306 final boolean scaledWindow =
2307 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2308
2309 if (scaledWindow) {
2310 // requested{Width|Height} Surface's physical size
2311 // attrs.{width|height} Size on screen
2312 win.mHScale = (attrs.width != requestedWidth) ?
2313 (attrs.width / (float)requestedWidth) : 1.0f;
2314 win.mVScale = (attrs.height != requestedHeight) ?
2315 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002316 } else {
2317 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002318 }
2319
2320 boolean imMayMove = (flagChanges&(
2321 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2322 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002324 boolean focusMayChange = win.mViewVisibility != viewVisibility
2325 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2326 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002327
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002328 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2329 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002331 win.mRelayoutCalled = true;
2332 final int oldVisibility = win.mViewVisibility;
2333 win.mViewVisibility = viewVisibility;
2334 if (viewVisibility == View.VISIBLE &&
2335 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2336 displayed = !win.isVisibleLw();
2337 if (win.mExiting) {
2338 win.mExiting = false;
2339 win.mAnimation = null;
2340 }
2341 if (win.mDestroying) {
2342 win.mDestroying = false;
2343 mDestroySurface.remove(win);
2344 }
2345 if (oldVisibility == View.GONE) {
2346 win.mEnterAnimationPending = true;
2347 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002348 if (displayed) {
2349 if (win.mSurface != null && !win.mDrawPending
2350 && !win.mCommitDrawPending && !mDisplayFrozen
2351 && mPolicy.isScreenOn()) {
2352 applyEnterAnimationLocked(win);
2353 }
2354 if ((win.mAttrs.flags
2355 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2356 if (DEBUG_VISIBILITY) Slog.v(TAG,
2357 "Relayout window turning screen on: " + win);
2358 win.mTurnOnScreen = true;
2359 }
2360 int diff = 0;
2361 if (win.mConfiguration != mCurConfiguration
2362 && (win.mConfiguration == null
2363 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2364 win.mConfiguration = mCurConfiguration;
2365 if (DEBUG_CONFIGURATION) {
2366 Slog.i(TAG, "Window " + win + " visible with new config: "
2367 + win.mConfiguration + " / 0x"
2368 + Integer.toHexString(diff));
2369 }
2370 outConfig.setTo(mCurConfiguration);
2371 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002372 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002373 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2374 // To change the format, we need to re-build the surface.
2375 win.destroySurfaceLocked();
2376 displayed = true;
2377 }
2378 try {
2379 Surface surface = win.createSurfaceLocked();
2380 if (surface != null) {
2381 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002382 win.mReportDestroySurface = false;
2383 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002384 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002385 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002386 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002387 // For some reason there isn't a surface. Clear the
2388 // caller's object so they see the same state.
2389 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002390 }
2391 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002392 mInputMonitor.updateInputWindowsLw();
2393
Joe Onorato8a9b2202010-02-26 18:56:32 -08002394 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002395 + client + " (" + win.mAttrs.getTitle() + ")",
2396 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002397 Binder.restoreCallingIdentity(origId);
2398 return 0;
2399 }
2400 if (displayed) {
2401 focusMayChange = true;
2402 }
2403 if (win.mAttrs.type == TYPE_INPUT_METHOD
2404 && mInputMethodWindow == null) {
2405 mInputMethodWindow = win;
2406 imMayMove = true;
2407 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002408 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2409 && win.mAppToken != null
2410 && win.mAppToken.startingWindow != null) {
2411 // Special handling of starting window over the base
2412 // window of the app: propagate lock screen flags to it,
2413 // to provide the correct semantics while starting.
2414 final int mask =
2415 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002416 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2417 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002418 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2419 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2420 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002421 } else {
2422 win.mEnterAnimationPending = false;
2423 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002424 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002425 + ": mExiting=" + win.mExiting
2426 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002427 // If we are not currently running the exit animation, we
2428 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002429 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002430 // Try starting an animation; if there isn't one, we
2431 // can destroy the surface right away.
2432 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2433 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2434 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2435 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002436 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002437 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002438 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002439 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002440 } else if (win.isAnimating()) {
2441 // Currently in a hide animation... turn this into
2442 // an exit.
2443 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002444 } else if (win == mWallpaperTarget) {
2445 // If the wallpaper is currently behind this
2446 // window, we need to change both of them inside
2447 // of a transaction to avoid artifacts.
2448 win.mExiting = true;
2449 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002450 } else {
2451 if (mInputMethodWindow == win) {
2452 mInputMethodWindow = null;
2453 }
2454 win.destroySurfaceLocked();
2455 }
2456 }
2457 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002458
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002459 if (win.mSurface == null || (win.getAttrs().flags
2460 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2461 || win.mSurfacePendingDestroy) {
2462 // We are being called from a local process, which
2463 // means outSurface holds its current surface. Ensure the
2464 // surface object is cleared, but we don't want it actually
2465 // destroyed at this point.
2466 win.mSurfacePendingDestroy = false;
2467 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002468 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002469 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002470 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002471 "Keeping surface, will report destroy: " + win);
2472 win.mReportDestroySurface = true;
2473 outSurface.copyFrom(win.mSurface);
2474 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002475 }
2476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002477 if (focusMayChange) {
2478 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2479 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002480 imMayMove = false;
2481 }
2482 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2483 }
Romain Guy06882f82009-06-10 13:36:04 -07002484
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002485 // updateFocusedWindowLocked() already assigned layers so we only need to
2486 // reassign them at this point if the IM window state gets shuffled
2487 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002489 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002490 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2491 // Little hack here -- we -should- be able to rely on the
2492 // function to return true if the IME has moved and needs
2493 // its layer recomputed. However, if the IME was hidden
2494 // and isn't actually moved in the list, its layer may be
2495 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002496 assignLayers = true;
2497 }
2498 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002499 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002500 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002501 assignLayers = true;
2502 }
2503 }
Romain Guy06882f82009-06-10 13:36:04 -07002504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002505 mLayoutNeeded = true;
2506 win.mGivenInsetsPending = insetsPending;
2507 if (assignLayers) {
2508 assignLayersLocked();
2509 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002510 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002511 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002512 if (displayed && win.mIsWallpaper) {
2513 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002514 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002515 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002516 if (win.mAppToken != null) {
2517 win.mAppToken.updateReportedVisibilityLocked();
2518 }
2519 outFrame.set(win.mFrame);
2520 outContentInsets.set(win.mContentInsets);
2521 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002522 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002523 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002524 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002525 + ", requestedHeight=" + requestedHeight
2526 + ", viewVisibility=" + viewVisibility
2527 + "\nRelayout returning frame=" + outFrame
2528 + ", surface=" + outSurface);
2529
Joe Onorato8a9b2202010-02-26 18:56:32 -08002530 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002531 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2532
2533 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002534
2535 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002536 }
2537
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002538 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002539 sendNewConfiguration();
2540 }
Romain Guy06882f82009-06-10 13:36:04 -07002541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002542 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002544 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2545 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2546 }
2547
2548 public void finishDrawingWindow(Session session, IWindow client) {
2549 final long origId = Binder.clearCallingIdentity();
2550 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002551 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002552 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002553 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2554 adjustWallpaperWindowsLocked();
2555 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002556 mLayoutNeeded = true;
2557 performLayoutAndPlaceSurfacesLocked();
2558 }
2559 }
2560 Binder.restoreCallingIdentity(origId);
2561 }
2562
2563 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002564 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002565 + (lp != null ? lp.packageName : null)
2566 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2567 if (lp != null && lp.windowAnimations != 0) {
2568 // If this is a system resource, don't try to load it from the
2569 // application resources. It is nice to avoid loading application
2570 // resources if we can.
2571 String packageName = lp.packageName != null ? lp.packageName : "android";
2572 int resId = lp.windowAnimations;
2573 if ((resId&0xFF000000) == 0x01000000) {
2574 packageName = "android";
2575 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002576 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002577 + packageName);
2578 return AttributeCache.instance().get(packageName, resId,
2579 com.android.internal.R.styleable.WindowAnimation);
2580 }
2581 return null;
2582 }
Romain Guy06882f82009-06-10 13:36:04 -07002583
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002584 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002585 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002586 + packageName + " resId=0x" + Integer.toHexString(resId));
2587 if (packageName != null) {
2588 if ((resId&0xFF000000) == 0x01000000) {
2589 packageName = "android";
2590 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002591 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002592 + packageName);
2593 return AttributeCache.instance().get(packageName, resId,
2594 com.android.internal.R.styleable.WindowAnimation);
2595 }
2596 return null;
2597 }
2598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002599 private void applyEnterAnimationLocked(WindowState win) {
2600 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2601 if (win.mEnterAnimationPending) {
2602 win.mEnterAnimationPending = false;
2603 transit = WindowManagerPolicy.TRANSIT_ENTER;
2604 }
2605
2606 applyAnimationLocked(win, transit, true);
2607 }
2608
2609 private boolean applyAnimationLocked(WindowState win,
2610 int transit, boolean isEntrance) {
2611 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2612 // If we are trying to apply an animation, but already running
2613 // an animation of the same type, then just leave that one alone.
2614 return true;
2615 }
Romain Guy06882f82009-06-10 13:36:04 -07002616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002617 // Only apply an animation if the display isn't frozen. If it is
2618 // frozen, there is no reason to animate and it can cause strange
2619 // artifacts when we unfreeze the display if some different animation
2620 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002621 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002622 int anim = mPolicy.selectAnimationLw(win, transit);
2623 int attr = -1;
2624 Animation a = null;
2625 if (anim != 0) {
2626 a = AnimationUtils.loadAnimation(mContext, anim);
2627 } else {
2628 switch (transit) {
2629 case WindowManagerPolicy.TRANSIT_ENTER:
2630 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2631 break;
2632 case WindowManagerPolicy.TRANSIT_EXIT:
2633 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2634 break;
2635 case WindowManagerPolicy.TRANSIT_SHOW:
2636 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2637 break;
2638 case WindowManagerPolicy.TRANSIT_HIDE:
2639 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2640 break;
2641 }
2642 if (attr >= 0) {
2643 a = loadAnimation(win.mAttrs, attr);
2644 }
2645 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002646 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002647 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2648 + " mAnimation=" + win.mAnimation
2649 + " isEntrance=" + isEntrance);
2650 if (a != null) {
2651 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002652 RuntimeException e = null;
2653 if (!HIDE_STACK_CRAWLS) {
2654 e = new RuntimeException();
2655 e.fillInStackTrace();
2656 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002657 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002658 }
2659 win.setAnimation(a);
2660 win.mAnimationIsEntrance = isEntrance;
2661 }
2662 } else {
2663 win.clearAnimation();
2664 }
2665
2666 return win.mAnimation != null;
2667 }
2668
2669 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2670 int anim = 0;
2671 Context context = mContext;
2672 if (animAttr >= 0) {
2673 AttributeCache.Entry ent = getCachedAnimations(lp);
2674 if (ent != null) {
2675 context = ent.context;
2676 anim = ent.array.getResourceId(animAttr, 0);
2677 }
2678 }
2679 if (anim != 0) {
2680 return AnimationUtils.loadAnimation(context, anim);
2681 }
2682 return null;
2683 }
Romain Guy06882f82009-06-10 13:36:04 -07002684
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002685 private Animation loadAnimation(String packageName, int resId) {
2686 int anim = 0;
2687 Context context = mContext;
2688 if (resId >= 0) {
2689 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2690 if (ent != null) {
2691 context = ent.context;
2692 anim = resId;
2693 }
2694 }
2695 if (anim != 0) {
2696 return AnimationUtils.loadAnimation(context, anim);
2697 }
2698 return null;
2699 }
2700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002701 private boolean applyAnimationLocked(AppWindowToken wtoken,
2702 WindowManager.LayoutParams lp, int transit, boolean enter) {
2703 // Only apply an animation if the display isn't frozen. If it is
2704 // frozen, there is no reason to animate and it can cause strange
2705 // artifacts when we unfreeze the display if some different animation
2706 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002707 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002708 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002709 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002710 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002711 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002712 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002713 } else if (mNextAppTransitionPackage != null) {
2714 a = loadAnimation(mNextAppTransitionPackage, enter ?
2715 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002716 } else {
2717 int animAttr = 0;
2718 switch (transit) {
2719 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2720 animAttr = enter
2721 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2722 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2723 break;
2724 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2725 animAttr = enter
2726 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2727 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2728 break;
2729 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2730 animAttr = enter
2731 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2732 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2733 break;
2734 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2735 animAttr = enter
2736 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2737 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2738 break;
2739 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2740 animAttr = enter
2741 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2742 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2743 break;
2744 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2745 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002746 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002747 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2748 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002749 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002750 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002751 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2752 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002753 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002754 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002755 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002756 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2757 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2758 break;
2759 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2760 animAttr = enter
2761 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2762 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2763 break;
2764 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2765 animAttr = enter
2766 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2767 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002768 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002769 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002770 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002771 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002772 + " anim=" + a
2773 + " animAttr=0x" + Integer.toHexString(animAttr)
2774 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002775 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002776 if (a != null) {
2777 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002778 RuntimeException e = null;
2779 if (!HIDE_STACK_CRAWLS) {
2780 e = new RuntimeException();
2781 e.fillInStackTrace();
2782 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002783 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002784 }
2785 wtoken.setAnimation(a);
2786 }
2787 } else {
2788 wtoken.clearAnimation();
2789 }
2790
2791 return wtoken.animation != null;
2792 }
2793
2794 // -------------------------------------------------------------
2795 // Application Window Tokens
2796 // -------------------------------------------------------------
2797
2798 public void validateAppTokens(List tokens) {
2799 int v = tokens.size()-1;
2800 int m = mAppTokens.size()-1;
2801 while (v >= 0 && m >= 0) {
2802 AppWindowToken wtoken = mAppTokens.get(m);
2803 if (wtoken.removed) {
2804 m--;
2805 continue;
2806 }
2807 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002808 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002809 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2810 }
2811 v--;
2812 m--;
2813 }
2814 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002815 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002816 v--;
2817 }
2818 while (m >= 0) {
2819 AppWindowToken wtoken = mAppTokens.get(m);
2820 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002821 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002822 }
2823 m--;
2824 }
2825 }
2826
2827 boolean checkCallingPermission(String permission, String func) {
2828 // Quick check: if the calling permission is me, it's all okay.
2829 if (Binder.getCallingPid() == Process.myPid()) {
2830 return true;
2831 }
Romain Guy06882f82009-06-10 13:36:04 -07002832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002833 if (mContext.checkCallingPermission(permission)
2834 == PackageManager.PERMISSION_GRANTED) {
2835 return true;
2836 }
2837 String msg = "Permission Denial: " + func + " from pid="
2838 + Binder.getCallingPid()
2839 + ", uid=" + Binder.getCallingUid()
2840 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002841 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002842 return false;
2843 }
Romain Guy06882f82009-06-10 13:36:04 -07002844
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002845 AppWindowToken findAppWindowToken(IBinder token) {
2846 WindowToken wtoken = mTokenMap.get(token);
2847 if (wtoken == null) {
2848 return null;
2849 }
2850 return wtoken.appWindowToken;
2851 }
Romain Guy06882f82009-06-10 13:36:04 -07002852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002853 public void addWindowToken(IBinder token, int type) {
2854 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2855 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002856 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002857 }
Romain Guy06882f82009-06-10 13:36:04 -07002858
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002859 synchronized(mWindowMap) {
2860 WindowToken wtoken = mTokenMap.get(token);
2861 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002862 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002863 return;
2864 }
2865 wtoken = new WindowToken(token, type, true);
2866 mTokenMap.put(token, wtoken);
2867 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002868 if (type == TYPE_WALLPAPER) {
2869 mWallpaperTokens.add(wtoken);
2870 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002871 }
2872 }
Romain Guy06882f82009-06-10 13:36:04 -07002873
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002874 public void removeWindowToken(IBinder token) {
2875 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2876 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002877 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002878 }
2879
2880 final long origId = Binder.clearCallingIdentity();
2881 synchronized(mWindowMap) {
2882 WindowToken wtoken = mTokenMap.remove(token);
2883 mTokenList.remove(wtoken);
2884 if (wtoken != null) {
2885 boolean delayed = false;
2886 if (!wtoken.hidden) {
2887 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002889 final int N = wtoken.windows.size();
2890 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002892 for (int i=0; i<N; i++) {
2893 WindowState win = wtoken.windows.get(i);
2894
2895 if (win.isAnimating()) {
2896 delayed = true;
2897 }
Romain Guy06882f82009-06-10 13:36:04 -07002898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002899 if (win.isVisibleNow()) {
2900 applyAnimationLocked(win,
2901 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002902 changed = true;
2903 }
2904 }
2905
2906 if (changed) {
2907 mLayoutNeeded = true;
2908 performLayoutAndPlaceSurfacesLocked();
2909 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2910 }
Romain Guy06882f82009-06-10 13:36:04 -07002911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002912 if (delayed) {
2913 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002914 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2915 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002916 }
2917 }
Romain Guy06882f82009-06-10 13:36:04 -07002918
Jeff Brownc5ed5912010-07-14 18:48:53 -07002919 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002920 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002921 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002922 }
2923 }
2924 Binder.restoreCallingIdentity(origId);
2925 }
2926
2927 public void addAppToken(int addPos, IApplicationToken token,
2928 int groupId, int requestedOrientation, boolean fullscreen) {
2929 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2930 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002931 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002932 }
Jeff Brown349703e2010-06-22 01:27:15 -07002933
2934 // Get the dispatching timeout here while we are not holding any locks so that it
2935 // can be cached by the AppWindowToken. The timeout value is used later by the
2936 // input dispatcher in code that does hold locks. If we did not cache the value
2937 // here we would run the chance of introducing a deadlock between the window manager
2938 // (which holds locks while updating the input dispatcher state) and the activity manager
2939 // (which holds locks while querying the application token).
2940 long inputDispatchingTimeoutNanos;
2941 try {
2942 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
2943 } catch (RemoteException ex) {
2944 Slog.w(TAG, "Could not get dispatching timeout.", ex);
2945 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
2946 }
Romain Guy06882f82009-06-10 13:36:04 -07002947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002948 synchronized(mWindowMap) {
2949 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2950 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002951 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002952 return;
2953 }
2954 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07002955 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002956 wtoken.groupId = groupId;
2957 wtoken.appFullscreen = fullscreen;
2958 wtoken.requestedOrientation = requestedOrientation;
2959 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002960 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002961 mTokenMap.put(token.asBinder(), wtoken);
2962 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002964 // Application tokens start out hidden.
2965 wtoken.hidden = true;
2966 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07002967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002968 //dump();
2969 }
2970 }
Romain Guy06882f82009-06-10 13:36:04 -07002971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002972 public void setAppGroupId(IBinder token, int groupId) {
2973 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2974 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002975 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002976 }
2977
2978 synchronized(mWindowMap) {
2979 AppWindowToken wtoken = findAppWindowToken(token);
2980 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002981 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002982 return;
2983 }
2984 wtoken.groupId = groupId;
2985 }
2986 }
Romain Guy06882f82009-06-10 13:36:04 -07002987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002988 public int getOrientationFromWindowsLocked() {
2989 int pos = mWindows.size() - 1;
2990 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07002991 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002992 pos--;
2993 if (wtoken.mAppToken != null) {
2994 // We hit an application window. so the orientation will be determined by the
2995 // app window. No point in continuing further.
2996 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
2997 }
Christopher Tateb696aee2010-04-02 19:08:30 -07002998 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002999 continue;
3000 }
3001 int req = wtoken.mAttrs.screenOrientation;
3002 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3003 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3004 continue;
3005 } else {
3006 return req;
3007 }
3008 }
3009 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3010 }
Romain Guy06882f82009-06-10 13:36:04 -07003011
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003012 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003013 int pos = mAppTokens.size() - 1;
3014 int curGroup = 0;
3015 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3016 boolean findingBehind = false;
3017 boolean haveGroup = false;
3018 boolean lastFullscreen = false;
3019 while (pos >= 0) {
3020 AppWindowToken wtoken = mAppTokens.get(pos);
3021 pos--;
3022 // if we're about to tear down this window and not seek for
3023 // the behind activity, don't use it for orientation
3024 if (!findingBehind
3025 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3026 continue;
3027 }
3028
3029 if (!haveGroup) {
3030 // We ignore any hidden applications on the top.
3031 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003032 continue;
3033 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003034 haveGroup = true;
3035 curGroup = wtoken.groupId;
3036 lastOrientation = wtoken.requestedOrientation;
3037 } else if (curGroup != wtoken.groupId) {
3038 // If we have hit a new application group, and the bottom
3039 // of the previous group didn't explicitly say to use
3040 // the orientation behind it, and the last app was
3041 // full screen, then we'll stick with the
3042 // user's orientation.
3043 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3044 && lastFullscreen) {
3045 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003046 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003047 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003048 int or = wtoken.requestedOrientation;
3049 // If this application is fullscreen, and didn't explicitly say
3050 // to use the orientation behind it, then just take whatever
3051 // orientation it has and ignores whatever is under it.
3052 lastFullscreen = wtoken.appFullscreen;
3053 if (lastFullscreen
3054 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3055 return or;
3056 }
3057 // If this application has requested an explicit orientation,
3058 // then use it.
3059 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
3060 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
3061 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
3062 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
3063 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
3064 return or;
3065 }
3066 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3067 }
3068 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003069 }
Romain Guy06882f82009-06-10 13:36:04 -07003070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003071 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003072 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003073 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3074 "updateOrientationFromAppTokens()")) {
3075 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3076 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003077
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003078 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003079 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003080
3081 synchronized(mWindowMap) {
3082 if (updateOrientationFromAppTokensLocked()) {
3083 if (freezeThisOneIfNeeded != null) {
3084 AppWindowToken wtoken = findAppWindowToken(
3085 freezeThisOneIfNeeded);
3086 if (wtoken != null) {
3087 startAppFreezingScreenLocked(wtoken,
3088 ActivityInfo.CONFIG_ORIENTATION);
3089 }
3090 }
3091 config = computeNewConfigurationLocked();
3092
3093 } else if (currentConfig != null) {
3094 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003095 // state mismatches the activity manager's, update it,
3096 // disregarding font scale, which should remain set to
3097 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003098 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003099 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003100 if (computeNewConfigurationLocked(mTempConfiguration)) {
3101 if (currentConfig.diff(mTempConfiguration) != 0) {
3102 mWaitingForConfig = true;
3103 mLayoutNeeded = true;
3104 startFreezingDisplayLocked();
3105 config = new Configuration(mTempConfiguration);
3106 }
3107 }
3108 }
3109 }
3110
Dianne Hackborncfaef692009-06-15 14:24:44 -07003111 Binder.restoreCallingIdentity(ident);
3112 return config;
3113 }
3114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003115 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003116 * Determine the new desired orientation of the display, returning
3117 * a non-null new Configuration if it has changed from the current
3118 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3119 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3120 * SCREEN. This will typically be done for you if you call
3121 * sendNewConfiguration().
3122 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003123 * The orientation is computed from non-application windows first. If none of
3124 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003125 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003126 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3127 * android.os.IBinder)
3128 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003129 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003130 if (mDisplayFrozen) {
3131 // If the display is frozen, some activities may be in the middle
3132 // of restarting, and thus have removed their old window. If the
3133 // window has the flag to hide the lock screen, then the lock screen
3134 // can re-appear and inflict its own orientation on us. Keep the
3135 // orientation stable until this all settles down.
3136 return false;
3137 }
3138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003139 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003140 long ident = Binder.clearCallingIdentity();
3141 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003142 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003144 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003145 mForcedAppOrientation = req;
3146 //send a message to Policy indicating orientation change to take
3147 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003148 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003149 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3150 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3151 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003152 }
3153 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003154
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003155 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003156 } finally {
3157 Binder.restoreCallingIdentity(ident);
3158 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003159 }
Romain Guy06882f82009-06-10 13:36:04 -07003160
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003161 int computeForcedAppOrientationLocked() {
3162 int req = getOrientationFromWindowsLocked();
3163 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3164 req = getOrientationFromAppTokensLocked();
3165 }
3166 return req;
3167 }
Romain Guy06882f82009-06-10 13:36:04 -07003168
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003169 public void setNewConfiguration(Configuration config) {
3170 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3171 "setNewConfiguration()")) {
3172 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3173 }
3174
3175 synchronized(mWindowMap) {
3176 mCurConfiguration = new Configuration(config);
3177 mWaitingForConfig = false;
3178 performLayoutAndPlaceSurfacesLocked();
3179 }
3180 }
3181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003182 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3183 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3184 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003185 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003186 }
Romain Guy06882f82009-06-10 13:36:04 -07003187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003188 synchronized(mWindowMap) {
3189 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3190 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003191 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003192 return;
3193 }
Romain Guy06882f82009-06-10 13:36:04 -07003194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003195 wtoken.requestedOrientation = requestedOrientation;
3196 }
3197 }
Romain Guy06882f82009-06-10 13:36:04 -07003198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003199 public int getAppOrientation(IApplicationToken token) {
3200 synchronized(mWindowMap) {
3201 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3202 if (wtoken == null) {
3203 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3204 }
Romain Guy06882f82009-06-10 13:36:04 -07003205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003206 return wtoken.requestedOrientation;
3207 }
3208 }
Romain Guy06882f82009-06-10 13:36:04 -07003209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003210 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3211 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3212 "setFocusedApp()")) {
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 synchronized(mWindowMap) {
3217 boolean changed = false;
3218 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003219 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003220 changed = mFocusedApp != null;
3221 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003222 if (changed) {
3223 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003224 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003225 } else {
3226 AppWindowToken newFocus = findAppWindowToken(token);
3227 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003228 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003229 return;
3230 }
3231 changed = mFocusedApp != newFocus;
3232 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003233 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003234 if (changed) {
3235 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003236 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003237 }
3238
3239 if (moveFocusNow && changed) {
3240 final long origId = Binder.clearCallingIdentity();
3241 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3242 Binder.restoreCallingIdentity(origId);
3243 }
3244 }
3245 }
3246
3247 public void prepareAppTransition(int transit) {
3248 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3249 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003250 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003251 }
Romain Guy06882f82009-06-10 13:36:04 -07003252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003253 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003254 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003255 TAG, "Prepare app transition: transit=" + transit
3256 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003257 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003258 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3259 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003260 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003261 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3262 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3263 // Opening a new task always supersedes a close for the anim.
3264 mNextAppTransition = transit;
3265 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3266 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3267 // Opening a new activity always supersedes a close for the anim.
3268 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003269 }
3270 mAppTransitionReady = false;
3271 mAppTransitionTimeout = false;
3272 mStartingIconInTransition = false;
3273 mSkipAppTransitionAnimation = false;
3274 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3275 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3276 5000);
3277 }
3278 }
3279 }
3280
3281 public int getPendingAppTransition() {
3282 return mNextAppTransition;
3283 }
Romain Guy06882f82009-06-10 13:36:04 -07003284
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003285 public void overridePendingAppTransition(String packageName,
3286 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003287 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003288 mNextAppTransitionPackage = packageName;
3289 mNextAppTransitionEnter = enterAnim;
3290 mNextAppTransitionExit = exitAnim;
3291 }
3292 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003294 public void executeAppTransition() {
3295 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3296 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003297 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003298 }
Romain Guy06882f82009-06-10 13:36:04 -07003299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003300 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003301 if (DEBUG_APP_TRANSITIONS) {
3302 RuntimeException e = new RuntimeException("here");
3303 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003304 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003305 + mNextAppTransition, e);
3306 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003307 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003308 mAppTransitionReady = true;
3309 final long origId = Binder.clearCallingIdentity();
3310 performLayoutAndPlaceSurfacesLocked();
3311 Binder.restoreCallingIdentity(origId);
3312 }
3313 }
3314 }
3315
3316 public void setAppStartingWindow(IBinder token, String pkg,
3317 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3318 IBinder transferFrom, boolean createIfNeeded) {
3319 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3320 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003321 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003322 }
3323
3324 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003325 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003326 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3327 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003329 AppWindowToken wtoken = findAppWindowToken(token);
3330 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003331 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003332 return;
3333 }
3334
3335 // If the display is frozen, we won't do anything until the
3336 // actual window is displayed so there is no reason to put in
3337 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003338 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003339 return;
3340 }
Romain Guy06882f82009-06-10 13:36:04 -07003341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003342 if (wtoken.startingData != null) {
3343 return;
3344 }
Romain Guy06882f82009-06-10 13:36:04 -07003345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003346 if (transferFrom != null) {
3347 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3348 if (ttoken != null) {
3349 WindowState startingWindow = ttoken.startingWindow;
3350 if (startingWindow != null) {
3351 if (mStartingIconInTransition) {
3352 // In this case, the starting icon has already
3353 // been displayed, so start letting windows get
3354 // shown immediately without any more transitions.
3355 mSkipAppTransitionAnimation = true;
3356 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003357 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003358 "Moving existing starting from " + ttoken
3359 + " to " + wtoken);
3360 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003362 // Transfer the starting window over to the new
3363 // token.
3364 wtoken.startingData = ttoken.startingData;
3365 wtoken.startingView = ttoken.startingView;
3366 wtoken.startingWindow = startingWindow;
3367 ttoken.startingData = null;
3368 ttoken.startingView = null;
3369 ttoken.startingWindow = null;
3370 ttoken.startingMoved = true;
3371 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003372 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003373 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003374 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003375 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003376 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003377 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003378 ttoken.windows.remove(startingWindow);
3379 ttoken.allAppWindows.remove(startingWindow);
3380 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003382 // Propagate other interesting state between the
3383 // tokens. If the old token is displayed, we should
3384 // immediately force the new one to be displayed. If
3385 // it is animating, we need to move that animation to
3386 // the new one.
3387 if (ttoken.allDrawn) {
3388 wtoken.allDrawn = true;
3389 }
3390 if (ttoken.firstWindowDrawn) {
3391 wtoken.firstWindowDrawn = true;
3392 }
3393 if (!ttoken.hidden) {
3394 wtoken.hidden = false;
3395 wtoken.hiddenRequested = false;
3396 wtoken.willBeHidden = false;
3397 }
3398 if (wtoken.clientHidden != ttoken.clientHidden) {
3399 wtoken.clientHidden = ttoken.clientHidden;
3400 wtoken.sendAppVisibilityToClients();
3401 }
3402 if (ttoken.animation != null) {
3403 wtoken.animation = ttoken.animation;
3404 wtoken.animating = ttoken.animating;
3405 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3406 ttoken.animation = null;
3407 ttoken.animLayerAdjustment = 0;
3408 wtoken.updateLayers();
3409 ttoken.updateLayers();
3410 }
Romain Guy06882f82009-06-10 13:36:04 -07003411
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003412 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003413 mLayoutNeeded = true;
3414 performLayoutAndPlaceSurfacesLocked();
3415 Binder.restoreCallingIdentity(origId);
3416 return;
3417 } else if (ttoken.startingData != null) {
3418 // The previous app was getting ready to show a
3419 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003420 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003421 "Moving pending starting from " + ttoken
3422 + " to " + wtoken);
3423 wtoken.startingData = ttoken.startingData;
3424 ttoken.startingData = null;
3425 ttoken.startingMoved = true;
3426 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3427 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3428 // want to process the message ASAP, before any other queued
3429 // messages.
3430 mH.sendMessageAtFrontOfQueue(m);
3431 return;
3432 }
3433 }
3434 }
3435
3436 // There is no existing starting window, and the caller doesn't
3437 // want us to create one, so that's it!
3438 if (!createIfNeeded) {
3439 return;
3440 }
Romain Guy06882f82009-06-10 13:36:04 -07003441
Dianne Hackborn284ac932009-08-28 10:34:25 -07003442 // If this is a translucent or wallpaper window, then don't
3443 // show a starting window -- the current effect (a full-screen
3444 // opaque starting window that fades away to the real contents
3445 // when it is ready) does not work for this.
3446 if (theme != 0) {
3447 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3448 com.android.internal.R.styleable.Window);
3449 if (ent.array.getBoolean(
3450 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3451 return;
3452 }
3453 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003454 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3455 return;
3456 }
3457 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003458 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3459 return;
3460 }
3461 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003463 mStartingIconInTransition = true;
3464 wtoken.startingData = new StartingData(
3465 pkg, theme, nonLocalizedLabel,
3466 labelRes, icon);
3467 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3468 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3469 // want to process the message ASAP, before any other queued
3470 // messages.
3471 mH.sendMessageAtFrontOfQueue(m);
3472 }
3473 }
3474
3475 public void setAppWillBeHidden(IBinder token) {
3476 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3477 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003478 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003479 }
3480
3481 AppWindowToken wtoken;
3482
3483 synchronized(mWindowMap) {
3484 wtoken = findAppWindowToken(token);
3485 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003486 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 -08003487 return;
3488 }
3489 wtoken.willBeHidden = true;
3490 }
3491 }
Romain Guy06882f82009-06-10 13:36:04 -07003492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003493 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3494 boolean visible, int transit, boolean performLayout) {
3495 boolean delayed = false;
3496
3497 if (wtoken.clientHidden == visible) {
3498 wtoken.clientHidden = !visible;
3499 wtoken.sendAppVisibilityToClients();
3500 }
Romain Guy06882f82009-06-10 13:36:04 -07003501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003502 wtoken.willBeHidden = false;
3503 if (wtoken.hidden == visible) {
3504 final int N = wtoken.allAppWindows.size();
3505 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003506 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003507 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3508 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003510 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003511
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003512 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003513 if (wtoken.animation == sDummyAnimation) {
3514 wtoken.animation = null;
3515 }
3516 applyAnimationLocked(wtoken, lp, transit, visible);
3517 changed = true;
3518 if (wtoken.animation != null) {
3519 delayed = runningAppAnimation = true;
3520 }
3521 }
Romain Guy06882f82009-06-10 13:36:04 -07003522
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003523 for (int i=0; i<N; i++) {
3524 WindowState win = wtoken.allAppWindows.get(i);
3525 if (win == wtoken.startingWindow) {
3526 continue;
3527 }
3528
3529 if (win.isAnimating()) {
3530 delayed = true;
3531 }
Romain Guy06882f82009-06-10 13:36:04 -07003532
Joe Onorato8a9b2202010-02-26 18:56:32 -08003533 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003534 //win.dump(" ");
3535 if (visible) {
3536 if (!win.isVisibleNow()) {
3537 if (!runningAppAnimation) {
3538 applyAnimationLocked(win,
3539 WindowManagerPolicy.TRANSIT_ENTER, true);
3540 }
3541 changed = true;
3542 }
3543 } else if (win.isVisibleNow()) {
3544 if (!runningAppAnimation) {
3545 applyAnimationLocked(win,
3546 WindowManagerPolicy.TRANSIT_EXIT, false);
3547 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003548 changed = true;
3549 }
3550 }
3551
3552 wtoken.hidden = wtoken.hiddenRequested = !visible;
3553 if (!visible) {
3554 unsetAppFreezingScreenLocked(wtoken, true, true);
3555 } else {
3556 // If we are being set visible, and the starting window is
3557 // not yet displayed, then make sure it doesn't get displayed.
3558 WindowState swin = wtoken.startingWindow;
3559 if (swin != null && (swin.mDrawPending
3560 || swin.mCommitDrawPending)) {
3561 swin.mPolicyVisibility = false;
3562 swin.mPolicyVisibilityAfterAnim = false;
3563 }
3564 }
Romain Guy06882f82009-06-10 13:36:04 -07003565
Joe Onorato8a9b2202010-02-26 18:56:32 -08003566 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003567 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3568 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003569
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003570 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003571 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003572 if (performLayout) {
3573 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3574 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003575 } else {
3576 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003577 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003578 }
3579 }
3580
3581 if (wtoken.animation != null) {
3582 delayed = true;
3583 }
Romain Guy06882f82009-06-10 13:36:04 -07003584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003585 return delayed;
3586 }
3587
3588 public void setAppVisibility(IBinder token, boolean visible) {
3589 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3590 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003591 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003592 }
3593
3594 AppWindowToken wtoken;
3595
3596 synchronized(mWindowMap) {
3597 wtoken = findAppWindowToken(token);
3598 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003599 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003600 return;
3601 }
3602
3603 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003604 RuntimeException e = null;
3605 if (!HIDE_STACK_CRAWLS) {
3606 e = new RuntimeException();
3607 e.fillInStackTrace();
3608 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003609 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003610 + "): mNextAppTransition=" + mNextAppTransition
3611 + " hidden=" + wtoken.hidden
3612 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3613 }
Romain Guy06882f82009-06-10 13:36:04 -07003614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003615 // If we are preparing an app transition, then delay changing
3616 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003617 if (!mDisplayFrozen && mPolicy.isScreenOn()
3618 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003619 // Already in requested state, don't do anything more.
3620 if (wtoken.hiddenRequested != visible) {
3621 return;
3622 }
3623 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003624
Joe Onorato8a9b2202010-02-26 18:56:32 -08003625 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003626 TAG, "Setting dummy animation on: " + wtoken);
3627 wtoken.setDummyAnimation();
3628 mOpeningApps.remove(wtoken);
3629 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003630 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003631 wtoken.inPendingTransaction = true;
3632 if (visible) {
3633 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003634 wtoken.startingDisplayed = false;
3635 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003636
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003637 // If the token is currently hidden (should be the
3638 // common case), then we need to set up to wait for
3639 // its windows to be ready.
3640 if (wtoken.hidden) {
3641 wtoken.allDrawn = false;
3642 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003643
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003644 if (wtoken.clientHidden) {
3645 // In the case where we are making an app visible
3646 // but holding off for a transition, we still need
3647 // to tell the client to make its windows visible so
3648 // they get drawn. Otherwise, we will wait on
3649 // performing the transition until all windows have
3650 // been drawn, they never will be, and we are sad.
3651 wtoken.clientHidden = false;
3652 wtoken.sendAppVisibilityToClients();
3653 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003654 }
3655 } else {
3656 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003657
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003658 // If the token is currently visible (should be the
3659 // common case), then set up to wait for it to be hidden.
3660 if (!wtoken.hidden) {
3661 wtoken.waitingToHide = true;
3662 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003663 }
3664 return;
3665 }
Romain Guy06882f82009-06-10 13:36:04 -07003666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003667 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003668 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003669 wtoken.updateReportedVisibilityLocked();
3670 Binder.restoreCallingIdentity(origId);
3671 }
3672 }
3673
3674 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3675 boolean unfreezeSurfaceNow, boolean force) {
3676 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003677 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003678 + " force=" + force);
3679 final int N = wtoken.allAppWindows.size();
3680 boolean unfrozeWindows = false;
3681 for (int i=0; i<N; i++) {
3682 WindowState w = wtoken.allAppWindows.get(i);
3683 if (w.mAppFreezing) {
3684 w.mAppFreezing = false;
3685 if (w.mSurface != null && !w.mOrientationChanging) {
3686 w.mOrientationChanging = true;
3687 }
3688 unfrozeWindows = true;
3689 }
3690 }
3691 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003692 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003693 wtoken.freezingScreen = false;
3694 mAppsFreezingScreen--;
3695 }
3696 if (unfreezeSurfaceNow) {
3697 if (unfrozeWindows) {
3698 mLayoutNeeded = true;
3699 performLayoutAndPlaceSurfacesLocked();
3700 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003701 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003702 }
3703 }
3704 }
Romain Guy06882f82009-06-10 13:36:04 -07003705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003706 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3707 int configChanges) {
3708 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003709 RuntimeException e = null;
3710 if (!HIDE_STACK_CRAWLS) {
3711 e = new RuntimeException();
3712 e.fillInStackTrace();
3713 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003714 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003715 + ": hidden=" + wtoken.hidden + " freezing="
3716 + wtoken.freezingScreen, e);
3717 }
3718 if (!wtoken.hiddenRequested) {
3719 if (!wtoken.freezingScreen) {
3720 wtoken.freezingScreen = true;
3721 mAppsFreezingScreen++;
3722 if (mAppsFreezingScreen == 1) {
3723 startFreezingDisplayLocked();
3724 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3725 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3726 5000);
3727 }
3728 }
3729 final int N = wtoken.allAppWindows.size();
3730 for (int i=0; i<N; i++) {
3731 WindowState w = wtoken.allAppWindows.get(i);
3732 w.mAppFreezing = true;
3733 }
3734 }
3735 }
Romain Guy06882f82009-06-10 13:36:04 -07003736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003737 public void startAppFreezingScreen(IBinder token, int configChanges) {
3738 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3739 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003740 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003741 }
3742
3743 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003744 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003745 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003746 return;
3747 }
Romain Guy06882f82009-06-10 13:36:04 -07003748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003749 AppWindowToken wtoken = findAppWindowToken(token);
3750 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003751 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003752 return;
3753 }
3754 final long origId = Binder.clearCallingIdentity();
3755 startAppFreezingScreenLocked(wtoken, configChanges);
3756 Binder.restoreCallingIdentity(origId);
3757 }
3758 }
Romain Guy06882f82009-06-10 13:36:04 -07003759
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003760 public void stopAppFreezingScreen(IBinder token, boolean force) {
3761 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3762 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003763 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003764 }
3765
3766 synchronized(mWindowMap) {
3767 AppWindowToken wtoken = findAppWindowToken(token);
3768 if (wtoken == null || wtoken.appToken == null) {
3769 return;
3770 }
3771 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003772 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003773 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3774 unsetAppFreezingScreenLocked(wtoken, true, force);
3775 Binder.restoreCallingIdentity(origId);
3776 }
3777 }
Romain Guy06882f82009-06-10 13:36:04 -07003778
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003779 public void removeAppToken(IBinder token) {
3780 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3781 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003782 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003783 }
3784
3785 AppWindowToken wtoken = null;
3786 AppWindowToken startingToken = null;
3787 boolean delayed = false;
3788
3789 final long origId = Binder.clearCallingIdentity();
3790 synchronized(mWindowMap) {
3791 WindowToken basewtoken = mTokenMap.remove(token);
3792 mTokenList.remove(basewtoken);
3793 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003794 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003795 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003796 wtoken.inPendingTransaction = false;
3797 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003798 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003799 if (mClosingApps.contains(wtoken)) {
3800 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003801 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003802 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003803 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003804 delayed = true;
3805 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003806 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003807 TAG, "Removing app " + wtoken + " delayed=" + delayed
3808 + " animation=" + wtoken.animation
3809 + " animating=" + wtoken.animating);
3810 if (delayed) {
3811 // set the token aside because it has an active animation to be finished
3812 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003813 } else {
3814 // Make sure there is no animation running on this token,
3815 // so any windows associated with it will be removed as
3816 // soon as their animations are complete
3817 wtoken.animation = null;
3818 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003819 }
3820 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003821 if (mLastEnterAnimToken == wtoken) {
3822 mLastEnterAnimToken = null;
3823 mLastEnterAnimParams = null;
3824 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003825 wtoken.removed = true;
3826 if (wtoken.startingData != null) {
3827 startingToken = wtoken;
3828 }
3829 unsetAppFreezingScreenLocked(wtoken, true, true);
3830 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003831 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003832 mFocusedApp = null;
3833 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003834 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003835 }
3836 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003837 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003838 }
Romain Guy06882f82009-06-10 13:36:04 -07003839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003840 if (!delayed && wtoken != null) {
3841 wtoken.updateReportedVisibilityLocked();
3842 }
3843 }
3844 Binder.restoreCallingIdentity(origId);
3845
3846 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003847 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003848 + startingToken + ": app token removed");
3849 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3850 mH.sendMessage(m);
3851 }
3852 }
3853
3854 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3855 final int NW = token.windows.size();
3856 for (int i=0; i<NW; i++) {
3857 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003858 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003859 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003860 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003861 int j = win.mChildWindows.size();
3862 while (j > 0) {
3863 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003864 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003865 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003866 "Tmp removing child window " + cwin);
3867 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003868 }
3869 }
3870 return NW > 0;
3871 }
3872
3873 void dumpAppTokensLocked() {
3874 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003875 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003876 }
3877 }
Romain Guy06882f82009-06-10 13:36:04 -07003878
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003879 void dumpWindowsLocked() {
3880 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003881 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003882 }
3883 }
Romain Guy06882f82009-06-10 13:36:04 -07003884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003885 private int findWindowOffsetLocked(int tokenPos) {
3886 final int NW = mWindows.size();
3887
3888 if (tokenPos >= mAppTokens.size()) {
3889 int i = NW;
3890 while (i > 0) {
3891 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07003892 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003893 if (win.getAppToken() != null) {
3894 return i+1;
3895 }
3896 }
3897 }
3898
3899 while (tokenPos > 0) {
3900 // Find the first app token below the new position that has
3901 // a window displayed.
3902 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003903 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003904 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003905 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003906 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07003907 "Skipping token -- currently sending to bottom");
3908 tokenPos--;
3909 continue;
3910 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003911 int i = wtoken.windows.size();
3912 while (i > 0) {
3913 i--;
3914 WindowState win = wtoken.windows.get(i);
3915 int j = win.mChildWindows.size();
3916 while (j > 0) {
3917 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003918 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003919 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003920 for (int pos=NW-1; pos>=0; pos--) {
3921 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003922 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003923 "Found child win @" + (pos+1));
3924 return pos+1;
3925 }
3926 }
3927 }
3928 }
3929 for (int pos=NW-1; pos>=0; pos--) {
3930 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003931 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003932 return pos+1;
3933 }
3934 }
3935 }
3936 tokenPos--;
3937 }
3938
3939 return 0;
3940 }
3941
3942 private final int reAddWindowLocked(int index, WindowState win) {
3943 final int NCW = win.mChildWindows.size();
3944 boolean added = false;
3945 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07003946 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003947 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003948 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003949 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003950 mWindows.add(index, win);
3951 index++;
3952 added = true;
3953 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003954 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003955 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003956 mWindows.add(index, cwin);
3957 index++;
3958 }
3959 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003960 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003961 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003962 mWindows.add(index, win);
3963 index++;
3964 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003965 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003966 return index;
3967 }
Romain Guy06882f82009-06-10 13:36:04 -07003968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003969 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3970 final int NW = token.windows.size();
3971 for (int i=0; i<NW; i++) {
3972 index = reAddWindowLocked(index, token.windows.get(i));
3973 }
3974 return index;
3975 }
3976
3977 public void moveAppToken(int index, IBinder token) {
3978 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3979 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003980 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003981 }
3982
3983 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003984 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003985 if (DEBUG_REORDER) dumpAppTokensLocked();
3986 final AppWindowToken wtoken = findAppWindowToken(token);
3987 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003988 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003989 + token + " (" + wtoken + ")");
3990 return;
3991 }
3992 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003993 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003994 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003995
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003996 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003997 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003998 if (DEBUG_REORDER) dumpWindowsLocked();
3999 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004000 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004001 if (DEBUG_REORDER) dumpWindowsLocked();
4002 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004003 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004004 if (DEBUG_REORDER) dumpWindowsLocked();
4005 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004006 mLayoutNeeded = true;
4007 performLayoutAndPlaceSurfacesLocked();
4008 }
4009 Binder.restoreCallingIdentity(origId);
4010 }
4011 }
4012
4013 private void removeAppTokensLocked(List<IBinder> tokens) {
4014 // XXX This should be done more efficiently!
4015 // (take advantage of the fact that both lists should be
4016 // ordered in the same way.)
4017 int N = tokens.size();
4018 for (int i=0; i<N; i++) {
4019 IBinder token = tokens.get(i);
4020 final AppWindowToken wtoken = findAppWindowToken(token);
4021 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004022 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004023 + token + " (" + wtoken + ")");
4024 i--;
4025 N--;
4026 }
4027 }
4028 }
4029
Dianne Hackborna8f60182009-09-01 19:01:50 -07004030 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4031 boolean updateFocusAndLayout) {
4032 // First remove all of the windows from the list.
4033 tmpRemoveAppWindowsLocked(wtoken);
4034
4035 // Where to start adding?
4036 int pos = findWindowOffsetLocked(tokenPos);
4037
4038 // And now add them back at the correct place.
4039 pos = reAddAppWindowsLocked(pos, wtoken);
4040
4041 if (updateFocusAndLayout) {
4042 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4043 assignLayersLocked();
4044 }
4045 mLayoutNeeded = true;
4046 performLayoutAndPlaceSurfacesLocked();
4047 }
4048 }
4049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004050 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4051 // First remove all of the windows from the list.
4052 final int N = tokens.size();
4053 int i;
4054 for (i=0; i<N; i++) {
4055 WindowToken token = mTokenMap.get(tokens.get(i));
4056 if (token != null) {
4057 tmpRemoveAppWindowsLocked(token);
4058 }
4059 }
4060
4061 // Where to start adding?
4062 int pos = findWindowOffsetLocked(tokenPos);
4063
4064 // And now add them back at the correct place.
4065 for (i=0; i<N; i++) {
4066 WindowToken token = mTokenMap.get(tokens.get(i));
4067 if (token != null) {
4068 pos = reAddAppWindowsLocked(pos, token);
4069 }
4070 }
4071
Dianne Hackborna8f60182009-09-01 19:01:50 -07004072 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4073 assignLayersLocked();
4074 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004075 mLayoutNeeded = true;
4076 performLayoutAndPlaceSurfacesLocked();
4077
4078 //dump();
4079 }
4080
4081 public void moveAppTokensToTop(List<IBinder> tokens) {
4082 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4083 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004084 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004085 }
4086
4087 final long origId = Binder.clearCallingIdentity();
4088 synchronized(mWindowMap) {
4089 removeAppTokensLocked(tokens);
4090 final int N = tokens.size();
4091 for (int i=0; i<N; i++) {
4092 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4093 if (wt != null) {
4094 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004095 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004096 mToTopApps.remove(wt);
4097 mToBottomApps.remove(wt);
4098 mToTopApps.add(wt);
4099 wt.sendingToBottom = false;
4100 wt.sendingToTop = true;
4101 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004102 }
4103 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004104
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004105 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004106 moveAppWindowsLocked(tokens, mAppTokens.size());
4107 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004108 }
4109 Binder.restoreCallingIdentity(origId);
4110 }
4111
4112 public void moveAppTokensToBottom(List<IBinder> tokens) {
4113 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4114 "moveAppTokensToBottom()")) {
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 final long origId = Binder.clearCallingIdentity();
4119 synchronized(mWindowMap) {
4120 removeAppTokensLocked(tokens);
4121 final int N = tokens.size();
4122 int pos = 0;
4123 for (int i=0; i<N; i++) {
4124 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4125 if (wt != null) {
4126 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004127 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004128 mToTopApps.remove(wt);
4129 mToBottomApps.remove(wt);
4130 mToBottomApps.add(i, wt);
4131 wt.sendingToTop = false;
4132 wt.sendingToBottom = true;
4133 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004134 pos++;
4135 }
4136 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004137
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004138 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004139 moveAppWindowsLocked(tokens, 0);
4140 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004141 }
4142 Binder.restoreCallingIdentity(origId);
4143 }
4144
4145 // -------------------------------------------------------------
4146 // Misc IWindowSession methods
4147 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004148
Jim Miller284b62e2010-06-08 14:27:42 -07004149 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004150 {
Jim Miller284b62e2010-06-08 14:27:42 -07004151 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4152 // called before DevicePolicyManagerService has started.
4153 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4154 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4155 Context.DEVICE_POLICY_SERVICE);
4156 if (dpm != null) {
4157 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4158 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4159 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4160 }
Jim Millerd6b57052010-06-07 17:52:42 -07004161 }
Jim Miller284b62e2010-06-08 14:27:42 -07004162 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004163 }
4164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004165 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004166 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004167 != PackageManager.PERMISSION_GRANTED) {
4168 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4169 }
Jim Millerd6b57052010-06-07 17:52:42 -07004170
Jim Miller284b62e2010-06-08 14:27:42 -07004171 synchronized (mKeyguardTokenWatcher) {
4172 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004173 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004174 }
4175
4176 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004177 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004178 != PackageManager.PERMISSION_GRANTED) {
4179 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4180 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004181
Jim Miller284b62e2010-06-08 14:27:42 -07004182 synchronized (mKeyguardTokenWatcher) {
4183 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004184
Jim Miller284b62e2010-06-08 14:27:42 -07004185 if (!mKeyguardTokenWatcher.isAcquired()) {
4186 // If we are the last one to reenable the keyguard wait until
4187 // we have actually finished reenabling until returning.
4188 // It is possible that reenableKeyguard() can be called before
4189 // the previous disableKeyguard() is handled, in which case
4190 // neither mKeyguardTokenWatcher.acquired() or released() would
4191 // be called. In that case mKeyguardDisabled will be false here
4192 // and we have nothing to wait for.
4193 while (mKeyguardDisabled) {
4194 try {
4195 mKeyguardTokenWatcher.wait();
4196 } catch (InterruptedException e) {
4197 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004198 }
4199 }
4200 }
4201 }
4202 }
4203
4204 /**
4205 * @see android.app.KeyguardManager#exitKeyguardSecurely
4206 */
4207 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004208 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004209 != PackageManager.PERMISSION_GRANTED) {
4210 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4211 }
4212 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4213 public void onKeyguardExitResult(boolean success) {
4214 try {
4215 callback.onKeyguardExitResult(success);
4216 } catch (RemoteException e) {
4217 // Client has died, we don't care.
4218 }
4219 }
4220 });
4221 }
4222
4223 public boolean inKeyguardRestrictedInputMode() {
4224 return mPolicy.inKeyguardRestrictedKeyInputMode();
4225 }
Romain Guy06882f82009-06-10 13:36:04 -07004226
Dianne Hackbornffa42482009-09-23 22:20:11 -07004227 public void closeSystemDialogs(String reason) {
4228 synchronized(mWindowMap) {
4229 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004230 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004231 if (w.mSurface != null) {
4232 try {
4233 w.mClient.closeSystemDialogs(reason);
4234 } catch (RemoteException e) {
4235 }
4236 }
4237 }
4238 }
4239 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004241 static float fixScale(float scale) {
4242 if (scale < 0) scale = 0;
4243 else if (scale > 20) scale = 20;
4244 return Math.abs(scale);
4245 }
Romain Guy06882f82009-06-10 13:36:04 -07004246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004247 public void setAnimationScale(int which, float scale) {
4248 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4249 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004250 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004251 }
4252
4253 if (scale < 0) scale = 0;
4254 else if (scale > 20) scale = 20;
4255 scale = Math.abs(scale);
4256 switch (which) {
4257 case 0: mWindowAnimationScale = fixScale(scale); break;
4258 case 1: mTransitionAnimationScale = fixScale(scale); break;
4259 }
Romain Guy06882f82009-06-10 13:36:04 -07004260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004261 // Persist setting
4262 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4263 }
Romain Guy06882f82009-06-10 13:36:04 -07004264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004265 public void setAnimationScales(float[] scales) {
4266 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4267 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004268 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004269 }
4270
4271 if (scales != null) {
4272 if (scales.length >= 1) {
4273 mWindowAnimationScale = fixScale(scales[0]);
4274 }
4275 if (scales.length >= 2) {
4276 mTransitionAnimationScale = fixScale(scales[1]);
4277 }
4278 }
Romain Guy06882f82009-06-10 13:36:04 -07004279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004280 // Persist setting
4281 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4282 }
Romain Guy06882f82009-06-10 13:36:04 -07004283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004284 public float getAnimationScale(int which) {
4285 switch (which) {
4286 case 0: return mWindowAnimationScale;
4287 case 1: return mTransitionAnimationScale;
4288 }
4289 return 0;
4290 }
Romain Guy06882f82009-06-10 13:36:04 -07004291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004292 public float[] getAnimationScales() {
4293 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4294 }
Romain Guy06882f82009-06-10 13:36:04 -07004295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004296 public int getSwitchState(int sw) {
4297 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4298 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004299 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004300 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004301 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004302 }
Romain Guy06882f82009-06-10 13:36:04 -07004303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004304 public int getSwitchStateForDevice(int devid, int sw) {
4305 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4306 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004307 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004308 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004309 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004310 }
Romain Guy06882f82009-06-10 13:36:04 -07004311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004312 public int getScancodeState(int sw) {
4313 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4314 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004315 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004316 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004317 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004318 }
Romain Guy06882f82009-06-10 13:36:04 -07004319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004320 public int getScancodeStateForDevice(int devid, int sw) {
4321 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4322 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004323 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004324 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004325 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004326 }
Romain Guy06882f82009-06-10 13:36:04 -07004327
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004328 public int getTrackballScancodeState(int sw) {
4329 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4330 "getTrackballScancodeState()")) {
4331 throw new SecurityException("Requires READ_INPUT_STATE permission");
4332 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004333 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004334 }
4335
4336 public int getDPadScancodeState(int sw) {
4337 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4338 "getDPadScancodeState()")) {
4339 throw new SecurityException("Requires READ_INPUT_STATE permission");
4340 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004341 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004342 }
4343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004344 public int getKeycodeState(int sw) {
4345 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4346 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004347 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004348 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004349 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004350 }
Romain Guy06882f82009-06-10 13:36:04 -07004351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004352 public int getKeycodeStateForDevice(int devid, int sw) {
4353 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4354 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004355 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004356 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004357 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004358 }
Romain Guy06882f82009-06-10 13:36:04 -07004359
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004360 public int getTrackballKeycodeState(int sw) {
4361 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4362 "getTrackballKeycodeState()")) {
4363 throw new SecurityException("Requires READ_INPUT_STATE permission");
4364 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004365 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004366 }
4367
4368 public int getDPadKeycodeState(int sw) {
4369 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4370 "getDPadKeycodeState()")) {
4371 throw new SecurityException("Requires READ_INPUT_STATE permission");
4372 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004373 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004374 }
Jeff Browna41ca772010-08-11 14:46:32 -07004375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004376 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004377 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004378 }
Romain Guy06882f82009-06-10 13:36:04 -07004379
Jeff Browna41ca772010-08-11 14:46:32 -07004380 public InputChannel monitorInput(String inputChannelName) {
4381 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4382 "monitorInput()")) {
4383 throw new SecurityException("Requires READ_INPUT_STATE permission");
4384 }
4385 return mInputManager.monitorInput(inputChannelName);
4386 }
4387
Jeff Brown8d608662010-08-30 03:02:23 -07004388 public InputDevice getInputDevice(int deviceId) {
4389 return mInputManager.getInputDevice(deviceId);
4390 }
4391
4392 public int[] getInputDeviceIds() {
4393 return mInputManager.getInputDeviceIds();
4394 }
4395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004396 public void enableScreenAfterBoot() {
4397 synchronized(mWindowMap) {
4398 if (mSystemBooted) {
4399 return;
4400 }
4401 mSystemBooted = true;
4402 }
Romain Guy06882f82009-06-10 13:36:04 -07004403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004404 performEnableScreen();
4405 }
Romain Guy06882f82009-06-10 13:36:04 -07004406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004407 public void enableScreenIfNeededLocked() {
4408 if (mDisplayEnabled) {
4409 return;
4410 }
4411 if (!mSystemBooted) {
4412 return;
4413 }
4414 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4415 }
Romain Guy06882f82009-06-10 13:36:04 -07004416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004417 public void performEnableScreen() {
4418 synchronized(mWindowMap) {
4419 if (mDisplayEnabled) {
4420 return;
4421 }
4422 if (!mSystemBooted) {
4423 return;
4424 }
Romain Guy06882f82009-06-10 13:36:04 -07004425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004426 // Don't enable the screen until all existing windows
4427 // have been drawn.
4428 final int N = mWindows.size();
4429 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004430 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004431 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004432 return;
4433 }
4434 }
Romain Guy06882f82009-06-10 13:36:04 -07004435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004436 mDisplayEnabled = true;
4437 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004438 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004439 StringWriter sw = new StringWriter();
4440 PrintWriter pw = new PrintWriter(sw);
4441 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004442 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004443 }
4444 try {
4445 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4446 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004447 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004448 Parcel data = Parcel.obtain();
4449 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4450 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4451 data, null, 0);
4452 data.recycle();
4453 }
4454 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004455 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004456 }
4457 }
Romain Guy06882f82009-06-10 13:36:04 -07004458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004459 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004461 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004462 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4463 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004464 }
Romain Guy06882f82009-06-10 13:36:04 -07004465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004466 public void setInTouchMode(boolean mode) {
4467 synchronized(mWindowMap) {
4468 mInTouchMode = mode;
4469 }
4470 }
4471
Romain Guy06882f82009-06-10 13:36:04 -07004472 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004473 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004474 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004475 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004476 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004477 }
4478
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004479 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004480 }
Romain Guy06882f82009-06-10 13:36:04 -07004481
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004482 public void setRotationUnchecked(int rotation,
4483 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004484 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004485 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004487 long origId = Binder.clearCallingIdentity();
4488 boolean changed;
4489 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004490 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004491 }
Romain Guy06882f82009-06-10 13:36:04 -07004492
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004493 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004494 sendNewConfiguration();
4495 }
Romain Guy06882f82009-06-10 13:36:04 -07004496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004497 Binder.restoreCallingIdentity(origId);
4498 }
Romain Guy06882f82009-06-10 13:36:04 -07004499
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004500 /**
4501 * Apply a new rotation to the screen, respecting the requests of
4502 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4503 * re-evaluate the desired rotation.
4504 *
4505 * Returns null if the rotation has been changed. In this case YOU
4506 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4507 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004508 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004509 boolean changed;
4510 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4511 rotation = mRequestedRotation;
4512 } else {
4513 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004514 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004515 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004516 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004517 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004518 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004519 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004520 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004522 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004523 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004524 "Rotation changed to " + rotation
4525 + " from " + mRotation
4526 + " (forceApp=" + mForcedAppOrientation
4527 + ", req=" + mRequestedRotation + ")");
4528 mRotation = rotation;
4529 mWindowsFreezingScreen = true;
4530 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4531 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4532 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004533 mWaitingForConfig = true;
4534 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004535 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004536 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004537 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004538 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004539 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004540 }
4541 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004542 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004543 if (w.mSurface != null) {
4544 w.mOrientationChanging = true;
4545 }
4546 }
4547 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4548 try {
4549 mRotationWatchers.get(i).onRotationChanged(rotation);
4550 } catch (RemoteException e) {
4551 }
4552 }
4553 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004555 return changed;
4556 }
Romain Guy06882f82009-06-10 13:36:04 -07004557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004558 public int getRotation() {
4559 return mRotation;
4560 }
4561
4562 public int watchRotation(IRotationWatcher watcher) {
4563 final IBinder watcherBinder = watcher.asBinder();
4564 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4565 public void binderDied() {
4566 synchronized (mWindowMap) {
4567 for (int i=0; i<mRotationWatchers.size(); i++) {
4568 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004569 IRotationWatcher removed = mRotationWatchers.remove(i);
4570 if (removed != null) {
4571 removed.asBinder().unlinkToDeath(this, 0);
4572 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004573 i--;
4574 }
4575 }
4576 }
4577 }
4578 };
Romain Guy06882f82009-06-10 13:36:04 -07004579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004580 synchronized (mWindowMap) {
4581 try {
4582 watcher.asBinder().linkToDeath(dr, 0);
4583 mRotationWatchers.add(watcher);
4584 } catch (RemoteException e) {
4585 // Client died, no cleanup needed.
4586 }
Romain Guy06882f82009-06-10 13:36:04 -07004587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004588 return mRotation;
4589 }
4590 }
4591
4592 /**
4593 * Starts the view server on the specified port.
4594 *
4595 * @param port The port to listener to.
4596 *
4597 * @return True if the server was successfully started, false otherwise.
4598 *
4599 * @see com.android.server.ViewServer
4600 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4601 */
4602 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004603 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004604 return false;
4605 }
4606
4607 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4608 return false;
4609 }
4610
4611 if (port < 1024) {
4612 return false;
4613 }
4614
4615 if (mViewServer != null) {
4616 if (!mViewServer.isRunning()) {
4617 try {
4618 return mViewServer.start();
4619 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004620 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004621 }
4622 }
4623 return false;
4624 }
4625
4626 try {
4627 mViewServer = new ViewServer(this, port);
4628 return mViewServer.start();
4629 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004630 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004631 }
4632 return false;
4633 }
4634
Romain Guy06882f82009-06-10 13:36:04 -07004635 private boolean isSystemSecure() {
4636 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4637 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4638 }
4639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004640 /**
4641 * Stops the view server if it exists.
4642 *
4643 * @return True if the server stopped, false if it wasn't started or
4644 * couldn't be stopped.
4645 *
4646 * @see com.android.server.ViewServer
4647 */
4648 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004649 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004650 return false;
4651 }
4652
4653 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4654 return false;
4655 }
4656
4657 if (mViewServer != null) {
4658 return mViewServer.stop();
4659 }
4660 return false;
4661 }
4662
4663 /**
4664 * Indicates whether the view server is running.
4665 *
4666 * @return True if the server is running, false otherwise.
4667 *
4668 * @see com.android.server.ViewServer
4669 */
4670 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004671 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004672 return false;
4673 }
4674
4675 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4676 return false;
4677 }
4678
4679 return mViewServer != null && mViewServer.isRunning();
4680 }
4681
4682 /**
4683 * Lists all availble windows in the system. The listing is written in the
4684 * specified Socket's output stream with the following syntax:
4685 * windowHashCodeInHexadecimal windowName
4686 * Each line of the ouput represents a different window.
4687 *
4688 * @param client The remote client to send the listing to.
4689 * @return False if an error occured, true otherwise.
4690 */
4691 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004692 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004693 return false;
4694 }
4695
4696 boolean result = true;
4697
Jeff Browne33348b2010-07-15 23:54:05 -07004698 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004699 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004700 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07004701 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004702 }
4703
4704 BufferedWriter out = null;
4705
4706 // Any uncaught exception will crash the system process
4707 try {
4708 OutputStream clientStream = client.getOutputStream();
4709 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4710
4711 final int count = windows.length;
4712 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004713 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004714 out.write(Integer.toHexString(System.identityHashCode(w)));
4715 out.write(' ');
4716 out.append(w.mAttrs.getTitle());
4717 out.write('\n');
4718 }
4719
4720 out.write("DONE.\n");
4721 out.flush();
4722 } catch (Exception e) {
4723 result = false;
4724 } finally {
4725 if (out != null) {
4726 try {
4727 out.close();
4728 } catch (IOException e) {
4729 result = false;
4730 }
4731 }
4732 }
4733
4734 return result;
4735 }
4736
4737 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07004738 * Returns the focused window in the following format:
4739 * windowHashCodeInHexadecimal windowName
4740 *
4741 * @param client The remote client to send the listing to.
4742 * @return False if an error occurred, true otherwise.
4743 */
4744 boolean viewServerGetFocusedWindow(Socket client) {
4745 if (isSystemSecure()) {
4746 return false;
4747 }
4748
4749 boolean result = true;
4750
4751 WindowState focusedWindow = getFocusedWindow();
4752
4753 BufferedWriter out = null;
4754
4755 // Any uncaught exception will crash the system process
4756 try {
4757 OutputStream clientStream = client.getOutputStream();
4758 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4759
4760 if(focusedWindow != null) {
4761 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
4762 out.write(' ');
4763 out.append(focusedWindow.mAttrs.getTitle());
4764 }
4765 out.write('\n');
4766 out.flush();
4767 } catch (Exception e) {
4768 result = false;
4769 } finally {
4770 if (out != null) {
4771 try {
4772 out.close();
4773 } catch (IOException e) {
4774 result = false;
4775 }
4776 }
4777 }
4778
4779 return result;
4780 }
4781
4782 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004783 * Sends a command to a target window. The result of the command, if any, will be
4784 * written in the output stream of the specified socket.
4785 *
4786 * The parameters must follow this syntax:
4787 * windowHashcode extra
4788 *
4789 * Where XX is the length in characeters of the windowTitle.
4790 *
4791 * The first parameter is the target window. The window with the specified hashcode
4792 * will be the target. If no target can be found, nothing happens. The extra parameters
4793 * will be delivered to the target window and as parameters to the command itself.
4794 *
4795 * @param client The remote client to sent the result, if any, to.
4796 * @param command The command to execute.
4797 * @param parameters The command parameters.
4798 *
4799 * @return True if the command was successfully delivered, false otherwise. This does
4800 * not indicate whether the command itself was successful.
4801 */
4802 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004803 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004804 return false;
4805 }
4806
4807 boolean success = true;
4808 Parcel data = null;
4809 Parcel reply = null;
4810
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07004811 BufferedWriter out = null;
4812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004813 // Any uncaught exception will crash the system process
4814 try {
4815 // Find the hashcode of the window
4816 int index = parameters.indexOf(' ');
4817 if (index == -1) {
4818 index = parameters.length();
4819 }
4820 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004821 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004822
4823 // Extract the command's parameter after the window description
4824 if (index < parameters.length()) {
4825 parameters = parameters.substring(index + 1);
4826 } else {
4827 parameters = "";
4828 }
4829
4830 final WindowManagerService.WindowState window = findWindow(hashCode);
4831 if (window == null) {
4832 return false;
4833 }
4834
4835 data = Parcel.obtain();
4836 data.writeInterfaceToken("android.view.IWindow");
4837 data.writeString(command);
4838 data.writeString(parameters);
4839 data.writeInt(1);
4840 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4841
4842 reply = Parcel.obtain();
4843
4844 final IBinder binder = window.mClient.asBinder();
4845 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4846 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4847
4848 reply.readException();
4849
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07004850 if (!client.isOutputShutdown()) {
4851 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
4852 out.write("DONE\n");
4853 out.flush();
4854 }
4855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004856 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004857 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004858 success = false;
4859 } finally {
4860 if (data != null) {
4861 data.recycle();
4862 }
4863 if (reply != null) {
4864 reply.recycle();
4865 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07004866 if (out != null) {
4867 try {
4868 out.close();
4869 } catch (IOException e) {
4870
4871 }
4872 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004873 }
4874
4875 return success;
4876 }
4877
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004878 public void addWindowChangeListener(WindowChangeListener listener) {
4879 synchronized(mWindowMap) {
4880 mWindowChangeListeners.add(listener);
4881 }
4882 }
4883
4884 public void removeWindowChangeListener(WindowChangeListener listener) {
4885 synchronized(mWindowMap) {
4886 mWindowChangeListeners.remove(listener);
4887 }
4888 }
4889
4890 private void notifyWindowsChanged() {
4891 WindowChangeListener[] windowChangeListeners;
4892 synchronized(mWindowMap) {
4893 if(mWindowChangeListeners.isEmpty()) {
4894 return;
4895 }
4896 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4897 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4898 }
4899 int N = windowChangeListeners.length;
4900 for(int i = 0; i < N; i++) {
4901 windowChangeListeners[i].windowsChanged();
4902 }
4903 }
4904
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07004905 private void notifyFocusChanged() {
4906 WindowChangeListener[] windowChangeListeners;
4907 synchronized(mWindowMap) {
4908 if(mWindowChangeListeners.isEmpty()) {
4909 return;
4910 }
4911 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4912 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4913 }
4914 int N = windowChangeListeners.length;
4915 for(int i = 0; i < N; i++) {
4916 windowChangeListeners[i].focusChanged();
4917 }
4918 }
4919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004920 private WindowState findWindow(int hashCode) {
4921 if (hashCode == -1) {
4922 return getFocusedWindow();
4923 }
4924
4925 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07004926 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004927 final int count = windows.size();
4928
4929 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004930 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004931 if (System.identityHashCode(w) == hashCode) {
4932 return w;
4933 }
4934 }
4935 }
4936
4937 return null;
4938 }
4939
4940 /*
4941 * Instruct the Activity Manager to fetch the current configuration and broadcast
4942 * that to config-changed listeners if appropriate.
4943 */
4944 void sendNewConfiguration() {
4945 try {
4946 mActivityManager.updateConfiguration(null);
4947 } catch (RemoteException e) {
4948 }
4949 }
Romain Guy06882f82009-06-10 13:36:04 -07004950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004951 public Configuration computeNewConfiguration() {
4952 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004953 return computeNewConfigurationLocked();
4954 }
4955 }
Romain Guy06882f82009-06-10 13:36:04 -07004956
Dianne Hackbornc485a602009-03-24 22:39:49 -07004957 Configuration computeNewConfigurationLocked() {
4958 Configuration config = new Configuration();
4959 if (!computeNewConfigurationLocked(config)) {
4960 return null;
4961 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004962 return config;
4963 }
Romain Guy06882f82009-06-10 13:36:04 -07004964
Dianne Hackbornc485a602009-03-24 22:39:49 -07004965 boolean computeNewConfigurationLocked(Configuration config) {
4966 if (mDisplay == null) {
4967 return false;
4968 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004969
4970 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07004971
4972 // Use the effective "visual" dimensions based on current rotation
4973 final boolean rotated = (mRotation == Surface.ROTATION_90
4974 || mRotation == Surface.ROTATION_270);
4975 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
4976 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
4977
Dianne Hackbornc485a602009-03-24 22:39:49 -07004978 int orientation = Configuration.ORIENTATION_SQUARE;
4979 if (dw < dh) {
4980 orientation = Configuration.ORIENTATION_PORTRAIT;
4981 } else if (dw > dh) {
4982 orientation = Configuration.ORIENTATION_LANDSCAPE;
4983 }
4984 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004985
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004986 DisplayMetrics dm = new DisplayMetrics();
4987 mDisplay.getMetrics(dm);
4988 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4989
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004990 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004991 // Note we only do this once because at this point we don't
4992 // expect the screen to change in this way at runtime, and want
4993 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07004994 int longSize = dw;
4995 int shortSize = dh;
4996 if (longSize < shortSize) {
4997 int tmp = longSize;
4998 longSize = shortSize;
4999 shortSize = tmp;
5000 }
5001 longSize = (int)(longSize/dm.density);
5002 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005003
Dianne Hackborn723738c2009-06-25 19:48:04 -07005004 // These semi-magic numbers define our compatibility modes for
5005 // applications with different screens. Don't change unless you
5006 // make sure to test lots and lots of apps!
5007 if (longSize < 470) {
5008 // This is shorter than an HVGA normal density screen (which
5009 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005010 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5011 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005012 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005013 // What size is this screen screen?
5014 if (longSize >= 800 && shortSize >= 600) {
5015 // SVGA or larger screens at medium density are the point
5016 // at which we consider it to be an extra large screen.
5017 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
5018 } else if (longSize >= 640 && shortSize >= 480) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005019 // VGA or larger screens at medium density are the point
5020 // at which we consider it to be a large screen.
5021 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5022 } else {
5023 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005024
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005025 // If this screen is wider than normal HVGA, or taller
5026 // than FWVGA, then for old apps we want to run in size
5027 // compatibility mode.
5028 if (shortSize > 321 || longSize > 570) {
5029 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5030 }
5031 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005032
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005033 // Is this a long screen?
5034 if (((longSize*3)/5) >= (shortSize-1)) {
5035 // Anything wider than WVGA (5:3) is considering to be long.
5036 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5037 } else {
5038 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5039 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005040 }
5041 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005042 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005043
Dianne Hackbornc485a602009-03-24 22:39:49 -07005044 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5045 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5046 mPolicy.adjustConfigurationLw(config);
5047 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005048 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005050 // -------------------------------------------------------------
5051 // Input Events and Focus Management
5052 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005053
Jeff Brown349703e2010-06-22 01:27:15 -07005054 InputMonitor mInputMonitor = new InputMonitor();
5055
5056 /* Tracks the progress of input dispatch and ensures that input dispatch state
5057 * is kept in sync with changes in window focus, visibility, registration, and
5058 * other relevant Window Manager state transitions. */
5059 final class InputMonitor {
5060 // Current window with input focus for keys and other non-touch events. May be null.
5061 private WindowState mInputFocus;
5062
5063 // When true, prevents input dispatch from proceeding until set to false again.
5064 private boolean mInputDispatchFrozen;
5065
5066 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5067 private boolean mInputDispatchEnabled = true;
5068
5069 // Temporary list of windows information to provide to the input dispatcher.
5070 private InputWindowList mTempInputWindows = new InputWindowList();
5071
5072 // Temporary input application object to provide to the input dispatcher.
5073 private InputApplication mTempInputApplication = new InputApplication();
5074
5075 /* Notifies the window manager about a broken input channel.
5076 *
5077 * Called by the InputManager.
5078 */
5079 public void notifyInputChannelBroken(InputChannel inputChannel) {
5080 synchronized (mWindowMap) {
5081 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5082 if (windowState == null) {
5083 return; // irrelevant
5084 }
5085
5086 Slog.i(TAG, "WINDOW DIED " + windowState);
5087 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005088 }
5089 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005090
Jeff Brown519e0242010-09-15 15:18:56 -07005091 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005092 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005093 *
5094 * Called by the InputManager.
5095 */
Jeff Brown519e0242010-09-15 15:18:56 -07005096 public long notifyANR(Object token, InputChannel inputChannel) {
5097 AppWindowToken appWindowToken = null;
5098 if (inputChannel != null) {
5099 synchronized (mWindowMap) {
5100 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5101 if (windowState != null) {
5102 Slog.i(TAG, "Input event dispatching timed out sending to "
5103 + windowState.mAttrs.getTitle());
5104 appWindowToken = windowState.mAppToken;
5105 }
Jeff Brown349703e2010-06-22 01:27:15 -07005106 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005107 }
5108
Jeff Brown519e0242010-09-15 15:18:56 -07005109 if (appWindowToken == null && token != null) {
5110 appWindowToken = (AppWindowToken) token;
5111 Slog.i(TAG, "Input event dispatching timed out sending to application "
5112 + appWindowToken.stringName);
5113 }
Jeff Brown349703e2010-06-22 01:27:15 -07005114
Jeff Brown519e0242010-09-15 15:18:56 -07005115 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005116 try {
5117 // Notify the activity manager about the timeout and let it decide whether
5118 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005119 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005120 if (! abort) {
5121 // The activity manager declined to abort dispatching.
5122 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005123 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005124 }
Jeff Brown349703e2010-06-22 01:27:15 -07005125 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005126 }
5127 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005128 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005129 }
5130
Jeff Brown349703e2010-06-22 01:27:15 -07005131 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5132 synchronized (mWindowMap) {
5133 return getWindowStateForInputChannelLocked(inputChannel);
5134 }
5135 }
5136
5137 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5138 int windowCount = mWindows.size();
5139 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005140 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005141 if (windowState.mInputChannel == inputChannel) {
5142 return windowState;
5143 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005144 }
5145
Jeff Brown349703e2010-06-22 01:27:15 -07005146 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005147 }
5148
Jeff Brown349703e2010-06-22 01:27:15 -07005149 /* Updates the cached window information provided to the input dispatcher. */
5150 public void updateInputWindowsLw() {
5151 // Populate the input window list with information about all of the windows that
5152 // could potentially receive input.
5153 // As an optimization, we could try to prune the list of windows but this turns
5154 // out to be difficult because only the native code knows for sure which window
5155 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005156 final ArrayList<WindowState> windows = mWindows;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005157 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005158 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005159 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005160 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005161 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005162 continue;
5163 }
5164
Jeff Brown349703e2010-06-22 01:27:15 -07005165 final int flags = child.mAttrs.flags;
5166 final int type = child.mAttrs.type;
5167
5168 final boolean hasFocus = (child == mInputFocus);
5169 final boolean isVisible = child.isVisibleLw();
5170 final boolean hasWallpaper = (child == mWallpaperTarget)
5171 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
5172
5173 // Add a window to our list of input windows.
5174 final InputWindow inputWindow = mTempInputWindows.add();
5175 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005176 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005177 inputWindow.layoutParamsFlags = flags;
5178 inputWindow.layoutParamsType = type;
5179 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5180 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005181 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005182 inputWindow.hasFocus = hasFocus;
5183 inputWindow.hasWallpaper = hasWallpaper;
5184 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005185 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005186 inputWindow.ownerPid = child.mSession.mPid;
5187 inputWindow.ownerUid = child.mSession.mUid;
5188
5189 final Rect frame = child.mFrame;
5190 inputWindow.frameLeft = frame.left;
5191 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005192 inputWindow.frameRight = frame.right;
5193 inputWindow.frameBottom = frame.bottom;
5194
5195 final Rect visibleFrame = child.mVisibleFrame;
5196 inputWindow.visibleFrameLeft = visibleFrame.left;
5197 inputWindow.visibleFrameTop = visibleFrame.top;
5198 inputWindow.visibleFrameRight = visibleFrame.right;
5199 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005200
5201 switch (child.mTouchableInsets) {
5202 default:
5203 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5204 inputWindow.touchableAreaLeft = frame.left;
5205 inputWindow.touchableAreaTop = frame.top;
5206 inputWindow.touchableAreaRight = frame.right;
5207 inputWindow.touchableAreaBottom = frame.bottom;
5208 break;
5209
5210 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5211 Rect inset = child.mGivenContentInsets;
5212 inputWindow.touchableAreaLeft = frame.left + inset.left;
5213 inputWindow.touchableAreaTop = frame.top + inset.top;
5214 inputWindow.touchableAreaRight = frame.right - inset.right;
5215 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5216 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005217 }
Jeff Brown349703e2010-06-22 01:27:15 -07005218
5219 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5220 Rect inset = child.mGivenVisibleInsets;
5221 inputWindow.touchableAreaLeft = frame.left + inset.left;
5222 inputWindow.touchableAreaTop = frame.top + inset.top;
5223 inputWindow.touchableAreaRight = frame.right - inset.right;
5224 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005225 break;
5226 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005227 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005228 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005229
Jeff Brown349703e2010-06-22 01:27:15 -07005230 // Send windows to native code.
5231 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005232
Jeff Brown349703e2010-06-22 01:27:15 -07005233 // Clear the list in preparation for the next round.
5234 // Also avoids keeping InputChannel objects referenced unnecessarily.
5235 mTempInputWindows.clear();
5236 }
5237
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005238 /* Provides feedback for a virtual key down. */
5239 public void virtualKeyDownFeedback() {
5240 synchronized (mWindowMap) {
5241 mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5242 }
5243 }
5244
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005245 /* Notifies that the lid switch changed state. */
5246 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5247 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5248 }
5249
Jeff Brown349703e2010-06-22 01:27:15 -07005250 /* Provides an opportunity for the window manager policy to intercept early key
5251 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005252 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5253 int policyFlags, boolean isScreenOn) {
5254 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5255 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005256 }
5257
5258 /* Provides an opportunity for the window manager policy to process a key before
5259 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005260 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5261 int action, int flags, int keyCode, int metaState, int repeatCount,
5262 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005263 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005264 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5265 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005266 }
5267
5268 /* Called when the current input focus changes.
5269 * Layer assignment is assumed to be complete by the time this is called.
5270 */
5271 public void setInputFocusLw(WindowState newWindow) {
5272 if (DEBUG_INPUT) {
5273 Slog.d(TAG, "Input focus has changed to " + newWindow);
5274 }
5275
5276 if (newWindow != mInputFocus) {
5277 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005278 // Displaying a window implicitly causes dispatching to be unpaused.
5279 // This is to protect against bugs if someone pauses dispatching but
5280 // forgets to resume.
5281 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005282 }
Jeff Brown349703e2010-06-22 01:27:15 -07005283
5284 mInputFocus = newWindow;
5285 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005286 }
5287 }
5288
Jeff Brown349703e2010-06-22 01:27:15 -07005289 public void setFocusedAppLw(AppWindowToken newApp) {
5290 // Focused app has changed.
5291 if (newApp == null) {
5292 mInputManager.setFocusedApplication(null);
5293 } else {
5294 mTempInputApplication.name = newApp.toString();
5295 mTempInputApplication.dispatchingTimeoutNanos =
5296 newApp.inputDispatchingTimeoutNanos;
5297 mTempInputApplication.token = newApp;
5298
5299 mInputManager.setFocusedApplication(mTempInputApplication);
5300 }
5301 }
5302
Jeff Brown349703e2010-06-22 01:27:15 -07005303 public void pauseDispatchingLw(WindowToken window) {
5304 if (! window.paused) {
5305 if (DEBUG_INPUT) {
5306 Slog.v(TAG, "Pausing WindowToken " + window);
5307 }
5308
5309 window.paused = true;
5310 updateInputWindowsLw();
5311 }
5312 }
5313
5314 public void resumeDispatchingLw(WindowToken window) {
5315 if (window.paused) {
5316 if (DEBUG_INPUT) {
5317 Slog.v(TAG, "Resuming WindowToken " + window);
5318 }
5319
5320 window.paused = false;
5321 updateInputWindowsLw();
5322 }
5323 }
5324
5325 public void freezeInputDispatchingLw() {
5326 if (! mInputDispatchFrozen) {
5327 if (DEBUG_INPUT) {
5328 Slog.v(TAG, "Freezing input dispatching");
5329 }
5330
5331 mInputDispatchFrozen = true;
5332 updateInputDispatchModeLw();
5333 }
5334 }
5335
5336 public void thawInputDispatchingLw() {
5337 if (mInputDispatchFrozen) {
5338 if (DEBUG_INPUT) {
5339 Slog.v(TAG, "Thawing input dispatching");
5340 }
5341
5342 mInputDispatchFrozen = false;
5343 updateInputDispatchModeLw();
5344 }
5345 }
5346
5347 public void setEventDispatchingLw(boolean enabled) {
5348 if (mInputDispatchEnabled != enabled) {
5349 if (DEBUG_INPUT) {
5350 Slog.v(TAG, "Setting event dispatching to " + enabled);
5351 }
5352
5353 mInputDispatchEnabled = enabled;
5354 updateInputDispatchModeLw();
5355 }
5356 }
5357
5358 private void updateInputDispatchModeLw() {
5359 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5360 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005361 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005363 public void pauseKeyDispatching(IBinder _token) {
5364 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5365 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005366 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005367 }
5368
5369 synchronized (mWindowMap) {
5370 WindowToken token = mTokenMap.get(_token);
5371 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005372 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005373 }
5374 }
5375 }
5376
5377 public void resumeKeyDispatching(IBinder _token) {
5378 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5379 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005380 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005381 }
5382
5383 synchronized (mWindowMap) {
5384 WindowToken token = mTokenMap.get(_token);
5385 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005386 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005387 }
5388 }
5389 }
5390
5391 public void setEventDispatching(boolean enabled) {
5392 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5393 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005394 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005395 }
5396
5397 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005398 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005399 }
5400 }
Romain Guy06882f82009-06-10 13:36:04 -07005401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005402 /**
5403 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005404 * Even when sync is false, this method may block while waiting for current
5405 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005406 *
5407 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005408 * {@link SystemClock#uptimeMillis()} as the timebase.)
5409 * @param sync If true, wait for the event to be completed before returning to the caller.
5410 * @return Returns true if event was dispatched, false if it was dropped for any reason
5411 */
5412 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5413 long downTime = ev.getDownTime();
5414 long eventTime = ev.getEventTime();
5415
5416 int action = ev.getAction();
5417 int code = ev.getKeyCode();
5418 int repeatCount = ev.getRepeatCount();
5419 int metaState = ev.getMetaState();
5420 int deviceId = ev.getDeviceId();
5421 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005422 int source = ev.getSource();
5423
5424 if (source == InputDevice.SOURCE_UNKNOWN) {
5425 source = InputDevice.SOURCE_KEYBOARD;
5426 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005427
5428 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5429 if (downTime == 0) downTime = eventTime;
5430
5431 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005432 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005433
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005434 final int pid = Binder.getCallingPid();
5435 final int uid = Binder.getCallingUid();
5436 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005437
Jeff Brownbbda99d2010-07-28 15:48:59 -07005438 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5439 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5440 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5441 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005442
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005443 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005444 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005445 }
5446
5447 /**
5448 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005449 * Even when sync is false, this method may block while waiting for current
5450 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005451 *
5452 * @param ev A motion event describing the pointer (touch) action. (As noted in
5453 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005454 * {@link SystemClock#uptimeMillis()} as the timebase.)
5455 * @param sync If true, wait for the event to be completed before returning to the caller.
5456 * @return Returns true if event was dispatched, false if it was dropped for any reason
5457 */
5458 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005459 final int pid = Binder.getCallingPid();
5460 final int uid = Binder.getCallingUid();
5461 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005462
Jeff Brownc5ed5912010-07-14 18:48:53 -07005463 MotionEvent newEvent = MotionEvent.obtain(ev);
5464 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5465 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5466 }
5467
Jeff Brownbbda99d2010-07-28 15:48:59 -07005468 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5469 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5470 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5471 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005472
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005473 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005474 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005475 }
Romain Guy06882f82009-06-10 13:36:04 -07005476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005477 /**
5478 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005479 * Even when sync is false, this method may block while waiting for current
5480 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005481 *
5482 * @param ev A motion event describing the trackball action. (As noted in
5483 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005484 * {@link SystemClock#uptimeMillis()} as the timebase.)
5485 * @param sync If true, wait for the event to be completed before returning to the caller.
5486 * @return Returns true if event was dispatched, false if it was dropped for any reason
5487 */
5488 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005489 final int pid = Binder.getCallingPid();
5490 final int uid = Binder.getCallingUid();
5491 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005492
Jeff Brownc5ed5912010-07-14 18:48:53 -07005493 MotionEvent newEvent = MotionEvent.obtain(ev);
5494 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5495 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5496 }
5497
Jeff Brownbbda99d2010-07-28 15:48:59 -07005498 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5499 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5500 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5501 INJECTION_TIMEOUT_MILLIS);
5502
5503 Binder.restoreCallingIdentity(ident);
5504 return reportInjectionResult(result);
5505 }
5506
5507 /**
5508 * Inject an input event into the UI without waiting for dispatch to commence.
5509 * This variant is useful for fire-and-forget input event injection. It does not
5510 * block any longer than it takes to enqueue the input event.
5511 *
5512 * @param ev An input event. (Be sure to set the input source correctly.)
5513 * @return Returns true if event was dispatched, false if it was dropped for any reason
5514 */
5515 public boolean injectInputEventNoWait(InputEvent ev) {
5516 final int pid = Binder.getCallingPid();
5517 final int uid = Binder.getCallingUid();
5518 final long ident = Binder.clearCallingIdentity();
5519
5520 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5521 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5522 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005523
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005524 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005525 return reportInjectionResult(result);
5526 }
5527
5528 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005529 switch (result) {
5530 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5531 Slog.w(TAG, "Input event injection permission denied.");
5532 throw new SecurityException(
5533 "Injecting to another application requires INJECT_EVENTS permission");
5534 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07005535 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005536 return true;
5537 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5538 Slog.w(TAG, "Input event injection timed out.");
5539 return false;
5540 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5541 default:
5542 Slog.w(TAG, "Input event injection failed.");
5543 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005544 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005545 }
Romain Guy06882f82009-06-10 13:36:04 -07005546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005547 private WindowState getFocusedWindow() {
5548 synchronized (mWindowMap) {
5549 return getFocusedWindowLocked();
5550 }
5551 }
5552
5553 private WindowState getFocusedWindowLocked() {
5554 return mCurrentFocus;
5555 }
Romain Guy06882f82009-06-10 13:36:04 -07005556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005557 public boolean detectSafeMode() {
5558 mSafeMode = mPolicy.detectSafeMode();
5559 return mSafeMode;
5560 }
Romain Guy06882f82009-06-10 13:36:04 -07005561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005562 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07005563 synchronized(mWindowMap) {
5564 if (mDisplay != null) {
5565 throw new IllegalStateException("Display already initialized");
5566 }
5567 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
5568 mDisplay = wm.getDefaultDisplay();
5569 mInitialDisplayWidth = mDisplay.getWidth();
5570 mInitialDisplayHeight = mDisplay.getHeight();
5571 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
5572 }
5573
5574 try {
5575 mActivityManager.updateConfiguration(null);
5576 } catch (RemoteException e) {
5577 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07005578
5579 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07005580 }
5581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005582 // -------------------------------------------------------------
5583 // Client Session State
5584 // -------------------------------------------------------------
5585
5586 private final class Session extends IWindowSession.Stub
5587 implements IBinder.DeathRecipient {
5588 final IInputMethodClient mClient;
5589 final IInputContext mInputContext;
5590 final int mUid;
5591 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005592 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005593 SurfaceSession mSurfaceSession;
5594 int mNumWindow = 0;
5595 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07005596
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005597 public Session(IInputMethodClient client, IInputContext inputContext) {
5598 mClient = client;
5599 mInputContext = inputContext;
5600 mUid = Binder.getCallingUid();
5601 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005602 StringBuilder sb = new StringBuilder();
5603 sb.append("Session{");
5604 sb.append(Integer.toHexString(System.identityHashCode(this)));
5605 sb.append(" uid ");
5606 sb.append(mUid);
5607 sb.append("}");
5608 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07005609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005610 synchronized (mWindowMap) {
5611 if (mInputMethodManager == null && mHaveInputMethods) {
5612 IBinder b = ServiceManager.getService(
5613 Context.INPUT_METHOD_SERVICE);
5614 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
5615 }
5616 }
5617 long ident = Binder.clearCallingIdentity();
5618 try {
5619 // Note: it is safe to call in to the input method manager
5620 // here because we are not holding our lock.
5621 if (mInputMethodManager != null) {
5622 mInputMethodManager.addClient(client, inputContext,
5623 mUid, mPid);
5624 } else {
5625 client.setUsingInputMethod(false);
5626 }
5627 client.asBinder().linkToDeath(this, 0);
5628 } catch (RemoteException e) {
5629 // The caller has died, so we can just forget about this.
5630 try {
5631 if (mInputMethodManager != null) {
5632 mInputMethodManager.removeClient(client);
5633 }
5634 } catch (RemoteException ee) {
5635 }
5636 } finally {
5637 Binder.restoreCallingIdentity(ident);
5638 }
5639 }
Romain Guy06882f82009-06-10 13:36:04 -07005640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005641 @Override
5642 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
5643 throws RemoteException {
5644 try {
5645 return super.onTransact(code, data, reply, flags);
5646 } catch (RuntimeException e) {
5647 // Log all 'real' exceptions thrown to the caller
5648 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005649 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005650 }
5651 throw e;
5652 }
5653 }
5654
5655 public void binderDied() {
5656 // Note: it is safe to call in to the input method manager
5657 // here because we are not holding our lock.
5658 try {
5659 if (mInputMethodManager != null) {
5660 mInputMethodManager.removeClient(mClient);
5661 }
5662 } catch (RemoteException e) {
5663 }
5664 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005665 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005666 mClientDead = true;
5667 killSessionLocked();
5668 }
5669 }
5670
5671 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005672 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
5673 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
5674 outInputChannel);
5675 }
5676
5677 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005678 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005679 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005680 }
Romain Guy06882f82009-06-10 13:36:04 -07005681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005682 public void remove(IWindow window) {
5683 removeWindow(this, window);
5684 }
Romain Guy06882f82009-06-10 13:36:04 -07005685
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005686 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
5687 int requestedWidth, int requestedHeight, int viewFlags,
5688 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005689 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07005690 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
5691 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005692 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005693 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07005694 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
5695 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005696 }
Romain Guy06882f82009-06-10 13:36:04 -07005697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005698 public void setTransparentRegion(IWindow window, Region region) {
5699 setTransparentRegionWindow(this, window, region);
5700 }
Romain Guy06882f82009-06-10 13:36:04 -07005701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005702 public void setInsets(IWindow window, int touchableInsets,
5703 Rect contentInsets, Rect visibleInsets) {
5704 setInsetsWindow(this, window, touchableInsets, contentInsets,
5705 visibleInsets);
5706 }
Romain Guy06882f82009-06-10 13:36:04 -07005707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005708 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
5709 getWindowDisplayFrame(this, window, outDisplayFrame);
5710 }
Romain Guy06882f82009-06-10 13:36:04 -07005711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005712 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005713 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005714 TAG, "IWindow finishDrawing called for " + window);
5715 finishDrawingWindow(this, window);
5716 }
5717
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005718 public void setInTouchMode(boolean mode) {
5719 synchronized(mWindowMap) {
5720 mInTouchMode = mode;
5721 }
5722 }
5723
5724 public boolean getInTouchMode() {
5725 synchronized(mWindowMap) {
5726 return mInTouchMode;
5727 }
5728 }
5729
5730 public boolean performHapticFeedback(IWindow window, int effectId,
5731 boolean always) {
5732 synchronized(mWindowMap) {
5733 long ident = Binder.clearCallingIdentity();
5734 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005735 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005736 windowForClientLocked(this, window, true),
5737 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005738 } finally {
5739 Binder.restoreCallingIdentity(ident);
5740 }
5741 }
5742 }
Romain Guy06882f82009-06-10 13:36:04 -07005743
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005744 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005745 synchronized(mWindowMap) {
5746 long ident = Binder.clearCallingIdentity();
5747 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005748 setWindowWallpaperPositionLocked(
5749 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005750 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005751 } finally {
5752 Binder.restoreCallingIdentity(ident);
5753 }
5754 }
5755 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005756
Dianne Hackborn19382ac2009-09-11 21:13:37 -07005757 public void wallpaperOffsetsComplete(IBinder window) {
5758 WindowManagerService.this.wallpaperOffsetsComplete(window);
5759 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005760
Dianne Hackborn75804932009-10-20 20:15:20 -07005761 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
5762 int z, Bundle extras, boolean sync) {
5763 synchronized(mWindowMap) {
5764 long ident = Binder.clearCallingIdentity();
5765 try {
5766 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005767 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07005768 action, x, y, z, extras, sync);
5769 } finally {
5770 Binder.restoreCallingIdentity(ident);
5771 }
5772 }
5773 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005774
Dianne Hackborn75804932009-10-20 20:15:20 -07005775 public void wallpaperCommandComplete(IBinder window, Bundle result) {
5776 WindowManagerService.this.wallpaperCommandComplete(window, result);
5777 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005778
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005779 void windowAddedLocked() {
5780 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005781 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005782 TAG, "First window added to " + this + ", creating SurfaceSession");
5783 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08005784 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005785 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005786 mSessions.add(this);
5787 }
5788 mNumWindow++;
5789 }
5790
5791 void windowRemovedLocked() {
5792 mNumWindow--;
5793 killSessionLocked();
5794 }
Romain Guy06882f82009-06-10 13:36:04 -07005795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005796 void killSessionLocked() {
5797 if (mNumWindow <= 0 && mClientDead) {
5798 mSessions.remove(this);
5799 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005800 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005801 TAG, "Last window removed from " + this
5802 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005803 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005804 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005805 try {
5806 mSurfaceSession.kill();
5807 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005808 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005809 + mSurfaceSession + " in session " + this
5810 + ": " + e.toString());
5811 }
5812 mSurfaceSession = null;
5813 }
5814 }
5815 }
Romain Guy06882f82009-06-10 13:36:04 -07005816
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005817 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005818 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
5819 pw.print(" mClientDead="); pw.print(mClientDead);
5820 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005821 }
5822
5823 @Override
5824 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005825 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005826 }
5827 }
5828
5829 // -------------------------------------------------------------
5830 // Client Window State
5831 // -------------------------------------------------------------
5832
5833 private final class WindowState implements WindowManagerPolicy.WindowState {
5834 final Session mSession;
5835 final IWindow mClient;
5836 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07005837 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005838 AppWindowToken mAppToken;
5839 AppWindowToken mTargetAppToken;
5840 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
5841 final DeathRecipient mDeathRecipient;
5842 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07005843 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005844 final int mBaseLayer;
5845 final int mSubLayer;
5846 final boolean mLayoutAttached;
5847 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005848 final boolean mIsWallpaper;
5849 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005850 int mViewVisibility;
5851 boolean mPolicyVisibility = true;
5852 boolean mPolicyVisibilityAfterAnim = true;
5853 boolean mAppFreezing;
5854 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07005855 boolean mReportDestroySurface;
5856 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005857 boolean mAttachedHidden; // is our parent window hidden?
5858 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07005859 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005860 int mRequestedWidth;
5861 int mRequestedHeight;
5862 int mLastRequestedWidth;
5863 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005864 int mLayer;
5865 int mAnimLayer;
5866 int mLastLayer;
5867 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07005868 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07005869 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005870
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005871 int mLayoutSeq = -1;
5872
5873 Configuration mConfiguration = null;
5874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005875 // Actual frame shown on-screen (may be modified by animation)
5876 final Rect mShownFrame = new Rect();
5877 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005878
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005879 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08005880 * Set when we have changed the size of the surface, to know that
5881 * we must tell them application to resize (and thus redraw itself).
5882 */
5883 boolean mSurfaceResized;
5884
5885 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005886 * Insets that determine the actually visible area
5887 */
5888 final Rect mVisibleInsets = new Rect();
5889 final Rect mLastVisibleInsets = new Rect();
5890 boolean mVisibleInsetsChanged;
5891
5892 /**
5893 * Insets that are covered by system windows
5894 */
5895 final Rect mContentInsets = new Rect();
5896 final Rect mLastContentInsets = new Rect();
5897 boolean mContentInsetsChanged;
5898
5899 /**
5900 * Set to true if we are waiting for this window to receive its
5901 * given internal insets before laying out other windows based on it.
5902 */
5903 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07005904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005905 /**
5906 * These are the content insets that were given during layout for
5907 * this window, to be applied to windows behind it.
5908 */
5909 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005911 /**
5912 * These are the visible insets that were given during layout for
5913 * this window, to be applied to windows behind it.
5914 */
5915 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005917 /**
5918 * Flag indicating whether the touchable region should be adjusted by
5919 * the visible insets; if false the area outside the visible insets is
5920 * NOT touchable, so we must use those to adjust the frame during hit
5921 * tests.
5922 */
5923 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07005924
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005925 // Current transformation being applied.
5926 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
5927 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
5928 float mHScale=1, mVScale=1;
5929 float mLastHScale=1, mLastVScale=1;
5930 final Matrix mTmpMatrix = new Matrix();
5931
5932 // "Real" frame that the application sees.
5933 final Rect mFrame = new Rect();
5934 final Rect mLastFrame = new Rect();
5935
5936 final Rect mContainingFrame = new Rect();
5937 final Rect mDisplayFrame = new Rect();
5938 final Rect mContentFrame = new Rect();
5939 final Rect mVisibleFrame = new Rect();
5940
5941 float mShownAlpha = 1;
5942 float mAlpha = 1;
5943 float mLastAlpha = 1;
5944
5945 // Set to true if, when the window gets displayed, it should perform
5946 // an enter animation.
5947 boolean mEnterAnimationPending;
5948
5949 // Currently running animation.
5950 boolean mAnimating;
5951 boolean mLocalAnimating;
5952 Animation mAnimation;
5953 boolean mAnimationIsEntrance;
5954 boolean mHasTransformation;
5955 boolean mHasLocalTransformation;
5956 final Transformation mTransformation = new Transformation();
5957
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005958 // If a window showing a wallpaper: the requested offset for the
5959 // wallpaper; if a wallpaper window: the currently applied offset.
5960 float mWallpaperX = -1;
5961 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005962
5963 // If a window showing a wallpaper: what fraction of the offset
5964 // range corresponds to a full virtual screen.
5965 float mWallpaperXStep = -1;
5966 float mWallpaperYStep = -1;
5967
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005968 // Wallpaper windows: pixels offset based on above variables.
5969 int mXOffset;
5970 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005972 // This is set after IWindowSession.relayout() has been called at
5973 // least once for the window. It allows us to detect the situation
5974 // where we don't yet have a surface, but should have one soon, so
5975 // we can give the window focus before waiting for the relayout.
5976 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07005977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005978 // This is set after the Surface has been created but before the
5979 // window has been drawn. During this time the surface is hidden.
5980 boolean mDrawPending;
5981
5982 // This is set after the window has finished drawing for the first
5983 // time but before its surface is shown. The surface will be
5984 // displayed when the next layout is run.
5985 boolean mCommitDrawPending;
5986
5987 // This is set during the time after the window's drawing has been
5988 // committed, and before its surface is actually shown. It is used
5989 // to delay showing the surface until all windows in a token are ready
5990 // to be shown.
5991 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07005992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005993 // Set when the window has been shown in the screen the first time.
5994 boolean mHasDrawn;
5995
5996 // Currently running an exit animation?
5997 boolean mExiting;
5998
5999 // Currently on the mDestroySurface list?
6000 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006002 // Completely remove from window manager after exit animation?
6003 boolean mRemoveOnExit;
6004
6005 // Set when the orientation is changing and this window has not yet
6006 // been updated for the new orientation.
6007 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006009 // Is this window now (or just being) removed?
6010 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006011
Dianne Hackborn16064f92010-03-25 00:47:24 -07006012 // For debugging, this is the last information given to the surface flinger.
6013 boolean mSurfaceShown;
6014 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6015 int mSurfaceLayer;
6016 float mSurfaceAlpha;
6017
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006018 // Input channel
6019 InputChannel mInputChannel;
6020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006021 WindowState(Session s, IWindow c, WindowToken token,
6022 WindowState attachedWindow, WindowManager.LayoutParams a,
6023 int viewVisibility) {
6024 mSession = s;
6025 mClient = c;
6026 mToken = token;
6027 mAttrs.copyFrom(a);
6028 mViewVisibility = viewVisibility;
6029 DeathRecipient deathRecipient = new DeathRecipient();
6030 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006031 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006032 TAG, "Window " + this + " client=" + c.asBinder()
6033 + " token=" + token + " (" + mAttrs.token + ")");
6034 try {
6035 c.asBinder().linkToDeath(deathRecipient, 0);
6036 } catch (RemoteException e) {
6037 mDeathRecipient = null;
6038 mAttachedWindow = null;
6039 mLayoutAttached = false;
6040 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006041 mIsWallpaper = false;
6042 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006043 mBaseLayer = 0;
6044 mSubLayer = 0;
6045 return;
6046 }
6047 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006048
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006049 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6050 mAttrs.type <= LAST_SUB_WINDOW)) {
6051 // The multiplier here is to reserve space for multiple
6052 // windows in the same type layer.
6053 mBaseLayer = mPolicy.windowTypeToLayerLw(
6054 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6055 + TYPE_LAYER_OFFSET;
6056 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6057 mAttachedWindow = attachedWindow;
6058 mAttachedWindow.mChildWindows.add(this);
6059 mLayoutAttached = mAttrs.type !=
6060 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6061 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6062 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006063 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6064 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006065 } else {
6066 // The multiplier here is to reserve space for multiple
6067 // windows in the same type layer.
6068 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6069 * TYPE_LAYER_MULTIPLIER
6070 + TYPE_LAYER_OFFSET;
6071 mSubLayer = 0;
6072 mAttachedWindow = null;
6073 mLayoutAttached = false;
6074 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6075 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006076 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6077 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006078 }
6079
6080 WindowState appWin = this;
6081 while (appWin.mAttachedWindow != null) {
6082 appWin = mAttachedWindow;
6083 }
6084 WindowToken appToken = appWin.mToken;
6085 while (appToken.appWindowToken == null) {
6086 WindowToken parent = mTokenMap.get(appToken.token);
6087 if (parent == null || appToken == parent) {
6088 break;
6089 }
6090 appToken = parent;
6091 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006092 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006093 mAppToken = appToken.appWindowToken;
6094
6095 mSurface = null;
6096 mRequestedWidth = 0;
6097 mRequestedHeight = 0;
6098 mLastRequestedWidth = 0;
6099 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006100 mXOffset = 0;
6101 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006102 mLayer = 0;
6103 mAnimLayer = 0;
6104 mLastLayer = 0;
6105 }
6106
6107 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006108 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006109 TAG, "Attaching " + this + " token=" + mToken
6110 + ", list=" + mToken.windows);
6111 mSession.windowAddedLocked();
6112 }
6113
6114 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6115 mHaveFrame = true;
6116
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006117 final Rect container = mContainingFrame;
6118 container.set(pf);
6119
6120 final Rect display = mDisplayFrame;
6121 display.set(df);
6122
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006123 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006124 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006125 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6126 display.intersect(mCompatibleScreenFrame);
6127 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006128 }
6129
6130 final int pw = container.right - container.left;
6131 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006132
6133 int w,h;
6134 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6135 w = mAttrs.width < 0 ? pw : mAttrs.width;
6136 h = mAttrs.height< 0 ? ph : mAttrs.height;
6137 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006138 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6139 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006140 }
Romain Guy06882f82009-06-10 13:36:04 -07006141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006142 final Rect content = mContentFrame;
6143 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006145 final Rect visible = mVisibleFrame;
6146 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006148 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006149 final int fw = frame.width();
6150 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006152 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6153 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6154
6155 Gravity.apply(mAttrs.gravity, w, h, container,
6156 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6157 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6158
6159 //System.out.println("Out: " + mFrame);
6160
6161 // Now make sure the window fits in the overall display.
6162 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006164 // Make sure the content and visible frames are inside of the
6165 // final window frame.
6166 if (content.left < frame.left) content.left = frame.left;
6167 if (content.top < frame.top) content.top = frame.top;
6168 if (content.right > frame.right) content.right = frame.right;
6169 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6170 if (visible.left < frame.left) visible.left = frame.left;
6171 if (visible.top < frame.top) visible.top = frame.top;
6172 if (visible.right > frame.right) visible.right = frame.right;
6173 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006175 final Rect contentInsets = mContentInsets;
6176 contentInsets.left = content.left-frame.left;
6177 contentInsets.top = content.top-frame.top;
6178 contentInsets.right = frame.right-content.right;
6179 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006181 final Rect visibleInsets = mVisibleInsets;
6182 visibleInsets.left = visible.left-frame.left;
6183 visibleInsets.top = visible.top-frame.top;
6184 visibleInsets.right = frame.right-visible.right;
6185 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006186
Dianne Hackborn284ac932009-08-28 10:34:25 -07006187 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6188 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006189 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006190 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006192 if (localLOGV) {
6193 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6194 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006195 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006196 + mRequestedWidth + ", mRequestedheight="
6197 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6198 + "): frame=" + mFrame.toShortString()
6199 + " ci=" + contentInsets.toShortString()
6200 + " vi=" + visibleInsets.toShortString());
6201 //}
6202 }
6203 }
Romain Guy06882f82009-06-10 13:36:04 -07006204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006205 public Rect getFrameLw() {
6206 return mFrame;
6207 }
6208
6209 public Rect getShownFrameLw() {
6210 return mShownFrame;
6211 }
6212
6213 public Rect getDisplayFrameLw() {
6214 return mDisplayFrame;
6215 }
6216
6217 public Rect getContentFrameLw() {
6218 return mContentFrame;
6219 }
6220
6221 public Rect getVisibleFrameLw() {
6222 return mVisibleFrame;
6223 }
6224
6225 public boolean getGivenInsetsPendingLw() {
6226 return mGivenInsetsPending;
6227 }
6228
6229 public Rect getGivenContentInsetsLw() {
6230 return mGivenContentInsets;
6231 }
Romain Guy06882f82009-06-10 13:36:04 -07006232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006233 public Rect getGivenVisibleInsetsLw() {
6234 return mGivenVisibleInsets;
6235 }
Romain Guy06882f82009-06-10 13:36:04 -07006236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006237 public WindowManager.LayoutParams getAttrs() {
6238 return mAttrs;
6239 }
6240
6241 public int getSurfaceLayer() {
6242 return mLayer;
6243 }
Romain Guy06882f82009-06-10 13:36:04 -07006244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006245 public IApplicationToken getAppToken() {
6246 return mAppToken != null ? mAppToken.appToken : null;
6247 }
Jeff Brown349703e2010-06-22 01:27:15 -07006248
6249 public long getInputDispatchingTimeoutNanos() {
6250 return mAppToken != null
6251 ? mAppToken.inputDispatchingTimeoutNanos
6252 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6253 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006254
6255 public boolean hasAppShownWindows() {
6256 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6257 }
6258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006259 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006260 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006261 TAG, "Setting animation in " + this + ": " + anim);
6262 mAnimating = false;
6263 mLocalAnimating = false;
6264 mAnimation = anim;
6265 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6266 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6267 }
6268
6269 public void clearAnimation() {
6270 if (mAnimation != null) {
6271 mAnimating = true;
6272 mLocalAnimating = false;
6273 mAnimation = null;
6274 }
6275 }
Romain Guy06882f82009-06-10 13:36:04 -07006276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006277 Surface createSurfaceLocked() {
6278 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006279 mReportDestroySurface = false;
6280 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006281 mDrawPending = true;
6282 mCommitDrawPending = false;
6283 mReadyToShow = false;
6284 if (mAppToken != null) {
6285 mAppToken.allDrawn = false;
6286 }
6287
6288 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006289 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006290 flags |= Surface.PUSH_BUFFERS;
6291 }
6292
6293 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6294 flags |= Surface.SECURE;
6295 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006296 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006297 TAG, "Creating surface in session "
6298 + mSession.mSurfaceSession + " window " + this
6299 + " w=" + mFrame.width()
6300 + " h=" + mFrame.height() + " format="
6301 + mAttrs.format + " flags=" + flags);
6302
6303 int w = mFrame.width();
6304 int h = mFrame.height();
6305 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6306 // for a scaled surface, we always want the requested
6307 // size.
6308 w = mRequestedWidth;
6309 h = mRequestedHeight;
6310 }
6311
Romain Guy9825ec62009-10-01 00:58:09 -07006312 // Something is wrong and SurfaceFlinger will not like this,
6313 // try to revert to sane values
6314 if (w <= 0) w = 1;
6315 if (h <= 0) h = 1;
6316
Dianne Hackborn16064f92010-03-25 00:47:24 -07006317 mSurfaceShown = false;
6318 mSurfaceLayer = 0;
6319 mSurfaceAlpha = 1;
6320 mSurfaceX = 0;
6321 mSurfaceY = 0;
6322 mSurfaceW = w;
6323 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006324 try {
6325 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006326 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006327 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006328 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006329 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006330 + mSurface + " IN SESSION "
6331 + mSession.mSurfaceSession
6332 + ": pid=" + mSession.mPid + " format="
6333 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006334 + Integer.toHexString(flags)
6335 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006336 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006337 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006338 reclaimSomeSurfaceMemoryLocked(this, "create");
6339 return null;
6340 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006341 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006342 return null;
6343 }
Romain Guy06882f82009-06-10 13:36:04 -07006344
Joe Onorato8a9b2202010-02-26 18:56:32 -08006345 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006346 TAG, "Got surface: " + mSurface
6347 + ", set left=" + mFrame.left + " top=" + mFrame.top
6348 + ", animLayer=" + mAnimLayer);
6349 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006350 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006351 if (SHOW_TRANSACTIONS) logSurface(this,
6352 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6353 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6354 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006355 }
6356 Surface.openTransaction();
6357 try {
6358 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006359 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006360 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006361 mSurface.setPosition(mSurfaceX, mSurfaceY);
6362 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006363 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006364 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006365 mSurface.hide();
6366 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006367 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006368 mSurface.setFlags(Surface.SURFACE_DITHER,
6369 Surface.SURFACE_DITHER);
6370 }
6371 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006372 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006373 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6374 }
6375 mLastHidden = true;
6376 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006377 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006378 Surface.closeTransaction();
6379 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006380 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006381 TAG, "Created surface " + this);
6382 }
6383 return mSurface;
6384 }
Romain Guy06882f82009-06-10 13:36:04 -07006385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006386 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006387 if (mAppToken != null && this == mAppToken.startingWindow) {
6388 mAppToken.startingDisplayed = false;
6389 }
Romain Guy06882f82009-06-10 13:36:04 -07006390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006391 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006392 mDrawPending = false;
6393 mCommitDrawPending = false;
6394 mReadyToShow = false;
6395
6396 int i = mChildWindows.size();
6397 while (i > 0) {
6398 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006399 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006400 c.mAttachedHidden = true;
6401 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006402
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006403 if (mReportDestroySurface) {
6404 mReportDestroySurface = false;
6405 mSurfacePendingDestroy = true;
6406 try {
6407 mClient.dispatchGetNewSurface();
6408 // We'll really destroy on the next time around.
6409 return;
6410 } catch (RemoteException e) {
6411 }
6412 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006414 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006415 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006416 RuntimeException e = null;
6417 if (!HIDE_STACK_CRAWLS) {
6418 e = new RuntimeException();
6419 e.fillInStackTrace();
6420 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006421 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006422 + mSurface + ", session " + mSession, e);
6423 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006424 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006425 RuntimeException e = null;
6426 if (!HIDE_STACK_CRAWLS) {
6427 e = new RuntimeException();
6428 e.fillInStackTrace();
6429 }
6430 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006431 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006432 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006433 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006434 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006435 + " surface " + mSurface + " session " + mSession
6436 + ": " + e.toString());
6437 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006438
Dianne Hackborn16064f92010-03-25 00:47:24 -07006439 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006440 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006441 }
6442 }
6443
6444 boolean finishDrawingLocked() {
6445 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006446 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006447 TAG, "finishDrawingLocked: " + mSurface);
6448 mCommitDrawPending = true;
6449 mDrawPending = false;
6450 return true;
6451 }
6452 return false;
6453 }
6454
6455 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006456 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006457 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006458 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006459 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006460 }
6461 mCommitDrawPending = false;
6462 mReadyToShow = true;
6463 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6464 final AppWindowToken atoken = mAppToken;
6465 if (atoken == null || atoken.allDrawn || starting) {
6466 performShowLocked();
6467 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006468 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006469 }
6470
6471 // This must be called while inside a transaction.
6472 boolean performShowLocked() {
6473 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006474 RuntimeException e = null;
6475 if (!HIDE_STACK_CRAWLS) {
6476 e = new RuntimeException();
6477 e.fillInStackTrace();
6478 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006479 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006480 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
6481 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
6482 }
6483 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006484 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
6485 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006486 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006487 + " during animation: policyVis=" + mPolicyVisibility
6488 + " attHidden=" + mAttachedHidden
6489 + " tok.hiddenRequested="
6490 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07006491 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006492 + (mAppToken != null ? mAppToken.hidden : false)
6493 + " animating=" + mAnimating
6494 + " tok animating="
6495 + (mAppToken != null ? mAppToken.animating : false));
6496 if (!showSurfaceRobustlyLocked(this)) {
6497 return false;
6498 }
6499 mLastAlpha = -1;
6500 mHasDrawn = true;
6501 mLastHidden = false;
6502 mReadyToShow = false;
6503 enableScreenIfNeededLocked();
6504
6505 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07006506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006507 int i = mChildWindows.size();
6508 while (i > 0) {
6509 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006510 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006511 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006512 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006513 if (c.mSurface != null) {
6514 c.performShowLocked();
6515 // It hadn't been shown, which means layout not
6516 // performed on it, so now we want to make sure to
6517 // do a layout. If called from within the transaction
6518 // loop, this will cause it to restart with a new
6519 // layout.
6520 mLayoutNeeded = true;
6521 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006522 }
6523 }
Romain Guy06882f82009-06-10 13:36:04 -07006524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006525 if (mAttrs.type != TYPE_APPLICATION_STARTING
6526 && mAppToken != null) {
6527 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006528
Dianne Hackborn248b1882009-09-16 16:46:44 -07006529 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006530 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006531 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006532 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07006533 // If this initial window is animating, stop it -- we
6534 // will do an animation to reveal it from behind the
6535 // starting window, so there is no need for it to also
6536 // be doing its own stuff.
6537 if (mAnimation != null) {
6538 mAnimation = null;
6539 // Make sure we clean up the animation.
6540 mAnimating = true;
6541 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006542 mFinishedStarting.add(mAppToken);
6543 mH.sendEmptyMessage(H.FINISHED_STARTING);
6544 }
6545 mAppToken.updateReportedVisibilityLocked();
6546 }
6547 }
6548 return true;
6549 }
Romain Guy06882f82009-06-10 13:36:04 -07006550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006551 // This must be called while inside a transaction. Returns true if
6552 // there is more animation to run.
6553 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08006554 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006555 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07006556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006557 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
6558 mHasTransformation = true;
6559 mHasLocalTransformation = true;
6560 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006561 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006562 TAG, "Starting animation in " + this +
6563 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
6564 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
6565 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
6566 mAnimation.setStartTime(currentTime);
6567 mLocalAnimating = true;
6568 mAnimating = true;
6569 }
6570 mTransformation.clear();
6571 final boolean more = mAnimation.getTransformation(
6572 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006573 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006574 TAG, "Stepped animation in " + this +
6575 ": more=" + more + ", xform=" + mTransformation);
6576 if (more) {
6577 // we're not done!
6578 return true;
6579 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006580 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006581 TAG, "Finished animation in " + this +
6582 " @ " + currentTime);
6583 mAnimation = null;
6584 //WindowManagerService.this.dump();
6585 }
6586 mHasLocalTransformation = false;
6587 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006588 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006589 // When our app token is animating, we kind-of pretend like
6590 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
6591 // part of this check means that we will only do this if
6592 // our window is not currently exiting, or it is not
6593 // locally animating itself. The idea being that one that
6594 // is exiting and doing a local animation should be removed
6595 // once that animation is done.
6596 mAnimating = true;
6597 mHasTransformation = true;
6598 mTransformation.clear();
6599 return false;
6600 } else if (mHasTransformation) {
6601 // Little trick to get through the path below to act like
6602 // we have finished an animation.
6603 mAnimating = true;
6604 } else if (isAnimating()) {
6605 mAnimating = true;
6606 }
6607 } else if (mAnimation != null) {
6608 // If the display is frozen, and there is a pending animation,
6609 // clear it and make sure we run the cleanup code.
6610 mAnimating = true;
6611 mLocalAnimating = true;
6612 mAnimation = null;
6613 }
Romain Guy06882f82009-06-10 13:36:04 -07006614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006615 if (!mAnimating && !mLocalAnimating) {
6616 return false;
6617 }
6618
Joe Onorato8a9b2202010-02-26 18:56:32 -08006619 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006620 TAG, "Animation done in " + this + ": exiting=" + mExiting
6621 + ", reportedVisible="
6622 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07006623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006624 mAnimating = false;
6625 mLocalAnimating = false;
6626 mAnimation = null;
6627 mAnimLayer = mLayer;
6628 if (mIsImWindow) {
6629 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006630 } else if (mIsWallpaper) {
6631 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006632 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006633 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006634 + " anim layer: " + mAnimLayer);
6635 mHasTransformation = false;
6636 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006637 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
6638 if (DEBUG_VISIBILITY) {
6639 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
6640 + mPolicyVisibilityAfterAnim);
6641 }
6642 mPolicyVisibility = mPolicyVisibilityAfterAnim;
6643 if (!mPolicyVisibility) {
6644 if (mCurrentFocus == this) {
6645 mFocusMayChange = true;
6646 }
6647 // Window is no longer visible -- make sure if we were waiting
6648 // for it to be displayed before enabling the display, that
6649 // we allow the display to be enabled now.
6650 enableScreenIfNeededLocked();
6651 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08006652 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006653 mTransformation.clear();
6654 if (mHasDrawn
6655 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
6656 && mAppToken != null
6657 && mAppToken.firstWindowDrawn
6658 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006659 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006660 + mToken + ": first real window done animating");
6661 mFinishedStarting.add(mAppToken);
6662 mH.sendEmptyMessage(H.FINISHED_STARTING);
6663 }
Romain Guy06882f82009-06-10 13:36:04 -07006664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006665 finishExit();
6666
6667 if (mAppToken != null) {
6668 mAppToken.updateReportedVisibilityLocked();
6669 }
6670
6671 return false;
6672 }
6673
6674 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006675 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006676 TAG, "finishExit in " + this
6677 + ": exiting=" + mExiting
6678 + " remove=" + mRemoveOnExit
6679 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07006680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006681 final int N = mChildWindows.size();
6682 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07006683 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006684 }
Romain Guy06882f82009-06-10 13:36:04 -07006685
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006686 if (!mExiting) {
6687 return;
6688 }
Romain Guy06882f82009-06-10 13:36:04 -07006689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006690 if (isWindowAnimating()) {
6691 return;
6692 }
6693
Joe Onorato8a9b2202010-02-26 18:56:32 -08006694 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006695 TAG, "Exit animation finished in " + this
6696 + ": remove=" + mRemoveOnExit);
6697 if (mSurface != null) {
6698 mDestroySurface.add(this);
6699 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006700 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006701 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006702 try {
6703 mSurface.hide();
6704 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006705 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006706 }
6707 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006708 }
6709 mExiting = false;
6710 if (mRemoveOnExit) {
6711 mPendingRemove.add(this);
6712 mRemoveOnExit = false;
6713 }
6714 }
Romain Guy06882f82009-06-10 13:36:04 -07006715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006716 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
6717 if (dsdx < .99999f || dsdx > 1.00001f) return false;
6718 if (dtdy < .99999f || dtdy > 1.00001f) return false;
6719 if (dtdx < -.000001f || dtdx > .000001f) return false;
6720 if (dsdy < -.000001f || dsdy > .000001f) return false;
6721 return true;
6722 }
Romain Guy06882f82009-06-10 13:36:04 -07006723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006724 void computeShownFrameLocked() {
6725 final boolean selfTransformation = mHasLocalTransformation;
6726 Transformation attachedTransformation =
6727 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
6728 ? mAttachedWindow.mTransformation : null;
6729 Transformation appTransformation =
6730 (mAppToken != null && mAppToken.hasTransformation)
6731 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006732
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006733 // Wallpapers are animated based on the "real" window they
6734 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006735 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07006736 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07006737 if (mWallpaperTarget.mHasLocalTransformation &&
6738 mWallpaperTarget.mAnimation != null &&
6739 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006740 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006741 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006742 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006743 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006744 }
6745 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07006746 mWallpaperTarget.mAppToken.hasTransformation &&
6747 mWallpaperTarget.mAppToken.animation != null &&
6748 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006749 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006750 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006751 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006752 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006753 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006754 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006756 if (selfTransformation || attachedTransformation != null
6757 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07006758 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006759 final Rect frame = mFrame;
6760 final float tmpFloats[] = mTmpFloats;
6761 final Matrix tmpMatrix = mTmpMatrix;
6762
6763 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07006764 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006765 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006766 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006767 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07006768 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006769 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006770 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006771 }
6772 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006773 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006774 }
6775
6776 // "convert" it into SurfaceFlinger's format
6777 // (a 2x2 matrix + an offset)
6778 // Here we must not transform the position of the surface
6779 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006780 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07006781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006782 tmpMatrix.getValues(tmpFloats);
6783 mDsDx = tmpFloats[Matrix.MSCALE_X];
6784 mDtDx = tmpFloats[Matrix.MSKEW_X];
6785 mDsDy = tmpFloats[Matrix.MSKEW_Y];
6786 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006787 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
6788 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006789 int w = frame.width();
6790 int h = frame.height();
6791 mShownFrame.set(x, y, x+w, y+h);
6792
6793 // Now set the alpha... but because our current hardware
6794 // can't do alpha transformation on a non-opaque surface,
6795 // turn it off if we are running an animation that is also
6796 // transforming since it is more important to have that
6797 // animation be smooth.
6798 mShownAlpha = mAlpha;
6799 if (!mLimitedAlphaCompositing
6800 || (!PixelFormat.formatHasAlpha(mAttrs.format)
6801 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
6802 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006803 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006804 if (selfTransformation) {
6805 mShownAlpha *= mTransformation.getAlpha();
6806 }
6807 if (attachedTransformation != null) {
6808 mShownAlpha *= attachedTransformation.getAlpha();
6809 }
6810 if (appTransformation != null) {
6811 mShownAlpha *= appTransformation.getAlpha();
6812 }
6813 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006814 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006815 }
Romain Guy06882f82009-06-10 13:36:04 -07006816
Joe Onorato8a9b2202010-02-26 18:56:32 -08006817 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006818 TAG, "Continuing animation in " + this +
6819 ": " + mShownFrame +
6820 ", alpha=" + mTransformation.getAlpha());
6821 return;
6822 }
Romain Guy06882f82009-06-10 13:36:04 -07006823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006824 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006825 if (mXOffset != 0 || mYOffset != 0) {
6826 mShownFrame.offset(mXOffset, mYOffset);
6827 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006828 mShownAlpha = mAlpha;
6829 mDsDx = 1;
6830 mDtDx = 0;
6831 mDsDy = 0;
6832 mDtDy = 1;
6833 }
Romain Guy06882f82009-06-10 13:36:04 -07006834
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006835 /**
6836 * Is this window visible? It is not visible if there is no
6837 * surface, or we are in the process of running an exit animation
6838 * that will remove the surface, or its app token has been hidden.
6839 */
6840 public boolean isVisibleLw() {
6841 final AppWindowToken atoken = mAppToken;
6842 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6843 && (atoken == null || !atoken.hiddenRequested)
6844 && !mExiting && !mDestroying;
6845 }
6846
6847 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006848 * Like {@link #isVisibleLw}, but also counts a window that is currently
6849 * "hidden" behind the keyguard as visible. This allows us to apply
6850 * things like window flags that impact the keyguard.
6851 * XXX I am starting to think we need to have ANOTHER visibility flag
6852 * for this "hidden behind keyguard" state rather than overloading
6853 * mPolicyVisibility. Ungh.
6854 */
6855 public boolean isVisibleOrBehindKeyguardLw() {
6856 final AppWindowToken atoken = mAppToken;
6857 return mSurface != null && !mAttachedHidden
6858 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006859 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006860 && !mExiting && !mDestroying;
6861 }
6862
6863 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006864 * Is this window visible, ignoring its app token? It is not visible
6865 * if there is no surface, or we are in the process of running an exit animation
6866 * that will remove the surface.
6867 */
6868 public boolean isWinVisibleLw() {
6869 final AppWindowToken atoken = mAppToken;
6870 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6871 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
6872 && !mExiting && !mDestroying;
6873 }
6874
6875 /**
6876 * The same as isVisible(), but follows the current hidden state of
6877 * the associated app token, not the pending requested hidden state.
6878 */
6879 boolean isVisibleNow() {
6880 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07006881 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006882 }
6883
6884 /**
6885 * Same as isVisible(), but we also count it as visible between the
6886 * call to IWindowSession.add() and the first relayout().
6887 */
6888 boolean isVisibleOrAdding() {
6889 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006890 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006891 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
6892 && mPolicyVisibility && !mAttachedHidden
6893 && (atoken == null || !atoken.hiddenRequested)
6894 && !mExiting && !mDestroying;
6895 }
6896
6897 /**
6898 * Is this window currently on-screen? It is on-screen either if it
6899 * is visible or it is currently running an animation before no longer
6900 * being visible.
6901 */
6902 boolean isOnScreen() {
6903 final AppWindowToken atoken = mAppToken;
6904 if (atoken != null) {
6905 return mSurface != null && mPolicyVisibility && !mDestroying
6906 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006907 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006908 } else {
6909 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006910 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006911 }
6912 }
Romain Guy06882f82009-06-10 13:36:04 -07006913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006914 /**
6915 * Like isOnScreen(), but we don't return true if the window is part
6916 * of a transition that has not yet been started.
6917 */
6918 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006919 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07006920 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006921 return false;
6922 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006923 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006924 final boolean animating = atoken != null
6925 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006926 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006927 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
6928 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006929 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006930 }
6931
6932 /** Is the window or its container currently animating? */
6933 boolean isAnimating() {
6934 final WindowState attached = mAttachedWindow;
6935 final AppWindowToken atoken = mAppToken;
6936 return mAnimation != null
6937 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07006938 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006939 (atoken.animation != null
6940 || atoken.inPendingTransaction));
6941 }
6942
6943 /** Is this window currently animating? */
6944 boolean isWindowAnimating() {
6945 return mAnimation != null;
6946 }
6947
6948 /**
6949 * Like isOnScreen, but returns false if the surface hasn't yet
6950 * been drawn.
6951 */
6952 public boolean isDisplayedLw() {
6953 final AppWindowToken atoken = mAppToken;
6954 return mSurface != null && mPolicyVisibility && !mDestroying
6955 && !mDrawPending && !mCommitDrawPending
6956 && ((!mAttachedHidden &&
6957 (atoken == null || !atoken.hiddenRequested))
6958 || mAnimating);
6959 }
6960
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006961 /**
6962 * Returns true if the window has a surface that it has drawn a
6963 * complete UI in to.
6964 */
6965 public boolean isDrawnLw() {
6966 final AppWindowToken atoken = mAppToken;
6967 return mSurface != null && !mDestroying
6968 && !mDrawPending && !mCommitDrawPending;
6969 }
6970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006971 public boolean fillsScreenLw(int screenWidth, int screenHeight,
6972 boolean shownFrame, boolean onlyOpaque) {
6973 if (mSurface == null) {
6974 return false;
6975 }
6976 if (mAppToken != null && !mAppToken.appFullscreen) {
6977 return false;
6978 }
6979 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
6980 return false;
6981 }
6982 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006983
6984 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
6985 return frame.left <= mCompatibleScreenFrame.left &&
6986 frame.top <= mCompatibleScreenFrame.top &&
6987 frame.right >= mCompatibleScreenFrame.right &&
6988 frame.bottom >= mCompatibleScreenFrame.bottom;
6989 } else {
Joe Onorato93056472010-09-10 10:30:46 -04006990 if ((mAttrs.flags & FLAG_FULLSCREEN) != 0) {
6991 return true;
6992 }
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006993 return frame.left <= 0 && frame.top <= 0
6994 && frame.right >= screenWidth
6995 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006996 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006997 }
Romain Guy06882f82009-06-10 13:36:04 -07006998
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006999 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007000 * Return true if the window is opaque and fully drawn. This indicates
7001 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007002 */
7003 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007004 return (mAttrs.format == PixelFormat.OPAQUE
7005 || mAttrs.type == TYPE_WALLPAPER)
7006 && mSurface != null && mAnimation == null
7007 && (mAppToken == null || mAppToken.animation == null)
7008 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007009 }
7010
7011 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7012 return
7013 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007014 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7015 // only if it's visible
7016 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007017 // and only if the application fills the compatible screen
7018 mFrame.left <= mCompatibleScreenFrame.left &&
7019 mFrame.top <= mCompatibleScreenFrame.top &&
7020 mFrame.right >= mCompatibleScreenFrame.right &&
7021 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007022 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007023 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007024 }
7025
7026 boolean isFullscreen(int screenWidth, int screenHeight) {
7027 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007028 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007029 }
7030
7031 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007032 disposeInputChannel();
7033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007034 if (mAttachedWindow != null) {
7035 mAttachedWindow.mChildWindows.remove(this);
7036 }
7037 destroySurfaceLocked();
7038 mSession.windowRemovedLocked();
7039 try {
7040 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7041 } catch (RuntimeException e) {
7042 // Ignore if it has already been removed (usually because
7043 // we are doing this as part of processing a death note.)
7044 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007045 }
7046
7047 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007048 if (mInputChannel != null) {
7049 mInputManager.unregisterInputChannel(mInputChannel);
7050
7051 mInputChannel.dispose();
7052 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007053 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007054 }
7055
7056 private class DeathRecipient implements IBinder.DeathRecipient {
7057 public void binderDied() {
7058 try {
7059 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007060 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007061 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007062 if (win != null) {
7063 removeWindowLocked(mSession, win);
7064 }
7065 }
7066 } catch (IllegalArgumentException ex) {
7067 // This will happen if the window has already been
7068 // removed.
7069 }
7070 }
7071 }
7072
7073 /** Returns true if this window desires key events. */
7074 public final boolean canReceiveKeys() {
7075 return isVisibleOrAdding()
7076 && (mViewVisibility == View.VISIBLE)
7077 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7078 }
7079
7080 public boolean hasDrawnLw() {
7081 return mHasDrawn;
7082 }
7083
7084 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007085 return showLw(doAnimation, true);
7086 }
7087
7088 boolean showLw(boolean doAnimation, boolean requestAnim) {
7089 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7090 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007091 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007092 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007093 if (doAnimation) {
7094 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7095 + mPolicyVisibility + " mAnimation=" + mAnimation);
7096 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7097 doAnimation = false;
7098 } else if (mPolicyVisibility && mAnimation == null) {
7099 // Check for the case where we are currently visible and
7100 // not animating; we do not want to do animation at such a
7101 // point to become visible when we already are.
7102 doAnimation = false;
7103 }
7104 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007105 mPolicyVisibility = true;
7106 mPolicyVisibilityAfterAnim = true;
7107 if (doAnimation) {
7108 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7109 }
7110 if (requestAnim) {
7111 requestAnimationLocked(0);
7112 }
7113 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007114 }
7115
7116 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007117 return hideLw(doAnimation, true);
7118 }
7119
7120 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007121 if (doAnimation) {
7122 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7123 doAnimation = false;
7124 }
7125 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007126 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7127 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007128 if (!current) {
7129 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007130 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007131 if (doAnimation) {
7132 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7133 if (mAnimation == null) {
7134 doAnimation = false;
7135 }
7136 }
7137 if (doAnimation) {
7138 mPolicyVisibilityAfterAnim = false;
7139 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007140 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007141 mPolicyVisibilityAfterAnim = false;
7142 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007143 // Window is no longer visible -- make sure if we were waiting
7144 // for it to be displayed before enabling the display, that
7145 // we allow the display to be enabled now.
7146 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007147 if (mCurrentFocus == this) {
7148 mFocusMayChange = true;
7149 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007150 }
7151 if (requestAnim) {
7152 requestAnimationLocked(0);
7153 }
7154 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007155 }
7156
7157 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007158 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7159 pw.print(" mClient="); pw.println(mClient.asBinder());
7160 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7161 if (mAttachedWindow != null || mLayoutAttached) {
7162 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7163 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7164 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007165 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7166 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7167 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007168 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7169 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007170 }
7171 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7172 pw.print(" mSubLayer="); pw.print(mSubLayer);
7173 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7174 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7175 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7176 pw.print("="); pw.print(mAnimLayer);
7177 pw.print(" mLastLayer="); pw.println(mLastLayer);
7178 if (mSurface != null) {
7179 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007180 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7181 pw.print(" layer="); pw.print(mSurfaceLayer);
7182 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7183 pw.print(" rect=("); pw.print(mSurfaceX);
7184 pw.print(","); pw.print(mSurfaceY);
7185 pw.print(") "); pw.print(mSurfaceW);
7186 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007187 }
7188 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7189 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7190 if (mAppToken != null) {
7191 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7192 }
7193 if (mTargetAppToken != null) {
7194 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7195 }
7196 pw.print(prefix); pw.print("mViewVisibility=0x");
7197 pw.print(Integer.toHexString(mViewVisibility));
7198 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007199 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7200 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007201 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7202 pw.print(prefix); pw.print("mPolicyVisibility=");
7203 pw.print(mPolicyVisibility);
7204 pw.print(" mPolicyVisibilityAfterAnim=");
7205 pw.print(mPolicyVisibilityAfterAnim);
7206 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7207 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007208 if (!mRelayoutCalled) {
7209 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7210 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007211 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007212 pw.print(" h="); pw.print(mRequestedHeight);
7213 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007214 if (mXOffset != 0 || mYOffset != 0) {
7215 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7216 pw.print(" y="); pw.println(mYOffset);
7217 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007218 pw.print(prefix); pw.print("mGivenContentInsets=");
7219 mGivenContentInsets.printShortString(pw);
7220 pw.print(" mGivenVisibleInsets=");
7221 mGivenVisibleInsets.printShortString(pw);
7222 pw.println();
7223 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7224 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7225 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7226 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007227 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007228 pw.print(prefix); pw.print("mShownFrame=");
7229 mShownFrame.printShortString(pw);
7230 pw.print(" last="); mLastShownFrame.printShortString(pw);
7231 pw.println();
7232 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7233 pw.print(" last="); mLastFrame.printShortString(pw);
7234 pw.println();
7235 pw.print(prefix); pw.print("mContainingFrame=");
7236 mContainingFrame.printShortString(pw);
7237 pw.print(" mDisplayFrame=");
7238 mDisplayFrame.printShortString(pw);
7239 pw.println();
7240 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7241 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7242 pw.println();
7243 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7244 pw.print(" last="); mLastContentInsets.printShortString(pw);
7245 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7246 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7247 pw.println();
7248 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7249 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7250 pw.print(" mAlpha="); pw.print(mAlpha);
7251 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7252 }
7253 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7254 || mAnimation != null) {
7255 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7256 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7257 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7258 pw.print(" mAnimation="); pw.println(mAnimation);
7259 }
7260 if (mHasTransformation || mHasLocalTransformation) {
7261 pw.print(prefix); pw.print("XForm: has=");
7262 pw.print(mHasTransformation);
7263 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7264 pw.print(" "); mTransformation.printShortString(pw);
7265 pw.println();
7266 }
7267 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7268 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7269 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7270 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7271 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7272 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7273 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7274 pw.print(" mDestroying="); pw.print(mDestroying);
7275 pw.print(" mRemoved="); pw.println(mRemoved);
7276 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007277 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007278 pw.print(prefix); pw.print("mOrientationChanging=");
7279 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007280 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7281 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007282 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007283 if (mHScale != 1 || mVScale != 1) {
7284 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7285 pw.print(" mVScale="); pw.println(mVScale);
7286 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007287 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007288 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7289 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7290 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007291 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7292 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7293 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7294 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007295 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007296
7297 String makeInputChannelName() {
7298 return Integer.toHexString(System.identityHashCode(this))
7299 + " " + mAttrs.getTitle();
7300 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007301
7302 @Override
7303 public String toString() {
7304 return "Window{"
7305 + Integer.toHexString(System.identityHashCode(this))
7306 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7307 }
7308 }
Romain Guy06882f82009-06-10 13:36:04 -07007309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007310 // -------------------------------------------------------------
7311 // Window Token State
7312 // -------------------------------------------------------------
7313
7314 class WindowToken {
7315 // The actual token.
7316 final IBinder token;
7317
7318 // The type of window this token is for, as per WindowManager.LayoutParams.
7319 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007321 // Set if this token was explicitly added by a client, so should
7322 // not be removed when all windows are removed.
7323 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007324
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007325 // For printing.
7326 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007328 // If this is an AppWindowToken, this is non-null.
7329 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007331 // All of the windows associated with this token.
7332 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7333
7334 // Is key dispatching paused for this token?
7335 boolean paused = false;
7336
7337 // Should this token's windows be hidden?
7338 boolean hidden;
7339
7340 // Temporary for finding which tokens no longer have visible windows.
7341 boolean hasVisible;
7342
Dianne Hackborna8f60182009-09-01 19:01:50 -07007343 // Set to true when this token is in a pending transaction where it
7344 // will be shown.
7345 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007346
Dianne Hackborna8f60182009-09-01 19:01:50 -07007347 // Set to true when this token is in a pending transaction where it
7348 // will be hidden.
7349 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007350
Dianne Hackborna8f60182009-09-01 19:01:50 -07007351 // Set to true when this token is in a pending transaction where its
7352 // windows will be put to the bottom of the list.
7353 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007354
Dianne Hackborna8f60182009-09-01 19:01:50 -07007355 // Set to true when this token is in a pending transaction where its
7356 // windows will be put to the top of the list.
7357 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007359 WindowToken(IBinder _token, int type, boolean _explicit) {
7360 token = _token;
7361 windowType = type;
7362 explicit = _explicit;
7363 }
7364
7365 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007366 pw.print(prefix); pw.print("token="); pw.println(token);
7367 pw.print(prefix); pw.print("windows="); pw.println(windows);
7368 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7369 pw.print(" hidden="); pw.print(hidden);
7370 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007371 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7372 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7373 pw.print(" waitingToHide="); pw.print(waitingToHide);
7374 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7375 pw.print(" sendingToTop="); pw.println(sendingToTop);
7376 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007377 }
7378
7379 @Override
7380 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007381 if (stringName == null) {
7382 StringBuilder sb = new StringBuilder();
7383 sb.append("WindowToken{");
7384 sb.append(Integer.toHexString(System.identityHashCode(this)));
7385 sb.append(" token="); sb.append(token); sb.append('}');
7386 stringName = sb.toString();
7387 }
7388 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007389 }
7390 };
7391
7392 class AppWindowToken extends WindowToken {
7393 // Non-null only for application tokens.
7394 final IApplicationToken appToken;
7395
7396 // All of the windows and child windows that are included in this
7397 // application token. Note this list is NOT sorted!
7398 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7399
7400 int groupId = -1;
7401 boolean appFullscreen;
7402 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007403
7404 // The input dispatching timeout for this application token in nanoseconds.
7405 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007407 // These are used for determining when all windows associated with
7408 // an activity have been drawn, so they can be made visible together
7409 // at the same time.
7410 int lastTransactionSequence = mTransactionSequence-1;
7411 int numInterestingWindows;
7412 int numDrawnWindows;
7413 boolean inPendingTransaction;
7414 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007415
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007416 // Is this token going to be hidden in a little while? If so, it
7417 // won't be taken into account for setting the screen orientation.
7418 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007420 // Is this window's surface needed? This is almost like hidden, except
7421 // it will sometimes be true a little earlier: when the token has
7422 // been shown, but is still waiting for its app transition to execute
7423 // before making its windows shown.
7424 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007426 // Have we told the window clients to hide themselves?
7427 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007429 // Last visibility state we reported to the app token.
7430 boolean reportedVisible;
7431
7432 // Set to true when the token has been removed from the window mgr.
7433 boolean removed;
7434
7435 // Have we been asked to have this token keep the screen frozen?
7436 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007438 boolean animating;
7439 Animation animation;
7440 boolean hasTransformation;
7441 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007443 // Offset to the window of all layers in the token, for use by
7444 // AppWindowToken animations.
7445 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007447 // Information about an application starting window if displayed.
7448 StartingData startingData;
7449 WindowState startingWindow;
7450 View startingView;
7451 boolean startingDisplayed;
7452 boolean startingMoved;
7453 boolean firstWindowDrawn;
7454
7455 AppWindowToken(IApplicationToken _token) {
7456 super(_token.asBinder(),
7457 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7458 appWindowToken = this;
7459 appToken = _token;
7460 }
Romain Guy06882f82009-06-10 13:36:04 -07007461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007462 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007463 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007464 TAG, "Setting animation in " + this + ": " + anim);
7465 animation = anim;
7466 animating = false;
7467 anim.restrictDuration(MAX_ANIMATION_DURATION);
7468 anim.scaleCurrentDuration(mTransitionAnimationScale);
7469 int zorder = anim.getZAdjustment();
7470 int adj = 0;
7471 if (zorder == Animation.ZORDER_TOP) {
7472 adj = TYPE_LAYER_OFFSET;
7473 } else if (zorder == Animation.ZORDER_BOTTOM) {
7474 adj = -TYPE_LAYER_OFFSET;
7475 }
Romain Guy06882f82009-06-10 13:36:04 -07007476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007477 if (animLayerAdjustment != adj) {
7478 animLayerAdjustment = adj;
7479 updateLayers();
7480 }
7481 }
Romain Guy06882f82009-06-10 13:36:04 -07007482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007483 public void setDummyAnimation() {
7484 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007485 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007486 TAG, "Setting dummy animation in " + this);
7487 animation = sDummyAnimation;
7488 }
7489 }
7490
7491 public void clearAnimation() {
7492 if (animation != null) {
7493 animation = null;
7494 animating = true;
7495 }
7496 }
Romain Guy06882f82009-06-10 13:36:04 -07007497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007498 void updateLayers() {
7499 final int N = allAppWindows.size();
7500 final int adj = animLayerAdjustment;
7501 for (int i=0; i<N; i++) {
7502 WindowState w = allAppWindows.get(i);
7503 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007504 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007505 + w.mAnimLayer);
7506 if (w == mInputMethodTarget) {
7507 setInputMethodAnimLayerAdjustment(adj);
7508 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007509 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007510 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007511 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007512 }
7513 }
Romain Guy06882f82009-06-10 13:36:04 -07007514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007515 void sendAppVisibilityToClients() {
7516 final int N = allAppWindows.size();
7517 for (int i=0; i<N; i++) {
7518 WindowState win = allAppWindows.get(i);
7519 if (win == startingWindow && clientHidden) {
7520 // Don't hide the starting window.
7521 continue;
7522 }
7523 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007524 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007525 "Setting visibility of " + win + ": " + (!clientHidden));
7526 win.mClient.dispatchAppVisibility(!clientHidden);
7527 } catch (RemoteException e) {
7528 }
7529 }
7530 }
Romain Guy06882f82009-06-10 13:36:04 -07007531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007532 void showAllWindowsLocked() {
7533 final int NW = allAppWindows.size();
7534 for (int i=0; i<NW; i++) {
7535 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007536 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007537 "performing show on: " + w);
7538 w.performShowLocked();
7539 }
7540 }
Romain Guy06882f82009-06-10 13:36:04 -07007541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007542 // This must be called while inside a transaction.
7543 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007544 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007545 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007547 if (animation == sDummyAnimation) {
7548 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007549 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007550 // when it is really time to animate, this will be set to
7551 // a real animation and the next call will execute normally.
7552 return false;
7553 }
Romain Guy06882f82009-06-10 13:36:04 -07007554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007555 if ((allDrawn || animating || startingDisplayed) && animation != null) {
7556 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007557 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007558 TAG, "Starting animation in " + this +
7559 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
7560 + " scale=" + mTransitionAnimationScale
7561 + " allDrawn=" + allDrawn + " animating=" + animating);
7562 animation.initialize(dw, dh, dw, dh);
7563 animation.setStartTime(currentTime);
7564 animating = true;
7565 }
7566 transformation.clear();
7567 final boolean more = animation.getTransformation(
7568 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007569 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007570 TAG, "Stepped animation in " + this +
7571 ": more=" + more + ", xform=" + transformation);
7572 if (more) {
7573 // we're done!
7574 hasTransformation = true;
7575 return true;
7576 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007577 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007578 TAG, "Finished animation in " + this +
7579 " @ " + currentTime);
7580 animation = null;
7581 }
7582 } else if (animation != null) {
7583 // If the display is frozen, and there is a pending animation,
7584 // clear it and make sure we run the cleanup code.
7585 animating = true;
7586 animation = null;
7587 }
7588
7589 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07007590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007591 if (!animating) {
7592 return false;
7593 }
7594
7595 clearAnimation();
7596 animating = false;
7597 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
7598 moveInputMethodWindowsIfNeededLocked(true);
7599 }
Romain Guy06882f82009-06-10 13:36:04 -07007600
Joe Onorato8a9b2202010-02-26 18:56:32 -08007601 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007602 TAG, "Animation done in " + this
7603 + ": reportedVisible=" + reportedVisible);
7604
7605 transformation.clear();
7606 if (animLayerAdjustment != 0) {
7607 animLayerAdjustment = 0;
7608 updateLayers();
7609 }
Romain Guy06882f82009-06-10 13:36:04 -07007610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007611 final int N = windows.size();
7612 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007613 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007614 }
7615 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07007616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007617 return false;
7618 }
7619
7620 void updateReportedVisibilityLocked() {
7621 if (appToken == null) {
7622 return;
7623 }
Romain Guy06882f82009-06-10 13:36:04 -07007624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007625 int numInteresting = 0;
7626 int numVisible = 0;
7627 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07007628
Joe Onorato8a9b2202010-02-26 18:56:32 -08007629 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007630 final int N = allAppWindows.size();
7631 for (int i=0; i<N; i++) {
7632 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08007633 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07007634 || win.mViewVisibility != View.VISIBLE
7635 || win.mAttrs.type == TYPE_APPLICATION_STARTING) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007636 continue;
7637 }
7638 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007639 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007640 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007641 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007642 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007643 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007644 + " pv=" + win.mPolicyVisibility
7645 + " dp=" + win.mDrawPending
7646 + " cdp=" + win.mCommitDrawPending
7647 + " ah=" + win.mAttachedHidden
7648 + " th="
7649 + (win.mAppToken != null
7650 ? win.mAppToken.hiddenRequested : false)
7651 + " a=" + win.mAnimating);
7652 }
7653 }
7654 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007655 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007656 if (!win.isAnimating()) {
7657 numVisible++;
7658 }
7659 nowGone = false;
7660 } else if (win.isAnimating()) {
7661 nowGone = false;
7662 }
7663 }
Romain Guy06882f82009-06-10 13:36:04 -07007664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007665 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007666 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007667 + numInteresting + " visible=" + numVisible);
7668 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007669 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007670 TAG, "Visibility changed in " + this
7671 + ": vis=" + nowVisible);
7672 reportedVisible = nowVisible;
7673 Message m = mH.obtainMessage(
7674 H.REPORT_APPLICATION_TOKEN_WINDOWS,
7675 nowVisible ? 1 : 0,
7676 nowGone ? 1 : 0,
7677 this);
7678 mH.sendMessage(m);
7679 }
7680 }
Romain Guy06882f82009-06-10 13:36:04 -07007681
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007682 WindowState findMainWindow() {
7683 int j = windows.size();
7684 while (j > 0) {
7685 j--;
7686 WindowState win = windows.get(j);
7687 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
7688 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
7689 return win;
7690 }
7691 }
7692 return null;
7693 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007695 void dump(PrintWriter pw, String prefix) {
7696 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007697 if (appToken != null) {
7698 pw.print(prefix); pw.println("app=true");
7699 }
7700 if (allAppWindows.size() > 0) {
7701 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
7702 }
7703 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007704 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007705 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
7706 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
7707 pw.print(" clientHidden="); pw.print(clientHidden);
7708 pw.print(" willBeHidden="); pw.print(willBeHidden);
7709 pw.print(" reportedVisible="); pw.println(reportedVisible);
7710 if (paused || freezingScreen) {
7711 pw.print(prefix); pw.print("paused="); pw.print(paused);
7712 pw.print(" freezingScreen="); pw.println(freezingScreen);
7713 }
7714 if (numInterestingWindows != 0 || numDrawnWindows != 0
7715 || inPendingTransaction || allDrawn) {
7716 pw.print(prefix); pw.print("numInterestingWindows=");
7717 pw.print(numInterestingWindows);
7718 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
7719 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
7720 pw.print(" allDrawn="); pw.println(allDrawn);
7721 }
7722 if (animating || animation != null) {
7723 pw.print(prefix); pw.print("animating="); pw.print(animating);
7724 pw.print(" animation="); pw.println(animation);
7725 }
7726 if (animLayerAdjustment != 0) {
7727 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
7728 }
7729 if (hasTransformation) {
7730 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
7731 pw.print(" transformation="); transformation.printShortString(pw);
7732 pw.println();
7733 }
7734 if (startingData != null || removed || firstWindowDrawn) {
7735 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
7736 pw.print(" removed="); pw.print(removed);
7737 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
7738 }
7739 if (startingWindow != null || startingView != null
7740 || startingDisplayed || startingMoved) {
7741 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
7742 pw.print(" startingView="); pw.print(startingView);
7743 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
7744 pw.print(" startingMoved"); pw.println(startingMoved);
7745 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007746 }
7747
7748 @Override
7749 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007750 if (stringName == null) {
7751 StringBuilder sb = new StringBuilder();
7752 sb.append("AppWindowToken{");
7753 sb.append(Integer.toHexString(System.identityHashCode(this)));
7754 sb.append(" token="); sb.append(token); sb.append('}');
7755 stringName = sb.toString();
7756 }
7757 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007758 }
7759 }
Romain Guy06882f82009-06-10 13:36:04 -07007760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007761 // -------------------------------------------------------------
7762 // DummyAnimation
7763 // -------------------------------------------------------------
7764
7765 // This is an animation that does nothing: it just immediately finishes
7766 // itself every time it is called. It is used as a stub animation in cases
7767 // where we want to synchronize multiple things that may be animating.
7768 static final class DummyAnimation extends Animation {
7769 public boolean getTransformation(long currentTime, Transformation outTransformation) {
7770 return false;
7771 }
7772 }
7773 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07007774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007775 // -------------------------------------------------------------
7776 // Async Handler
7777 // -------------------------------------------------------------
7778
7779 static final class StartingData {
7780 final String pkg;
7781 final int theme;
7782 final CharSequence nonLocalizedLabel;
7783 final int labelRes;
7784 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07007785
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007786 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
7787 int _labelRes, int _icon) {
7788 pkg = _pkg;
7789 theme = _theme;
7790 nonLocalizedLabel = _nonLocalizedLabel;
7791 labelRes = _labelRes;
7792 icon = _icon;
7793 }
7794 }
7795
7796 private final class H extends Handler {
7797 public static final int REPORT_FOCUS_CHANGE = 2;
7798 public static final int REPORT_LOSING_FOCUS = 3;
7799 public static final int ANIMATE = 4;
7800 public static final int ADD_STARTING = 5;
7801 public static final int REMOVE_STARTING = 6;
7802 public static final int FINISHED_STARTING = 7;
7803 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007804 public static final int WINDOW_FREEZE_TIMEOUT = 11;
7805 public static final int HOLD_SCREEN_CHANGED = 12;
7806 public static final int APP_TRANSITION_TIMEOUT = 13;
7807 public static final int PERSIST_ANIMATION_SCALE = 14;
7808 public static final int FORCE_GC = 15;
7809 public static final int ENABLE_SCREEN = 16;
7810 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007811 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07007812 public static final int REPORT_WINDOWS_CHANGE = 19;
Romain Guy06882f82009-06-10 13:36:04 -07007813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007814 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07007815
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007816 public H() {
7817 }
Romain Guy06882f82009-06-10 13:36:04 -07007818
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007819 @Override
7820 public void handleMessage(Message msg) {
7821 switch (msg.what) {
7822 case REPORT_FOCUS_CHANGE: {
7823 WindowState lastFocus;
7824 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07007825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007826 synchronized(mWindowMap) {
7827 lastFocus = mLastFocus;
7828 newFocus = mCurrentFocus;
7829 if (lastFocus == newFocus) {
7830 // Focus is not changing, so nothing to do.
7831 return;
7832 }
7833 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007834 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007835 // + " to " + newFocus);
7836 if (newFocus != null && lastFocus != null
7837 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007838 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007839 mLosingFocus.add(lastFocus);
7840 lastFocus = null;
7841 }
7842 }
7843
7844 if (lastFocus != newFocus) {
7845 //System.out.println("Changing focus from " + lastFocus
7846 // + " to " + newFocus);
7847 if (newFocus != null) {
7848 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007849 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007850 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
7851 } catch (RemoteException e) {
7852 // Ignore if process has died.
7853 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07007854 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007855 }
7856
7857 if (lastFocus != null) {
7858 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007859 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007860 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
7861 } catch (RemoteException e) {
7862 // Ignore if process has died.
7863 }
7864 }
7865 }
7866 } break;
7867
7868 case REPORT_LOSING_FOCUS: {
7869 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07007870
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007871 synchronized(mWindowMap) {
7872 losers = mLosingFocus;
7873 mLosingFocus = new ArrayList<WindowState>();
7874 }
7875
7876 final int N = losers.size();
7877 for (int i=0; i<N; i++) {
7878 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007879 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007880 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
7881 } catch (RemoteException e) {
7882 // Ignore if process has died.
7883 }
7884 }
7885 } break;
7886
7887 case ANIMATE: {
7888 synchronized(mWindowMap) {
7889 mAnimationPending = false;
7890 performLayoutAndPlaceSurfacesLocked();
7891 }
7892 } break;
7893
7894 case ADD_STARTING: {
7895 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7896 final StartingData sd = wtoken.startingData;
7897
7898 if (sd == null) {
7899 // Animation has been canceled... do nothing.
7900 return;
7901 }
Romain Guy06882f82009-06-10 13:36:04 -07007902
Joe Onorato8a9b2202010-02-26 18:56:32 -08007903 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007904 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07007905
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007906 View view = null;
7907 try {
7908 view = mPolicy.addStartingWindow(
7909 wtoken.token, sd.pkg,
7910 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
7911 sd.icon);
7912 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007913 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007914 }
7915
7916 if (view != null) {
7917 boolean abort = false;
7918
7919 synchronized(mWindowMap) {
7920 if (wtoken.removed || wtoken.startingData == null) {
7921 // If the window was successfully added, then
7922 // we need to remove it.
7923 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007924 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007925 "Aborted starting " + wtoken
7926 + ": removed=" + wtoken.removed
7927 + " startingData=" + wtoken.startingData);
7928 wtoken.startingWindow = null;
7929 wtoken.startingData = null;
7930 abort = true;
7931 }
7932 } else {
7933 wtoken.startingView = view;
7934 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007935 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007936 "Added starting " + wtoken
7937 + ": startingWindow="
7938 + wtoken.startingWindow + " startingView="
7939 + wtoken.startingView);
7940 }
7941
7942 if (abort) {
7943 try {
7944 mPolicy.removeStartingWindow(wtoken.token, view);
7945 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007946 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007947 }
7948 }
7949 }
7950 } break;
7951
7952 case REMOVE_STARTING: {
7953 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7954 IBinder token = null;
7955 View view = null;
7956 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007957 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007958 + wtoken + ": startingWindow="
7959 + wtoken.startingWindow + " startingView="
7960 + wtoken.startingView);
7961 if (wtoken.startingWindow != null) {
7962 view = wtoken.startingView;
7963 token = wtoken.token;
7964 wtoken.startingData = null;
7965 wtoken.startingView = null;
7966 wtoken.startingWindow = null;
7967 }
7968 }
7969 if (view != null) {
7970 try {
7971 mPolicy.removeStartingWindow(token, view);
7972 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007973 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007974 }
7975 }
7976 } break;
7977
7978 case FINISHED_STARTING: {
7979 IBinder token = null;
7980 View view = null;
7981 while (true) {
7982 synchronized (mWindowMap) {
7983 final int N = mFinishedStarting.size();
7984 if (N <= 0) {
7985 break;
7986 }
7987 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
7988
Joe Onorato8a9b2202010-02-26 18:56:32 -08007989 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007990 "Finished starting " + wtoken
7991 + ": startingWindow=" + wtoken.startingWindow
7992 + " startingView=" + wtoken.startingView);
7993
7994 if (wtoken.startingWindow == null) {
7995 continue;
7996 }
7997
7998 view = wtoken.startingView;
7999 token = wtoken.token;
8000 wtoken.startingData = null;
8001 wtoken.startingView = null;
8002 wtoken.startingWindow = null;
8003 }
8004
8005 try {
8006 mPolicy.removeStartingWindow(token, view);
8007 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008008 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008009 }
8010 }
8011 } break;
8012
8013 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8014 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8015
8016 boolean nowVisible = msg.arg1 != 0;
8017 boolean nowGone = msg.arg2 != 0;
8018
8019 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008020 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008021 TAG, "Reporting visible in " + wtoken
8022 + " visible=" + nowVisible
8023 + " gone=" + nowGone);
8024 if (nowVisible) {
8025 wtoken.appToken.windowsVisible();
8026 } else {
8027 wtoken.appToken.windowsGone();
8028 }
8029 } catch (RemoteException ex) {
8030 }
8031 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008033 case WINDOW_FREEZE_TIMEOUT: {
8034 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008035 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008036 int i = mWindows.size();
8037 while (i > 0) {
8038 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008039 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008040 if (w.mOrientationChanging) {
8041 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008042 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008043 }
8044 }
8045 performLayoutAndPlaceSurfacesLocked();
8046 }
8047 break;
8048 }
Romain Guy06882f82009-06-10 13:36:04 -07008049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008050 case HOLD_SCREEN_CHANGED: {
8051 Session oldHold;
8052 Session newHold;
8053 synchronized (mWindowMap) {
8054 oldHold = mLastReportedHold;
8055 newHold = (Session)msg.obj;
8056 mLastReportedHold = newHold;
8057 }
Romain Guy06882f82009-06-10 13:36:04 -07008058
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008059 if (oldHold != newHold) {
8060 try {
8061 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008062 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008063 "window",
8064 BatteryStats.WAKE_TYPE_WINDOW);
8065 }
8066 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008067 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008068 "window",
8069 BatteryStats.WAKE_TYPE_WINDOW);
8070 }
8071 } catch (RemoteException e) {
8072 }
8073 }
8074 break;
8075 }
Romain Guy06882f82009-06-10 13:36:04 -07008076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008077 case APP_TRANSITION_TIMEOUT: {
8078 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008079 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008080 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008081 "*** APP TRANSITION TIMEOUT");
8082 mAppTransitionReady = true;
8083 mAppTransitionTimeout = true;
8084 performLayoutAndPlaceSurfacesLocked();
8085 }
8086 }
8087 break;
8088 }
Romain Guy06882f82009-06-10 13:36:04 -07008089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008090 case PERSIST_ANIMATION_SCALE: {
8091 Settings.System.putFloat(mContext.getContentResolver(),
8092 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8093 Settings.System.putFloat(mContext.getContentResolver(),
8094 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8095 break;
8096 }
Romain Guy06882f82009-06-10 13:36:04 -07008097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008098 case FORCE_GC: {
8099 synchronized(mWindowMap) {
8100 if (mAnimationPending) {
8101 // If we are animating, don't do the gc now but
8102 // delay a bit so we don't interrupt the animation.
8103 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8104 2000);
8105 return;
8106 }
8107 // If we are currently rotating the display, it will
8108 // schedule a new message when done.
8109 if (mDisplayFrozen) {
8110 return;
8111 }
8112 mFreezeGcPending = 0;
8113 }
8114 Runtime.getRuntime().gc();
8115 break;
8116 }
Romain Guy06882f82009-06-10 13:36:04 -07008117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008118 case ENABLE_SCREEN: {
8119 performEnableScreen();
8120 break;
8121 }
Romain Guy06882f82009-06-10 13:36:04 -07008122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008123 case APP_FREEZE_TIMEOUT: {
8124 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008125 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008126 int i = mAppTokens.size();
8127 while (i > 0) {
8128 i--;
8129 AppWindowToken tok = mAppTokens.get(i);
8130 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008131 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008132 unsetAppFreezingScreenLocked(tok, true, true);
8133 }
8134 }
8135 }
8136 break;
8137 }
Romain Guy06882f82009-06-10 13:36:04 -07008138
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008139 case SEND_NEW_CONFIGURATION: {
8140 removeMessages(SEND_NEW_CONFIGURATION);
8141 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008142 break;
8143 }
Romain Guy06882f82009-06-10 13:36:04 -07008144
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008145 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008146 if (mWindowsChanged) {
8147 synchronized (mWindowMap) {
8148 mWindowsChanged = false;
8149 }
8150 notifyWindowsChanged();
8151 }
8152 break;
8153 }
8154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008155 }
8156 }
8157 }
8158
8159 // -------------------------------------------------------------
8160 // IWindowManager API
8161 // -------------------------------------------------------------
8162
8163 public IWindowSession openSession(IInputMethodClient client,
8164 IInputContext inputContext) {
8165 if (client == null) throw new IllegalArgumentException("null client");
8166 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008167 Session session = new Session(client, inputContext);
8168 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008169 }
8170
8171 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8172 synchronized (mWindowMap) {
8173 // The focus for the client is the window immediately below
8174 // where we would place the input method window.
8175 int idx = findDesiredInputMethodWindowIndexLocked(false);
8176 WindowState imFocus;
8177 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008178 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008179 if (imFocus != null) {
8180 if (imFocus.mSession.mClient != null &&
8181 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8182 return true;
8183 }
8184 }
8185 }
8186 }
8187 return false;
8188 }
Romain Guy06882f82009-06-10 13:36:04 -07008189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008190 // -------------------------------------------------------------
8191 // Internals
8192 // -------------------------------------------------------------
8193
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008194 final WindowState windowForClientLocked(Session session, IWindow client,
8195 boolean throwOnError) {
8196 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008197 }
Romain Guy06882f82009-06-10 13:36:04 -07008198
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008199 final WindowState windowForClientLocked(Session session, IBinder client,
8200 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008201 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008202 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008203 TAG, "Looking up client " + client + ": " + win);
8204 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008205 RuntimeException ex = new IllegalArgumentException(
8206 "Requested window " + client + " does not exist");
8207 if (throwOnError) {
8208 throw ex;
8209 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008210 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008211 return null;
8212 }
8213 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008214 RuntimeException ex = new IllegalArgumentException(
8215 "Requested window " + client + " is in session " +
8216 win.mSession + ", not " + session);
8217 if (throwOnError) {
8218 throw ex;
8219 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008220 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008221 return null;
8222 }
8223
8224 return win;
8225 }
8226
Dianne Hackborna8f60182009-09-01 19:01:50 -07008227 final void rebuildAppWindowListLocked() {
8228 int NW = mWindows.size();
8229 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008230 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008231 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008232
Dianne Hackborna8f60182009-09-01 19:01:50 -07008233 // First remove all existing app windows.
8234 i=0;
8235 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008236 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008237 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008238 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008239 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008240 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008241 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008242 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008243 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008244 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008245 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8246 && lastWallpaper == i-1) {
8247 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008248 }
8249 i++;
8250 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008251
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008252 // The wallpaper window(s) typically live at the bottom of the stack,
8253 // so skip them before adding app tokens.
8254 lastWallpaper++;
8255 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008256
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008257 // First add all of the exiting app tokens... these are no longer
8258 // in the main app list, but still have windows shown. We put them
8259 // in the back because now that the animation is over we no longer
8260 // will care about them.
8261 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008262 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008263 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8264 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008265
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008266 // And add in the still active app tokens in Z order.
8267 NT = mAppTokens.size();
8268 for (int j=0; j<NT; j++) {
8269 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008270 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008271
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008272 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008273 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008274 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008275 + " windows but added " + i);
8276 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008277 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008279 private final void assignLayersLocked() {
8280 int N = mWindows.size();
8281 int curBaseLayer = 0;
8282 int curLayer = 0;
8283 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008285 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008286 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008287 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8288 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008289 curLayer += WINDOW_LAYER_MULTIPLIER;
8290 w.mLayer = curLayer;
8291 } else {
8292 curBaseLayer = curLayer = w.mBaseLayer;
8293 w.mLayer = curLayer;
8294 }
8295 if (w.mTargetAppToken != null) {
8296 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8297 } else if (w.mAppToken != null) {
8298 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8299 } else {
8300 w.mAnimLayer = w.mLayer;
8301 }
8302 if (w.mIsImWindow) {
8303 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008304 } else if (w.mIsWallpaper) {
8305 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008306 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008307 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008308 + w.mAnimLayer);
8309 //System.out.println(
8310 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8311 }
8312 }
8313
8314 private boolean mInLayout = false;
8315 private final void performLayoutAndPlaceSurfacesLocked() {
8316 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008317 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008318 throw new RuntimeException("Recursive call!");
8319 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008320 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008321 return;
8322 }
8323
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008324 if (mWaitingForConfig) {
8325 // Our configuration has changed (most likely rotation), but we
8326 // don't yet have the complete configuration to report to
8327 // applications. Don't do any window layout until we have it.
8328 return;
8329 }
8330
Dianne Hackbornce2ef762010-09-20 11:39:14 -07008331 if (mDisplay == null) {
8332 // Not yet initialized, nothing to do.
8333 return;
8334 }
8335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008336 boolean recoveringMemory = false;
8337 if (mForceRemoves != null) {
8338 recoveringMemory = true;
8339 // Wait a little it for things to settle down, and off we go.
8340 for (int i=0; i<mForceRemoves.size(); i++) {
8341 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008342 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008343 removeWindowInnerLocked(ws.mSession, ws);
8344 }
8345 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008346 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008347 Object tmp = new Object();
8348 synchronized (tmp) {
8349 try {
8350 tmp.wait(250);
8351 } catch (InterruptedException e) {
8352 }
8353 }
8354 }
Romain Guy06882f82009-06-10 13:36:04 -07008355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008356 mInLayout = true;
8357 try {
8358 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008360 int i = mPendingRemove.size()-1;
8361 if (i >= 0) {
8362 while (i >= 0) {
8363 WindowState w = mPendingRemove.get(i);
8364 removeWindowInnerLocked(w.mSession, w);
8365 i--;
8366 }
8367 mPendingRemove.clear();
8368
8369 mInLayout = false;
8370 assignLayersLocked();
8371 mLayoutNeeded = true;
8372 performLayoutAndPlaceSurfacesLocked();
8373
8374 } else {
8375 mInLayout = false;
8376 if (mLayoutNeeded) {
8377 requestAnimationLocked(0);
8378 }
8379 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008380 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008381 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8382 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008383 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008384 } catch (RuntimeException e) {
8385 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008386 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008387 }
8388 }
8389
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008390 private final int performLayoutLockedInner() {
8391 if (!mLayoutNeeded) {
8392 return 0;
8393 }
8394
8395 mLayoutNeeded = false;
8396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008397 final int dw = mDisplay.getWidth();
8398 final int dh = mDisplay.getHeight();
8399
8400 final int N = mWindows.size();
8401 int i;
8402
Joe Onorato8a9b2202010-02-26 18:56:32 -08008403 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008404 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8405
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008406 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008407
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008408 int seq = mLayoutSeq+1;
8409 if (seq < 0) seq = 0;
8410 mLayoutSeq = seq;
8411
8412 // First perform layout of any root windows (not attached
8413 // to another window).
8414 int topAttached = -1;
8415 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008416 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008417
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008418 // Don't do layout of a window if it is not visible, or
8419 // soon won't be visible, to avoid wasting time and funky
8420 // changes while a window is animating away.
8421 final AppWindowToken atoken = win.mAppToken;
8422 final boolean gone = win.mViewVisibility == View.GONE
8423 || !win.mRelayoutCalled
8424 || win.mRootToken.hidden
8425 || (atoken != null && atoken.hiddenRequested)
8426 || win.mAttachedHidden
8427 || win.mExiting || win.mDestroying;
8428
8429 if (!win.mLayoutAttached) {
8430 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
8431 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
8432 + " mLayoutAttached=" + win.mLayoutAttached);
8433 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
8434 + win.mViewVisibility + " mRelayoutCalled="
8435 + win.mRelayoutCalled + " hidden="
8436 + win.mRootToken.hidden + " hiddenRequested="
8437 + (atoken != null && atoken.hiddenRequested)
8438 + " mAttachedHidden=" + win.mAttachedHidden);
8439 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008440
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008441 // If this view is GONE, then skip it -- keep the current
8442 // frame, and let the caller know so they can ignore it
8443 // if they want. (We do the normal layout for INVISIBLE
8444 // windows, since that means "perform layout as normal,
8445 // just don't display").
8446 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008447 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008448 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8449 win.mLayoutSeq = seq;
8450 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8451 + win.mFrame + " mContainingFrame="
8452 + win.mContainingFrame + " mDisplayFrame="
8453 + win.mDisplayFrame);
8454 } else {
8455 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008456 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008457 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008458 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008459
8460 // Now perform layout of attached windows, which usually
8461 // depend on the position of the window they are attached to.
8462 // XXX does not deal with windows that are attached to windows
8463 // that are themselves attached.
8464 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008465 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008466
8467 // If this view is GONE, then skip it -- keep the current
8468 // frame, and let the caller know so they can ignore it
8469 // if they want. (We do the normal layout for INVISIBLE
8470 // windows, since that means "perform layout as normal,
8471 // just don't display").
8472 if (win.mLayoutAttached) {
8473 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
8474 + " mHaveFrame=" + win.mHaveFrame
8475 + " mViewVisibility=" + win.mViewVisibility
8476 + " mRelayoutCalled=" + win.mRelayoutCalled);
8477 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
8478 || !win.mHaveFrame) {
8479 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
8480 win.mLayoutSeq = seq;
8481 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8482 + win.mFrame + " mContainingFrame="
8483 + win.mContainingFrame + " mDisplayFrame="
8484 + win.mDisplayFrame);
8485 }
8486 }
8487 }
Jeff Brown349703e2010-06-22 01:27:15 -07008488
8489 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008490 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008491
8492 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008493 }
Romain Guy06882f82009-06-10 13:36:04 -07008494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008495 private final void performLayoutAndPlaceSurfacesLockedInner(
8496 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04008497 if (mDisplay == null) {
8498 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
8499 return;
8500 }
8501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008502 final long currentTime = SystemClock.uptimeMillis();
8503 final int dw = mDisplay.getWidth();
8504 final int dh = mDisplay.getHeight();
8505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008506 int i;
8507
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008508 if (mFocusMayChange) {
8509 mFocusMayChange = false;
8510 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
8511 }
8512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008513 // Initialize state of exiting tokens.
8514 for (i=mExitingTokens.size()-1; i>=0; i--) {
8515 mExitingTokens.get(i).hasVisible = false;
8516 }
8517
8518 // Initialize state of exiting applications.
8519 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
8520 mExitingAppTokens.get(i).hasVisible = false;
8521 }
8522
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008523 boolean orientationChangeComplete = true;
8524 Session holdScreen = null;
8525 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05008526 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008527 boolean focusDisplayed = false;
8528 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008529 boolean createWatermark = false;
8530
8531 if (mFxSession == null) {
8532 mFxSession = new SurfaceSession();
8533 createWatermark = true;
8534 }
8535
8536 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008537
8538 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008539
8540 if (createWatermark) {
8541 createWatermark();
8542 }
8543 if (mWatermark != null) {
8544 mWatermark.positionSurface(dw, dh);
8545 }
8546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008547 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008548 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008549 int repeats = 0;
8550 int changes = 0;
8551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008552 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008553 repeats++;
8554 if (repeats > 6) {
8555 Slog.w(TAG, "Animation repeat aborted after too many iterations");
8556 mLayoutNeeded = false;
8557 break;
8558 }
8559
8560 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
8561 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
8562 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
8563 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
8564 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
8565 assignLayersLocked();
8566 mLayoutNeeded = true;
8567 }
8568 }
8569 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
8570 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
8571 if (updateOrientationFromAppTokensLocked()) {
8572 mLayoutNeeded = true;
8573 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
8574 }
8575 }
8576 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
8577 mLayoutNeeded = true;
8578 }
8579 }
8580
8581 // FIRST LOOP: Perform a layout, if needed.
8582 if (repeats < 4) {
8583 changes = performLayoutLockedInner();
8584 if (changes != 0) {
8585 continue;
8586 }
8587 } else {
8588 Slog.w(TAG, "Layout repeat skipped after too many iterations");
8589 changes = 0;
8590 }
8591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008592 final int transactionSequence = ++mTransactionSequence;
8593
8594 // Update animations of all applications, including those
8595 // associated with exiting/removed apps
8596 boolean tokensAnimating = false;
8597 final int NAT = mAppTokens.size();
8598 for (i=0; i<NAT; i++) {
8599 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8600 tokensAnimating = true;
8601 }
8602 }
8603 final int NEAT = mExitingAppTokens.size();
8604 for (i=0; i<NEAT; i++) {
8605 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8606 tokensAnimating = true;
8607 }
8608 }
8609
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008610 // SECOND LOOP: Execute animations and update visibility of windows.
8611
Joe Onorato8a9b2202010-02-26 18:56:32 -08008612 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008613 + transactionSequence + " tokensAnimating="
8614 + tokensAnimating);
8615
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008616 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008617
8618 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008619 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008620 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008621
8622 mPolicy.beginAnimationLw(dw, dh);
8623
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008624 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008626 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008627 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008628
8629 final WindowManager.LayoutParams attrs = w.mAttrs;
8630
8631 if (w.mSurface != null) {
8632 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008633 if (w.commitFinishDrawingLocked(currentTime)) {
8634 if ((w.mAttrs.flags
8635 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008636 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008637 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008638 wallpaperMayChange = true;
8639 }
8640 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008641
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008642 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008643 if (w.stepAnimationLocked(currentTime, dw, dh)) {
8644 animating = true;
8645 //w.dump(" ");
8646 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008647 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
8648 wallpaperMayChange = true;
8649 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008650
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008651 if (mPolicy.doesForceHide(w, attrs)) {
8652 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008653 if (DEBUG_VISIBILITY) Slog.v(TAG,
8654 "Animation done that could impact force hide: "
8655 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008656 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008657 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008658 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
8659 forceHiding = true;
8660 }
8661 } else if (mPolicy.canBeForceHidden(w, attrs)) {
8662 boolean changed;
8663 if (forceHiding) {
8664 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008665 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8666 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008667 } else {
8668 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008669 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8670 "Now policy shown: " + w);
8671 if (changed) {
8672 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008673 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008674 // Assume we will need to animate. If
8675 // we don't (because the wallpaper will
8676 // stay with the lock screen), then we will
8677 // clean up later.
8678 Animation a = mPolicy.createForceHideEnterAnimation();
8679 if (a != null) {
8680 w.setAnimation(a);
8681 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008682 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008683 if (mCurrentFocus == null ||
8684 mCurrentFocus.mLayer < w.mLayer) {
8685 // We are showing on to of the current
8686 // focus, so re-evaluate focus to make
8687 // sure it is correct.
8688 mFocusMayChange = true;
8689 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008690 }
8691 }
8692 if (changed && (attrs.flags
8693 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
8694 wallpaperMayChange = true;
8695 }
8696 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008698 mPolicy.animatingWindowLw(w, attrs);
8699 }
8700
8701 final AppWindowToken atoken = w.mAppToken;
8702 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
8703 if (atoken.lastTransactionSequence != transactionSequence) {
8704 atoken.lastTransactionSequence = transactionSequence;
8705 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
8706 atoken.startingDisplayed = false;
8707 }
8708 if ((w.isOnScreen() || w.mAttrs.type
8709 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
8710 && !w.mExiting && !w.mDestroying) {
8711 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008712 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008713 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008714 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008715 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008716 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008717 + " pv=" + w.mPolicyVisibility
8718 + " dp=" + w.mDrawPending
8719 + " cdp=" + w.mCommitDrawPending
8720 + " ah=" + w.mAttachedHidden
8721 + " th=" + atoken.hiddenRequested
8722 + " a=" + w.mAnimating);
8723 }
8724 }
8725 if (w != atoken.startingWindow) {
8726 if (!atoken.freezingScreen || !w.mAppFreezing) {
8727 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008728 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008729 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008730 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008731 "tokenMayBeDrawn: " + atoken
8732 + " freezingScreen=" + atoken.freezingScreen
8733 + " mAppFreezing=" + w.mAppFreezing);
8734 tokenMayBeDrawn = true;
8735 }
8736 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008737 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008738 atoken.startingDisplayed = true;
8739 }
8740 }
8741 } else if (w.mReadyToShow) {
8742 w.performShowLocked();
8743 }
8744 }
8745
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008746 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008747
8748 if (tokenMayBeDrawn) {
8749 // See if any windows have been drawn, so they (and others
8750 // associated with them) can now be shown.
8751 final int NT = mTokenList.size();
8752 for (i=0; i<NT; i++) {
8753 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
8754 if (wtoken == null) {
8755 continue;
8756 }
8757 if (wtoken.freezingScreen) {
8758 int numInteresting = wtoken.numInterestingWindows;
8759 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008760 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008761 "allDrawn: " + wtoken
8762 + " interesting=" + numInteresting
8763 + " drawn=" + wtoken.numDrawnWindows);
8764 wtoken.showAllWindowsLocked();
8765 unsetAppFreezingScreenLocked(wtoken, false, true);
8766 orientationChangeComplete = true;
8767 }
8768 } else if (!wtoken.allDrawn) {
8769 int numInteresting = wtoken.numInterestingWindows;
8770 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008771 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008772 "allDrawn: " + wtoken
8773 + " interesting=" + numInteresting
8774 + " drawn=" + wtoken.numDrawnWindows);
8775 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008776 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008777
8778 // We can now show all of the drawn windows!
8779 if (!mOpeningApps.contains(wtoken)) {
8780 wtoken.showAllWindowsLocked();
8781 }
8782 }
8783 }
8784 }
8785 }
8786
8787 // If we are ready to perform an app transition, check through
8788 // all of the app tokens to be shown and see if they are ready
8789 // to go.
8790 if (mAppTransitionReady) {
8791 int NN = mOpeningApps.size();
8792 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008793 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008794 "Checking " + NN + " opening apps (frozen="
8795 + mDisplayFrozen + " timeout="
8796 + mAppTransitionTimeout + ")...");
8797 if (!mDisplayFrozen && !mAppTransitionTimeout) {
8798 // If the display isn't frozen, wait to do anything until
8799 // all of the apps are ready. Otherwise just go because
8800 // we'll unfreeze the display when everyone is ready.
8801 for (i=0; i<NN && goodToGo; i++) {
8802 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008803 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008804 "Check opening app" + wtoken + ": allDrawn="
8805 + wtoken.allDrawn + " startingDisplayed="
8806 + wtoken.startingDisplayed);
8807 if (!wtoken.allDrawn && !wtoken.startingDisplayed
8808 && !wtoken.startingMoved) {
8809 goodToGo = false;
8810 }
8811 }
8812 }
8813 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008814 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008815 int transit = mNextAppTransition;
8816 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008817 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008818 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008819 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008820 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008821 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008822 mAppTransitionTimeout = false;
8823 mStartingIconInTransition = false;
8824 mSkipAppTransitionAnimation = false;
8825
8826 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
8827
Dianne Hackborna8f60182009-09-01 19:01:50 -07008828 // If there are applications waiting to come to the
8829 // top of the stack, now is the time to move their windows.
8830 // (Note that we don't do apps going to the bottom
8831 // here -- we want to keep their windows in the old
8832 // Z-order until the animation completes.)
8833 if (mToTopApps.size() > 0) {
8834 NN = mAppTokens.size();
8835 for (i=0; i<NN; i++) {
8836 AppWindowToken wtoken = mAppTokens.get(i);
8837 if (wtoken.sendingToTop) {
8838 wtoken.sendingToTop = false;
8839 moveAppWindowsLocked(wtoken, NN, false);
8840 }
8841 }
8842 mToTopApps.clear();
8843 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008844
Dianne Hackborn25994b42009-09-04 14:21:19 -07008845 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008846
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008847 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008848 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008849
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008850 // The top-most window will supply the layout params,
8851 // and we will determine it below.
8852 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008853 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008854 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008855
Joe Onorato8a9b2202010-02-26 18:56:32 -08008856 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008857 "New wallpaper target=" + mWallpaperTarget
8858 + ", lower target=" + mLowerWallpaperTarget
8859 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07008860 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008861 // Do a first pass through the tokens for two
8862 // things:
8863 // (1) Determine if both the closing and opening
8864 // app token sets are wallpaper targets, in which
8865 // case special animations are needed
8866 // (since the wallpaper needs to stay static
8867 // behind them).
8868 // (2) Find the layout params of the top-most
8869 // application window in the tokens, which is
8870 // what will control the animation theme.
8871 final int NC = mClosingApps.size();
8872 NN = NC + mOpeningApps.size();
8873 for (i=0; i<NN; i++) {
8874 AppWindowToken wtoken;
8875 int mode;
8876 if (i < NC) {
8877 wtoken = mClosingApps.get(i);
8878 mode = 1;
8879 } else {
8880 wtoken = mOpeningApps.get(i-NC);
8881 mode = 2;
8882 }
8883 if (mLowerWallpaperTarget != null) {
8884 if (mLowerWallpaperTarget.mAppToken == wtoken
8885 || mUpperWallpaperTarget.mAppToken == wtoken) {
8886 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008887 }
8888 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008889 if (wtoken.appFullscreen) {
8890 WindowState ws = wtoken.findMainWindow();
8891 if (ws != null) {
8892 // If this is a compatibility mode
8893 // window, we will always use its anim.
8894 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
8895 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008896 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008897 bestAnimLayer = Integer.MAX_VALUE;
8898 } else if (ws.mLayer > bestAnimLayer) {
8899 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008900 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008901 bestAnimLayer = ws.mLayer;
8902 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07008903 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008904 }
8905 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008906
Dianne Hackborn25994b42009-09-04 14:21:19 -07008907 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008908 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008909 "Wallpaper animation!");
8910 switch (transit) {
8911 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
8912 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
8913 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
8914 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
8915 break;
8916 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
8917 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
8918 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
8919 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
8920 break;
8921 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008922 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008923 "New transit: " + transit);
8924 } else if (oldWallpaper != null) {
8925 // We are transitioning from an activity with
8926 // a wallpaper to one without.
8927 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008928 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008929 "New transit away from wallpaper: " + transit);
8930 } else if (mWallpaperTarget != null) {
8931 // We are transitioning from an activity without
8932 // a wallpaper to now showing the wallpaper
8933 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008934 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008935 "New transit into wallpaper: " + transit);
8936 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008937
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008938 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
8939 mLastEnterAnimToken = animToken;
8940 mLastEnterAnimParams = animLp;
8941 } else if (mLastEnterAnimParams != null) {
8942 animLp = mLastEnterAnimParams;
8943 mLastEnterAnimToken = null;
8944 mLastEnterAnimParams = null;
8945 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008946
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008947 // If all closing windows are obscured, then there is
8948 // no need to do an animation. This is the case, for
8949 // example, when this transition is being done behind
8950 // the lock screen.
8951 if (!mPolicy.allowAppAnimationsLw()) {
8952 animLp = null;
8953 }
8954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008955 NN = mOpeningApps.size();
8956 for (i=0; i<NN; i++) {
8957 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008958 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008959 "Now opening app" + wtoken);
8960 wtoken.reportedVisible = false;
8961 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008962 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008963 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008964 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008965 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008966 wtoken.showAllWindowsLocked();
8967 }
8968 NN = mClosingApps.size();
8969 for (i=0; i<NN; i++) {
8970 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008971 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008972 "Now closing app" + wtoken);
8973 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008974 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008975 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008976 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008977 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008978 // Force the allDrawn flag, because we want to start
8979 // this guy's animations regardless of whether it's
8980 // gotten drawn.
8981 wtoken.allDrawn = true;
8982 }
8983
Dianne Hackborn8b571a82009-09-25 16:09:43 -07008984 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008986 mOpeningApps.clear();
8987 mClosingApps.clear();
8988
8989 // This has changed the visibility of windows, so perform
8990 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008991 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008992 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07008993 if (!moveInputMethodWindowsIfNeededLocked(true)) {
8994 assignLayersLocked();
8995 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008996 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008997 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008998 }
8999 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009000
Dianne Hackborn16064f92010-03-25 00:47:24 -07009001 int adjResult = 0;
9002
Dianne Hackborna8f60182009-09-01 19:01:50 -07009003 if (!animating && mAppTransitionRunning) {
9004 // We have finished the animation of an app transition. To do
9005 // this, we have delayed a lot of operations like showing and
9006 // hiding apps, moving apps in Z-order, etc. The app token list
9007 // reflects the correct Z-order, but the window list may now
9008 // be out of sync with it. So here we will just rebuild the
9009 // entire app window list. Fun!
9010 mAppTransitionRunning = false;
9011 // Clear information about apps that were moving.
9012 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009013
Dianne Hackborna8f60182009-09-01 19:01:50 -07009014 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009015 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009016 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009017 moveInputMethodWindowsIfNeededLocked(false);
9018 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009019 // Since the window list has been rebuilt, focus might
9020 // have to be recomputed since the actual order of windows
9021 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009022 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009023 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009024
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009025 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009026 // At this point, there was a window with a wallpaper that
9027 // was force hiding other windows behind it, but now it
9028 // is going away. This may be simple -- just animate
9029 // away the wallpaper and its window -- or it may be
9030 // hard -- the wallpaper now needs to be shown behind
9031 // something that was hidden.
9032 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009033 if (mLowerWallpaperTarget != null
9034 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009035 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009036 "wallpaperForceHiding changed with lower="
9037 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009038 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009039 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9040 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9041 if (mLowerWallpaperTarget.mAppToken.hidden) {
9042 // The lower target has become hidden before we
9043 // actually started the animation... let's completely
9044 // re-evaluate everything.
9045 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009046 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009047 }
9048 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009049 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009050 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009051 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009052 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009053 + " NEW: " + mWallpaperTarget
9054 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009055 if (mLowerWallpaperTarget == null) {
9056 // Whoops, we don't need a special wallpaper animation.
9057 // Clear them out.
9058 forceHiding = false;
9059 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009060 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009061 if (w.mSurface != null) {
9062 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009063 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009064 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009065 forceHiding = true;
9066 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9067 if (!w.mAnimating) {
9068 // We set the animation above so it
9069 // is not yet running.
9070 w.clearAnimation();
9071 }
9072 }
9073 }
9074 }
9075 }
9076 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009077
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009078 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009079 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009080 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009081 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009082 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009083
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009084 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009085 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009086 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009087 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009088 assignLayersLocked();
9089 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009090 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009091 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009092 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009093 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009094
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009095 if (mFocusMayChange) {
9096 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009097 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009098 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009099 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009100 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009101 }
9102
9103 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009104 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009105 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009106
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009107 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9108 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009109
Jeff Browne33348b2010-07-15 23:54:05 -07009110 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009111 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009112
9113 // THIRD LOOP: Update the surfaces of all windows.
9114
9115 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9116
9117 boolean obscured = false;
9118 boolean blurring = false;
9119 boolean dimming = false;
9120 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009121 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009122 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009123
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009124 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009125
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009126 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009127 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009128
9129 boolean displayed = false;
9130 final WindowManager.LayoutParams attrs = w.mAttrs;
9131 final int attrFlags = attrs.flags;
9132
9133 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009134 // XXX NOTE: The logic here could be improved. We have
9135 // the decision about whether to resize a window separated
9136 // from whether to hide the surface. This can cause us to
9137 // resize a surface even if we are going to hide it. You
9138 // can see this by (1) holding device in landscape mode on
9139 // home screen; (2) tapping browser icon (device will rotate
9140 // to landscape; (3) tap home. The wallpaper will be resized
9141 // in step 2 but then immediately hidden, causing us to
9142 // have to resize and then redraw it again in step 3. It
9143 // would be nice to figure out how to avoid this, but it is
9144 // difficult because we do need to resize surfaces in some
9145 // cases while they are hidden such as when first showing a
9146 // window.
9147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009148 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009149 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009150 TAG, "Placing surface #" + i + " " + w.mSurface
9151 + ": new=" + w.mShownFrame + ", old="
9152 + w.mLastShownFrame);
9153
9154 boolean resize;
9155 int width, height;
9156 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9157 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9158 w.mLastRequestedHeight != w.mRequestedHeight;
9159 // for a scaled surface, we just want to use
9160 // the requested size.
9161 width = w.mRequestedWidth;
9162 height = w.mRequestedHeight;
9163 w.mLastRequestedWidth = width;
9164 w.mLastRequestedHeight = height;
9165 w.mLastShownFrame.set(w.mShownFrame);
9166 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009167 if (SHOW_TRANSACTIONS) logSurface(w,
9168 "POS " + w.mShownFrame.left
9169 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009170 w.mSurfaceX = w.mShownFrame.left;
9171 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009172 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9173 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009174 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009175 if (!recoveringMemory) {
9176 reclaimSomeSurfaceMemoryLocked(w, "position");
9177 }
9178 }
9179 } else {
9180 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9181 width = w.mShownFrame.width();
9182 height = w.mShownFrame.height();
9183 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009184 }
9185
9186 if (resize) {
9187 if (width < 1) width = 1;
9188 if (height < 1) height = 1;
9189 if (w.mSurface != null) {
9190 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009191 if (SHOW_TRANSACTIONS) logSurface(w,
9192 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009193 + w.mShownFrame.top + " SIZE "
9194 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009195 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009196 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009197 w.mSurfaceW = width;
9198 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009199 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009200 w.mSurfaceX = w.mShownFrame.left;
9201 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009202 w.mSurface.setPosition(w.mShownFrame.left,
9203 w.mShownFrame.top);
9204 } catch (RuntimeException e) {
9205 // If something goes wrong with the surface (such
9206 // as running out of memory), don't take down the
9207 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009208 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009209 + "size=(" + width + "x" + height
9210 + "), pos=(" + w.mShownFrame.left
9211 + "," + w.mShownFrame.top + ")", e);
9212 if (!recoveringMemory) {
9213 reclaimSomeSurfaceMemoryLocked(w, "size");
9214 }
9215 }
9216 }
9217 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009218 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009219 w.mContentInsetsChanged =
9220 !w.mLastContentInsets.equals(w.mContentInsets);
9221 w.mVisibleInsetsChanged =
9222 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009223 boolean configChanged =
9224 w.mConfiguration != mCurConfiguration
9225 && (w.mConfiguration == null
9226 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009227 if (DEBUG_CONFIGURATION && configChanged) {
9228 Slog.v(TAG, "Win " + w + " config changed: "
9229 + mCurConfiguration);
9230 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009231 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009232 + ": configChanged=" + configChanged
9233 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009234 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009235 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009236 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009237 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009238 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009239 w.mLastFrame.set(w.mFrame);
9240 w.mLastContentInsets.set(w.mContentInsets);
9241 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009242 // If the screen is currently frozen, then keep
9243 // it frozen until this window draws at its new
9244 // orientation.
9245 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009246 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009247 "Resizing while display frozen: " + w);
9248 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009249 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009250 mWindowsFreezingScreen = true;
9251 // XXX should probably keep timeout from
9252 // when we first froze the display.
9253 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9254 mH.sendMessageDelayed(mH.obtainMessage(
9255 H.WINDOW_FREEZE_TIMEOUT), 2000);
9256 }
9257 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009258 // If the orientation is changing, then we need to
9259 // hold off on unfreezing the display until this
9260 // window has been redrawn; to do that, we need
9261 // to go through the process of getting informed
9262 // by the application when it has finished drawing.
9263 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009264 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009265 "Orientation start waiting for draw in "
9266 + w + ", surface " + w.mSurface);
9267 w.mDrawPending = true;
9268 w.mCommitDrawPending = false;
9269 w.mReadyToShow = false;
9270 if (w.mAppToken != null) {
9271 w.mAppToken.allDrawn = false;
9272 }
9273 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009274 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009275 "Resizing window " + w + " to " + w.mFrame);
9276 mResizingWindows.add(w);
9277 } else if (w.mOrientationChanging) {
9278 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009279 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009280 "Orientation not waiting for draw in "
9281 + w + ", surface " + w.mSurface);
9282 w.mOrientationChanging = false;
9283 }
9284 }
9285 }
9286
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009287 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009288 if (!w.mLastHidden) {
9289 //dump();
9290 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009291 if (SHOW_TRANSACTIONS) logSurface(w,
9292 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009293 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009294 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009295 try {
9296 w.mSurface.hide();
9297 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009298 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009299 }
9300 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009301 }
9302 // If we are waiting for this window to handle an
9303 // orientation change, well, it is hidden, so
9304 // doesn't really matter. Note that this does
9305 // introduce a potential glitch if the window
9306 // becomes unhidden before it has drawn for the
9307 // new orientation.
9308 if (w.mOrientationChanging) {
9309 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009310 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009311 "Orientation change skips hidden " + w);
9312 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009313 } else if (w.mLastLayer != w.mAnimLayer
9314 || w.mLastAlpha != w.mShownAlpha
9315 || w.mLastDsDx != w.mDsDx
9316 || w.mLastDtDx != w.mDtDx
9317 || w.mLastDsDy != w.mDsDy
9318 || w.mLastDtDy != w.mDtDy
9319 || w.mLastHScale != w.mHScale
9320 || w.mLastVScale != w.mVScale
9321 || w.mLastHidden) {
9322 displayed = true;
9323 w.mLastAlpha = w.mShownAlpha;
9324 w.mLastLayer = w.mAnimLayer;
9325 w.mLastDsDx = w.mDsDx;
9326 w.mLastDtDx = w.mDtDx;
9327 w.mLastDsDy = w.mDsDy;
9328 w.mLastDtDy = w.mDtDy;
9329 w.mLastHScale = w.mHScale;
9330 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009331 if (SHOW_TRANSACTIONS) logSurface(w,
9332 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009333 + " matrix=[" + (w.mDsDx*w.mHScale)
9334 + "," + (w.mDtDx*w.mVScale)
9335 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009336 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009337 if (w.mSurface != null) {
9338 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009339 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009340 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009341 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009342 w.mSurface.setLayer(w.mAnimLayer);
9343 w.mSurface.setMatrix(
9344 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9345 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9346 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009347 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009348 if (!recoveringMemory) {
9349 reclaimSomeSurfaceMemoryLocked(w, "update");
9350 }
9351 }
9352 }
9353
9354 if (w.mLastHidden && !w.mDrawPending
9355 && !w.mCommitDrawPending
9356 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009357 if (SHOW_TRANSACTIONS) logSurface(w,
9358 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009359 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009360 + " during relayout");
9361 if (showSurfaceRobustlyLocked(w)) {
9362 w.mHasDrawn = true;
9363 w.mLastHidden = false;
9364 } else {
9365 w.mOrientationChanging = false;
9366 }
9367 }
9368 if (w.mSurface != null) {
9369 w.mToken.hasVisible = true;
9370 }
9371 } else {
9372 displayed = true;
9373 }
9374
9375 if (displayed) {
9376 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009377 if (attrs.width == LayoutParams.MATCH_PARENT
9378 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009379 covered = true;
9380 }
9381 }
9382 if (w.mOrientationChanging) {
9383 if (w.mDrawPending || w.mCommitDrawPending) {
9384 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009385 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009386 "Orientation continue waiting for draw in " + w);
9387 } else {
9388 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009389 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009390 "Orientation change complete in " + w);
9391 }
9392 }
9393 w.mToken.hasVisible = true;
9394 }
9395 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009396 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009397 "Orientation change skips hidden " + w);
9398 w.mOrientationChanging = false;
9399 }
9400
9401 final boolean canBeSeen = w.isDisplayedLw();
9402
9403 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9404 focusDisplayed = true;
9405 }
9406
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009407 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009409 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009410 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009411 if (w.mSurface != null) {
9412 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9413 holdScreen = w.mSession;
9414 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009415 if (!syswin && w.mAttrs.screenBrightness >= 0
9416 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009417 screenBrightness = w.mAttrs.screenBrightness;
9418 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009419 if (!syswin && w.mAttrs.buttonBrightness >= 0
9420 && buttonBrightness < 0) {
9421 buttonBrightness = w.mAttrs.buttonBrightness;
9422 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05009423 if (canBeSeen
9424 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9425 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9426 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009427 syswin = true;
9428 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009429 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009430
Dianne Hackborn25994b42009-09-04 14:21:19 -07009431 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
9432 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009433 // This window completely covers everything behind it,
9434 // so we want to leave all of them as unblurred (for
9435 // performance reasons).
9436 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009437 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009438 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009439 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009440 obscured = true;
9441 if (mBackgroundFillerSurface == null) {
9442 try {
9443 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009444 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009445 0, dw, dh,
9446 PixelFormat.OPAQUE,
9447 Surface.FX_SURFACE_NORMAL);
9448 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009449 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009450 }
9451 }
9452 try {
9453 mBackgroundFillerSurface.setPosition(0, 0);
9454 mBackgroundFillerSurface.setSize(dw, dh);
9455 // Using the same layer as Dim because they will never be shown at the
9456 // same time.
9457 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9458 mBackgroundFillerSurface.show();
9459 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009460 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009461 }
9462 backgroundFillerShown = true;
9463 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009464 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009465 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009466 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009467 + ": blurring=" + blurring
9468 + " obscured=" + obscured
9469 + " displayed=" + displayed);
9470 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9471 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009472 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009473 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009474 if (mDimAnimator == null) {
9475 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009476 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009477 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009478 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009479 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009480 }
9481 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
9482 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009483 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009484 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009485 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009486 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009487 + mBlurSurface + ": CREATE");
9488 try {
Romain Guy06882f82009-06-10 13:36:04 -07009489 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009490 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009491 -1, 16, 16,
9492 PixelFormat.OPAQUE,
9493 Surface.FX_SURFACE_BLUR);
9494 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009495 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009496 }
9497 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009498 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009499 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9500 + mBlurSurface + ": pos=(0,0) (" +
9501 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009502 mBlurSurface.setPosition(0, 0);
9503 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009504 mBlurSurface.setLayer(w.mAnimLayer-2);
9505 if (!mBlurShown) {
9506 try {
9507 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9508 + mBlurSurface + ": SHOW");
9509 mBlurSurface.show();
9510 } catch (RuntimeException e) {
9511 Slog.w(TAG, "Failure showing blur surface", e);
9512 }
9513 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009514 }
9515 }
9516 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009517 }
9518 }
9519 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009520
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009521 if (obscuredChanged && mWallpaperTarget == w) {
9522 // This is the wallpaper target and its obscured state
9523 // changed... make sure the current wallaper's visibility
9524 // has been updated accordingly.
9525 updateWallpaperVisibilityLocked();
9526 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009527 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009528
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009529 if (backgroundFillerShown == false && mBackgroundFillerShown) {
9530 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009531 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009532 try {
9533 mBackgroundFillerSurface.hide();
9534 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009535 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009536 }
9537 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009538
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009539 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009540 animating |= mDimAnimator.updateSurface(dimming, currentTime,
9541 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009542 }
Romain Guy06882f82009-06-10 13:36:04 -07009543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009544 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009545 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009546 + ": HIDE");
9547 try {
9548 mBlurSurface.hide();
9549 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009550 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009551 }
9552 mBlurShown = false;
9553 }
9554
Joe Onorato8a9b2202010-02-26 18:56:32 -08009555 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009556 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009557 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009558 }
9559
Jeff Browne33348b2010-07-15 23:54:05 -07009560 mInputMonitor.updateInputWindowsLw();
9561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009562 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -07009563
Dianne Hackbornb9fb1702010-08-23 16:49:02 -07009564 if (mWatermark != null) {
9565 mWatermark.drawIfNeeded();
9566 }
9567
Joe Onorato8a9b2202010-02-26 18:56:32 -08009568 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009569 "With display frozen, orientationChangeComplete="
9570 + orientationChangeComplete);
9571 if (orientationChangeComplete) {
9572 if (mWindowsFreezingScreen) {
9573 mWindowsFreezingScreen = false;
9574 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9575 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009576 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009577 }
Romain Guy06882f82009-06-10 13:36:04 -07009578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009579 i = mResizingWindows.size();
9580 if (i > 0) {
9581 do {
9582 i--;
9583 WindowState win = mResizingWindows.get(i);
9584 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009585 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
9586 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009587 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009588 boolean configChanged =
9589 win.mConfiguration != mCurConfiguration
9590 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009591 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
9592 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
9593 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009594 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009595 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009596 + " / " + mCurConfiguration + " / 0x"
9597 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009598 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009599 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009600 win.mClient.resized(win.mFrame.width(),
9601 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009602 win.mLastVisibleInsets, win.mDrawPending,
9603 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009604 win.mContentInsetsChanged = false;
9605 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009606 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009607 } catch (RemoteException e) {
9608 win.mOrientationChanging = false;
9609 }
9610 } while (i > 0);
9611 mResizingWindows.clear();
9612 }
Romain Guy06882f82009-06-10 13:36:04 -07009613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009614 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009615 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009616 i = mDestroySurface.size();
9617 if (i > 0) {
9618 do {
9619 i--;
9620 WindowState win = mDestroySurface.get(i);
9621 win.mDestroying = false;
9622 if (mInputMethodWindow == win) {
9623 mInputMethodWindow = null;
9624 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009625 if (win == mWallpaperTarget) {
9626 wallpaperDestroyed = true;
9627 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009628 win.destroySurfaceLocked();
9629 } while (i > 0);
9630 mDestroySurface.clear();
9631 }
9632
9633 // Time to remove any exiting tokens?
9634 for (i=mExitingTokens.size()-1; i>=0; i--) {
9635 WindowToken token = mExitingTokens.get(i);
9636 if (!token.hasVisible) {
9637 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07009638 if (token.windowType == TYPE_WALLPAPER) {
9639 mWallpaperTokens.remove(token);
9640 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009641 }
9642 }
9643
9644 // Time to remove any exiting applications?
9645 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9646 AppWindowToken token = mExitingAppTokens.get(i);
9647 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009648 // Make sure there is no animation running on this token,
9649 // so any windows associated with it will be removed as
9650 // soon as their animations are complete
9651 token.animation = null;
9652 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009653 mAppTokens.remove(token);
9654 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009655 if (mLastEnterAnimToken == token) {
9656 mLastEnterAnimToken = null;
9657 mLastEnterAnimParams = null;
9658 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009659 }
9660 }
9661
Dianne Hackborna8f60182009-09-01 19:01:50 -07009662 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009663
Dianne Hackborna8f60182009-09-01 19:01:50 -07009664 if (!animating && mAppTransitionRunning) {
9665 // We have finished the animation of an app transition. To do
9666 // this, we have delayed a lot of operations like showing and
9667 // hiding apps, moving apps in Z-order, etc. The app token list
9668 // reflects the correct Z-order, but the window list may now
9669 // be out of sync with it. So here we will just rebuild the
9670 // entire app window list. Fun!
9671 mAppTransitionRunning = false;
9672 needRelayout = true;
9673 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009674 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009675 // Clear information about apps that were moving.
9676 mToBottomApps.clear();
9677 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009678
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009679 if (focusDisplayed) {
9680 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
9681 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009682 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009683 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009684 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009685 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009686 requestAnimationLocked(0);
9687 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009688 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
9689 }
Jeff Browneb857f12010-07-16 10:06:33 -07009690
Jeff Browne33348b2010-07-15 23:54:05 -07009691 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -07009692
Jeff Brown8e03b752010-06-13 19:16:55 -07009693 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009694 if (screenBrightness < 0 || screenBrightness > 1.0f) {
9695 mPowerManager.setScreenBrightnessOverride(-1);
9696 } else {
9697 mPowerManager.setScreenBrightnessOverride((int)
9698 (screenBrightness * Power.BRIGHTNESS_ON));
9699 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009700 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
9701 mPowerManager.setButtonBrightnessOverride(-1);
9702 } else {
9703 mPowerManager.setButtonBrightnessOverride((int)
9704 (buttonBrightness * Power.BRIGHTNESS_ON));
9705 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009706 if (holdScreen != mHoldingScreenOn) {
9707 mHoldingScreenOn = holdScreen;
9708 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
9709 mH.sendMessage(m);
9710 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009711
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009712 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009713 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009714 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
9715 LocalPowerManager.BUTTON_EVENT, true);
9716 mTurnOnScreen = false;
9717 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08009718
9719 // Check to see if we are now in a state where the screen should
9720 // be enabled, because the window obscured flags have changed.
9721 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009722 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009723
9724 /**
9725 * Must be called with the main window manager lock held.
9726 */
9727 void setHoldScreenLocked(boolean holding) {
9728 boolean state = mHoldingScreenWakeLock.isHeld();
9729 if (holding != state) {
9730 if (holding) {
9731 mHoldingScreenWakeLock.acquire();
9732 } else {
9733 mPolicy.screenOnStoppedLw();
9734 mHoldingScreenWakeLock.release();
9735 }
9736 }
9737 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009738
9739 void requestAnimationLocked(long delay) {
9740 if (!mAnimationPending) {
9741 mAnimationPending = true;
9742 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
9743 }
9744 }
Romain Guy06882f82009-06-10 13:36:04 -07009745
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009746 /**
9747 * Have the surface flinger show a surface, robustly dealing with
9748 * error conditions. In particular, if there is not enough memory
9749 * to show the surface, then we will try to get rid of other surfaces
9750 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -07009751 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009752 * @return Returns true if the surface was successfully shown.
9753 */
9754 boolean showSurfaceRobustlyLocked(WindowState win) {
9755 try {
9756 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009757 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009758 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009759 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009760 if (DEBUG_VISIBILITY) Slog.v(TAG,
9761 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009762 win.mTurnOnScreen = false;
9763 mTurnOnScreen = true;
9764 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009765 }
9766 return true;
9767 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009768 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009769 }
Romain Guy06882f82009-06-10 13:36:04 -07009770
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009771 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -07009772
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009773 return false;
9774 }
Romain Guy06882f82009-06-10 13:36:04 -07009775
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009776 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
9777 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -07009778
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009779 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009780 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -07009781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009782 if (mForceRemoves == null) {
9783 mForceRemoves = new ArrayList<WindowState>();
9784 }
Romain Guy06882f82009-06-10 13:36:04 -07009785
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009786 long callingIdentity = Binder.clearCallingIdentity();
9787 try {
9788 // There was some problem... first, do a sanity check of the
9789 // window list to make sure we haven't left any dangling surfaces
9790 // around.
9791 int N = mWindows.size();
9792 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009793 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009794 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009795 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009796 if (ws.mSurface != null) {
9797 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009798 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009799 + ws + " surface=" + ws.mSurface
9800 + " token=" + win.mToken
9801 + " pid=" + ws.mSession.mPid
9802 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009803 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009804 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009805 ws.mSurface = null;
9806 mForceRemoves.add(ws);
9807 i--;
9808 N--;
9809 leakedSurface = true;
9810 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009811 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009812 + ws + " surface=" + ws.mSurface
9813 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009814 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009815 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009816 ws.mSurface = null;
9817 leakedSurface = true;
9818 }
9819 }
9820 }
Romain Guy06882f82009-06-10 13:36:04 -07009821
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009822 boolean killedApps = false;
9823 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009824 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009825 SparseIntArray pidCandidates = new SparseIntArray();
9826 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009827 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009828 if (ws.mSurface != null) {
9829 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
9830 }
9831 }
9832 if (pidCandidates.size() > 0) {
9833 int[] pids = new int[pidCandidates.size()];
9834 for (int i=0; i<pids.length; i++) {
9835 pids[i] = pidCandidates.keyAt(i);
9836 }
9837 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -07009838 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009839 killedApps = true;
9840 }
9841 } catch (RemoteException e) {
9842 }
9843 }
9844 }
Romain Guy06882f82009-06-10 13:36:04 -07009845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009846 if (leakedSurface || killedApps) {
9847 // We managed to reclaim some memory, so get rid of the trouble
9848 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009849 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009850 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009851 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009852 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009853 win.mSurface = null;
9854 }
Romain Guy06882f82009-06-10 13:36:04 -07009855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009856 try {
9857 win.mClient.dispatchGetNewSurface();
9858 } catch (RemoteException e) {
9859 }
9860 }
9861 } finally {
9862 Binder.restoreCallingIdentity(callingIdentity);
9863 }
9864 }
Romain Guy06882f82009-06-10 13:36:04 -07009865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009866 private boolean updateFocusedWindowLocked(int mode) {
9867 WindowState newFocus = computeFocusedWindowLocked();
9868 if (mCurrentFocus != newFocus) {
9869 // This check makes sure that we don't already have the focus
9870 // change message pending.
9871 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
9872 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009873 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009874 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
9875 final WindowState oldFocus = mCurrentFocus;
9876 mCurrentFocus = newFocus;
9877 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -07009878
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009879 final WindowState imWindow = mInputMethodWindow;
9880 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009881 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009882 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009883 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
9884 mLayoutNeeded = true;
9885 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009886 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
9887 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009888 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
9889 // Client will do the layout, but we need to assign layers
9890 // for handleNewWindowLocked() below.
9891 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009892 }
9893 }
Jeff Brown349703e2010-06-22 01:27:15 -07009894
9895 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
9896 // If we defer assigning layers, then the caller is responsible for
9897 // doing this part.
9898 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009899 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009900 return true;
9901 }
9902 return false;
9903 }
Jeff Brown349703e2010-06-22 01:27:15 -07009904
9905 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009906 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07009907 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009908
9909 private WindowState computeFocusedWindowLocked() {
9910 WindowState result = null;
9911 WindowState win;
9912
9913 int i = mWindows.size() - 1;
9914 int nextAppIndex = mAppTokens.size()-1;
9915 WindowToken nextApp = nextAppIndex >= 0
9916 ? mAppTokens.get(nextAppIndex) : null;
9917
9918 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009919 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009920
Joe Onorato8a9b2202010-02-26 18:56:32 -08009921 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009922 TAG, "Looking for focus: " + i
9923 + " = " + win
9924 + ", flags=" + win.mAttrs.flags
9925 + ", canReceive=" + win.canReceiveKeys());
9926
9927 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -07009928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009929 // If this window's application has been removed, just skip it.
9930 if (thisApp != null && thisApp.removed) {
9931 i--;
9932 continue;
9933 }
Romain Guy06882f82009-06-10 13:36:04 -07009934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009935 // If there is a focused app, don't allow focus to go to any
9936 // windows below it. If this is an application window, step
9937 // through the app tokens until we find its app.
9938 if (thisApp != null && nextApp != null && thisApp != nextApp
9939 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
9940 int origAppIndex = nextAppIndex;
9941 while (nextAppIndex > 0) {
9942 if (nextApp == mFocusedApp) {
9943 // Whoops, we are below the focused app... no focus
9944 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -08009945 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009946 TAG, "Reached focused app: " + mFocusedApp);
9947 return null;
9948 }
9949 nextAppIndex--;
9950 nextApp = mAppTokens.get(nextAppIndex);
9951 if (nextApp == thisApp) {
9952 break;
9953 }
9954 }
9955 if (thisApp != nextApp) {
9956 // Uh oh, the app token doesn't exist! This shouldn't
9957 // happen, but if it does we can get totally hosed...
9958 // so restart at the original app.
9959 nextAppIndex = origAppIndex;
9960 nextApp = mAppTokens.get(nextAppIndex);
9961 }
9962 }
9963
9964 // Dispatch to this window if it is wants key events.
9965 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009966 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009967 TAG, "Found focus @ " + i + " = " + win);
9968 result = win;
9969 break;
9970 }
9971
9972 i--;
9973 }
9974
9975 return result;
9976 }
9977
9978 private void startFreezingDisplayLocked() {
9979 if (mDisplayFrozen) {
9980 return;
9981 }
Romain Guy06882f82009-06-10 13:36:04 -07009982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009983 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -07009984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009985 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009986 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009987 if (mFreezeGcPending != 0) {
9988 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009989 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009990 mH.removeMessages(H.FORCE_GC);
9991 Runtime.getRuntime().gc();
9992 mFreezeGcPending = now;
9993 }
9994 } else {
9995 mFreezeGcPending = now;
9996 }
Romain Guy06882f82009-06-10 13:36:04 -07009997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009998 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -07009999
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010000 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010001
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010002 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10003 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010004 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010005 mAppTransitionReady = true;
10006 }
Romain Guy06882f82009-06-10 13:36:04 -070010007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010008 if (PROFILE_ORIENTATION) {
10009 File file = new File("/data/system/frozen");
10010 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10011 }
10012 Surface.freezeDisplay(0);
10013 }
Romain Guy06882f82009-06-10 13:36:04 -070010014
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010015 private void stopFreezingDisplayLocked() {
10016 if (!mDisplayFrozen) {
10017 return;
10018 }
Romain Guy06882f82009-06-10 13:36:04 -070010019
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010020 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10021 return;
10022 }
10023
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010024 mDisplayFrozen = false;
10025 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10026 if (PROFILE_ORIENTATION) {
10027 Debug.stopMethodTracing();
10028 }
10029 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010030
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010031 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010032
Christopher Tateb696aee2010-04-02 19:08:30 -070010033 // While the display is frozen we don't re-compute the orientation
10034 // to avoid inconsistent states. However, something interesting
10035 // could have actually changed during that time so re-evaluate it
10036 // now to catch that.
10037 if (updateOrientationFromAppTokensLocked()) {
10038 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10039 }
10040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010041 // A little kludge: a lot could have happened while the
10042 // display was frozen, so now that we are coming back we
10043 // do a gc so that any remote references the system
10044 // processes holds on others can be released if they are
10045 // no longer needed.
10046 mH.removeMessages(H.FORCE_GC);
10047 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10048 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010050 mScreenFrozenLock.release();
10051 }
Romain Guy06882f82009-06-10 13:36:04 -070010052
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010053 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10054 DisplayMetrics dm) {
10055 if (index < tokens.length) {
10056 String str = tokens[index];
10057 if (str != null && str.length() > 0) {
10058 try {
10059 int val = Integer.parseInt(str);
10060 return val;
10061 } catch (Exception e) {
10062 }
10063 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010064 }
10065 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10066 return defDps;
10067 }
10068 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10069 return val;
10070 }
10071
10072 class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010073 final String[] mTokens;
10074 final String mText;
10075 final Paint mTextPaint;
10076 final int mTextWidth;
10077 final int mTextHeight;
10078 final int mTextAscent;
10079 final int mTextDescent;
10080 final int mDeltaX;
10081 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010082
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010083 Surface mSurface;
10084 int mLastDW;
10085 int mLastDH;
10086 boolean mDrawNeeded;
10087
10088 Watermark(SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010089 final DisplayMetrics dm = new DisplayMetrics();
10090 mDisplay.getMetrics(dm);
10091
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010092 if (false) {
10093 Log.i(TAG, "*********************** WATERMARK");
10094 for (int i=0; i<tokens.length; i++) {
10095 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10096 }
10097 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010098
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010099 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010100
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010101 StringBuilder builder = new StringBuilder(32);
10102 int len = mTokens[0].length();
10103 len = len & ~1;
10104 for (int i=0; i<len; i+=2) {
10105 int c1 = mTokens[0].charAt(i);
10106 int c2 = mTokens[0].charAt(i+1);
10107 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10108 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10109 else c1 -= '0';
10110 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10111 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10112 else c2 -= '0';
10113 builder.append((char)(255-((c1*16)+c2)));
10114 }
10115 mText = builder.toString();
10116 if (false) {
10117 Log.i(TAG, "Final text: " + mText);
10118 }
10119
10120 int fontSize = getPropertyInt(tokens, 1,
10121 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10122
10123 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10124 mTextPaint.setTextSize(fontSize);
10125 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10126
10127 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
10128 mTextWidth = (int)mTextPaint.measureText(mText);
10129 mTextAscent = fm.ascent;
10130 mTextDescent = fm.descent;
10131 mTextHeight = fm.descent - fm.ascent;
10132
10133 mDeltaX = getPropertyInt(tokens, 2,
10134 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
10135 mDeltaY = getPropertyInt(tokens, 3,
10136 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
10137 int shadowColor = getPropertyInt(tokens, 4,
10138 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
10139 int color = getPropertyInt(tokens, 5,
10140 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
10141 int shadowRadius = getPropertyInt(tokens, 6,
10142 TypedValue.COMPLEX_UNIT_PX, 7, dm);
10143 int shadowDx = getPropertyInt(tokens, 8,
10144 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10145 int shadowDy = getPropertyInt(tokens, 9,
10146 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10147
10148 mTextPaint.setColor(color);
10149 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010150
10151 try {
10152 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010153 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010154 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010155 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010156 mSurface.show();
10157 } catch (OutOfResourcesException e) {
10158 }
10159 }
10160
10161 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010162 if (mLastDW != dw || mLastDH != dh) {
10163 mLastDW = dw;
10164 mLastDH = dh;
10165 mSurface.setSize(dw, dh);
10166 mDrawNeeded = true;
10167 }
10168 }
10169
10170 void drawIfNeeded() {
10171 if (mDrawNeeded) {
10172 final int dw = mLastDW;
10173 final int dh = mLastDH;
10174
10175 mDrawNeeded = false;
10176 Rect dirty = new Rect(0, 0, dw, dh);
10177 Canvas c = null;
10178 try {
10179 c = mSurface.lockCanvas(dirty);
10180 } catch (IllegalArgumentException e) {
10181 } catch (OutOfResourcesException e) {
10182 }
10183 if (c != null) {
10184 int deltaX = mDeltaX;
10185 int deltaY = mDeltaY;
10186
10187 // deltaX shouldn't be close to a round fraction of our
10188 // x step, or else things will line up too much.
10189 int div = (dw+mTextWidth)/deltaX;
10190 int rem = (dw+mTextWidth) - (div*deltaX);
10191 int qdelta = deltaX/4;
10192 if (rem < qdelta || rem > (deltaX-qdelta)) {
10193 deltaX += deltaX/3;
10194 }
10195
10196 int y = -mTextHeight;
10197 int x = -mTextWidth;
10198 while (y < (dh+mTextHeight)) {
10199 c.drawText(mText, x, y, mTextPaint);
10200 x += deltaX;
10201 if (x >= dw) {
10202 x -= (dw+mTextWidth);
10203 y += deltaY;
10204 }
10205 }
10206 mSurface.unlockCanvasAndPost(c);
10207 }
10208 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010209 }
10210 }
10211
10212 void createWatermark() {
10213 if (mWatermark != null) {
10214 return;
10215 }
10216
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010217 File file = new File("/system/etc/setup.conf");
10218 FileInputStream in = null;
10219 try {
10220 in = new FileInputStream(file);
10221 DataInputStream ind = new DataInputStream(in);
10222 String line = ind.readLine();
10223 if (line != null) {
10224 String[] toks = line.split("%");
10225 if (toks != null && toks.length > 0) {
10226 mWatermark = new Watermark(mFxSession, toks);
10227 }
10228 }
10229 } catch (FileNotFoundException e) {
10230 } catch (IOException e) {
10231 } finally {
10232 if (in != null) {
10233 try {
10234 in.close();
10235 } catch (IOException e) {
10236 }
10237 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010238 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010239 }
10240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010241 @Override
10242 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10243 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10244 != PackageManager.PERMISSION_GRANTED) {
10245 pw.println("Permission Denial: can't dump WindowManager from from pid="
10246 + Binder.getCallingPid()
10247 + ", uid=" + Binder.getCallingUid());
10248 return;
10249 }
Romain Guy06882f82009-06-10 13:36:04 -070010250
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010251 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010252 pw.println(" ");
10253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010254 synchronized(mWindowMap) {
10255 pw.println("Current Window Manager state:");
10256 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010257 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010258 pw.print(" Window #"); pw.print(i); pw.print(' ');
10259 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010260 w.dump(pw, " ");
10261 }
10262 if (mInputMethodDialogs.size() > 0) {
10263 pw.println(" ");
10264 pw.println(" Input method dialogs:");
10265 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10266 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010267 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010268 }
10269 }
10270 if (mPendingRemove.size() > 0) {
10271 pw.println(" ");
10272 pw.println(" Remove pending for:");
10273 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10274 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010275 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10276 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010277 w.dump(pw, " ");
10278 }
10279 }
10280 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10281 pw.println(" ");
10282 pw.println(" Windows force removing:");
10283 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10284 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010285 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10286 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010287 w.dump(pw, " ");
10288 }
10289 }
10290 if (mDestroySurface.size() > 0) {
10291 pw.println(" ");
10292 pw.println(" Windows waiting to destroy their surface:");
10293 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10294 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010295 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10296 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010297 w.dump(pw, " ");
10298 }
10299 }
10300 if (mLosingFocus.size() > 0) {
10301 pw.println(" ");
10302 pw.println(" Windows losing focus:");
10303 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10304 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010305 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10306 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010307 w.dump(pw, " ");
10308 }
10309 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010310 if (mResizingWindows.size() > 0) {
10311 pw.println(" ");
10312 pw.println(" Windows waiting to resize:");
10313 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10314 WindowState w = mResizingWindows.get(i);
10315 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10316 pw.print(w); pw.println(":");
10317 w.dump(pw, " ");
10318 }
10319 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010320 if (mSessions.size() > 0) {
10321 pw.println(" ");
10322 pw.println(" All active sessions:");
10323 Iterator<Session> it = mSessions.iterator();
10324 while (it.hasNext()) {
10325 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010326 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010327 s.dump(pw, " ");
10328 }
10329 }
10330 if (mTokenMap.size() > 0) {
10331 pw.println(" ");
10332 pw.println(" All tokens:");
10333 Iterator<WindowToken> it = mTokenMap.values().iterator();
10334 while (it.hasNext()) {
10335 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010336 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010337 token.dump(pw, " ");
10338 }
10339 }
10340 if (mTokenList.size() > 0) {
10341 pw.println(" ");
10342 pw.println(" Window token list:");
10343 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010344 pw.print(" #"); pw.print(i); pw.print(": ");
10345 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010346 }
10347 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010348 if (mWallpaperTokens.size() > 0) {
10349 pw.println(" ");
10350 pw.println(" Wallpaper tokens:");
10351 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10352 WindowToken token = mWallpaperTokens.get(i);
10353 pw.print(" Wallpaper #"); pw.print(i);
10354 pw.print(' '); pw.print(token); pw.println(':');
10355 token.dump(pw, " ");
10356 }
10357 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010358 if (mAppTokens.size() > 0) {
10359 pw.println(" ");
10360 pw.println(" Application tokens in Z order:");
10361 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010362 pw.print(" App #"); pw.print(i); pw.print(": ");
10363 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010364 }
10365 }
10366 if (mFinishedStarting.size() > 0) {
10367 pw.println(" ");
10368 pw.println(" Finishing start of application tokens:");
10369 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10370 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010371 pw.print(" Finished Starting #"); pw.print(i);
10372 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010373 token.dump(pw, " ");
10374 }
10375 }
10376 if (mExitingTokens.size() > 0) {
10377 pw.println(" ");
10378 pw.println(" Exiting tokens:");
10379 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10380 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010381 pw.print(" Exiting #"); pw.print(i);
10382 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010383 token.dump(pw, " ");
10384 }
10385 }
10386 if (mExitingAppTokens.size() > 0) {
10387 pw.println(" ");
10388 pw.println(" Exiting application tokens:");
10389 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10390 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010391 pw.print(" Exiting App #"); pw.print(i);
10392 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010393 token.dump(pw, " ");
10394 }
10395 }
10396 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010397 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10398 pw.print(" mLastFocus="); pw.println(mLastFocus);
10399 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10400 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10401 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010402 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010403 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10404 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10405 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10406 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010407 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10408 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10409 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010410 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10411 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10412 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10413 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010414 if (mDimAnimator != null) {
10415 mDimAnimator.printTo(pw);
10416 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080010417 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010418 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010419 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010420 pw.print(mInputMethodAnimLayerAdjustment);
10421 pw.print(" mWallpaperAnimLayerAdjustment=");
10422 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010423 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10424 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010425 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10426 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010427 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
10428 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010429 pw.print(" mRotation="); pw.print(mRotation);
10430 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10431 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10432 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10433 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10434 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10435 pw.print(" mNextAppTransition=0x");
10436 pw.print(Integer.toHexString(mNextAppTransition));
10437 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010438 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010439 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010440 if (mNextAppTransitionPackage != null) {
10441 pw.print(" mNextAppTransitionPackage=");
10442 pw.print(mNextAppTransitionPackage);
10443 pw.print(", mNextAppTransitionEnter=0x");
10444 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10445 pw.print(", mNextAppTransitionExit=0x");
10446 pw.print(Integer.toHexString(mNextAppTransitionExit));
10447 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010448 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10449 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010450 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10451 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10452 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10453 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010454 if (mOpeningApps.size() > 0) {
10455 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10456 }
10457 if (mClosingApps.size() > 0) {
10458 pw.print(" mClosingApps="); pw.println(mClosingApps);
10459 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010460 if (mToTopApps.size() > 0) {
10461 pw.print(" mToTopApps="); pw.println(mToTopApps);
10462 }
10463 if (mToBottomApps.size() > 0) {
10464 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10465 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010466 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10467 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010468 }
10469 }
10470
Jeff Brown349703e2010-06-22 01:27:15 -070010471 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010472 public void monitor() {
10473 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010474 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070010475 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010476
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010477 /**
10478 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010479 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010480 */
10481 private static class DimAnimator {
10482 Surface mDimSurface;
10483 boolean mDimShown = false;
10484 float mDimCurrentAlpha;
10485 float mDimTargetAlpha;
10486 float mDimDeltaPerMs;
10487 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010488
10489 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010490
10491 DimAnimator (SurfaceSession session) {
10492 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010493 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010494 + mDimSurface + ": CREATE");
10495 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010496 mDimSurface = new Surface(session, 0,
10497 "DimSurface",
10498 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010499 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010010500 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010501 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010502 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010503 }
10504 }
10505 }
10506
10507 /**
10508 * Show the dim surface.
10509 */
10510 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010511 if (!mDimShown) {
10512 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
10513 dw + "x" + dh + ")");
10514 mDimShown = true;
10515 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010516 mLastDimWidth = dw;
10517 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010518 mDimSurface.setPosition(0, 0);
10519 mDimSurface.setSize(dw, dh);
10520 mDimSurface.show();
10521 } catch (RuntimeException e) {
10522 Slog.w(TAG, "Failure showing dim surface", e);
10523 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010524 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
10525 mLastDimWidth = dw;
10526 mLastDimHeight = dh;
10527 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010528 }
10529 }
10530
10531 /**
10532 * Set's the dim surface's layer and update dim parameters that will be used in
10533 * {@link updateSurface} after all windows are examined.
10534 */
10535 void updateParameters(WindowState w, long currentTime) {
10536 mDimSurface.setLayer(w.mAnimLayer-1);
10537
10538 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010539 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010540 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010541 if (mDimTargetAlpha != target) {
10542 // If the desired dim level has changed, then
10543 // start an animation to it.
10544 mLastDimAnimTime = currentTime;
10545 long duration = (w.mAnimating && w.mAnimation != null)
10546 ? w.mAnimation.computeDurationHint()
10547 : DEFAULT_DIM_DURATION;
10548 if (target > mDimTargetAlpha) {
10549 // This is happening behind the activity UI,
10550 // so we can make it run a little longer to
10551 // give a stronger impression without disrupting
10552 // the user.
10553 duration *= DIM_DURATION_MULTIPLIER;
10554 }
10555 if (duration < 1) {
10556 // Don't divide by zero
10557 duration = 1;
10558 }
10559 mDimTargetAlpha = target;
10560 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
10561 }
10562 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010563
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010564 /**
10565 * Updating the surface's alpha. Returns true if the animation continues, or returns
10566 * false when the animation is finished and the dim surface is hidden.
10567 */
10568 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
10569 if (!dimming) {
10570 if (mDimTargetAlpha != 0) {
10571 mLastDimAnimTime = currentTime;
10572 mDimTargetAlpha = 0;
10573 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
10574 }
10575 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010576
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010577 boolean animating = false;
10578 if (mLastDimAnimTime != 0) {
10579 mDimCurrentAlpha += mDimDeltaPerMs
10580 * (currentTime-mLastDimAnimTime);
10581 boolean more = true;
10582 if (displayFrozen) {
10583 // If the display is frozen, there is no reason to animate.
10584 more = false;
10585 } else if (mDimDeltaPerMs > 0) {
10586 if (mDimCurrentAlpha > mDimTargetAlpha) {
10587 more = false;
10588 }
10589 } else if (mDimDeltaPerMs < 0) {
10590 if (mDimCurrentAlpha < mDimTargetAlpha) {
10591 more = false;
10592 }
10593 } else {
10594 more = false;
10595 }
10596
10597 // Do we need to continue animating?
10598 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010599 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010600 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
10601 mLastDimAnimTime = currentTime;
10602 mDimSurface.setAlpha(mDimCurrentAlpha);
10603 animating = true;
10604 } else {
10605 mDimCurrentAlpha = mDimTargetAlpha;
10606 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010607 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010608 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
10609 mDimSurface.setAlpha(mDimCurrentAlpha);
10610 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010611 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010612 + ": HIDE");
10613 try {
10614 mDimSurface.hide();
10615 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010616 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010617 }
10618 mDimShown = false;
10619 }
10620 }
10621 }
10622 return animating;
10623 }
10624
10625 public void printTo(PrintWriter pw) {
10626 pw.print(" mDimShown="); pw.print(mDimShown);
10627 pw.print(" current="); pw.print(mDimCurrentAlpha);
10628 pw.print(" target="); pw.print(mDimTargetAlpha);
10629 pw.print(" delta="); pw.print(mDimDeltaPerMs);
10630 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
10631 }
10632 }
10633
10634 /**
10635 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
10636 * This is used for opening/closing transition for apps in compatible mode.
10637 */
10638 private static class FadeInOutAnimation extends Animation {
10639 int mWidth;
10640 boolean mFadeIn;
10641
10642 public FadeInOutAnimation(boolean fadeIn) {
10643 setInterpolator(new AccelerateInterpolator());
10644 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
10645 mFadeIn = fadeIn;
10646 }
10647
10648 @Override
10649 protected void applyTransformation(float interpolatedTime, Transformation t) {
10650 float x = interpolatedTime;
10651 if (!mFadeIn) {
10652 x = 1.0f - x; // reverse the interpolation for fade out
10653 }
10654 if (x < 0.5) {
10655 // move the window out of the screen.
10656 t.getMatrix().setTranslate(mWidth, 0);
10657 } else {
10658 t.getMatrix().setTranslate(0, 0);// show
10659 t.setAlpha((x - 0.5f) * 2);
10660 }
10661 }
10662
10663 @Override
10664 public void initialize(int width, int height, int parentWidth, int parentHeight) {
10665 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
10666 mWidth = width;
10667 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010668
10669 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070010670 public int getZAdjustment() {
10671 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010672 }
10673 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010674}