blob: 51467e8234fde7ef8736305e9414748df4bca5cc [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;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR;
27import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
28import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070029import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
31import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS;
33import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
34import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
35import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
36import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070037import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038
39import com.android.internal.app.IBatteryStats;
40import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080041import com.android.internal.policy.impl.PhoneWindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import com.android.internal.view.IInputContext;
43import com.android.internal.view.IInputMethodClient;
44import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080045import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import com.android.server.am.BatteryStatsService;
47
48import android.Manifest;
49import android.app.ActivityManagerNative;
50import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070051import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070052import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070054import android.content.Intent;
55import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import android.content.pm.ActivityInfo;
57import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070058import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059import android.content.res.Configuration;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070060import android.graphics.Canvas;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.graphics.Matrix;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070062import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import android.graphics.PixelFormat;
64import android.graphics.Rect;
65import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070066import android.graphics.Typeface;
67import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068import android.os.BatteryStats;
69import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070070import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071import android.os.Debug;
72import android.os.Handler;
73import android.os.IBinder;
74import android.os.LocalPowerManager;
75import android.os.Looper;
76import android.os.Message;
77import android.os.Parcel;
78import android.os.ParcelFileDescriptor;
79import android.os.Power;
80import android.os.PowerManager;
81import android.os.Process;
82import android.os.RemoteException;
83import android.os.ServiceManager;
84import android.os.SystemClock;
85import android.os.SystemProperties;
86import android.os.TokenWatcher;
87import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070088import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070090import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080091import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070093import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094import android.view.Display;
95import android.view.Gravity;
Jeff Brown00fa7bd2010-07-02 15:37:36 -070096import android.view.HapticFeedbackConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097import android.view.IApplicationToken;
98import android.view.IOnKeyguardExitResult;
99import android.view.IRotationWatcher;
100import android.view.IWindow;
101import android.view.IWindowManager;
102import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700103import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700104import android.view.InputDevice;
Jeff Brown6ec402b2010-07-28 15:48:59 -0700105import android.view.InputEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106import android.view.KeyEvent;
107import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108import android.view.Surface;
109import android.view.SurfaceSession;
110import android.view.View;
111import android.view.ViewTreeObserver;
112import android.view.WindowManager;
113import android.view.WindowManagerImpl;
114import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700115import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700117import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118import android.view.animation.Animation;
119import android.view.animation.AnimationUtils;
120import android.view.animation.Transformation;
121
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700122import java.io.BufferedReader;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700124import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125import java.io.File;
126import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700127import java.io.FileInputStream;
128import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129import java.io.IOException;
130import java.io.OutputStream;
131import java.io.OutputStreamWriter;
132import java.io.PrintWriter;
133import java.io.StringWriter;
134import java.net.Socket;
135import java.util.ArrayList;
136import java.util.HashMap;
137import java.util.HashSet;
138import java.util.Iterator;
139import java.util.List;
140
141/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700142public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700143 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 static final String TAG = "WindowManager";
145 static final boolean DEBUG = false;
146 static final boolean DEBUG_FOCUS = false;
147 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800148 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800149 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 static final boolean DEBUG_LAYERS = false;
151 static final boolean DEBUG_INPUT = false;
152 static final boolean DEBUG_INPUT_METHOD = false;
153 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700154 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700156 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 static final boolean DEBUG_APP_TRANSITIONS = false;
158 static final boolean DEBUG_STARTING_WINDOW = false;
159 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700160 static final boolean DEBUG_WALLPAPER = false;
Dianne Hackbornce73c1e2010-04-12 23:11:38 -0700161 static final boolean DEBUG_FREEZE = 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;
Romain Guy06882f82009-06-10 13:36:04 -07001792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001793 synchronized(mWindowMap) {
1794 // Instantiating a Display requires talking with the simulator,
1795 // so don't do it until we know the system is mostly up and
1796 // running.
1797 if (mDisplay == null) {
1798 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
1799 mDisplay = wm.getDefaultDisplay();
Christopher Tateb696aee2010-04-02 19:08:30 -07001800 mInitialDisplayWidth = mDisplay.getWidth();
1801 mInitialDisplayHeight = mDisplay.getHeight();
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001802 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001803 reportNewConfig = true;
1804 }
Romain Guy06882f82009-06-10 13:36:04 -07001805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001806 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001807 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001808 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1809 }
1810
1811 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001812 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001813 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001814 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001815 + attrs.token + ". Aborting.");
1816 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1817 }
1818 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1819 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001820 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001821 + attrs.token + ". Aborting.");
1822 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1823 }
1824 }
1825
1826 boolean addToken = false;
1827 WindowToken token = mTokenMap.get(attrs.token);
1828 if (token == null) {
1829 if (attrs.type >= FIRST_APPLICATION_WINDOW
1830 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001831 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001832 + attrs.token + ". Aborting.");
1833 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1834 }
1835 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001836 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001837 + attrs.token + ". Aborting.");
1838 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1839 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001840 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001841 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001842 + attrs.token + ". Aborting.");
1843 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1844 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001845 token = new WindowToken(attrs.token, -1, false);
1846 addToken = true;
1847 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1848 && attrs.type <= LAST_APPLICATION_WINDOW) {
1849 AppWindowToken atoken = token.appWindowToken;
1850 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001851 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001852 + token + ". Aborting.");
1853 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1854 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001855 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001856 + token + ". Aborting.");
1857 return WindowManagerImpl.ADD_APP_EXITING;
1858 }
1859 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1860 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001861 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001862 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1863 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1864 }
1865 } else if (attrs.type == TYPE_INPUT_METHOD) {
1866 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001867 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001868 + attrs.token + ". Aborting.");
1869 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1870 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001871 } else if (attrs.type == TYPE_WALLPAPER) {
1872 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001873 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001874 + attrs.token + ". Aborting.");
1875 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1876 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001877 }
1878
1879 win = new WindowState(session, client, token,
1880 attachedWindow, attrs, viewVisibility);
1881 if (win.mDeathRecipient == null) {
1882 // Client has apparently died, so there is no reason to
1883 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001884 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001885 + " that is dead, aborting.");
1886 return WindowManagerImpl.ADD_APP_EXITING;
1887 }
1888
1889 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001891 res = mPolicy.prepareAddWindowLw(win, attrs);
1892 if (res != WindowManagerImpl.ADD_OKAY) {
1893 return res;
1894 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001895
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001896 if (outInputChannel != null) {
1897 String name = win.makeInputChannelName();
1898 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1899 win.mInputChannel = inputChannels[0];
1900 inputChannels[1].transferToBinderOutParameter(outInputChannel);
1901
1902 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001903 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001904
1905 // From now on, no exceptions or errors allowed!
1906
1907 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001909 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001911 if (addToken) {
1912 mTokenMap.put(attrs.token, token);
1913 mTokenList.add(token);
1914 }
1915 win.attach();
1916 mWindowMap.put(client.asBinder(), win);
1917
1918 if (attrs.type == TYPE_APPLICATION_STARTING &&
1919 token.appWindowToken != null) {
1920 token.appWindowToken.startingWindow = win;
1921 }
1922
1923 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001924
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001925 if (attrs.type == TYPE_INPUT_METHOD) {
1926 mInputMethodWindow = win;
1927 addInputMethodWindowToListLocked(win);
1928 imMayMove = false;
1929 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1930 mInputMethodDialogs.add(win);
1931 addWindowToListInOrderLocked(win, true);
1932 adjustInputMethodDialogsLocked();
1933 imMayMove = false;
1934 } else {
1935 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001936 if (attrs.type == TYPE_WALLPAPER) {
1937 mLastWallpaperTimeoutTime = 0;
1938 adjustWallpaperWindowsLocked();
1939 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001940 adjustWallpaperWindowsLocked();
1941 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001942 }
Romain Guy06882f82009-06-10 13:36:04 -07001943
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001944 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001946 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001948 if (mInTouchMode) {
1949 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1950 }
1951 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1952 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1953 }
Romain Guy06882f82009-06-10 13:36:04 -07001954
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001955 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001956 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07001957 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
1958 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001959 imMayMove = false;
1960 }
1961 }
Romain Guy06882f82009-06-10 13:36:04 -07001962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001963 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07001964 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001965 }
Romain Guy06882f82009-06-10 13:36:04 -07001966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001967 assignLayersLocked();
1968 // Don't do layout here, the window must call
1969 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07001970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001971 //dump();
1972
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001973 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07001974 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001975 }
Jeff Brown349703e2010-06-22 01:27:15 -07001976
Joe Onorato8a9b2202010-02-26 18:56:32 -08001977 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001978 TAG, "New client " + client.asBinder()
1979 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001980
1981 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
1982 reportNewConfig = true;
1983 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001984 }
1985
1986 // sendNewConfiguration() checks caller permissions so we must call it with
1987 // privilege. updateOrientationFromAppTokens() clears and resets the caller
1988 // identity anyway, so it's safe to just clear & restore around this whole
1989 // block.
1990 final long origId = Binder.clearCallingIdentity();
1991 if (reportNewConfig) {
1992 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001993 }
1994 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07001995
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001996 return res;
1997 }
Romain Guy06882f82009-06-10 13:36:04 -07001998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001999 public void removeWindow(Session session, IWindow client) {
2000 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002001 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002002 if (win == null) {
2003 return;
2004 }
2005 removeWindowLocked(session, win);
2006 }
2007 }
Romain Guy06882f82009-06-10 13:36:04 -07002008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002009 public void removeWindowLocked(Session session, WindowState win) {
2010
Joe Onorato8a9b2202010-02-26 18:56:32 -08002011 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002012 TAG, "Remove " + win + " client="
2013 + Integer.toHexString(System.identityHashCode(
2014 win.mClient.asBinder()))
2015 + ", surface=" + win.mSurface);
2016
2017 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002018
2019 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002020
Joe Onorato8a9b2202010-02-26 18:56:32 -08002021 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002022 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2023 + " mExiting=" + win.mExiting
2024 + " isAnimating=" + win.isAnimating()
2025 + " app-animation="
2026 + (win.mAppToken != null ? win.mAppToken.animation : null)
2027 + " inPendingTransaction="
2028 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2029 + " mDisplayFrozen=" + mDisplayFrozen);
2030 // Visibility of the removed window. Will be used later to update orientation later on.
2031 boolean wasVisible = false;
2032 // First, see if we need to run an animation. If we do, we have
2033 // to hold off on removing the window until the animation is done.
2034 // If the display is frozen, just remove immediately, since the
2035 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002036 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002037 // If we are not currently running the exit animation, we
2038 // need to see about starting one.
2039 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002041 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2042 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2043 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2044 }
2045 // Try starting an animation.
2046 if (applyAnimationLocked(win, transit, false)) {
2047 win.mExiting = true;
2048 }
2049 }
2050 if (win.mExiting || win.isAnimating()) {
2051 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002052 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002053 win.mExiting = true;
2054 win.mRemoveOnExit = true;
2055 mLayoutNeeded = true;
2056 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2057 performLayoutAndPlaceSurfacesLocked();
2058 if (win.mAppToken != null) {
2059 win.mAppToken.updateReportedVisibilityLocked();
2060 }
2061 //dump();
2062 Binder.restoreCallingIdentity(origId);
2063 return;
2064 }
2065 }
2066
2067 removeWindowInnerLocked(session, win);
2068 // Removing a visible window will effect the computed orientation
2069 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002070 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002071 != mForcedAppOrientation
2072 && updateOrientationFromAppTokensLocked()) {
2073 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002074 }
2075 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2076 Binder.restoreCallingIdentity(origId);
2077 }
Romain Guy06882f82009-06-10 13:36:04 -07002078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002079 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002080 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002082 if (mInputMethodTarget == win) {
2083 moveInputMethodWindowsIfNeededLocked(false);
2084 }
Romain Guy06882f82009-06-10 13:36:04 -07002085
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002086 if (false) {
2087 RuntimeException e = new RuntimeException("here");
2088 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002089 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002090 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002092 mPolicy.removeWindowLw(win);
2093 win.removeLocked();
2094
2095 mWindowMap.remove(win.mClient.asBinder());
2096 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002097 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002098 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002099
2100 if (mInputMethodWindow == win) {
2101 mInputMethodWindow = null;
2102 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2103 mInputMethodDialogs.remove(win);
2104 }
Romain Guy06882f82009-06-10 13:36:04 -07002105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002106 final WindowToken token = win.mToken;
2107 final AppWindowToken atoken = win.mAppToken;
2108 token.windows.remove(win);
2109 if (atoken != null) {
2110 atoken.allAppWindows.remove(win);
2111 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002112 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002113 TAG, "**** Removing window " + win + ": count="
2114 + token.windows.size());
2115 if (token.windows.size() == 0) {
2116 if (!token.explicit) {
2117 mTokenMap.remove(token.token);
2118 mTokenList.remove(token);
2119 } else if (atoken != null) {
2120 atoken.firstWindowDrawn = false;
2121 }
2122 }
2123
2124 if (atoken != null) {
2125 if (atoken.startingWindow == win) {
2126 atoken.startingWindow = null;
2127 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2128 // If this is the last window and we had requested a starting
2129 // transition window, well there is no point now.
2130 atoken.startingData = null;
2131 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2132 // If this is the last window except for a starting transition
2133 // window, we need to get rid of the starting transition.
2134 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002135 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002136 + ": no more real windows");
2137 }
2138 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2139 mH.sendMessage(m);
2140 }
2141 }
Romain Guy06882f82009-06-10 13:36:04 -07002142
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002143 if (win.mAttrs.type == TYPE_WALLPAPER) {
2144 mLastWallpaperTimeoutTime = 0;
2145 adjustWallpaperWindowsLocked();
2146 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002147 adjustWallpaperWindowsLocked();
2148 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002150 if (!mInLayout) {
2151 assignLayersLocked();
2152 mLayoutNeeded = true;
2153 performLayoutAndPlaceSurfacesLocked();
2154 if (win.mAppToken != null) {
2155 win.mAppToken.updateReportedVisibilityLocked();
2156 }
2157 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002158
2159 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002160 }
2161
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002162 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2163 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2164 + ": " + msg + " / " + w.mAttrs.getTitle();
2165 if (where != null) {
2166 Slog.i(TAG, str, where);
2167 } else {
2168 Slog.i(TAG, str);
2169 }
2170 }
2171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002172 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2173 long origId = Binder.clearCallingIdentity();
2174 try {
2175 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002176 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002177 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002178 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002179 Surface.openTransaction();
2180 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002181 if (SHOW_TRANSACTIONS) logSurface(w,
2182 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002183 w.mSurface.setTransparentRegionHint(region);
2184 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002185 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002186 Surface.closeTransaction();
2187 }
2188 }
2189 }
2190 } finally {
2191 Binder.restoreCallingIdentity(origId);
2192 }
2193 }
2194
2195 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002196 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002197 Rect visibleInsets) {
2198 long origId = Binder.clearCallingIdentity();
2199 try {
2200 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002201 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002202 if (w != null) {
2203 w.mGivenInsetsPending = false;
2204 w.mGivenContentInsets.set(contentInsets);
2205 w.mGivenVisibleInsets.set(visibleInsets);
2206 w.mTouchableInsets = touchableInsets;
2207 mLayoutNeeded = true;
2208 performLayoutAndPlaceSurfacesLocked();
2209 }
2210 }
2211 } finally {
2212 Binder.restoreCallingIdentity(origId);
2213 }
2214 }
Romain Guy06882f82009-06-10 13:36:04 -07002215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002216 public void getWindowDisplayFrame(Session session, IWindow client,
2217 Rect outDisplayFrame) {
2218 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002219 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002220 if (win == null) {
2221 outDisplayFrame.setEmpty();
2222 return;
2223 }
2224 outDisplayFrame.set(win.mDisplayFrame);
2225 }
2226 }
2227
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002228 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2229 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002230 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2231 window.mWallpaperX = x;
2232 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002233 window.mWallpaperXStep = xStep;
2234 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002235 if (updateWallpaperOffsetLocked(window, true)) {
2236 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002237 }
2238 }
2239 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002240
Dianne Hackborn75804932009-10-20 20:15:20 -07002241 void wallpaperCommandComplete(IBinder window, Bundle result) {
2242 synchronized (mWindowMap) {
2243 if (mWaitingOnWallpaper != null &&
2244 mWaitingOnWallpaper.mClient.asBinder() == window) {
2245 mWaitingOnWallpaper = null;
2246 mWindowMap.notifyAll();
2247 }
2248 }
2249 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002250
Dianne Hackborn75804932009-10-20 20:15:20 -07002251 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2252 String action, int x, int y, int z, Bundle extras, boolean sync) {
2253 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2254 || window == mUpperWallpaperTarget) {
2255 boolean doWait = sync;
2256 int curTokenIndex = mWallpaperTokens.size();
2257 while (curTokenIndex > 0) {
2258 curTokenIndex--;
2259 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2260 int curWallpaperIndex = token.windows.size();
2261 while (curWallpaperIndex > 0) {
2262 curWallpaperIndex--;
2263 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2264 try {
2265 wallpaper.mClient.dispatchWallpaperCommand(action,
2266 x, y, z, extras, sync);
2267 // We only want to be synchronous with one wallpaper.
2268 sync = false;
2269 } catch (RemoteException e) {
2270 }
2271 }
2272 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002273
Dianne Hackborn75804932009-10-20 20:15:20 -07002274 if (doWait) {
2275 // XXX Need to wait for result.
2276 }
2277 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002278
Dianne Hackborn75804932009-10-20 20:15:20 -07002279 return null;
2280 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002282 public int relayoutWindow(Session session, IWindow client,
2283 WindowManager.LayoutParams attrs, int requestedWidth,
2284 int requestedHeight, int viewVisibility, boolean insetsPending,
2285 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002286 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002287 boolean displayed = false;
2288 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002289 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002290 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002292 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002293 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002294 if (win == null) {
2295 return 0;
2296 }
2297 win.mRequestedWidth = requestedWidth;
2298 win.mRequestedHeight = requestedHeight;
2299
2300 if (attrs != null) {
2301 mPolicy.adjustWindowParamsLw(attrs);
2302 }
Romain Guy06882f82009-06-10 13:36:04 -07002303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002304 int attrChanges = 0;
2305 int flagChanges = 0;
2306 if (attrs != null) {
2307 flagChanges = win.mAttrs.flags ^= attrs.flags;
2308 attrChanges = win.mAttrs.copyFrom(attrs);
2309 }
2310
Joe Onorato8a9b2202010-02-26 18:56:32 -08002311 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002312
2313 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2314 win.mAlpha = attrs.alpha;
2315 }
2316
2317 final boolean scaledWindow =
2318 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2319
2320 if (scaledWindow) {
2321 // requested{Width|Height} Surface's physical size
2322 // attrs.{width|height} Size on screen
2323 win.mHScale = (attrs.width != requestedWidth) ?
2324 (attrs.width / (float)requestedWidth) : 1.0f;
2325 win.mVScale = (attrs.height != requestedHeight) ?
2326 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002327 } else {
2328 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002329 }
2330
2331 boolean imMayMove = (flagChanges&(
2332 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2333 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002335 boolean focusMayChange = win.mViewVisibility != viewVisibility
2336 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2337 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002338
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002339 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2340 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002342 win.mRelayoutCalled = true;
2343 final int oldVisibility = win.mViewVisibility;
2344 win.mViewVisibility = viewVisibility;
2345 if (viewVisibility == View.VISIBLE &&
2346 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2347 displayed = !win.isVisibleLw();
2348 if (win.mExiting) {
2349 win.mExiting = false;
2350 win.mAnimation = null;
2351 }
2352 if (win.mDestroying) {
2353 win.mDestroying = false;
2354 mDestroySurface.remove(win);
2355 }
2356 if (oldVisibility == View.GONE) {
2357 win.mEnterAnimationPending = true;
2358 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002359 if (displayed) {
2360 if (win.mSurface != null && !win.mDrawPending
2361 && !win.mCommitDrawPending && !mDisplayFrozen
2362 && mPolicy.isScreenOn()) {
2363 applyEnterAnimationLocked(win);
2364 }
2365 if ((win.mAttrs.flags
2366 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2367 if (DEBUG_VISIBILITY) Slog.v(TAG,
2368 "Relayout window turning screen on: " + win);
2369 win.mTurnOnScreen = true;
2370 }
2371 int diff = 0;
2372 if (win.mConfiguration != mCurConfiguration
2373 && (win.mConfiguration == null
2374 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2375 win.mConfiguration = mCurConfiguration;
2376 if (DEBUG_CONFIGURATION) {
2377 Slog.i(TAG, "Window " + win + " visible with new config: "
2378 + win.mConfiguration + " / 0x"
2379 + Integer.toHexString(diff));
2380 }
2381 outConfig.setTo(mCurConfiguration);
2382 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002383 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002384 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2385 // To change the format, we need to re-build the surface.
2386 win.destroySurfaceLocked();
2387 displayed = true;
2388 }
2389 try {
2390 Surface surface = win.createSurfaceLocked();
2391 if (surface != null) {
2392 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002393 win.mReportDestroySurface = false;
2394 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002395 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002396 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002397 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002398 // For some reason there isn't a surface. Clear the
2399 // caller's object so they see the same state.
2400 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002401 }
2402 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002403 mInputMonitor.updateInputWindowsLw();
2404
Joe Onorato8a9b2202010-02-26 18:56:32 -08002405 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002406 + client + " (" + win.mAttrs.getTitle() + ")",
2407 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002408 Binder.restoreCallingIdentity(origId);
2409 return 0;
2410 }
2411 if (displayed) {
2412 focusMayChange = true;
2413 }
2414 if (win.mAttrs.type == TYPE_INPUT_METHOD
2415 && mInputMethodWindow == null) {
2416 mInputMethodWindow = win;
2417 imMayMove = true;
2418 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002419 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2420 && win.mAppToken != null
2421 && win.mAppToken.startingWindow != null) {
2422 // Special handling of starting window over the base
2423 // window of the app: propagate lock screen flags to it,
2424 // to provide the correct semantics while starting.
2425 final int mask =
2426 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002427 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2428 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002429 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2430 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2431 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002432 } else {
2433 win.mEnterAnimationPending = false;
2434 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002435 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002436 + ": mExiting=" + win.mExiting
2437 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002438 // If we are not currently running the exit animation, we
2439 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002440 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002441 // Try starting an animation; if there isn't one, we
2442 // can destroy the surface right away.
2443 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2444 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2445 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2446 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002447 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002448 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002449 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002450 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002451 } else if (win.isAnimating()) {
2452 // Currently in a hide animation... turn this into
2453 // an exit.
2454 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002455 } else if (win == mWallpaperTarget) {
2456 // If the wallpaper is currently behind this
2457 // window, we need to change both of them inside
2458 // of a transaction to avoid artifacts.
2459 win.mExiting = true;
2460 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002461 } else {
2462 if (mInputMethodWindow == win) {
2463 mInputMethodWindow = null;
2464 }
2465 win.destroySurfaceLocked();
2466 }
2467 }
2468 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002469
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002470 if (win.mSurface == null || (win.getAttrs().flags
2471 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2472 || win.mSurfacePendingDestroy) {
2473 // We are being called from a local process, which
2474 // means outSurface holds its current surface. Ensure the
2475 // surface object is cleared, but we don't want it actually
2476 // destroyed at this point.
2477 win.mSurfacePendingDestroy = false;
2478 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002479 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002480 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002481 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002482 "Keeping surface, will report destroy: " + win);
2483 win.mReportDestroySurface = true;
2484 outSurface.copyFrom(win.mSurface);
2485 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002486 }
2487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002488 if (focusMayChange) {
2489 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2490 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002491 imMayMove = false;
2492 }
2493 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2494 }
Romain Guy06882f82009-06-10 13:36:04 -07002495
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002496 // updateFocusedWindowLocked() already assigned layers so we only need to
2497 // reassign them at this point if the IM window state gets shuffled
2498 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002500 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002501 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2502 // Little hack here -- we -should- be able to rely on the
2503 // function to return true if the IME has moved and needs
2504 // its layer recomputed. However, if the IME was hidden
2505 // and isn't actually moved in the list, its layer may be
2506 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002507 assignLayers = true;
2508 }
2509 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002510 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002511 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002512 assignLayers = true;
2513 }
2514 }
Romain Guy06882f82009-06-10 13:36:04 -07002515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002516 mLayoutNeeded = true;
2517 win.mGivenInsetsPending = insetsPending;
2518 if (assignLayers) {
2519 assignLayersLocked();
2520 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002521 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002522 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002523 if (displayed && win.mIsWallpaper) {
2524 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002525 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002526 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002527 if (win.mAppToken != null) {
2528 win.mAppToken.updateReportedVisibilityLocked();
2529 }
2530 outFrame.set(win.mFrame);
2531 outContentInsets.set(win.mContentInsets);
2532 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002533 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002534 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002535 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002536 + ", requestedHeight=" + requestedHeight
2537 + ", viewVisibility=" + viewVisibility
2538 + "\nRelayout returning frame=" + outFrame
2539 + ", surface=" + outSurface);
2540
Joe Onorato8a9b2202010-02-26 18:56:32 -08002541 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002542 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2543
2544 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002545
2546 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002547 }
2548
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002549 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002550 sendNewConfiguration();
2551 }
Romain Guy06882f82009-06-10 13:36:04 -07002552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002553 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002555 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2556 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2557 }
2558
2559 public void finishDrawingWindow(Session session, IWindow client) {
2560 final long origId = Binder.clearCallingIdentity();
2561 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002562 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002563 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002564 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2565 adjustWallpaperWindowsLocked();
2566 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002567 mLayoutNeeded = true;
2568 performLayoutAndPlaceSurfacesLocked();
2569 }
2570 }
2571 Binder.restoreCallingIdentity(origId);
2572 }
2573
2574 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002575 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002576 + (lp != null ? lp.packageName : null)
2577 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2578 if (lp != null && lp.windowAnimations != 0) {
2579 // If this is a system resource, don't try to load it from the
2580 // application resources. It is nice to avoid loading application
2581 // resources if we can.
2582 String packageName = lp.packageName != null ? lp.packageName : "android";
2583 int resId = lp.windowAnimations;
2584 if ((resId&0xFF000000) == 0x01000000) {
2585 packageName = "android";
2586 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002587 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002588 + packageName);
2589 return AttributeCache.instance().get(packageName, resId,
2590 com.android.internal.R.styleable.WindowAnimation);
2591 }
2592 return null;
2593 }
Romain Guy06882f82009-06-10 13:36:04 -07002594
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002595 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002596 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002597 + packageName + " resId=0x" + Integer.toHexString(resId));
2598 if (packageName != null) {
2599 if ((resId&0xFF000000) == 0x01000000) {
2600 packageName = "android";
2601 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002602 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002603 + packageName);
2604 return AttributeCache.instance().get(packageName, resId,
2605 com.android.internal.R.styleable.WindowAnimation);
2606 }
2607 return null;
2608 }
2609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002610 private void applyEnterAnimationLocked(WindowState win) {
2611 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2612 if (win.mEnterAnimationPending) {
2613 win.mEnterAnimationPending = false;
2614 transit = WindowManagerPolicy.TRANSIT_ENTER;
2615 }
2616
2617 applyAnimationLocked(win, transit, true);
2618 }
2619
2620 private boolean applyAnimationLocked(WindowState win,
2621 int transit, boolean isEntrance) {
2622 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2623 // If we are trying to apply an animation, but already running
2624 // an animation of the same type, then just leave that one alone.
2625 return true;
2626 }
Romain Guy06882f82009-06-10 13:36:04 -07002627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002628 // Only apply an animation if the display isn't frozen. If it is
2629 // frozen, there is no reason to animate and it can cause strange
2630 // artifacts when we unfreeze the display if some different animation
2631 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002632 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002633 int anim = mPolicy.selectAnimationLw(win, transit);
2634 int attr = -1;
2635 Animation a = null;
2636 if (anim != 0) {
2637 a = AnimationUtils.loadAnimation(mContext, anim);
2638 } else {
2639 switch (transit) {
2640 case WindowManagerPolicy.TRANSIT_ENTER:
2641 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2642 break;
2643 case WindowManagerPolicy.TRANSIT_EXIT:
2644 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2645 break;
2646 case WindowManagerPolicy.TRANSIT_SHOW:
2647 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2648 break;
2649 case WindowManagerPolicy.TRANSIT_HIDE:
2650 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2651 break;
2652 }
2653 if (attr >= 0) {
2654 a = loadAnimation(win.mAttrs, attr);
2655 }
2656 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002657 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002658 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2659 + " mAnimation=" + win.mAnimation
2660 + " isEntrance=" + isEntrance);
2661 if (a != null) {
2662 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002663 RuntimeException e = null;
2664 if (!HIDE_STACK_CRAWLS) {
2665 e = new RuntimeException();
2666 e.fillInStackTrace();
2667 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002668 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002669 }
2670 win.setAnimation(a);
2671 win.mAnimationIsEntrance = isEntrance;
2672 }
2673 } else {
2674 win.clearAnimation();
2675 }
2676
2677 return win.mAnimation != null;
2678 }
2679
2680 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2681 int anim = 0;
2682 Context context = mContext;
2683 if (animAttr >= 0) {
2684 AttributeCache.Entry ent = getCachedAnimations(lp);
2685 if (ent != null) {
2686 context = ent.context;
2687 anim = ent.array.getResourceId(animAttr, 0);
2688 }
2689 }
2690 if (anim != 0) {
2691 return AnimationUtils.loadAnimation(context, anim);
2692 }
2693 return null;
2694 }
Romain Guy06882f82009-06-10 13:36:04 -07002695
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002696 private Animation loadAnimation(String packageName, int resId) {
2697 int anim = 0;
2698 Context context = mContext;
2699 if (resId >= 0) {
2700 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2701 if (ent != null) {
2702 context = ent.context;
2703 anim = resId;
2704 }
2705 }
2706 if (anim != 0) {
2707 return AnimationUtils.loadAnimation(context, anim);
2708 }
2709 return null;
2710 }
2711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002712 private boolean applyAnimationLocked(AppWindowToken wtoken,
2713 WindowManager.LayoutParams lp, int transit, boolean enter) {
2714 // Only apply an animation if the display isn't frozen. If it is
2715 // frozen, there is no reason to animate and it can cause strange
2716 // artifacts when we unfreeze the display if some different animation
2717 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002718 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002719 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002720 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002721 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002722 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002723 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002724 } else if (mNextAppTransitionPackage != null) {
2725 a = loadAnimation(mNextAppTransitionPackage, enter ?
2726 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002727 } else {
2728 int animAttr = 0;
2729 switch (transit) {
2730 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2731 animAttr = enter
2732 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2733 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2734 break;
2735 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2736 animAttr = enter
2737 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2738 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2739 break;
2740 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2741 animAttr = enter
2742 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2743 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2744 break;
2745 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2746 animAttr = enter
2747 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2748 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2749 break;
2750 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2751 animAttr = enter
2752 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2753 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2754 break;
2755 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2756 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002757 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002758 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2759 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002760 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002761 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002762 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2763 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002764 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002765 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002766 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002767 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2768 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2769 break;
2770 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2771 animAttr = enter
2772 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2773 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2774 break;
2775 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2776 animAttr = enter
2777 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2778 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002779 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002780 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002781 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002782 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002783 + " anim=" + a
2784 + " animAttr=0x" + Integer.toHexString(animAttr)
2785 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002786 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002787 if (a != null) {
2788 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002789 RuntimeException e = null;
2790 if (!HIDE_STACK_CRAWLS) {
2791 e = new RuntimeException();
2792 e.fillInStackTrace();
2793 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002794 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002795 }
2796 wtoken.setAnimation(a);
2797 }
2798 } else {
2799 wtoken.clearAnimation();
2800 }
2801
2802 return wtoken.animation != null;
2803 }
2804
2805 // -------------------------------------------------------------
2806 // Application Window Tokens
2807 // -------------------------------------------------------------
2808
2809 public void validateAppTokens(List tokens) {
2810 int v = tokens.size()-1;
2811 int m = mAppTokens.size()-1;
2812 while (v >= 0 && m >= 0) {
2813 AppWindowToken wtoken = mAppTokens.get(m);
2814 if (wtoken.removed) {
2815 m--;
2816 continue;
2817 }
2818 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002819 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002820 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2821 }
2822 v--;
2823 m--;
2824 }
2825 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002826 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002827 v--;
2828 }
2829 while (m >= 0) {
2830 AppWindowToken wtoken = mAppTokens.get(m);
2831 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002832 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002833 }
2834 m--;
2835 }
2836 }
2837
2838 boolean checkCallingPermission(String permission, String func) {
2839 // Quick check: if the calling permission is me, it's all okay.
2840 if (Binder.getCallingPid() == Process.myPid()) {
2841 return true;
2842 }
Romain Guy06882f82009-06-10 13:36:04 -07002843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002844 if (mContext.checkCallingPermission(permission)
2845 == PackageManager.PERMISSION_GRANTED) {
2846 return true;
2847 }
2848 String msg = "Permission Denial: " + func + " from pid="
2849 + Binder.getCallingPid()
2850 + ", uid=" + Binder.getCallingUid()
2851 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002852 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002853 return false;
2854 }
Romain Guy06882f82009-06-10 13:36:04 -07002855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002856 AppWindowToken findAppWindowToken(IBinder token) {
2857 WindowToken wtoken = mTokenMap.get(token);
2858 if (wtoken == null) {
2859 return null;
2860 }
2861 return wtoken.appWindowToken;
2862 }
Romain Guy06882f82009-06-10 13:36:04 -07002863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002864 public void addWindowToken(IBinder token, int type) {
2865 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2866 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002867 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002868 }
Romain Guy06882f82009-06-10 13:36:04 -07002869
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002870 synchronized(mWindowMap) {
2871 WindowToken wtoken = mTokenMap.get(token);
2872 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002873 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002874 return;
2875 }
2876 wtoken = new WindowToken(token, type, true);
2877 mTokenMap.put(token, wtoken);
2878 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002879 if (type == TYPE_WALLPAPER) {
2880 mWallpaperTokens.add(wtoken);
2881 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002882 }
2883 }
Romain Guy06882f82009-06-10 13:36:04 -07002884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002885 public void removeWindowToken(IBinder token) {
2886 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2887 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002888 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002889 }
2890
2891 final long origId = Binder.clearCallingIdentity();
2892 synchronized(mWindowMap) {
2893 WindowToken wtoken = mTokenMap.remove(token);
2894 mTokenList.remove(wtoken);
2895 if (wtoken != null) {
2896 boolean delayed = false;
2897 if (!wtoken.hidden) {
2898 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002900 final int N = wtoken.windows.size();
2901 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002903 for (int i=0; i<N; i++) {
2904 WindowState win = wtoken.windows.get(i);
2905
2906 if (win.isAnimating()) {
2907 delayed = true;
2908 }
Romain Guy06882f82009-06-10 13:36:04 -07002909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002910 if (win.isVisibleNow()) {
2911 applyAnimationLocked(win,
2912 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002913 changed = true;
2914 }
2915 }
2916
2917 if (changed) {
2918 mLayoutNeeded = true;
2919 performLayoutAndPlaceSurfacesLocked();
2920 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2921 }
Romain Guy06882f82009-06-10 13:36:04 -07002922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002923 if (delayed) {
2924 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002925 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2926 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002927 }
2928 }
Romain Guy06882f82009-06-10 13:36:04 -07002929
Jeff Brownc5ed5912010-07-14 18:48:53 -07002930 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002931 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002932 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002933 }
2934 }
2935 Binder.restoreCallingIdentity(origId);
2936 }
2937
2938 public void addAppToken(int addPos, IApplicationToken token,
2939 int groupId, int requestedOrientation, boolean fullscreen) {
2940 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2941 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002942 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002943 }
Jeff Brown349703e2010-06-22 01:27:15 -07002944
2945 // Get the dispatching timeout here while we are not holding any locks so that it
2946 // can be cached by the AppWindowToken. The timeout value is used later by the
2947 // input dispatcher in code that does hold locks. If we did not cache the value
2948 // here we would run the chance of introducing a deadlock between the window manager
2949 // (which holds locks while updating the input dispatcher state) and the activity manager
2950 // (which holds locks while querying the application token).
2951 long inputDispatchingTimeoutNanos;
2952 try {
2953 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
2954 } catch (RemoteException ex) {
2955 Slog.w(TAG, "Could not get dispatching timeout.", ex);
2956 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
2957 }
Romain Guy06882f82009-06-10 13:36:04 -07002958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002959 synchronized(mWindowMap) {
2960 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2961 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002962 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002963 return;
2964 }
2965 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07002966 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002967 wtoken.groupId = groupId;
2968 wtoken.appFullscreen = fullscreen;
2969 wtoken.requestedOrientation = requestedOrientation;
2970 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002971 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002972 mTokenMap.put(token.asBinder(), wtoken);
2973 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002975 // Application tokens start out hidden.
2976 wtoken.hidden = true;
2977 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07002978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002979 //dump();
2980 }
2981 }
Romain Guy06882f82009-06-10 13:36:04 -07002982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002983 public void setAppGroupId(IBinder token, int groupId) {
2984 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2985 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002986 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002987 }
2988
2989 synchronized(mWindowMap) {
2990 AppWindowToken wtoken = findAppWindowToken(token);
2991 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002992 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002993 return;
2994 }
2995 wtoken.groupId = groupId;
2996 }
2997 }
Romain Guy06882f82009-06-10 13:36:04 -07002998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002999 public int getOrientationFromWindowsLocked() {
3000 int pos = mWindows.size() - 1;
3001 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003002 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003003 pos--;
3004 if (wtoken.mAppToken != null) {
3005 // We hit an application window. so the orientation will be determined by the
3006 // app window. No point in continuing further.
3007 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3008 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003009 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003010 continue;
3011 }
3012 int req = wtoken.mAttrs.screenOrientation;
3013 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3014 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3015 continue;
3016 } else {
3017 return req;
3018 }
3019 }
3020 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3021 }
Romain Guy06882f82009-06-10 13:36:04 -07003022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003023 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003024 int pos = mAppTokens.size() - 1;
3025 int curGroup = 0;
3026 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3027 boolean findingBehind = false;
3028 boolean haveGroup = false;
3029 boolean lastFullscreen = false;
3030 while (pos >= 0) {
3031 AppWindowToken wtoken = mAppTokens.get(pos);
3032 pos--;
3033 // if we're about to tear down this window and not seek for
3034 // the behind activity, don't use it for orientation
3035 if (!findingBehind
3036 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3037 continue;
3038 }
3039
3040 if (!haveGroup) {
3041 // We ignore any hidden applications on the top.
3042 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003043 continue;
3044 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003045 haveGroup = true;
3046 curGroup = wtoken.groupId;
3047 lastOrientation = wtoken.requestedOrientation;
3048 } else if (curGroup != wtoken.groupId) {
3049 // If we have hit a new application group, and the bottom
3050 // of the previous group didn't explicitly say to use
3051 // the orientation behind it, and the last app was
3052 // full screen, then we'll stick with the
3053 // user's orientation.
3054 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3055 && lastFullscreen) {
3056 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003057 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003058 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003059 int or = wtoken.requestedOrientation;
3060 // If this application is fullscreen, and didn't explicitly say
3061 // to use the orientation behind it, then just take whatever
3062 // orientation it has and ignores whatever is under it.
3063 lastFullscreen = wtoken.appFullscreen;
3064 if (lastFullscreen
3065 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3066 return or;
3067 }
3068 // If this application has requested an explicit orientation,
3069 // then use it.
3070 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
3071 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
3072 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
3073 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
3074 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
3075 return or;
3076 }
3077 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3078 }
3079 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003080 }
Romain Guy06882f82009-06-10 13:36:04 -07003081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003082 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003083 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003084 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3085 "updateOrientationFromAppTokens()")) {
3086 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3087 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003088
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003089 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003090 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003091
3092 synchronized(mWindowMap) {
3093 if (updateOrientationFromAppTokensLocked()) {
3094 if (freezeThisOneIfNeeded != null) {
3095 AppWindowToken wtoken = findAppWindowToken(
3096 freezeThisOneIfNeeded);
3097 if (wtoken != null) {
3098 startAppFreezingScreenLocked(wtoken,
3099 ActivityInfo.CONFIG_ORIENTATION);
3100 }
3101 }
3102 config = computeNewConfigurationLocked();
3103
3104 } else if (currentConfig != null) {
3105 // No obvious action we need to take, but if our current
repo sync . build/envsetup.sh lunch passion-eng4fc3d2f2010-09-27 17:39:50 -07003106 // state mismatches the activity manager's, update it,
3107 // disregarding font scale, which should remain set to
3108 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003109 mTempConfiguration.setToDefaults();
repo sync . build/envsetup.sh lunch passion-eng4fc3d2f2010-09-27 17:39:50 -07003110 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003111 if (computeNewConfigurationLocked(mTempConfiguration)) {
3112 if (currentConfig.diff(mTempConfiguration) != 0) {
3113 mWaitingForConfig = true;
3114 mLayoutNeeded = true;
3115 startFreezingDisplayLocked();
3116 config = new Configuration(mTempConfiguration);
3117 }
3118 }
3119 }
3120 }
3121
Dianne Hackborncfaef692009-06-15 14:24:44 -07003122 Binder.restoreCallingIdentity(ident);
3123 return config;
3124 }
3125
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003126 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003127 * Determine the new desired orientation of the display, returning
3128 * a non-null new Configuration if it has changed from the current
3129 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3130 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3131 * SCREEN. This will typically be done for you if you call
3132 * sendNewConfiguration().
3133 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003134 * The orientation is computed from non-application windows first. If none of
3135 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003136 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003137 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3138 * android.os.IBinder)
3139 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003140 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003141 if (mDisplayFrozen) {
3142 // If the display is frozen, some activities may be in the middle
3143 // of restarting, and thus have removed their old window. If the
3144 // window has the flag to hide the lock screen, then the lock screen
3145 // can re-appear and inflict its own orientation on us. Keep the
3146 // orientation stable until this all settles down.
3147 return false;
3148 }
3149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003150 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003151 long ident = Binder.clearCallingIdentity();
3152 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003153 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003155 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003156 mForcedAppOrientation = req;
3157 //send a message to Policy indicating orientation change to take
3158 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003159 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003160 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3161 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3162 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003163 }
3164 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003165
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003166 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003167 } finally {
3168 Binder.restoreCallingIdentity(ident);
3169 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003170 }
Romain Guy06882f82009-06-10 13:36:04 -07003171
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003172 int computeForcedAppOrientationLocked() {
3173 int req = getOrientationFromWindowsLocked();
3174 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3175 req = getOrientationFromAppTokensLocked();
3176 }
3177 return req;
3178 }
Romain Guy06882f82009-06-10 13:36:04 -07003179
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003180 public void setNewConfiguration(Configuration config) {
3181 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3182 "setNewConfiguration()")) {
3183 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3184 }
3185
3186 synchronized(mWindowMap) {
3187 mCurConfiguration = new Configuration(config);
3188 mWaitingForConfig = false;
3189 performLayoutAndPlaceSurfacesLocked();
3190 }
3191 }
3192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003193 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3194 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3195 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003196 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003197 }
Romain Guy06882f82009-06-10 13:36:04 -07003198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003199 synchronized(mWindowMap) {
3200 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3201 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003202 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003203 return;
3204 }
Romain Guy06882f82009-06-10 13:36:04 -07003205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003206 wtoken.requestedOrientation = requestedOrientation;
3207 }
3208 }
Romain Guy06882f82009-06-10 13:36:04 -07003209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003210 public int getAppOrientation(IApplicationToken token) {
3211 synchronized(mWindowMap) {
3212 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3213 if (wtoken == null) {
3214 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3215 }
Romain Guy06882f82009-06-10 13:36:04 -07003216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003217 return wtoken.requestedOrientation;
3218 }
3219 }
Romain Guy06882f82009-06-10 13:36:04 -07003220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003221 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3222 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3223 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003224 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003225 }
3226
3227 synchronized(mWindowMap) {
3228 boolean changed = false;
3229 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003230 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003231 changed = mFocusedApp != null;
3232 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003233 if (changed) {
3234 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003235 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003236 } else {
3237 AppWindowToken newFocus = findAppWindowToken(token);
3238 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003239 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003240 return;
3241 }
3242 changed = mFocusedApp != newFocus;
3243 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003244 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003245 if (changed) {
3246 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003247 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003248 }
3249
3250 if (moveFocusNow && changed) {
3251 final long origId = Binder.clearCallingIdentity();
3252 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3253 Binder.restoreCallingIdentity(origId);
3254 }
3255 }
3256 }
3257
3258 public void prepareAppTransition(int transit) {
3259 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3260 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003261 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003262 }
Romain Guy06882f82009-06-10 13:36:04 -07003263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003264 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003265 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003266 TAG, "Prepare app transition: transit=" + transit
3267 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003268 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003269 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3270 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003271 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003272 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3273 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3274 // Opening a new task always supersedes a close for the anim.
3275 mNextAppTransition = transit;
3276 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3277 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3278 // Opening a new activity always supersedes a close for the anim.
3279 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003280 }
3281 mAppTransitionReady = false;
3282 mAppTransitionTimeout = false;
3283 mStartingIconInTransition = false;
3284 mSkipAppTransitionAnimation = false;
3285 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3286 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3287 5000);
3288 }
3289 }
3290 }
3291
3292 public int getPendingAppTransition() {
3293 return mNextAppTransition;
3294 }
Romain Guy06882f82009-06-10 13:36:04 -07003295
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003296 public void overridePendingAppTransition(String packageName,
3297 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003298 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003299 mNextAppTransitionPackage = packageName;
3300 mNextAppTransitionEnter = enterAnim;
3301 mNextAppTransitionExit = exitAnim;
3302 }
3303 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003305 public void executeAppTransition() {
3306 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3307 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003308 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003309 }
Romain Guy06882f82009-06-10 13:36:04 -07003310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003311 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003312 if (DEBUG_APP_TRANSITIONS) {
3313 RuntimeException e = new RuntimeException("here");
3314 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003315 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003316 + mNextAppTransition, e);
3317 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003318 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003319 mAppTransitionReady = true;
3320 final long origId = Binder.clearCallingIdentity();
3321 performLayoutAndPlaceSurfacesLocked();
3322 Binder.restoreCallingIdentity(origId);
3323 }
3324 }
3325 }
3326
3327 public void setAppStartingWindow(IBinder token, String pkg,
3328 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3329 IBinder transferFrom, boolean createIfNeeded) {
3330 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3331 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003332 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003333 }
3334
3335 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003336 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003337 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3338 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003340 AppWindowToken wtoken = findAppWindowToken(token);
3341 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003342 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003343 return;
3344 }
3345
3346 // If the display is frozen, we won't do anything until the
3347 // actual window is displayed so there is no reason to put in
3348 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003349 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003350 return;
3351 }
Romain Guy06882f82009-06-10 13:36:04 -07003352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003353 if (wtoken.startingData != null) {
3354 return;
3355 }
Romain Guy06882f82009-06-10 13:36:04 -07003356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003357 if (transferFrom != null) {
3358 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3359 if (ttoken != null) {
3360 WindowState startingWindow = ttoken.startingWindow;
3361 if (startingWindow != null) {
3362 if (mStartingIconInTransition) {
3363 // In this case, the starting icon has already
3364 // been displayed, so start letting windows get
3365 // shown immediately without any more transitions.
3366 mSkipAppTransitionAnimation = true;
3367 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003368 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003369 "Moving existing starting from " + ttoken
3370 + " to " + wtoken);
3371 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003373 // Transfer the starting window over to the new
3374 // token.
3375 wtoken.startingData = ttoken.startingData;
3376 wtoken.startingView = ttoken.startingView;
3377 wtoken.startingWindow = startingWindow;
3378 ttoken.startingData = null;
3379 ttoken.startingView = null;
3380 ttoken.startingWindow = null;
3381 ttoken.startingMoved = true;
3382 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003383 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003384 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003385 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003386 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003387 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003388 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003389 ttoken.windows.remove(startingWindow);
3390 ttoken.allAppWindows.remove(startingWindow);
3391 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003393 // Propagate other interesting state between the
3394 // tokens. If the old token is displayed, we should
3395 // immediately force the new one to be displayed. If
3396 // it is animating, we need to move that animation to
3397 // the new one.
3398 if (ttoken.allDrawn) {
3399 wtoken.allDrawn = true;
3400 }
3401 if (ttoken.firstWindowDrawn) {
3402 wtoken.firstWindowDrawn = true;
3403 }
3404 if (!ttoken.hidden) {
3405 wtoken.hidden = false;
3406 wtoken.hiddenRequested = false;
3407 wtoken.willBeHidden = false;
3408 }
3409 if (wtoken.clientHidden != ttoken.clientHidden) {
3410 wtoken.clientHidden = ttoken.clientHidden;
3411 wtoken.sendAppVisibilityToClients();
3412 }
3413 if (ttoken.animation != null) {
3414 wtoken.animation = ttoken.animation;
3415 wtoken.animating = ttoken.animating;
3416 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3417 ttoken.animation = null;
3418 ttoken.animLayerAdjustment = 0;
3419 wtoken.updateLayers();
3420 ttoken.updateLayers();
3421 }
Romain Guy06882f82009-06-10 13:36:04 -07003422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003423 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003424 mLayoutNeeded = true;
3425 performLayoutAndPlaceSurfacesLocked();
3426 Binder.restoreCallingIdentity(origId);
3427 return;
3428 } else if (ttoken.startingData != null) {
3429 // The previous app was getting ready to show a
3430 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003431 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003432 "Moving pending starting from " + ttoken
3433 + " to " + wtoken);
3434 wtoken.startingData = ttoken.startingData;
3435 ttoken.startingData = null;
3436 ttoken.startingMoved = true;
3437 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3438 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3439 // want to process the message ASAP, before any other queued
3440 // messages.
3441 mH.sendMessageAtFrontOfQueue(m);
3442 return;
3443 }
3444 }
3445 }
3446
3447 // There is no existing starting window, and the caller doesn't
3448 // want us to create one, so that's it!
3449 if (!createIfNeeded) {
3450 return;
3451 }
Romain Guy06882f82009-06-10 13:36:04 -07003452
Dianne Hackborn284ac932009-08-28 10:34:25 -07003453 // If this is a translucent or wallpaper window, then don't
3454 // show a starting window -- the current effect (a full-screen
3455 // opaque starting window that fades away to the real contents
3456 // when it is ready) does not work for this.
3457 if (theme != 0) {
3458 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3459 com.android.internal.R.styleable.Window);
3460 if (ent.array.getBoolean(
3461 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3462 return;
3463 }
3464 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003465 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3466 return;
3467 }
3468 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003469 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3470 return;
3471 }
3472 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003474 mStartingIconInTransition = true;
3475 wtoken.startingData = new StartingData(
3476 pkg, theme, nonLocalizedLabel,
3477 labelRes, icon);
3478 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3479 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3480 // want to process the message ASAP, before any other queued
3481 // messages.
3482 mH.sendMessageAtFrontOfQueue(m);
3483 }
3484 }
3485
3486 public void setAppWillBeHidden(IBinder token) {
3487 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3488 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003489 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003490 }
3491
3492 AppWindowToken wtoken;
3493
3494 synchronized(mWindowMap) {
3495 wtoken = findAppWindowToken(token);
3496 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003497 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 -08003498 return;
3499 }
3500 wtoken.willBeHidden = true;
3501 }
3502 }
Romain Guy06882f82009-06-10 13:36:04 -07003503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003504 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3505 boolean visible, int transit, boolean performLayout) {
3506 boolean delayed = false;
3507
3508 if (wtoken.clientHidden == visible) {
3509 wtoken.clientHidden = !visible;
3510 wtoken.sendAppVisibilityToClients();
3511 }
Romain Guy06882f82009-06-10 13:36:04 -07003512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003513 wtoken.willBeHidden = false;
3514 if (wtoken.hidden == visible) {
3515 final int N = wtoken.allAppWindows.size();
3516 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003517 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003518 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3519 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003521 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003522
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003523 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003524 if (wtoken.animation == sDummyAnimation) {
3525 wtoken.animation = null;
3526 }
3527 applyAnimationLocked(wtoken, lp, transit, visible);
3528 changed = true;
3529 if (wtoken.animation != null) {
3530 delayed = runningAppAnimation = true;
3531 }
3532 }
Romain Guy06882f82009-06-10 13:36:04 -07003533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003534 for (int i=0; i<N; i++) {
3535 WindowState win = wtoken.allAppWindows.get(i);
3536 if (win == wtoken.startingWindow) {
3537 continue;
3538 }
3539
3540 if (win.isAnimating()) {
3541 delayed = true;
3542 }
Romain Guy06882f82009-06-10 13:36:04 -07003543
Joe Onorato8a9b2202010-02-26 18:56:32 -08003544 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003545 //win.dump(" ");
3546 if (visible) {
3547 if (!win.isVisibleNow()) {
3548 if (!runningAppAnimation) {
3549 applyAnimationLocked(win,
3550 WindowManagerPolicy.TRANSIT_ENTER, true);
3551 }
3552 changed = true;
3553 }
3554 } else if (win.isVisibleNow()) {
3555 if (!runningAppAnimation) {
3556 applyAnimationLocked(win,
3557 WindowManagerPolicy.TRANSIT_EXIT, false);
3558 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003559 changed = true;
3560 }
3561 }
3562
3563 wtoken.hidden = wtoken.hiddenRequested = !visible;
3564 if (!visible) {
3565 unsetAppFreezingScreenLocked(wtoken, true, true);
3566 } else {
3567 // If we are being set visible, and the starting window is
3568 // not yet displayed, then make sure it doesn't get displayed.
3569 WindowState swin = wtoken.startingWindow;
3570 if (swin != null && (swin.mDrawPending
3571 || swin.mCommitDrawPending)) {
3572 swin.mPolicyVisibility = false;
3573 swin.mPolicyVisibilityAfterAnim = false;
3574 }
3575 }
Romain Guy06882f82009-06-10 13:36:04 -07003576
Joe Onorato8a9b2202010-02-26 18:56:32 -08003577 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003578 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3579 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003580
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003581 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003582 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003583 if (performLayout) {
3584 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3585 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003586 } else {
3587 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003588 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003589 }
3590 }
3591
3592 if (wtoken.animation != null) {
3593 delayed = true;
3594 }
Romain Guy06882f82009-06-10 13:36:04 -07003595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003596 return delayed;
3597 }
3598
3599 public void setAppVisibility(IBinder token, boolean visible) {
3600 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3601 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003602 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003603 }
3604
3605 AppWindowToken wtoken;
3606
3607 synchronized(mWindowMap) {
3608 wtoken = findAppWindowToken(token);
3609 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003610 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003611 return;
3612 }
3613
3614 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003615 RuntimeException e = null;
3616 if (!HIDE_STACK_CRAWLS) {
3617 e = new RuntimeException();
3618 e.fillInStackTrace();
3619 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003620 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003621 + "): mNextAppTransition=" + mNextAppTransition
3622 + " hidden=" + wtoken.hidden
3623 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3624 }
Romain Guy06882f82009-06-10 13:36:04 -07003625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003626 // If we are preparing an app transition, then delay changing
3627 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003628 if (!mDisplayFrozen && mPolicy.isScreenOn()
3629 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003630 // Already in requested state, don't do anything more.
3631 if (wtoken.hiddenRequested != visible) {
3632 return;
3633 }
3634 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003635
Joe Onorato8a9b2202010-02-26 18:56:32 -08003636 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003637 TAG, "Setting dummy animation on: " + wtoken);
3638 wtoken.setDummyAnimation();
3639 mOpeningApps.remove(wtoken);
3640 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003641 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003642 wtoken.inPendingTransaction = true;
3643 if (visible) {
3644 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003645 wtoken.startingDisplayed = false;
3646 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003647
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003648 // If the token is currently hidden (should be the
3649 // common case), then we need to set up to wait for
3650 // its windows to be ready.
3651 if (wtoken.hidden) {
3652 wtoken.allDrawn = false;
3653 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003654
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003655 if (wtoken.clientHidden) {
3656 // In the case where we are making an app visible
3657 // but holding off for a transition, we still need
3658 // to tell the client to make its windows visible so
3659 // they get drawn. Otherwise, we will wait on
3660 // performing the transition until all windows have
3661 // been drawn, they never will be, and we are sad.
3662 wtoken.clientHidden = false;
3663 wtoken.sendAppVisibilityToClients();
3664 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003665 }
3666 } else {
3667 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003668
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003669 // If the token is currently visible (should be the
3670 // common case), then set up to wait for it to be hidden.
3671 if (!wtoken.hidden) {
3672 wtoken.waitingToHide = true;
3673 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003674 }
3675 return;
3676 }
Romain Guy06882f82009-06-10 13:36:04 -07003677
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003678 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003679 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003680 wtoken.updateReportedVisibilityLocked();
3681 Binder.restoreCallingIdentity(origId);
3682 }
3683 }
3684
3685 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3686 boolean unfreezeSurfaceNow, boolean force) {
3687 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003688 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003689 + " force=" + force);
3690 final int N = wtoken.allAppWindows.size();
3691 boolean unfrozeWindows = false;
3692 for (int i=0; i<N; i++) {
3693 WindowState w = wtoken.allAppWindows.get(i);
3694 if (w.mAppFreezing) {
3695 w.mAppFreezing = false;
3696 if (w.mSurface != null && !w.mOrientationChanging) {
3697 w.mOrientationChanging = true;
3698 }
3699 unfrozeWindows = true;
3700 }
3701 }
3702 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003703 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003704 wtoken.freezingScreen = false;
3705 mAppsFreezingScreen--;
3706 }
3707 if (unfreezeSurfaceNow) {
3708 if (unfrozeWindows) {
3709 mLayoutNeeded = true;
3710 performLayoutAndPlaceSurfacesLocked();
3711 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003712 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003713 }
3714 }
3715 }
Romain Guy06882f82009-06-10 13:36:04 -07003716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003717 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3718 int configChanges) {
3719 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003720 RuntimeException e = null;
3721 if (!HIDE_STACK_CRAWLS) {
3722 e = new RuntimeException();
3723 e.fillInStackTrace();
3724 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003725 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003726 + ": hidden=" + wtoken.hidden + " freezing="
3727 + wtoken.freezingScreen, e);
3728 }
3729 if (!wtoken.hiddenRequested) {
3730 if (!wtoken.freezingScreen) {
3731 wtoken.freezingScreen = true;
3732 mAppsFreezingScreen++;
3733 if (mAppsFreezingScreen == 1) {
3734 startFreezingDisplayLocked();
3735 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3736 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3737 5000);
3738 }
3739 }
3740 final int N = wtoken.allAppWindows.size();
3741 for (int i=0; i<N; i++) {
3742 WindowState w = wtoken.allAppWindows.get(i);
3743 w.mAppFreezing = true;
3744 }
3745 }
3746 }
Romain Guy06882f82009-06-10 13:36:04 -07003747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003748 public void startAppFreezingScreen(IBinder token, int configChanges) {
3749 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3750 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003751 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003752 }
3753
3754 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003755 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003756 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003757 return;
3758 }
Romain Guy06882f82009-06-10 13:36:04 -07003759
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003760 AppWindowToken wtoken = findAppWindowToken(token);
3761 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003762 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003763 return;
3764 }
3765 final long origId = Binder.clearCallingIdentity();
3766 startAppFreezingScreenLocked(wtoken, configChanges);
3767 Binder.restoreCallingIdentity(origId);
3768 }
3769 }
Romain Guy06882f82009-06-10 13:36:04 -07003770
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003771 public void stopAppFreezingScreen(IBinder token, boolean force) {
3772 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3773 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003774 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003775 }
3776
3777 synchronized(mWindowMap) {
3778 AppWindowToken wtoken = findAppWindowToken(token);
3779 if (wtoken == null || wtoken.appToken == null) {
3780 return;
3781 }
3782 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003783 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003784 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3785 unsetAppFreezingScreenLocked(wtoken, true, force);
3786 Binder.restoreCallingIdentity(origId);
3787 }
3788 }
Romain Guy06882f82009-06-10 13:36:04 -07003789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003790 public void removeAppToken(IBinder token) {
3791 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3792 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003793 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003794 }
3795
3796 AppWindowToken wtoken = null;
3797 AppWindowToken startingToken = null;
3798 boolean delayed = false;
3799
3800 final long origId = Binder.clearCallingIdentity();
3801 synchronized(mWindowMap) {
3802 WindowToken basewtoken = mTokenMap.remove(token);
3803 mTokenList.remove(basewtoken);
3804 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003805 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003806 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003807 wtoken.inPendingTransaction = false;
3808 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003809 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003810 if (mClosingApps.contains(wtoken)) {
3811 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003812 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003813 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003814 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003815 delayed = true;
3816 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003817 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003818 TAG, "Removing app " + wtoken + " delayed=" + delayed
3819 + " animation=" + wtoken.animation
3820 + " animating=" + wtoken.animating);
3821 if (delayed) {
3822 // set the token aside because it has an active animation to be finished
3823 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003824 } else {
3825 // Make sure there is no animation running on this token,
3826 // so any windows associated with it will be removed as
3827 // soon as their animations are complete
3828 wtoken.animation = null;
3829 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003830 }
3831 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003832 if (mLastEnterAnimToken == wtoken) {
3833 mLastEnterAnimToken = null;
3834 mLastEnterAnimParams = null;
3835 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003836 wtoken.removed = true;
3837 if (wtoken.startingData != null) {
3838 startingToken = wtoken;
3839 }
3840 unsetAppFreezingScreenLocked(wtoken, true, true);
3841 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003842 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003843 mFocusedApp = null;
3844 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003845 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003846 }
3847 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003848 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003849 }
Romain Guy06882f82009-06-10 13:36:04 -07003850
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003851 if (!delayed && wtoken != null) {
3852 wtoken.updateReportedVisibilityLocked();
3853 }
3854 }
3855 Binder.restoreCallingIdentity(origId);
3856
3857 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003858 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003859 + startingToken + ": app token removed");
3860 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3861 mH.sendMessage(m);
3862 }
3863 }
3864
3865 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3866 final int NW = token.windows.size();
3867 for (int i=0; i<NW; i++) {
3868 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003869 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003870 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003871 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003872 int j = win.mChildWindows.size();
3873 while (j > 0) {
3874 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003875 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003876 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003877 "Tmp removing child window " + cwin);
3878 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003879 }
3880 }
3881 return NW > 0;
3882 }
3883
3884 void dumpAppTokensLocked() {
3885 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003886 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003887 }
3888 }
Romain Guy06882f82009-06-10 13:36:04 -07003889
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003890 void dumpWindowsLocked() {
3891 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003892 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003893 }
3894 }
Romain Guy06882f82009-06-10 13:36:04 -07003895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003896 private int findWindowOffsetLocked(int tokenPos) {
3897 final int NW = mWindows.size();
3898
3899 if (tokenPos >= mAppTokens.size()) {
3900 int i = NW;
3901 while (i > 0) {
3902 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07003903 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003904 if (win.getAppToken() != null) {
3905 return i+1;
3906 }
3907 }
3908 }
3909
3910 while (tokenPos > 0) {
3911 // Find the first app token below the new position that has
3912 // a window displayed.
3913 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003914 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003915 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003916 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003917 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07003918 "Skipping token -- currently sending to bottom");
3919 tokenPos--;
3920 continue;
3921 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003922 int i = wtoken.windows.size();
3923 while (i > 0) {
3924 i--;
3925 WindowState win = wtoken.windows.get(i);
3926 int j = win.mChildWindows.size();
3927 while (j > 0) {
3928 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003929 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003930 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003931 for (int pos=NW-1; pos>=0; pos--) {
3932 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003933 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003934 "Found child win @" + (pos+1));
3935 return pos+1;
3936 }
3937 }
3938 }
3939 }
3940 for (int pos=NW-1; pos>=0; pos--) {
3941 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003942 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003943 return pos+1;
3944 }
3945 }
3946 }
3947 tokenPos--;
3948 }
3949
3950 return 0;
3951 }
3952
3953 private final int reAddWindowLocked(int index, WindowState win) {
3954 final int NCW = win.mChildWindows.size();
3955 boolean added = false;
3956 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07003957 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003958 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003959 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003960 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003961 mWindows.add(index, win);
3962 index++;
3963 added = true;
3964 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003965 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003966 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003967 mWindows.add(index, cwin);
3968 index++;
3969 }
3970 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003971 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003972 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003973 mWindows.add(index, win);
3974 index++;
3975 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003976 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003977 return index;
3978 }
Romain Guy06882f82009-06-10 13:36:04 -07003979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003980 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3981 final int NW = token.windows.size();
3982 for (int i=0; i<NW; i++) {
3983 index = reAddWindowLocked(index, token.windows.get(i));
3984 }
3985 return index;
3986 }
3987
3988 public void moveAppToken(int index, IBinder token) {
3989 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3990 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003991 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003992 }
3993
3994 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003995 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003996 if (DEBUG_REORDER) dumpAppTokensLocked();
3997 final AppWindowToken wtoken = findAppWindowToken(token);
3998 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003999 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004000 + token + " (" + wtoken + ")");
4001 return;
4002 }
4003 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004004 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004005 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004007 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004008 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004009 if (DEBUG_REORDER) dumpWindowsLocked();
4010 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004011 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004012 if (DEBUG_REORDER) dumpWindowsLocked();
4013 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004014 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004015 if (DEBUG_REORDER) dumpWindowsLocked();
4016 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004017 mLayoutNeeded = true;
4018 performLayoutAndPlaceSurfacesLocked();
4019 }
4020 Binder.restoreCallingIdentity(origId);
4021 }
4022 }
4023
4024 private void removeAppTokensLocked(List<IBinder> tokens) {
4025 // XXX This should be done more efficiently!
4026 // (take advantage of the fact that both lists should be
4027 // ordered in the same way.)
4028 int N = tokens.size();
4029 for (int i=0; i<N; i++) {
4030 IBinder token = tokens.get(i);
4031 final AppWindowToken wtoken = findAppWindowToken(token);
4032 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004033 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004034 + token + " (" + wtoken + ")");
4035 i--;
4036 N--;
4037 }
4038 }
4039 }
4040
Dianne Hackborna8f60182009-09-01 19:01:50 -07004041 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4042 boolean updateFocusAndLayout) {
4043 // First remove all of the windows from the list.
4044 tmpRemoveAppWindowsLocked(wtoken);
4045
4046 // Where to start adding?
4047 int pos = findWindowOffsetLocked(tokenPos);
4048
4049 // And now add them back at the correct place.
4050 pos = reAddAppWindowsLocked(pos, wtoken);
4051
4052 if (updateFocusAndLayout) {
4053 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4054 assignLayersLocked();
4055 }
4056 mLayoutNeeded = true;
4057 performLayoutAndPlaceSurfacesLocked();
4058 }
4059 }
4060
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004061 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4062 // First remove all of the windows from the list.
4063 final int N = tokens.size();
4064 int i;
4065 for (i=0; i<N; i++) {
4066 WindowToken token = mTokenMap.get(tokens.get(i));
4067 if (token != null) {
4068 tmpRemoveAppWindowsLocked(token);
4069 }
4070 }
4071
4072 // Where to start adding?
4073 int pos = findWindowOffsetLocked(tokenPos);
4074
4075 // And now add them back at the correct place.
4076 for (i=0; i<N; i++) {
4077 WindowToken token = mTokenMap.get(tokens.get(i));
4078 if (token != null) {
4079 pos = reAddAppWindowsLocked(pos, token);
4080 }
4081 }
4082
Dianne Hackborna8f60182009-09-01 19:01:50 -07004083 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4084 assignLayersLocked();
4085 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004086 mLayoutNeeded = true;
4087 performLayoutAndPlaceSurfacesLocked();
4088
4089 //dump();
4090 }
4091
4092 public void moveAppTokensToTop(List<IBinder> tokens) {
4093 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4094 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004095 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004096 }
4097
4098 final long origId = Binder.clearCallingIdentity();
4099 synchronized(mWindowMap) {
4100 removeAppTokensLocked(tokens);
4101 final int N = tokens.size();
4102 for (int i=0; i<N; i++) {
4103 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4104 if (wt != null) {
4105 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004106 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004107 mToTopApps.remove(wt);
4108 mToBottomApps.remove(wt);
4109 mToTopApps.add(wt);
4110 wt.sendingToBottom = false;
4111 wt.sendingToTop = true;
4112 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004113 }
4114 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004115
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004116 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004117 moveAppWindowsLocked(tokens, mAppTokens.size());
4118 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004119 }
4120 Binder.restoreCallingIdentity(origId);
4121 }
4122
4123 public void moveAppTokensToBottom(List<IBinder> tokens) {
4124 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4125 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004126 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004127 }
4128
4129 final long origId = Binder.clearCallingIdentity();
4130 synchronized(mWindowMap) {
4131 removeAppTokensLocked(tokens);
4132 final int N = tokens.size();
4133 int pos = 0;
4134 for (int i=0; i<N; i++) {
4135 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4136 if (wt != null) {
4137 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004138 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004139 mToTopApps.remove(wt);
4140 mToBottomApps.remove(wt);
4141 mToBottomApps.add(i, wt);
4142 wt.sendingToTop = false;
4143 wt.sendingToBottom = true;
4144 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004145 pos++;
4146 }
4147 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004148
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004149 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004150 moveAppWindowsLocked(tokens, 0);
4151 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004152 }
4153 Binder.restoreCallingIdentity(origId);
4154 }
4155
4156 // -------------------------------------------------------------
4157 // Misc IWindowSession methods
4158 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004159
Jim Miller284b62e2010-06-08 14:27:42 -07004160 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004161 {
Jim Miller284b62e2010-06-08 14:27:42 -07004162 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4163 // called before DevicePolicyManagerService has started.
4164 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4165 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4166 Context.DEVICE_POLICY_SERVICE);
4167 if (dpm != null) {
4168 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4169 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4170 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4171 }
Jim Millerd6b57052010-06-07 17:52:42 -07004172 }
Jim Miller284b62e2010-06-08 14:27:42 -07004173 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004174 }
4175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004176 public void disableKeyguard(IBinder token, String tag) {
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 }
Jim Millerd6b57052010-06-07 17:52:42 -07004181
Jim Miller284b62e2010-06-08 14:27:42 -07004182 synchronized (mKeyguardTokenWatcher) {
4183 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004184 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004185 }
4186
4187 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004188 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004189 != PackageManager.PERMISSION_GRANTED) {
4190 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4191 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004192
Jim Miller284b62e2010-06-08 14:27:42 -07004193 synchronized (mKeyguardTokenWatcher) {
4194 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004195
Jim Miller284b62e2010-06-08 14:27:42 -07004196 if (!mKeyguardTokenWatcher.isAcquired()) {
4197 // If we are the last one to reenable the keyguard wait until
4198 // we have actually finished reenabling until returning.
4199 // It is possible that reenableKeyguard() can be called before
4200 // the previous disableKeyguard() is handled, in which case
4201 // neither mKeyguardTokenWatcher.acquired() or released() would
4202 // be called. In that case mKeyguardDisabled will be false here
4203 // and we have nothing to wait for.
4204 while (mKeyguardDisabled) {
4205 try {
4206 mKeyguardTokenWatcher.wait();
4207 } catch (InterruptedException e) {
4208 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004209 }
4210 }
4211 }
4212 }
4213 }
4214
4215 /**
4216 * @see android.app.KeyguardManager#exitKeyguardSecurely
4217 */
4218 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004219 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004220 != PackageManager.PERMISSION_GRANTED) {
4221 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4222 }
4223 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4224 public void onKeyguardExitResult(boolean success) {
4225 try {
4226 callback.onKeyguardExitResult(success);
4227 } catch (RemoteException e) {
4228 // Client has died, we don't care.
4229 }
4230 }
4231 });
4232 }
4233
4234 public boolean inKeyguardRestrictedInputMode() {
4235 return mPolicy.inKeyguardRestrictedKeyInputMode();
4236 }
Romain Guy06882f82009-06-10 13:36:04 -07004237
Dianne Hackbornffa42482009-09-23 22:20:11 -07004238 public void closeSystemDialogs(String reason) {
4239 synchronized(mWindowMap) {
4240 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004241 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004242 if (w.mSurface != null) {
4243 try {
4244 w.mClient.closeSystemDialogs(reason);
4245 } catch (RemoteException e) {
4246 }
4247 }
4248 }
4249 }
4250 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004252 static float fixScale(float scale) {
4253 if (scale < 0) scale = 0;
4254 else if (scale > 20) scale = 20;
4255 return Math.abs(scale);
4256 }
Romain Guy06882f82009-06-10 13:36:04 -07004257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004258 public void setAnimationScale(int which, float scale) {
4259 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4260 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004261 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004262 }
4263
4264 if (scale < 0) scale = 0;
4265 else if (scale > 20) scale = 20;
4266 scale = Math.abs(scale);
4267 switch (which) {
4268 case 0: mWindowAnimationScale = fixScale(scale); break;
4269 case 1: mTransitionAnimationScale = fixScale(scale); break;
4270 }
Romain Guy06882f82009-06-10 13:36:04 -07004271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004272 // Persist setting
4273 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4274 }
Romain Guy06882f82009-06-10 13:36:04 -07004275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004276 public void setAnimationScales(float[] scales) {
4277 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4278 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004279 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004280 }
4281
4282 if (scales != null) {
4283 if (scales.length >= 1) {
4284 mWindowAnimationScale = fixScale(scales[0]);
4285 }
4286 if (scales.length >= 2) {
4287 mTransitionAnimationScale = fixScale(scales[1]);
4288 }
4289 }
Romain Guy06882f82009-06-10 13:36:04 -07004290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004291 // Persist setting
4292 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4293 }
Romain Guy06882f82009-06-10 13:36:04 -07004294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004295 public float getAnimationScale(int which) {
4296 switch (which) {
4297 case 0: return mWindowAnimationScale;
4298 case 1: return mTransitionAnimationScale;
4299 }
4300 return 0;
4301 }
Romain Guy06882f82009-06-10 13:36:04 -07004302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004303 public float[] getAnimationScales() {
4304 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4305 }
Romain Guy06882f82009-06-10 13:36:04 -07004306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004307 public int getSwitchState(int sw) {
4308 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4309 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004310 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004311 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004312 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004313 }
Romain Guy06882f82009-06-10 13:36:04 -07004314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004315 public int getSwitchStateForDevice(int devid, int sw) {
4316 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4317 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004318 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004319 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004320 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004321 }
Romain Guy06882f82009-06-10 13:36:04 -07004322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004323 public int getScancodeState(int sw) {
4324 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4325 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004326 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004327 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004328 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004329 }
Romain Guy06882f82009-06-10 13:36:04 -07004330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004331 public int getScancodeStateForDevice(int devid, int sw) {
4332 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4333 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004334 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004335 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004336 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004337 }
Romain Guy06882f82009-06-10 13:36:04 -07004338
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004339 public int getTrackballScancodeState(int sw) {
4340 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4341 "getTrackballScancodeState()")) {
4342 throw new SecurityException("Requires READ_INPUT_STATE permission");
4343 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004344 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004345 }
4346
4347 public int getDPadScancodeState(int sw) {
4348 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4349 "getDPadScancodeState()")) {
4350 throw new SecurityException("Requires READ_INPUT_STATE permission");
4351 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004352 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004353 }
4354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004355 public int getKeycodeState(int sw) {
4356 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4357 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004358 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004359 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004360 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004361 }
Romain Guy06882f82009-06-10 13:36:04 -07004362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004363 public int getKeycodeStateForDevice(int devid, int sw) {
4364 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4365 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004366 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004367 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004368 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004369 }
Romain Guy06882f82009-06-10 13:36:04 -07004370
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004371 public int getTrackballKeycodeState(int sw) {
4372 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4373 "getTrackballKeycodeState()")) {
4374 throw new SecurityException("Requires READ_INPUT_STATE permission");
4375 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004376 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004377 }
4378
4379 public int getDPadKeycodeState(int sw) {
4380 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4381 "getDPadKeycodeState()")) {
4382 throw new SecurityException("Requires READ_INPUT_STATE permission");
4383 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004384 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004385 }
Jeff Browna41ca772010-08-11 14:46:32 -07004386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004387 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004388 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004389 }
Romain Guy06882f82009-06-10 13:36:04 -07004390
Jeff Browna41ca772010-08-11 14:46:32 -07004391 public InputChannel monitorInput(String inputChannelName) {
4392 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4393 "monitorInput()")) {
4394 throw new SecurityException("Requires READ_INPUT_STATE permission");
4395 }
4396 return mInputManager.monitorInput(inputChannelName);
4397 }
4398
Jeff Brown8d608662010-08-30 03:02:23 -07004399 public InputDevice getInputDevice(int deviceId) {
4400 return mInputManager.getInputDevice(deviceId);
4401 }
4402
4403 public int[] getInputDeviceIds() {
4404 return mInputManager.getInputDeviceIds();
4405 }
4406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004407 public void enableScreenAfterBoot() {
4408 synchronized(mWindowMap) {
4409 if (mSystemBooted) {
4410 return;
4411 }
4412 mSystemBooted = true;
4413 }
Romain Guy06882f82009-06-10 13:36:04 -07004414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004415 performEnableScreen();
4416 }
Romain Guy06882f82009-06-10 13:36:04 -07004417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004418 public void enableScreenIfNeededLocked() {
4419 if (mDisplayEnabled) {
4420 return;
4421 }
4422 if (!mSystemBooted) {
4423 return;
4424 }
4425 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4426 }
Romain Guy06882f82009-06-10 13:36:04 -07004427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004428 public void performEnableScreen() {
4429 synchronized(mWindowMap) {
4430 if (mDisplayEnabled) {
4431 return;
4432 }
4433 if (!mSystemBooted) {
4434 return;
4435 }
Romain Guy06882f82009-06-10 13:36:04 -07004436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004437 // Don't enable the screen until all existing windows
4438 // have been drawn.
4439 final int N = mWindows.size();
4440 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004441 WindowState w = mWindows.get(i);
Dianne Hackborn5943c202010-04-12 21:36:49 -07004442 if (w.isVisibleLw() && !w.mObscured
4443 && (w.mOrientationChanging || !w.isDrawnLw())) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004444 return;
4445 }
4446 }
Romain Guy06882f82009-06-10 13:36:04 -07004447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004448 mDisplayEnabled = true;
4449 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004450 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004451 StringWriter sw = new StringWriter();
4452 PrintWriter pw = new PrintWriter(sw);
4453 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004454 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004455 }
4456 try {
4457 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4458 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004459 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004460 Parcel data = Parcel.obtain();
4461 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4462 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4463 data, null, 0);
4464 data.recycle();
4465 }
4466 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004467 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004468 }
4469 }
Romain Guy06882f82009-06-10 13:36:04 -07004470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004471 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004473 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004474 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4475 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004476 }
Romain Guy06882f82009-06-10 13:36:04 -07004477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004478 public void setInTouchMode(boolean mode) {
4479 synchronized(mWindowMap) {
4480 mInTouchMode = mode;
4481 }
4482 }
4483
Romain Guy06882f82009-06-10 13:36:04 -07004484 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004485 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004486 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004487 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004488 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004489 }
4490
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004491 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004492 }
Romain Guy06882f82009-06-10 13:36:04 -07004493
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004494 public void setRotationUnchecked(int rotation,
4495 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004496 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004497 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004499 long origId = Binder.clearCallingIdentity();
4500 boolean changed;
4501 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004502 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004503 }
Romain Guy06882f82009-06-10 13:36:04 -07004504
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004505 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004506 sendNewConfiguration();
4507 }
Romain Guy06882f82009-06-10 13:36:04 -07004508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004509 Binder.restoreCallingIdentity(origId);
4510 }
Romain Guy06882f82009-06-10 13:36:04 -07004511
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004512 /**
4513 * Apply a new rotation to the screen, respecting the requests of
4514 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4515 * re-evaluate the desired rotation.
4516 *
4517 * Returns null if the rotation has been changed. In this case YOU
4518 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4519 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004520 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004521 boolean changed;
4522 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4523 rotation = mRequestedRotation;
4524 } else {
4525 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004526 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004527 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004528 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004529 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004530 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004531 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004532 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004534 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004535 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004536 "Rotation changed to " + rotation
4537 + " from " + mRotation
4538 + " (forceApp=" + mForcedAppOrientation
4539 + ", req=" + mRequestedRotation + ")");
4540 mRotation = rotation;
4541 mWindowsFreezingScreen = true;
4542 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4543 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4544 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004545 mWaitingForConfig = true;
4546 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004547 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004548 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004549 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004550 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004551 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004552 }
4553 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004554 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004555 if (w.mSurface != null) {
4556 w.mOrientationChanging = true;
4557 }
4558 }
4559 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4560 try {
4561 mRotationWatchers.get(i).onRotationChanged(rotation);
4562 } catch (RemoteException e) {
4563 }
4564 }
4565 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004567 return changed;
4568 }
Romain Guy06882f82009-06-10 13:36:04 -07004569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004570 public int getRotation() {
4571 return mRotation;
4572 }
4573
4574 public int watchRotation(IRotationWatcher watcher) {
4575 final IBinder watcherBinder = watcher.asBinder();
4576 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4577 public void binderDied() {
4578 synchronized (mWindowMap) {
4579 for (int i=0; i<mRotationWatchers.size(); i++) {
4580 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004581 IRotationWatcher removed = mRotationWatchers.remove(i);
4582 if (removed != null) {
4583 removed.asBinder().unlinkToDeath(this, 0);
4584 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004585 i--;
4586 }
4587 }
4588 }
4589 }
4590 };
Romain Guy06882f82009-06-10 13:36:04 -07004591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004592 synchronized (mWindowMap) {
4593 try {
4594 watcher.asBinder().linkToDeath(dr, 0);
4595 mRotationWatchers.add(watcher);
4596 } catch (RemoteException e) {
4597 // Client died, no cleanup needed.
4598 }
Romain Guy06882f82009-06-10 13:36:04 -07004599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004600 return mRotation;
4601 }
4602 }
4603
4604 /**
4605 * Starts the view server on the specified port.
4606 *
4607 * @param port The port to listener to.
4608 *
4609 * @return True if the server was successfully started, false otherwise.
4610 *
4611 * @see com.android.server.ViewServer
4612 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4613 */
4614 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004615 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004616 return false;
4617 }
4618
4619 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4620 return false;
4621 }
4622
4623 if (port < 1024) {
4624 return false;
4625 }
4626
4627 if (mViewServer != null) {
4628 if (!mViewServer.isRunning()) {
4629 try {
4630 return mViewServer.start();
4631 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004632 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004633 }
4634 }
4635 return false;
4636 }
4637
4638 try {
4639 mViewServer = new ViewServer(this, port);
4640 return mViewServer.start();
4641 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004642 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004643 }
4644 return false;
4645 }
4646
Romain Guy06882f82009-06-10 13:36:04 -07004647 private boolean isSystemSecure() {
4648 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4649 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4650 }
4651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004652 /**
4653 * Stops the view server if it exists.
4654 *
4655 * @return True if the server stopped, false if it wasn't started or
4656 * couldn't be stopped.
4657 *
4658 * @see com.android.server.ViewServer
4659 */
4660 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004661 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004662 return false;
4663 }
4664
4665 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4666 return false;
4667 }
4668
4669 if (mViewServer != null) {
4670 return mViewServer.stop();
4671 }
4672 return false;
4673 }
4674
4675 /**
4676 * Indicates whether the view server is running.
4677 *
4678 * @return True if the server is running, false otherwise.
4679 *
4680 * @see com.android.server.ViewServer
4681 */
4682 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004683 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004684 return false;
4685 }
4686
4687 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4688 return false;
4689 }
4690
4691 return mViewServer != null && mViewServer.isRunning();
4692 }
4693
4694 /**
4695 * Lists all availble windows in the system. The listing is written in the
4696 * specified Socket's output stream with the following syntax:
4697 * windowHashCodeInHexadecimal windowName
4698 * Each line of the ouput represents a different window.
4699 *
4700 * @param client The remote client to send the listing to.
4701 * @return False if an error occured, true otherwise.
4702 */
4703 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004704 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004705 return false;
4706 }
4707
4708 boolean result = true;
4709
Jeff Browne33348b2010-07-15 23:54:05 -07004710 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004711 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004712 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07004713 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004714 }
4715
4716 BufferedWriter out = null;
4717
4718 // Any uncaught exception will crash the system process
4719 try {
4720 OutputStream clientStream = client.getOutputStream();
4721 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4722
4723 final int count = windows.length;
4724 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004725 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004726 out.write(Integer.toHexString(System.identityHashCode(w)));
4727 out.write(' ');
4728 out.append(w.mAttrs.getTitle());
4729 out.write('\n');
4730 }
4731
4732 out.write("DONE.\n");
4733 out.flush();
4734 } catch (Exception e) {
4735 result = false;
4736 } finally {
4737 if (out != null) {
4738 try {
4739 out.close();
4740 } catch (IOException e) {
4741 result = false;
4742 }
4743 }
4744 }
4745
4746 return result;
4747 }
4748
4749 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07004750 * Returns the focused window in the following format:
4751 * windowHashCodeInHexadecimal windowName
4752 *
4753 * @param client The remote client to send the listing to.
4754 * @return False if an error occurred, true otherwise.
4755 */
4756 boolean viewServerGetFocusedWindow(Socket client) {
4757 if (isSystemSecure()) {
4758 return false;
4759 }
4760
4761 boolean result = true;
4762
4763 WindowState focusedWindow = getFocusedWindow();
4764
4765 BufferedWriter out = null;
4766
4767 // Any uncaught exception will crash the system process
4768 try {
4769 OutputStream clientStream = client.getOutputStream();
4770 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4771
4772 if(focusedWindow != null) {
4773 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
4774 out.write(' ');
4775 out.append(focusedWindow.mAttrs.getTitle());
4776 }
4777 out.write('\n');
4778 out.flush();
4779 } catch (Exception e) {
4780 result = false;
4781 } finally {
4782 if (out != null) {
4783 try {
4784 out.close();
4785 } catch (IOException e) {
4786 result = false;
4787 }
4788 }
4789 }
4790
4791 return result;
4792 }
4793
4794 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004795 * Sends a command to a target window. The result of the command, if any, will be
4796 * written in the output stream of the specified socket.
4797 *
4798 * The parameters must follow this syntax:
4799 * windowHashcode extra
4800 *
4801 * Where XX is the length in characeters of the windowTitle.
4802 *
4803 * The first parameter is the target window. The window with the specified hashcode
4804 * will be the target. If no target can be found, nothing happens. The extra parameters
4805 * will be delivered to the target window and as parameters to the command itself.
4806 *
4807 * @param client The remote client to sent the result, if any, to.
4808 * @param command The command to execute.
4809 * @param parameters The command parameters.
4810 *
4811 * @return True if the command was successfully delivered, false otherwise. This does
4812 * not indicate whether the command itself was successful.
4813 */
4814 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004815 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004816 return false;
4817 }
4818
4819 boolean success = true;
4820 Parcel data = null;
4821 Parcel reply = null;
4822
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07004823 BufferedWriter out = null;
4824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004825 // Any uncaught exception will crash the system process
4826 try {
4827 // Find the hashcode of the window
4828 int index = parameters.indexOf(' ');
4829 if (index == -1) {
4830 index = parameters.length();
4831 }
4832 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004833 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004834
4835 // Extract the command's parameter after the window description
4836 if (index < parameters.length()) {
4837 parameters = parameters.substring(index + 1);
4838 } else {
4839 parameters = "";
4840 }
4841
4842 final WindowManagerService.WindowState window = findWindow(hashCode);
4843 if (window == null) {
4844 return false;
4845 }
4846
4847 data = Parcel.obtain();
4848 data.writeInterfaceToken("android.view.IWindow");
4849 data.writeString(command);
4850 data.writeString(parameters);
4851 data.writeInt(1);
4852 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4853
4854 reply = Parcel.obtain();
4855
4856 final IBinder binder = window.mClient.asBinder();
4857 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4858 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4859
4860 reply.readException();
4861
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07004862 if (!client.isOutputShutdown()) {
4863 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
4864 out.write("DONE\n");
4865 out.flush();
4866 }
4867
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004868 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004869 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004870 success = false;
4871 } finally {
4872 if (data != null) {
4873 data.recycle();
4874 }
4875 if (reply != null) {
4876 reply.recycle();
4877 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07004878 if (out != null) {
4879 try {
4880 out.close();
4881 } catch (IOException e) {
4882
4883 }
4884 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004885 }
4886
4887 return success;
4888 }
4889
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004890 public void addWindowChangeListener(WindowChangeListener listener) {
4891 synchronized(mWindowMap) {
4892 mWindowChangeListeners.add(listener);
4893 }
4894 }
4895
4896 public void removeWindowChangeListener(WindowChangeListener listener) {
4897 synchronized(mWindowMap) {
4898 mWindowChangeListeners.remove(listener);
4899 }
4900 }
4901
4902 private void notifyWindowsChanged() {
4903 WindowChangeListener[] windowChangeListeners;
4904 synchronized(mWindowMap) {
4905 if(mWindowChangeListeners.isEmpty()) {
4906 return;
4907 }
4908 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4909 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4910 }
4911 int N = windowChangeListeners.length;
4912 for(int i = 0; i < N; i++) {
4913 windowChangeListeners[i].windowsChanged();
4914 }
4915 }
4916
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07004917 private void notifyFocusChanged() {
4918 WindowChangeListener[] windowChangeListeners;
4919 synchronized(mWindowMap) {
4920 if(mWindowChangeListeners.isEmpty()) {
4921 return;
4922 }
4923 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4924 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4925 }
4926 int N = windowChangeListeners.length;
4927 for(int i = 0; i < N; i++) {
4928 windowChangeListeners[i].focusChanged();
4929 }
4930 }
4931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004932 private WindowState findWindow(int hashCode) {
4933 if (hashCode == -1) {
4934 return getFocusedWindow();
4935 }
4936
4937 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07004938 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004939 final int count = windows.size();
4940
4941 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004942 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004943 if (System.identityHashCode(w) == hashCode) {
4944 return w;
4945 }
4946 }
4947 }
4948
4949 return null;
4950 }
4951
4952 /*
4953 * Instruct the Activity Manager to fetch the current configuration and broadcast
4954 * that to config-changed listeners if appropriate.
4955 */
4956 void sendNewConfiguration() {
4957 try {
4958 mActivityManager.updateConfiguration(null);
4959 } catch (RemoteException e) {
4960 }
4961 }
Romain Guy06882f82009-06-10 13:36:04 -07004962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004963 public Configuration computeNewConfiguration() {
4964 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004965 return computeNewConfigurationLocked();
4966 }
4967 }
Romain Guy06882f82009-06-10 13:36:04 -07004968
Dianne Hackbornc485a602009-03-24 22:39:49 -07004969 Configuration computeNewConfigurationLocked() {
4970 Configuration config = new Configuration();
4971 if (!computeNewConfigurationLocked(config)) {
4972 return null;
4973 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004974 return config;
4975 }
Romain Guy06882f82009-06-10 13:36:04 -07004976
Dianne Hackbornc485a602009-03-24 22:39:49 -07004977 boolean computeNewConfigurationLocked(Configuration config) {
4978 if (mDisplay == null) {
4979 return false;
4980 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004981
4982 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07004983
4984 // Use the effective "visual" dimensions based on current rotation
4985 final boolean rotated = (mRotation == Surface.ROTATION_90
4986 || mRotation == Surface.ROTATION_270);
4987 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
4988 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
4989
Dianne Hackbornc485a602009-03-24 22:39:49 -07004990 int orientation = Configuration.ORIENTATION_SQUARE;
4991 if (dw < dh) {
4992 orientation = Configuration.ORIENTATION_PORTRAIT;
4993 } else if (dw > dh) {
4994 orientation = Configuration.ORIENTATION_LANDSCAPE;
4995 }
4996 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004997
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004998 DisplayMetrics dm = new DisplayMetrics();
4999 mDisplay.getMetrics(dm);
5000 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5001
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005002 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005003 // Note we only do this once because at this point we don't
5004 // expect the screen to change in this way at runtime, and want
5005 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005006 int longSize = dw;
5007 int shortSize = dh;
5008 if (longSize < shortSize) {
5009 int tmp = longSize;
5010 longSize = shortSize;
5011 shortSize = tmp;
5012 }
5013 longSize = (int)(longSize/dm.density);
5014 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005015
Dianne Hackborn723738c2009-06-25 19:48:04 -07005016 // These semi-magic numbers define our compatibility modes for
5017 // applications with different screens. Don't change unless you
5018 // make sure to test lots and lots of apps!
5019 if (longSize < 470) {
5020 // This is shorter than an HVGA normal density screen (which
5021 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005022 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5023 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005024 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005025 // What size is this screen screen?
5026 if (longSize >= 800 && shortSize >= 600) {
5027 // SVGA or larger screens at medium density are the point
5028 // at which we consider it to be an extra large screen.
5029 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
5030 } else if (longSize >= 640 && shortSize >= 480) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005031 // VGA or larger screens at medium density are the point
5032 // at which we consider it to be a large screen.
5033 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5034 } else {
5035 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005036
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005037 // If this screen is wider than normal HVGA, or taller
5038 // than FWVGA, then for old apps we want to run in size
5039 // compatibility mode.
5040 if (shortSize > 321 || longSize > 570) {
5041 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5042 }
5043 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005044
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005045 // Is this a long screen?
5046 if (((longSize*3)/5) >= (shortSize-1)) {
5047 // Anything wider than WVGA (5:3) is considering to be long.
5048 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5049 } else {
5050 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5051 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005052 }
5053 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005054 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005055
Dianne Hackbornc485a602009-03-24 22:39:49 -07005056 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5057 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5058 mPolicy.adjustConfigurationLw(config);
5059 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005060 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005061
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005062 // -------------------------------------------------------------
5063 // Input Events and Focus Management
5064 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005065
Jeff Brown349703e2010-06-22 01:27:15 -07005066 InputMonitor mInputMonitor = new InputMonitor();
5067
5068 /* Tracks the progress of input dispatch and ensures that input dispatch state
5069 * is kept in sync with changes in window focus, visibility, registration, and
5070 * other relevant Window Manager state transitions. */
5071 final class InputMonitor {
5072 // Current window with input focus for keys and other non-touch events. May be null.
5073 private WindowState mInputFocus;
5074
5075 // When true, prevents input dispatch from proceeding until set to false again.
5076 private boolean mInputDispatchFrozen;
5077
5078 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5079 private boolean mInputDispatchEnabled = true;
5080
5081 // Temporary list of windows information to provide to the input dispatcher.
5082 private InputWindowList mTempInputWindows = new InputWindowList();
5083
5084 // Temporary input application object to provide to the input dispatcher.
5085 private InputApplication mTempInputApplication = new InputApplication();
5086
5087 /* Notifies the window manager about a broken input channel.
5088 *
5089 * Called by the InputManager.
5090 */
5091 public void notifyInputChannelBroken(InputChannel inputChannel) {
5092 synchronized (mWindowMap) {
5093 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5094 if (windowState == null) {
5095 return; // irrelevant
5096 }
5097
5098 Slog.i(TAG, "WINDOW DIED " + windowState);
5099 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005100 }
5101 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005102
Jeff Brown519e0242010-09-15 15:18:56 -07005103 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005104 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005105 *
5106 * Called by the InputManager.
5107 */
Jeff Brown519e0242010-09-15 15:18:56 -07005108 public long notifyANR(Object token, InputChannel inputChannel) {
5109 AppWindowToken appWindowToken = null;
5110 if (inputChannel != null) {
5111 synchronized (mWindowMap) {
5112 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5113 if (windowState != null) {
5114 Slog.i(TAG, "Input event dispatching timed out sending to "
5115 + windowState.mAttrs.getTitle());
5116 appWindowToken = windowState.mAppToken;
5117 }
Jeff Brown349703e2010-06-22 01:27:15 -07005118 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005119 }
5120
Jeff Brown519e0242010-09-15 15:18:56 -07005121 if (appWindowToken == null && token != null) {
5122 appWindowToken = (AppWindowToken) token;
5123 Slog.i(TAG, "Input event dispatching timed out sending to application "
5124 + appWindowToken.stringName);
5125 }
Jeff Brown349703e2010-06-22 01:27:15 -07005126
Jeff Brown519e0242010-09-15 15:18:56 -07005127 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005128 try {
5129 // Notify the activity manager about the timeout and let it decide whether
5130 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005131 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005132 if (! abort) {
5133 // The activity manager declined to abort dispatching.
5134 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005135 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005136 }
Jeff Brown349703e2010-06-22 01:27:15 -07005137 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005138 }
5139 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005140 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005141 }
5142
Jeff Brown349703e2010-06-22 01:27:15 -07005143 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5144 synchronized (mWindowMap) {
5145 return getWindowStateForInputChannelLocked(inputChannel);
5146 }
5147 }
5148
5149 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5150 int windowCount = mWindows.size();
5151 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005152 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005153 if (windowState.mInputChannel == inputChannel) {
5154 return windowState;
5155 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005156 }
5157
Jeff Brown349703e2010-06-22 01:27:15 -07005158 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005159 }
5160
Jeff Brown349703e2010-06-22 01:27:15 -07005161 /* Updates the cached window information provided to the input dispatcher. */
5162 public void updateInputWindowsLw() {
5163 // Populate the input window list with information about all of the windows that
5164 // could potentially receive input.
5165 // As an optimization, we could try to prune the list of windows but this turns
5166 // out to be difficult because only the native code knows for sure which window
5167 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005168 final ArrayList<WindowState> windows = mWindows;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005169 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005170 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005171 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005172 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005173 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005174 continue;
5175 }
5176
Jeff Brown349703e2010-06-22 01:27:15 -07005177 final int flags = child.mAttrs.flags;
5178 final int type = child.mAttrs.type;
5179
5180 final boolean hasFocus = (child == mInputFocus);
5181 final boolean isVisible = child.isVisibleLw();
5182 final boolean hasWallpaper = (child == mWallpaperTarget)
5183 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
5184
5185 // Add a window to our list of input windows.
5186 final InputWindow inputWindow = mTempInputWindows.add();
5187 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005188 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005189 inputWindow.layoutParamsFlags = flags;
5190 inputWindow.layoutParamsType = type;
5191 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5192 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005193 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005194 inputWindow.hasFocus = hasFocus;
5195 inputWindow.hasWallpaper = hasWallpaper;
5196 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005197 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005198 inputWindow.ownerPid = child.mSession.mPid;
5199 inputWindow.ownerUid = child.mSession.mUid;
5200
5201 final Rect frame = child.mFrame;
5202 inputWindow.frameLeft = frame.left;
5203 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005204 inputWindow.frameRight = frame.right;
5205 inputWindow.frameBottom = frame.bottom;
5206
5207 final Rect visibleFrame = child.mVisibleFrame;
5208 inputWindow.visibleFrameLeft = visibleFrame.left;
5209 inputWindow.visibleFrameTop = visibleFrame.top;
5210 inputWindow.visibleFrameRight = visibleFrame.right;
5211 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005212
5213 switch (child.mTouchableInsets) {
5214 default:
5215 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5216 inputWindow.touchableAreaLeft = frame.left;
5217 inputWindow.touchableAreaTop = frame.top;
5218 inputWindow.touchableAreaRight = frame.right;
5219 inputWindow.touchableAreaBottom = frame.bottom;
5220 break;
5221
5222 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5223 Rect inset = child.mGivenContentInsets;
5224 inputWindow.touchableAreaLeft = frame.left + inset.left;
5225 inputWindow.touchableAreaTop = frame.top + inset.top;
5226 inputWindow.touchableAreaRight = frame.right - inset.right;
5227 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5228 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005229 }
Jeff Brown349703e2010-06-22 01:27:15 -07005230
5231 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5232 Rect inset = child.mGivenVisibleInsets;
5233 inputWindow.touchableAreaLeft = frame.left + inset.left;
5234 inputWindow.touchableAreaTop = frame.top + inset.top;
5235 inputWindow.touchableAreaRight = frame.right - inset.right;
5236 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005237 break;
5238 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005239 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005240 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005241
Jeff Brown349703e2010-06-22 01:27:15 -07005242 // Send windows to native code.
5243 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005244
Jeff Brown349703e2010-06-22 01:27:15 -07005245 // Clear the list in preparation for the next round.
5246 // Also avoids keeping InputChannel objects referenced unnecessarily.
5247 mTempInputWindows.clear();
5248 }
5249
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005250 /* Provides feedback for a virtual key down. */
5251 public void virtualKeyDownFeedback() {
5252 synchronized (mWindowMap) {
5253 mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5254 }
5255 }
5256
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005257 /* Notifies that the lid switch changed state. */
5258 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5259 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5260 }
5261
Jeff Brown349703e2010-06-22 01:27:15 -07005262 /* Provides an opportunity for the window manager policy to intercept early key
5263 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005264 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5265 int policyFlags, boolean isScreenOn) {
5266 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5267 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005268 }
5269
5270 /* Provides an opportunity for the window manager policy to process a key before
5271 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005272 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5273 int action, int flags, int keyCode, int metaState, int repeatCount,
5274 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005275 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005276 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5277 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005278 }
5279
5280 /* Called when the current input focus changes.
5281 * Layer assignment is assumed to be complete by the time this is called.
5282 */
5283 public void setInputFocusLw(WindowState newWindow) {
5284 if (DEBUG_INPUT) {
5285 Slog.d(TAG, "Input focus has changed to " + newWindow);
5286 }
5287
5288 if (newWindow != mInputFocus) {
5289 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005290 // Displaying a window implicitly causes dispatching to be unpaused.
5291 // This is to protect against bugs if someone pauses dispatching but
5292 // forgets to resume.
5293 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005294 }
Jeff Brown349703e2010-06-22 01:27:15 -07005295
5296 mInputFocus = newWindow;
5297 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005298 }
5299 }
5300
Jeff Brown349703e2010-06-22 01:27:15 -07005301 public void setFocusedAppLw(AppWindowToken newApp) {
5302 // Focused app has changed.
5303 if (newApp == null) {
5304 mInputManager.setFocusedApplication(null);
5305 } else {
5306 mTempInputApplication.name = newApp.toString();
5307 mTempInputApplication.dispatchingTimeoutNanos =
5308 newApp.inputDispatchingTimeoutNanos;
5309 mTempInputApplication.token = newApp;
5310
5311 mInputManager.setFocusedApplication(mTempInputApplication);
5312 }
5313 }
5314
Jeff Brown349703e2010-06-22 01:27:15 -07005315 public void pauseDispatchingLw(WindowToken window) {
5316 if (! window.paused) {
5317 if (DEBUG_INPUT) {
5318 Slog.v(TAG, "Pausing WindowToken " + window);
5319 }
5320
5321 window.paused = true;
5322 updateInputWindowsLw();
5323 }
5324 }
5325
5326 public void resumeDispatchingLw(WindowToken window) {
5327 if (window.paused) {
5328 if (DEBUG_INPUT) {
5329 Slog.v(TAG, "Resuming WindowToken " + window);
5330 }
5331
5332 window.paused = false;
5333 updateInputWindowsLw();
5334 }
5335 }
5336
5337 public void freezeInputDispatchingLw() {
5338 if (! mInputDispatchFrozen) {
5339 if (DEBUG_INPUT) {
5340 Slog.v(TAG, "Freezing input dispatching");
5341 }
5342
5343 mInputDispatchFrozen = true;
5344 updateInputDispatchModeLw();
5345 }
5346 }
5347
5348 public void thawInputDispatchingLw() {
5349 if (mInputDispatchFrozen) {
5350 if (DEBUG_INPUT) {
5351 Slog.v(TAG, "Thawing input dispatching");
5352 }
5353
5354 mInputDispatchFrozen = false;
5355 updateInputDispatchModeLw();
5356 }
5357 }
5358
5359 public void setEventDispatchingLw(boolean enabled) {
5360 if (mInputDispatchEnabled != enabled) {
5361 if (DEBUG_INPUT) {
5362 Slog.v(TAG, "Setting event dispatching to " + enabled);
5363 }
5364
5365 mInputDispatchEnabled = enabled;
5366 updateInputDispatchModeLw();
5367 }
5368 }
5369
5370 private void updateInputDispatchModeLw() {
5371 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5372 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005373 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005375 public void pauseKeyDispatching(IBinder _token) {
5376 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5377 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005378 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005379 }
5380
5381 synchronized (mWindowMap) {
5382 WindowToken token = mTokenMap.get(_token);
5383 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005384 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005385 }
5386 }
5387 }
5388
5389 public void resumeKeyDispatching(IBinder _token) {
5390 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5391 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005392 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005393 }
5394
5395 synchronized (mWindowMap) {
5396 WindowToken token = mTokenMap.get(_token);
5397 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005398 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005399 }
5400 }
5401 }
5402
5403 public void setEventDispatching(boolean enabled) {
5404 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5405 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005406 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005407 }
5408
5409 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005410 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005411 }
5412 }
Romain Guy06882f82009-06-10 13:36:04 -07005413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005414 /**
5415 * Injects a keystroke event into the UI.
Jeff Brown6ec402b2010-07-28 15:48:59 -07005416 * Even when sync is false, this method may block while waiting for current
5417 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005418 *
5419 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005420 * {@link SystemClock#uptimeMillis()} as the timebase.)
5421 * @param sync If true, wait for the event to be completed before returning to the caller.
5422 * @return Returns true if event was dispatched, false if it was dropped for any reason
5423 */
5424 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5425 long downTime = ev.getDownTime();
5426 long eventTime = ev.getEventTime();
5427
5428 int action = ev.getAction();
5429 int code = ev.getKeyCode();
5430 int repeatCount = ev.getRepeatCount();
5431 int metaState = ev.getMetaState();
5432 int deviceId = ev.getDeviceId();
5433 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005434 int source = ev.getSource();
5435
5436 if (source == InputDevice.SOURCE_UNKNOWN) {
5437 source = InputDevice.SOURCE_KEYBOARD;
5438 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005439
5440 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5441 if (downTime == 0) downTime = eventTime;
5442
5443 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005444 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005445
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005446 final int pid = Binder.getCallingPid();
5447 final int uid = Binder.getCallingUid();
5448 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005449
Jeff Brown6ec402b2010-07-28 15:48:59 -07005450 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5451 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5452 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5453 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005454
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005455 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005456 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005457 }
5458
5459 /**
5460 * Inject a pointer (touch) event into the UI.
Jeff Brown6ec402b2010-07-28 15:48:59 -07005461 * Even when sync is false, this method may block while waiting for current
5462 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005463 *
5464 * @param ev A motion event describing the pointer (touch) action. (As noted in
5465 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005466 * {@link SystemClock#uptimeMillis()} as the timebase.)
5467 * @param sync If true, wait for the event to be completed before returning to the caller.
5468 * @return Returns true if event was dispatched, false if it was dropped for any reason
5469 */
5470 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005471 final int pid = Binder.getCallingPid();
5472 final int uid = Binder.getCallingUid();
5473 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005474
Jeff Brownc5ed5912010-07-14 18:48:53 -07005475 MotionEvent newEvent = MotionEvent.obtain(ev);
5476 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5477 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5478 }
5479
Jeff Brown6ec402b2010-07-28 15:48:59 -07005480 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5481 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5482 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5483 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005484
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005485 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005486 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005487 }
Romain Guy06882f82009-06-10 13:36:04 -07005488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005489 /**
5490 * Inject a trackball (navigation device) event into the UI.
Jeff Brown6ec402b2010-07-28 15:48:59 -07005491 * Even when sync is false, this method may block while waiting for current
5492 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005493 *
5494 * @param ev A motion event describing the trackball action. (As noted in
5495 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005496 * {@link SystemClock#uptimeMillis()} as the timebase.)
5497 * @param sync If true, wait for the event to be completed before returning to the caller.
5498 * @return Returns true if event was dispatched, false if it was dropped for any reason
5499 */
5500 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005501 final int pid = Binder.getCallingPid();
5502 final int uid = Binder.getCallingUid();
5503 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005504
Jeff Brownc5ed5912010-07-14 18:48:53 -07005505 MotionEvent newEvent = MotionEvent.obtain(ev);
5506 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5507 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5508 }
5509
Jeff Brown6ec402b2010-07-28 15:48:59 -07005510 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5511 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5512 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5513 INJECTION_TIMEOUT_MILLIS);
5514
5515 Binder.restoreCallingIdentity(ident);
5516 return reportInjectionResult(result);
5517 }
5518
5519 /**
5520 * Inject an input event into the UI without waiting for dispatch to commence.
5521 * This variant is useful for fire-and-forget input event injection. It does not
5522 * block any longer than it takes to enqueue the input event.
5523 *
5524 * @param ev An input event. (Be sure to set the input source correctly.)
5525 * @return Returns true if event was dispatched, false if it was dropped for any reason
5526 */
5527 public boolean injectInputEventNoWait(InputEvent ev) {
5528 final int pid = Binder.getCallingPid();
5529 final int uid = Binder.getCallingUid();
5530 final long ident = Binder.clearCallingIdentity();
5531
5532 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5533 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5534 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005535
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005536 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005537 return reportInjectionResult(result);
5538 }
5539
5540 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005541 switch (result) {
5542 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5543 Slog.w(TAG, "Input event injection permission denied.");
5544 throw new SecurityException(
5545 "Injecting to another application requires INJECT_EVENTS permission");
5546 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07005547 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005548 return true;
5549 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5550 Slog.w(TAG, "Input event injection timed out.");
5551 return false;
5552 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5553 default:
5554 Slog.w(TAG, "Input event injection failed.");
5555 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005556 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005557 }
Romain Guy06882f82009-06-10 13:36:04 -07005558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005559 private WindowState getFocusedWindow() {
5560 synchronized (mWindowMap) {
5561 return getFocusedWindowLocked();
5562 }
5563 }
5564
5565 private WindowState getFocusedWindowLocked() {
5566 return mCurrentFocus;
5567 }
Romain Guy06882f82009-06-10 13:36:04 -07005568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005569 public boolean detectSafeMode() {
5570 mSafeMode = mPolicy.detectSafeMode();
5571 return mSafeMode;
5572 }
Romain Guy06882f82009-06-10 13:36:04 -07005573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005574 public void systemReady() {
5575 mPolicy.systemReady();
5576 }
Romain Guy06882f82009-06-10 13:36:04 -07005577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005578 // -------------------------------------------------------------
5579 // Client Session State
5580 // -------------------------------------------------------------
5581
5582 private final class Session extends IWindowSession.Stub
5583 implements IBinder.DeathRecipient {
5584 final IInputMethodClient mClient;
5585 final IInputContext mInputContext;
5586 final int mUid;
5587 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005588 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005589 SurfaceSession mSurfaceSession;
5590 int mNumWindow = 0;
5591 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07005592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005593 public Session(IInputMethodClient client, IInputContext inputContext) {
5594 mClient = client;
5595 mInputContext = inputContext;
5596 mUid = Binder.getCallingUid();
5597 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005598 StringBuilder sb = new StringBuilder();
5599 sb.append("Session{");
5600 sb.append(Integer.toHexString(System.identityHashCode(this)));
5601 sb.append(" uid ");
5602 sb.append(mUid);
5603 sb.append("}");
5604 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07005605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005606 synchronized (mWindowMap) {
5607 if (mInputMethodManager == null && mHaveInputMethods) {
5608 IBinder b = ServiceManager.getService(
5609 Context.INPUT_METHOD_SERVICE);
5610 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
5611 }
5612 }
5613 long ident = Binder.clearCallingIdentity();
5614 try {
5615 // Note: it is safe to call in to the input method manager
5616 // here because we are not holding our lock.
5617 if (mInputMethodManager != null) {
5618 mInputMethodManager.addClient(client, inputContext,
5619 mUid, mPid);
5620 } else {
5621 client.setUsingInputMethod(false);
5622 }
5623 client.asBinder().linkToDeath(this, 0);
5624 } catch (RemoteException e) {
5625 // The caller has died, so we can just forget about this.
5626 try {
5627 if (mInputMethodManager != null) {
5628 mInputMethodManager.removeClient(client);
5629 }
5630 } catch (RemoteException ee) {
5631 }
5632 } finally {
5633 Binder.restoreCallingIdentity(ident);
5634 }
5635 }
Romain Guy06882f82009-06-10 13:36:04 -07005636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005637 @Override
5638 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
5639 throws RemoteException {
5640 try {
5641 return super.onTransact(code, data, reply, flags);
5642 } catch (RuntimeException e) {
5643 // Log all 'real' exceptions thrown to the caller
5644 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005645 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005646 }
5647 throw e;
5648 }
5649 }
5650
5651 public void binderDied() {
5652 // Note: it is safe to call in to the input method manager
5653 // here because we are not holding our lock.
5654 try {
5655 if (mInputMethodManager != null) {
5656 mInputMethodManager.removeClient(mClient);
5657 }
5658 } catch (RemoteException e) {
5659 }
5660 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005661 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005662 mClientDead = true;
5663 killSessionLocked();
5664 }
5665 }
5666
5667 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005668 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
5669 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
5670 outInputChannel);
5671 }
5672
5673 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005674 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005675 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005676 }
Romain Guy06882f82009-06-10 13:36:04 -07005677
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005678 public void remove(IWindow window) {
5679 removeWindow(this, window);
5680 }
Romain Guy06882f82009-06-10 13:36:04 -07005681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005682 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
5683 int requestedWidth, int requestedHeight, int viewFlags,
5684 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005685 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07005686 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
5687 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005688 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005689 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07005690 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
5691 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005692 }
Romain Guy06882f82009-06-10 13:36:04 -07005693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005694 public void setTransparentRegion(IWindow window, Region region) {
5695 setTransparentRegionWindow(this, window, region);
5696 }
Romain Guy06882f82009-06-10 13:36:04 -07005697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005698 public void setInsets(IWindow window, int touchableInsets,
5699 Rect contentInsets, Rect visibleInsets) {
5700 setInsetsWindow(this, window, touchableInsets, contentInsets,
5701 visibleInsets);
5702 }
Romain Guy06882f82009-06-10 13:36:04 -07005703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005704 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
5705 getWindowDisplayFrame(this, window, outDisplayFrame);
5706 }
Romain Guy06882f82009-06-10 13:36:04 -07005707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005708 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005709 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005710 TAG, "IWindow finishDrawing called for " + window);
5711 finishDrawingWindow(this, window);
5712 }
5713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005714 public void setInTouchMode(boolean mode) {
5715 synchronized(mWindowMap) {
5716 mInTouchMode = mode;
5717 }
5718 }
5719
5720 public boolean getInTouchMode() {
5721 synchronized(mWindowMap) {
5722 return mInTouchMode;
5723 }
5724 }
5725
5726 public boolean performHapticFeedback(IWindow window, int effectId,
5727 boolean always) {
5728 synchronized(mWindowMap) {
5729 long ident = Binder.clearCallingIdentity();
5730 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005731 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005732 windowForClientLocked(this, window, true),
5733 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005734 } finally {
5735 Binder.restoreCallingIdentity(ident);
5736 }
5737 }
5738 }
Romain Guy06882f82009-06-10 13:36:04 -07005739
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005740 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005741 synchronized(mWindowMap) {
5742 long ident = Binder.clearCallingIdentity();
5743 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005744 setWindowWallpaperPositionLocked(
5745 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005746 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005747 } finally {
5748 Binder.restoreCallingIdentity(ident);
5749 }
5750 }
5751 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005752
Dianne Hackborn19382ac2009-09-11 21:13:37 -07005753 public void wallpaperOffsetsComplete(IBinder window) {
5754 WindowManagerService.this.wallpaperOffsetsComplete(window);
5755 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005756
Dianne Hackborn75804932009-10-20 20:15:20 -07005757 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
5758 int z, Bundle extras, boolean sync) {
5759 synchronized(mWindowMap) {
5760 long ident = Binder.clearCallingIdentity();
5761 try {
5762 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005763 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07005764 action, x, y, z, extras, sync);
5765 } finally {
5766 Binder.restoreCallingIdentity(ident);
5767 }
5768 }
5769 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005770
Dianne Hackborn75804932009-10-20 20:15:20 -07005771 public void wallpaperCommandComplete(IBinder window, Bundle result) {
5772 WindowManagerService.this.wallpaperCommandComplete(window, result);
5773 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005775 void windowAddedLocked() {
5776 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005777 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005778 TAG, "First window added to " + this + ", creating SurfaceSession");
5779 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08005780 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005781 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005782 mSessions.add(this);
5783 }
5784 mNumWindow++;
5785 }
5786
5787 void windowRemovedLocked() {
5788 mNumWindow--;
5789 killSessionLocked();
5790 }
Romain Guy06882f82009-06-10 13:36:04 -07005791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005792 void killSessionLocked() {
5793 if (mNumWindow <= 0 && mClientDead) {
5794 mSessions.remove(this);
5795 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005796 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005797 TAG, "Last window removed from " + this
5798 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005799 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005800 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005801 try {
5802 mSurfaceSession.kill();
5803 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005804 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005805 + mSurfaceSession + " in session " + this
5806 + ": " + e.toString());
5807 }
5808 mSurfaceSession = null;
5809 }
5810 }
5811 }
Romain Guy06882f82009-06-10 13:36:04 -07005812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005813 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005814 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
5815 pw.print(" mClientDead="); pw.print(mClientDead);
5816 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005817 }
5818
5819 @Override
5820 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005821 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005822 }
5823 }
5824
5825 // -------------------------------------------------------------
5826 // Client Window State
5827 // -------------------------------------------------------------
5828
5829 private final class WindowState implements WindowManagerPolicy.WindowState {
5830 final Session mSession;
5831 final IWindow mClient;
5832 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07005833 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005834 AppWindowToken mAppToken;
5835 AppWindowToken mTargetAppToken;
5836 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
5837 final DeathRecipient mDeathRecipient;
5838 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07005839 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005840 final int mBaseLayer;
5841 final int mSubLayer;
5842 final boolean mLayoutAttached;
5843 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005844 final boolean mIsWallpaper;
5845 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005846 int mViewVisibility;
5847 boolean mPolicyVisibility = true;
5848 boolean mPolicyVisibilityAfterAnim = true;
5849 boolean mAppFreezing;
5850 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07005851 boolean mReportDestroySurface;
5852 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005853 boolean mAttachedHidden; // is our parent window hidden?
5854 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07005855 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005856 int mRequestedWidth;
5857 int mRequestedHeight;
5858 int mLastRequestedWidth;
5859 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005860 int mLayer;
5861 int mAnimLayer;
5862 int mLastLayer;
5863 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07005864 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07005865 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005866
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005867 int mLayoutSeq = -1;
5868
5869 Configuration mConfiguration = null;
5870
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005871 // Actual frame shown on-screen (may be modified by animation)
5872 final Rect mShownFrame = new Rect();
5873 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005875 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08005876 * Set when we have changed the size of the surface, to know that
5877 * we must tell them application to resize (and thus redraw itself).
5878 */
5879 boolean mSurfaceResized;
5880
5881 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005882 * Insets that determine the actually visible area
5883 */
5884 final Rect mVisibleInsets = new Rect();
5885 final Rect mLastVisibleInsets = new Rect();
5886 boolean mVisibleInsetsChanged;
5887
5888 /**
5889 * Insets that are covered by system windows
5890 */
5891 final Rect mContentInsets = new Rect();
5892 final Rect mLastContentInsets = new Rect();
5893 boolean mContentInsetsChanged;
5894
5895 /**
5896 * Set to true if we are waiting for this window to receive its
5897 * given internal insets before laying out other windows based on it.
5898 */
5899 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07005900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005901 /**
5902 * These are the content insets that were given during layout for
5903 * this window, to be applied to windows behind it.
5904 */
5905 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005907 /**
5908 * These are the visible insets that were given during layout for
5909 * this window, to be applied to windows behind it.
5910 */
5911 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005913 /**
5914 * Flag indicating whether the touchable region should be adjusted by
5915 * the visible insets; if false the area outside the visible insets is
5916 * NOT touchable, so we must use those to adjust the frame during hit
5917 * tests.
5918 */
5919 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07005920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005921 // Current transformation being applied.
5922 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
5923 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
5924 float mHScale=1, mVScale=1;
5925 float mLastHScale=1, mLastVScale=1;
5926 final Matrix mTmpMatrix = new Matrix();
5927
5928 // "Real" frame that the application sees.
5929 final Rect mFrame = new Rect();
5930 final Rect mLastFrame = new Rect();
5931
5932 final Rect mContainingFrame = new Rect();
5933 final Rect mDisplayFrame = new Rect();
5934 final Rect mContentFrame = new Rect();
5935 final Rect mVisibleFrame = new Rect();
5936
5937 float mShownAlpha = 1;
5938 float mAlpha = 1;
5939 float mLastAlpha = 1;
5940
5941 // Set to true if, when the window gets displayed, it should perform
5942 // an enter animation.
5943 boolean mEnterAnimationPending;
5944
5945 // Currently running animation.
5946 boolean mAnimating;
5947 boolean mLocalAnimating;
5948 Animation mAnimation;
5949 boolean mAnimationIsEntrance;
5950 boolean mHasTransformation;
5951 boolean mHasLocalTransformation;
5952 final Transformation mTransformation = new Transformation();
5953
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005954 // If a window showing a wallpaper: the requested offset for the
5955 // wallpaper; if a wallpaper window: the currently applied offset.
5956 float mWallpaperX = -1;
5957 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005958
5959 // If a window showing a wallpaper: what fraction of the offset
5960 // range corresponds to a full virtual screen.
5961 float mWallpaperXStep = -1;
5962 float mWallpaperYStep = -1;
5963
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005964 // Wallpaper windows: pixels offset based on above variables.
5965 int mXOffset;
5966 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005968 // This is set after IWindowSession.relayout() has been called at
5969 // least once for the window. It allows us to detect the situation
5970 // where we don't yet have a surface, but should have one soon, so
5971 // we can give the window focus before waiting for the relayout.
5972 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07005973
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005974 // This is set after the Surface has been created but before the
5975 // window has been drawn. During this time the surface is hidden.
5976 boolean mDrawPending;
5977
5978 // This is set after the window has finished drawing for the first
5979 // time but before its surface is shown. The surface will be
5980 // displayed when the next layout is run.
5981 boolean mCommitDrawPending;
5982
5983 // This is set during the time after the window's drawing has been
5984 // committed, and before its surface is actually shown. It is used
5985 // to delay showing the surface until all windows in a token are ready
5986 // to be shown.
5987 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07005988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005989 // Set when the window has been shown in the screen the first time.
5990 boolean mHasDrawn;
5991
5992 // Currently running an exit animation?
5993 boolean mExiting;
5994
5995 // Currently on the mDestroySurface list?
5996 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07005997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005998 // Completely remove from window manager after exit animation?
5999 boolean mRemoveOnExit;
6000
6001 // Set when the orientation is changing and this window has not yet
6002 // been updated for the new orientation.
6003 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006005 // Is this window now (or just being) removed?
6006 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006007
Dianne Hackborn16064f92010-03-25 00:47:24 -07006008 // For debugging, this is the last information given to the surface flinger.
6009 boolean mSurfaceShown;
6010 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6011 int mSurfaceLayer;
6012 float mSurfaceAlpha;
6013
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006014 // Input channel
6015 InputChannel mInputChannel;
6016
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006017 WindowState(Session s, IWindow c, WindowToken token,
6018 WindowState attachedWindow, WindowManager.LayoutParams a,
6019 int viewVisibility) {
6020 mSession = s;
6021 mClient = c;
6022 mToken = token;
6023 mAttrs.copyFrom(a);
6024 mViewVisibility = viewVisibility;
6025 DeathRecipient deathRecipient = new DeathRecipient();
6026 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006027 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006028 TAG, "Window " + this + " client=" + c.asBinder()
6029 + " token=" + token + " (" + mAttrs.token + ")");
6030 try {
6031 c.asBinder().linkToDeath(deathRecipient, 0);
6032 } catch (RemoteException e) {
6033 mDeathRecipient = null;
6034 mAttachedWindow = null;
6035 mLayoutAttached = false;
6036 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006037 mIsWallpaper = false;
6038 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006039 mBaseLayer = 0;
6040 mSubLayer = 0;
6041 return;
6042 }
6043 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006045 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6046 mAttrs.type <= LAST_SUB_WINDOW)) {
6047 // The multiplier here is to reserve space for multiple
6048 // windows in the same type layer.
6049 mBaseLayer = mPolicy.windowTypeToLayerLw(
6050 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6051 + TYPE_LAYER_OFFSET;
6052 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6053 mAttachedWindow = attachedWindow;
6054 mAttachedWindow.mChildWindows.add(this);
6055 mLayoutAttached = mAttrs.type !=
6056 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6057 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6058 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006059 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6060 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006061 } else {
6062 // The multiplier here is to reserve space for multiple
6063 // windows in the same type layer.
6064 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6065 * TYPE_LAYER_MULTIPLIER
6066 + TYPE_LAYER_OFFSET;
6067 mSubLayer = 0;
6068 mAttachedWindow = null;
6069 mLayoutAttached = false;
6070 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6071 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006072 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6073 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006074 }
6075
6076 WindowState appWin = this;
6077 while (appWin.mAttachedWindow != null) {
6078 appWin = mAttachedWindow;
6079 }
6080 WindowToken appToken = appWin.mToken;
6081 while (appToken.appWindowToken == null) {
6082 WindowToken parent = mTokenMap.get(appToken.token);
6083 if (parent == null || appToken == parent) {
6084 break;
6085 }
6086 appToken = parent;
6087 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006088 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006089 mAppToken = appToken.appWindowToken;
6090
6091 mSurface = null;
6092 mRequestedWidth = 0;
6093 mRequestedHeight = 0;
6094 mLastRequestedWidth = 0;
6095 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006096 mXOffset = 0;
6097 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006098 mLayer = 0;
6099 mAnimLayer = 0;
6100 mLastLayer = 0;
6101 }
6102
6103 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006104 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006105 TAG, "Attaching " + this + " token=" + mToken
6106 + ", list=" + mToken.windows);
6107 mSession.windowAddedLocked();
6108 }
6109
6110 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6111 mHaveFrame = true;
6112
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006113 final Rect container = mContainingFrame;
6114 container.set(pf);
6115
6116 final Rect display = mDisplayFrame;
6117 display.set(df);
6118
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006119 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006120 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006121 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6122 display.intersect(mCompatibleScreenFrame);
6123 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006124 }
6125
6126 final int pw = container.right - container.left;
6127 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006128
6129 int w,h;
6130 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6131 w = mAttrs.width < 0 ? pw : mAttrs.width;
6132 h = mAttrs.height< 0 ? ph : mAttrs.height;
6133 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006134 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6135 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006136 }
Romain Guy06882f82009-06-10 13:36:04 -07006137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006138 final Rect content = mContentFrame;
6139 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006141 final Rect visible = mVisibleFrame;
6142 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006144 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006145 final int fw = frame.width();
6146 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006148 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6149 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6150
6151 Gravity.apply(mAttrs.gravity, w, h, container,
6152 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6153 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6154
6155 //System.out.println("Out: " + mFrame);
6156
6157 // Now make sure the window fits in the overall display.
6158 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006160 // Make sure the content and visible frames are inside of the
6161 // final window frame.
6162 if (content.left < frame.left) content.left = frame.left;
6163 if (content.top < frame.top) content.top = frame.top;
6164 if (content.right > frame.right) content.right = frame.right;
6165 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6166 if (visible.left < frame.left) visible.left = frame.left;
6167 if (visible.top < frame.top) visible.top = frame.top;
6168 if (visible.right > frame.right) visible.right = frame.right;
6169 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006171 final Rect contentInsets = mContentInsets;
6172 contentInsets.left = content.left-frame.left;
6173 contentInsets.top = content.top-frame.top;
6174 contentInsets.right = frame.right-content.right;
6175 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006177 final Rect visibleInsets = mVisibleInsets;
6178 visibleInsets.left = visible.left-frame.left;
6179 visibleInsets.top = visible.top-frame.top;
6180 visibleInsets.right = frame.right-visible.right;
6181 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006182
Dianne Hackborn284ac932009-08-28 10:34:25 -07006183 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6184 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006185 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006186 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006188 if (localLOGV) {
6189 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6190 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006191 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006192 + mRequestedWidth + ", mRequestedheight="
6193 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6194 + "): frame=" + mFrame.toShortString()
6195 + " ci=" + contentInsets.toShortString()
6196 + " vi=" + visibleInsets.toShortString());
6197 //}
6198 }
6199 }
Romain Guy06882f82009-06-10 13:36:04 -07006200
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006201 public Rect getFrameLw() {
6202 return mFrame;
6203 }
6204
6205 public Rect getShownFrameLw() {
6206 return mShownFrame;
6207 }
6208
6209 public Rect getDisplayFrameLw() {
6210 return mDisplayFrame;
6211 }
6212
6213 public Rect getContentFrameLw() {
6214 return mContentFrame;
6215 }
6216
6217 public Rect getVisibleFrameLw() {
6218 return mVisibleFrame;
6219 }
6220
6221 public boolean getGivenInsetsPendingLw() {
6222 return mGivenInsetsPending;
6223 }
6224
6225 public Rect getGivenContentInsetsLw() {
6226 return mGivenContentInsets;
6227 }
Romain Guy06882f82009-06-10 13:36:04 -07006228
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006229 public Rect getGivenVisibleInsetsLw() {
6230 return mGivenVisibleInsets;
6231 }
Romain Guy06882f82009-06-10 13:36:04 -07006232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006233 public WindowManager.LayoutParams getAttrs() {
6234 return mAttrs;
6235 }
6236
6237 public int getSurfaceLayer() {
6238 return mLayer;
6239 }
Romain Guy06882f82009-06-10 13:36:04 -07006240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006241 public IApplicationToken getAppToken() {
6242 return mAppToken != null ? mAppToken.appToken : null;
6243 }
Jeff Brown349703e2010-06-22 01:27:15 -07006244
6245 public long getInputDispatchingTimeoutNanos() {
6246 return mAppToken != null
6247 ? mAppToken.inputDispatchingTimeoutNanos
6248 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6249 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006250
6251 public boolean hasAppShownWindows() {
6252 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6253 }
6254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006255 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006256 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006257 TAG, "Setting animation in " + this + ": " + anim);
6258 mAnimating = false;
6259 mLocalAnimating = false;
6260 mAnimation = anim;
6261 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6262 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6263 }
6264
6265 public void clearAnimation() {
6266 if (mAnimation != null) {
6267 mAnimating = true;
6268 mLocalAnimating = false;
6269 mAnimation = null;
6270 }
6271 }
Romain Guy06882f82009-06-10 13:36:04 -07006272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006273 Surface createSurfaceLocked() {
6274 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006275 mReportDestroySurface = false;
6276 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006277 mDrawPending = true;
6278 mCommitDrawPending = false;
6279 mReadyToShow = false;
6280 if (mAppToken != null) {
6281 mAppToken.allDrawn = false;
6282 }
6283
6284 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006285 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006286 flags |= Surface.PUSH_BUFFERS;
6287 }
6288
6289 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6290 flags |= Surface.SECURE;
6291 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006292 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006293 TAG, "Creating surface in session "
6294 + mSession.mSurfaceSession + " window " + this
6295 + " w=" + mFrame.width()
6296 + " h=" + mFrame.height() + " format="
6297 + mAttrs.format + " flags=" + flags);
6298
6299 int w = mFrame.width();
6300 int h = mFrame.height();
6301 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6302 // for a scaled surface, we always want the requested
6303 // size.
6304 w = mRequestedWidth;
6305 h = mRequestedHeight;
6306 }
6307
Romain Guy9825ec62009-10-01 00:58:09 -07006308 // Something is wrong and SurfaceFlinger will not like this,
6309 // try to revert to sane values
6310 if (w <= 0) w = 1;
6311 if (h <= 0) h = 1;
6312
Dianne Hackborn16064f92010-03-25 00:47:24 -07006313 mSurfaceShown = false;
6314 mSurfaceLayer = 0;
6315 mSurfaceAlpha = 1;
6316 mSurfaceX = 0;
6317 mSurfaceY = 0;
6318 mSurfaceW = w;
6319 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006320 try {
6321 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006322 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006323 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006324 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006325 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006326 + mSurface + " IN SESSION "
6327 + mSession.mSurfaceSession
6328 + ": pid=" + mSession.mPid + " format="
6329 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006330 + Integer.toHexString(flags)
6331 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006332 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006333 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006334 reclaimSomeSurfaceMemoryLocked(this, "create");
6335 return null;
6336 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006337 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006338 return null;
6339 }
Romain Guy06882f82009-06-10 13:36:04 -07006340
Joe Onorato8a9b2202010-02-26 18:56:32 -08006341 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006342 TAG, "Got surface: " + mSurface
6343 + ", set left=" + mFrame.left + " top=" + mFrame.top
6344 + ", animLayer=" + mAnimLayer);
6345 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006346 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006347 if (SHOW_TRANSACTIONS) logSurface(this,
6348 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6349 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6350 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006351 }
6352 Surface.openTransaction();
6353 try {
6354 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006355 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006356 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006357 mSurface.setPosition(mSurfaceX, mSurfaceY);
6358 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006359 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006360 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006361 mSurface.hide();
6362 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006363 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006364 mSurface.setFlags(Surface.SURFACE_DITHER,
6365 Surface.SURFACE_DITHER);
6366 }
6367 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006368 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006369 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6370 }
6371 mLastHidden = true;
6372 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006373 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006374 Surface.closeTransaction();
6375 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006376 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006377 TAG, "Created surface " + this);
6378 }
6379 return mSurface;
6380 }
Romain Guy06882f82009-06-10 13:36:04 -07006381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006382 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006383 if (mAppToken != null && this == mAppToken.startingWindow) {
6384 mAppToken.startingDisplayed = false;
6385 }
Romain Guy06882f82009-06-10 13:36:04 -07006386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006387 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006388 mDrawPending = false;
6389 mCommitDrawPending = false;
6390 mReadyToShow = false;
6391
6392 int i = mChildWindows.size();
6393 while (i > 0) {
6394 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006395 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006396 c.mAttachedHidden = true;
6397 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006398
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006399 if (mReportDestroySurface) {
6400 mReportDestroySurface = false;
6401 mSurfacePendingDestroy = true;
6402 try {
6403 mClient.dispatchGetNewSurface();
6404 // We'll really destroy on the next time around.
6405 return;
6406 } catch (RemoteException e) {
6407 }
6408 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006410 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006411 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006412 RuntimeException e = null;
6413 if (!HIDE_STACK_CRAWLS) {
6414 e = new RuntimeException();
6415 e.fillInStackTrace();
6416 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006417 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006418 + mSurface + ", session " + mSession, e);
6419 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006420 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006421 RuntimeException e = null;
6422 if (!HIDE_STACK_CRAWLS) {
6423 e = new RuntimeException();
6424 e.fillInStackTrace();
6425 }
6426 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006427 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006428 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006429 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006430 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006431 + " surface " + mSurface + " session " + mSession
6432 + ": " + e.toString());
6433 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006434
Dianne Hackborn16064f92010-03-25 00:47:24 -07006435 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006436 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006437 }
6438 }
6439
6440 boolean finishDrawingLocked() {
6441 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006442 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006443 TAG, "finishDrawingLocked: " + mSurface);
6444 mCommitDrawPending = true;
6445 mDrawPending = false;
6446 return true;
6447 }
6448 return false;
6449 }
6450
6451 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006452 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006453 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006454 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006455 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006456 }
6457 mCommitDrawPending = false;
6458 mReadyToShow = true;
6459 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6460 final AppWindowToken atoken = mAppToken;
6461 if (atoken == null || atoken.allDrawn || starting) {
6462 performShowLocked();
6463 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006464 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006465 }
6466
6467 // This must be called while inside a transaction.
6468 boolean performShowLocked() {
6469 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006470 RuntimeException e = null;
6471 if (!HIDE_STACK_CRAWLS) {
6472 e = new RuntimeException();
6473 e.fillInStackTrace();
6474 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006475 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006476 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
6477 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
6478 }
6479 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006480 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
6481 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006482 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006483 + " during animation: policyVis=" + mPolicyVisibility
6484 + " attHidden=" + mAttachedHidden
6485 + " tok.hiddenRequested="
6486 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07006487 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006488 + (mAppToken != null ? mAppToken.hidden : false)
6489 + " animating=" + mAnimating
6490 + " tok animating="
6491 + (mAppToken != null ? mAppToken.animating : false));
6492 if (!showSurfaceRobustlyLocked(this)) {
6493 return false;
6494 }
6495 mLastAlpha = -1;
6496 mHasDrawn = true;
6497 mLastHidden = false;
6498 mReadyToShow = false;
6499 enableScreenIfNeededLocked();
6500
6501 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07006502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006503 int i = mChildWindows.size();
6504 while (i > 0) {
6505 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006506 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006507 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006508 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006509 if (c.mSurface != null) {
6510 c.performShowLocked();
6511 // It hadn't been shown, which means layout not
6512 // performed on it, so now we want to make sure to
6513 // do a layout. If called from within the transaction
6514 // loop, this will cause it to restart with a new
6515 // layout.
6516 mLayoutNeeded = true;
6517 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006518 }
6519 }
Romain Guy06882f82009-06-10 13:36:04 -07006520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006521 if (mAttrs.type != TYPE_APPLICATION_STARTING
6522 && mAppToken != null) {
6523 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006524
Dianne Hackborn248b1882009-09-16 16:46:44 -07006525 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006526 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006527 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006528 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07006529 // If this initial window is animating, stop it -- we
6530 // will do an animation to reveal it from behind the
6531 // starting window, so there is no need for it to also
6532 // be doing its own stuff.
6533 if (mAnimation != null) {
6534 mAnimation = null;
6535 // Make sure we clean up the animation.
6536 mAnimating = true;
6537 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006538 mFinishedStarting.add(mAppToken);
6539 mH.sendEmptyMessage(H.FINISHED_STARTING);
6540 }
6541 mAppToken.updateReportedVisibilityLocked();
6542 }
6543 }
6544 return true;
6545 }
Romain Guy06882f82009-06-10 13:36:04 -07006546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006547 // This must be called while inside a transaction. Returns true if
6548 // there is more animation to run.
6549 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08006550 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006551 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07006552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006553 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
6554 mHasTransformation = true;
6555 mHasLocalTransformation = true;
6556 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006557 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006558 TAG, "Starting animation in " + this +
6559 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
6560 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
6561 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
6562 mAnimation.setStartTime(currentTime);
6563 mLocalAnimating = true;
6564 mAnimating = true;
6565 }
6566 mTransformation.clear();
6567 final boolean more = mAnimation.getTransformation(
6568 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006569 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006570 TAG, "Stepped animation in " + this +
6571 ": more=" + more + ", xform=" + mTransformation);
6572 if (more) {
6573 // we're not done!
6574 return true;
6575 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006576 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006577 TAG, "Finished animation in " + this +
6578 " @ " + currentTime);
6579 mAnimation = null;
6580 //WindowManagerService.this.dump();
6581 }
6582 mHasLocalTransformation = false;
6583 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006584 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006585 // When our app token is animating, we kind-of pretend like
6586 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
6587 // part of this check means that we will only do this if
6588 // our window is not currently exiting, or it is not
6589 // locally animating itself. The idea being that one that
6590 // is exiting and doing a local animation should be removed
6591 // once that animation is done.
6592 mAnimating = true;
6593 mHasTransformation = true;
6594 mTransformation.clear();
6595 return false;
6596 } else if (mHasTransformation) {
6597 // Little trick to get through the path below to act like
6598 // we have finished an animation.
6599 mAnimating = true;
6600 } else if (isAnimating()) {
6601 mAnimating = true;
6602 }
6603 } else if (mAnimation != null) {
6604 // If the display is frozen, and there is a pending animation,
6605 // clear it and make sure we run the cleanup code.
6606 mAnimating = true;
6607 mLocalAnimating = true;
6608 mAnimation = null;
6609 }
Romain Guy06882f82009-06-10 13:36:04 -07006610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006611 if (!mAnimating && !mLocalAnimating) {
6612 return false;
6613 }
6614
Joe Onorato8a9b2202010-02-26 18:56:32 -08006615 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006616 TAG, "Animation done in " + this + ": exiting=" + mExiting
6617 + ", reportedVisible="
6618 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07006619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006620 mAnimating = false;
6621 mLocalAnimating = false;
6622 mAnimation = null;
6623 mAnimLayer = mLayer;
6624 if (mIsImWindow) {
6625 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006626 } else if (mIsWallpaper) {
6627 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006628 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006629 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006630 + " anim layer: " + mAnimLayer);
6631 mHasTransformation = false;
6632 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006633 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
6634 if (DEBUG_VISIBILITY) {
6635 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
6636 + mPolicyVisibilityAfterAnim);
6637 }
6638 mPolicyVisibility = mPolicyVisibilityAfterAnim;
6639 if (!mPolicyVisibility) {
6640 if (mCurrentFocus == this) {
6641 mFocusMayChange = true;
6642 }
6643 // Window is no longer visible -- make sure if we were waiting
6644 // for it to be displayed before enabling the display, that
6645 // we allow the display to be enabled now.
6646 enableScreenIfNeededLocked();
6647 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08006648 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006649 mTransformation.clear();
6650 if (mHasDrawn
6651 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
6652 && mAppToken != null
6653 && mAppToken.firstWindowDrawn
6654 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006655 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006656 + mToken + ": first real window done animating");
6657 mFinishedStarting.add(mAppToken);
6658 mH.sendEmptyMessage(H.FINISHED_STARTING);
6659 }
Romain Guy06882f82009-06-10 13:36:04 -07006660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006661 finishExit();
6662
6663 if (mAppToken != null) {
6664 mAppToken.updateReportedVisibilityLocked();
6665 }
6666
6667 return false;
6668 }
6669
6670 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006671 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006672 TAG, "finishExit in " + this
6673 + ": exiting=" + mExiting
6674 + " remove=" + mRemoveOnExit
6675 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07006676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006677 final int N = mChildWindows.size();
6678 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07006679 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006680 }
Romain Guy06882f82009-06-10 13:36:04 -07006681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006682 if (!mExiting) {
6683 return;
6684 }
Romain Guy06882f82009-06-10 13:36:04 -07006685
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006686 if (isWindowAnimating()) {
6687 return;
6688 }
6689
Joe Onorato8a9b2202010-02-26 18:56:32 -08006690 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006691 TAG, "Exit animation finished in " + this
6692 + ": remove=" + mRemoveOnExit);
6693 if (mSurface != null) {
6694 mDestroySurface.add(this);
6695 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006696 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006697 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006698 try {
6699 mSurface.hide();
6700 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006701 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006702 }
6703 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006704 }
6705 mExiting = false;
6706 if (mRemoveOnExit) {
6707 mPendingRemove.add(this);
6708 mRemoveOnExit = false;
6709 }
6710 }
Romain Guy06882f82009-06-10 13:36:04 -07006711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006712 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
6713 if (dsdx < .99999f || dsdx > 1.00001f) return false;
6714 if (dtdy < .99999f || dtdy > 1.00001f) return false;
6715 if (dtdx < -.000001f || dtdx > .000001f) return false;
6716 if (dsdy < -.000001f || dsdy > .000001f) return false;
6717 return true;
6718 }
Romain Guy06882f82009-06-10 13:36:04 -07006719
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006720 void computeShownFrameLocked() {
6721 final boolean selfTransformation = mHasLocalTransformation;
6722 Transformation attachedTransformation =
6723 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
6724 ? mAttachedWindow.mTransformation : null;
6725 Transformation appTransformation =
6726 (mAppToken != null && mAppToken.hasTransformation)
6727 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006728
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006729 // Wallpapers are animated based on the "real" window they
6730 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006731 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07006732 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07006733 if (mWallpaperTarget.mHasLocalTransformation &&
6734 mWallpaperTarget.mAnimation != null &&
6735 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006736 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006737 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006738 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006739 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006740 }
6741 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07006742 mWallpaperTarget.mAppToken.hasTransformation &&
6743 mWallpaperTarget.mAppToken.animation != null &&
6744 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006745 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006746 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006747 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006748 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006749 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006750 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006752 if (selfTransformation || attachedTransformation != null
6753 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07006754 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006755 final Rect frame = mFrame;
6756 final float tmpFloats[] = mTmpFloats;
6757 final Matrix tmpMatrix = mTmpMatrix;
6758
6759 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07006760 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006761 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006762 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006763 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07006764 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006765 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006766 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006767 }
6768 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006769 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006770 }
6771
6772 // "convert" it into SurfaceFlinger's format
6773 // (a 2x2 matrix + an offset)
6774 // Here we must not transform the position of the surface
6775 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006776 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07006777
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006778 tmpMatrix.getValues(tmpFloats);
6779 mDsDx = tmpFloats[Matrix.MSCALE_X];
6780 mDtDx = tmpFloats[Matrix.MSKEW_X];
6781 mDsDy = tmpFloats[Matrix.MSKEW_Y];
6782 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006783 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
6784 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006785 int w = frame.width();
6786 int h = frame.height();
6787 mShownFrame.set(x, y, x+w, y+h);
6788
6789 // Now set the alpha... but because our current hardware
6790 // can't do alpha transformation on a non-opaque surface,
6791 // turn it off if we are running an animation that is also
6792 // transforming since it is more important to have that
6793 // animation be smooth.
6794 mShownAlpha = mAlpha;
6795 if (!mLimitedAlphaCompositing
6796 || (!PixelFormat.formatHasAlpha(mAttrs.format)
6797 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
6798 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006799 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006800 if (selfTransformation) {
6801 mShownAlpha *= mTransformation.getAlpha();
6802 }
6803 if (attachedTransformation != null) {
6804 mShownAlpha *= attachedTransformation.getAlpha();
6805 }
6806 if (appTransformation != null) {
6807 mShownAlpha *= appTransformation.getAlpha();
6808 }
6809 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006810 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006811 }
Romain Guy06882f82009-06-10 13:36:04 -07006812
Joe Onorato8a9b2202010-02-26 18:56:32 -08006813 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006814 TAG, "Continuing animation in " + this +
6815 ": " + mShownFrame +
6816 ", alpha=" + mTransformation.getAlpha());
6817 return;
6818 }
Romain Guy06882f82009-06-10 13:36:04 -07006819
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006820 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006821 if (mXOffset != 0 || mYOffset != 0) {
6822 mShownFrame.offset(mXOffset, mYOffset);
6823 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006824 mShownAlpha = mAlpha;
6825 mDsDx = 1;
6826 mDtDx = 0;
6827 mDsDy = 0;
6828 mDtDy = 1;
6829 }
Romain Guy06882f82009-06-10 13:36:04 -07006830
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006831 /**
6832 * Is this window visible? It is not visible if there is no
6833 * surface, or we are in the process of running an exit animation
6834 * that will remove the surface, or its app token has been hidden.
6835 */
6836 public boolean isVisibleLw() {
6837 final AppWindowToken atoken = mAppToken;
6838 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6839 && (atoken == null || !atoken.hiddenRequested)
6840 && !mExiting && !mDestroying;
6841 }
6842
6843 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006844 * Like {@link #isVisibleLw}, but also counts a window that is currently
6845 * "hidden" behind the keyguard as visible. This allows us to apply
6846 * things like window flags that impact the keyguard.
6847 * XXX I am starting to think we need to have ANOTHER visibility flag
6848 * for this "hidden behind keyguard" state rather than overloading
6849 * mPolicyVisibility. Ungh.
6850 */
6851 public boolean isVisibleOrBehindKeyguardLw() {
6852 final AppWindowToken atoken = mAppToken;
6853 return mSurface != null && !mAttachedHidden
6854 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackborn5943c202010-04-12 21:36:49 -07006855 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending))
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006856 && !mExiting && !mDestroying;
6857 }
6858
6859 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006860 * Is this window visible, ignoring its app token? It is not visible
6861 * if there is no surface, or we are in the process of running an exit animation
6862 * that will remove the surface.
6863 */
6864 public boolean isWinVisibleLw() {
6865 final AppWindowToken atoken = mAppToken;
6866 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6867 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
6868 && !mExiting && !mDestroying;
6869 }
6870
6871 /**
6872 * The same as isVisible(), but follows the current hidden state of
6873 * the associated app token, not the pending requested hidden state.
6874 */
6875 boolean isVisibleNow() {
6876 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07006877 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006878 }
6879
6880 /**
6881 * Same as isVisible(), but we also count it as visible between the
6882 * call to IWindowSession.add() and the first relayout().
6883 */
6884 boolean isVisibleOrAdding() {
6885 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006886 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006887 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
6888 && mPolicyVisibility && !mAttachedHidden
6889 && (atoken == null || !atoken.hiddenRequested)
6890 && !mExiting && !mDestroying;
6891 }
6892
6893 /**
6894 * Is this window currently on-screen? It is on-screen either if it
6895 * is visible or it is currently running an animation before no longer
6896 * being visible.
6897 */
6898 boolean isOnScreen() {
6899 final AppWindowToken atoken = mAppToken;
6900 if (atoken != null) {
6901 return mSurface != null && mPolicyVisibility && !mDestroying
6902 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006903 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006904 } else {
6905 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006906 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006907 }
6908 }
Romain Guy06882f82009-06-10 13:36:04 -07006909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006910 /**
6911 * Like isOnScreen(), but we don't return true if the window is part
6912 * of a transition that has not yet been started.
6913 */
6914 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006915 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07006916 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006917 return false;
6918 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006919 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006920 final boolean animating = atoken != null
6921 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006922 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006923 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
6924 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006925 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006926 }
6927
6928 /** Is the window or its container currently animating? */
6929 boolean isAnimating() {
6930 final WindowState attached = mAttachedWindow;
6931 final AppWindowToken atoken = mAppToken;
6932 return mAnimation != null
6933 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07006934 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006935 (atoken.animation != null
6936 || atoken.inPendingTransaction));
6937 }
6938
6939 /** Is this window currently animating? */
6940 boolean isWindowAnimating() {
6941 return mAnimation != null;
6942 }
6943
6944 /**
6945 * Like isOnScreen, but returns false if the surface hasn't yet
6946 * been drawn.
6947 */
6948 public boolean isDisplayedLw() {
6949 final AppWindowToken atoken = mAppToken;
6950 return mSurface != null && mPolicyVisibility && !mDestroying
6951 && !mDrawPending && !mCommitDrawPending
6952 && ((!mAttachedHidden &&
6953 (atoken == null || !atoken.hiddenRequested))
6954 || mAnimating);
6955 }
6956
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006957 /**
6958 * Returns true if the window has a surface that it has drawn a
Dianne Hackborn5943c202010-04-12 21:36:49 -07006959 * complete UI in to. Note that this returns true if the orientation
6960 * is changing even if the window hasn't redrawn because we don't want
6961 * to stop things from executing during that time.
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006962 */
6963 public boolean isDrawnLw() {
6964 final AppWindowToken atoken = mAppToken;
6965 return mSurface != null && !mDestroying
Dianne Hackborn5943c202010-04-12 21:36:49 -07006966 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending));
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006967 }
6968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006969 public boolean fillsScreenLw(int screenWidth, int screenHeight,
6970 boolean shownFrame, boolean onlyOpaque) {
6971 if (mSurface == null) {
6972 return false;
6973 }
6974 if (mAppToken != null && !mAppToken.appFullscreen) {
6975 return false;
6976 }
6977 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
6978 return false;
6979 }
6980 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006981
6982 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
6983 return frame.left <= mCompatibleScreenFrame.left &&
6984 frame.top <= mCompatibleScreenFrame.top &&
6985 frame.right >= mCompatibleScreenFrame.right &&
6986 frame.bottom >= mCompatibleScreenFrame.bottom;
6987 } else {
6988 return frame.left <= 0 && frame.top <= 0
6989 && frame.right >= screenWidth
6990 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006991 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006992 }
Romain Guy06882f82009-06-10 13:36:04 -07006993
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006994 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07006995 * Return true if the window is opaque and fully drawn. This indicates
6996 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006997 */
6998 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07006999 return (mAttrs.format == PixelFormat.OPAQUE
7000 || mAttrs.type == TYPE_WALLPAPER)
7001 && mSurface != null && mAnimation == null
7002 && (mAppToken == null || mAppToken.animation == null)
7003 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007004 }
7005
7006 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7007 return
7008 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007009 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7010 // only if it's visible
7011 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007012 // and only if the application fills the compatible screen
7013 mFrame.left <= mCompatibleScreenFrame.left &&
7014 mFrame.top <= mCompatibleScreenFrame.top &&
7015 mFrame.right >= mCompatibleScreenFrame.right &&
7016 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007017 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007018 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007019 }
7020
7021 boolean isFullscreen(int screenWidth, int screenHeight) {
7022 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007023 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007024 }
7025
7026 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007027 disposeInputChannel();
7028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007029 if (mAttachedWindow != null) {
7030 mAttachedWindow.mChildWindows.remove(this);
7031 }
7032 destroySurfaceLocked();
7033 mSession.windowRemovedLocked();
7034 try {
7035 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7036 } catch (RuntimeException e) {
7037 // Ignore if it has already been removed (usually because
7038 // we are doing this as part of processing a death note.)
7039 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007040 }
7041
7042 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007043 if (mInputChannel != null) {
7044 mInputManager.unregisterInputChannel(mInputChannel);
7045
7046 mInputChannel.dispose();
7047 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007048 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007049 }
7050
7051 private class DeathRecipient implements IBinder.DeathRecipient {
7052 public void binderDied() {
7053 try {
7054 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007055 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007056 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007057 if (win != null) {
7058 removeWindowLocked(mSession, win);
7059 }
7060 }
7061 } catch (IllegalArgumentException ex) {
7062 // This will happen if the window has already been
7063 // removed.
7064 }
7065 }
7066 }
7067
7068 /** Returns true if this window desires key events. */
7069 public final boolean canReceiveKeys() {
7070 return isVisibleOrAdding()
7071 && (mViewVisibility == View.VISIBLE)
7072 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7073 }
7074
7075 public boolean hasDrawnLw() {
7076 return mHasDrawn;
7077 }
7078
7079 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007080 return showLw(doAnimation, true);
7081 }
7082
7083 boolean showLw(boolean doAnimation, boolean requestAnim) {
7084 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7085 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007086 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007087 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007088 if (doAnimation) {
7089 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7090 + mPolicyVisibility + " mAnimation=" + mAnimation);
7091 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7092 doAnimation = false;
7093 } else if (mPolicyVisibility && mAnimation == null) {
7094 // Check for the case where we are currently visible and
7095 // not animating; we do not want to do animation at such a
7096 // point to become visible when we already are.
7097 doAnimation = false;
7098 }
7099 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007100 mPolicyVisibility = true;
7101 mPolicyVisibilityAfterAnim = true;
7102 if (doAnimation) {
7103 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7104 }
7105 if (requestAnim) {
7106 requestAnimationLocked(0);
7107 }
7108 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007109 }
7110
7111 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007112 return hideLw(doAnimation, true);
7113 }
7114
7115 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007116 if (doAnimation) {
7117 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7118 doAnimation = false;
7119 }
7120 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007121 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7122 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007123 if (!current) {
7124 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007125 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007126 if (doAnimation) {
7127 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7128 if (mAnimation == null) {
7129 doAnimation = false;
7130 }
7131 }
7132 if (doAnimation) {
7133 mPolicyVisibilityAfterAnim = false;
7134 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007135 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007136 mPolicyVisibilityAfterAnim = false;
7137 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007138 // Window is no longer visible -- make sure if we were waiting
7139 // for it to be displayed before enabling the display, that
7140 // we allow the display to be enabled now.
7141 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007142 if (mCurrentFocus == this) {
7143 mFocusMayChange = true;
7144 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007145 }
7146 if (requestAnim) {
7147 requestAnimationLocked(0);
7148 }
7149 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007150 }
7151
7152 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007153 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7154 pw.print(" mClient="); pw.println(mClient.asBinder());
7155 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7156 if (mAttachedWindow != null || mLayoutAttached) {
7157 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7158 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7159 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007160 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7161 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7162 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007163 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7164 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007165 }
7166 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7167 pw.print(" mSubLayer="); pw.print(mSubLayer);
7168 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7169 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7170 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7171 pw.print("="); pw.print(mAnimLayer);
7172 pw.print(" mLastLayer="); pw.println(mLastLayer);
7173 if (mSurface != null) {
7174 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007175 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7176 pw.print(" layer="); pw.print(mSurfaceLayer);
7177 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7178 pw.print(" rect=("); pw.print(mSurfaceX);
7179 pw.print(","); pw.print(mSurfaceY);
7180 pw.print(") "); pw.print(mSurfaceW);
7181 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007182 }
7183 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7184 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7185 if (mAppToken != null) {
7186 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7187 }
7188 if (mTargetAppToken != null) {
7189 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7190 }
7191 pw.print(prefix); pw.print("mViewVisibility=0x");
7192 pw.print(Integer.toHexString(mViewVisibility));
7193 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007194 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7195 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007196 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7197 pw.print(prefix); pw.print("mPolicyVisibility=");
7198 pw.print(mPolicyVisibility);
7199 pw.print(" mPolicyVisibilityAfterAnim=");
7200 pw.print(mPolicyVisibilityAfterAnim);
7201 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7202 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007203 if (!mRelayoutCalled) {
7204 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7205 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007206 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007207 pw.print(" h="); pw.print(mRequestedHeight);
7208 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007209 if (mXOffset != 0 || mYOffset != 0) {
7210 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7211 pw.print(" y="); pw.println(mYOffset);
7212 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007213 pw.print(prefix); pw.print("mGivenContentInsets=");
7214 mGivenContentInsets.printShortString(pw);
7215 pw.print(" mGivenVisibleInsets=");
7216 mGivenVisibleInsets.printShortString(pw);
7217 pw.println();
7218 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7219 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7220 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7221 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007222 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007223 pw.print(prefix); pw.print("mShownFrame=");
7224 mShownFrame.printShortString(pw);
7225 pw.print(" last="); mLastShownFrame.printShortString(pw);
7226 pw.println();
7227 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7228 pw.print(" last="); mLastFrame.printShortString(pw);
7229 pw.println();
7230 pw.print(prefix); pw.print("mContainingFrame=");
7231 mContainingFrame.printShortString(pw);
7232 pw.print(" mDisplayFrame=");
7233 mDisplayFrame.printShortString(pw);
7234 pw.println();
7235 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7236 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7237 pw.println();
7238 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7239 pw.print(" last="); mLastContentInsets.printShortString(pw);
7240 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7241 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7242 pw.println();
7243 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7244 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7245 pw.print(" mAlpha="); pw.print(mAlpha);
7246 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7247 }
7248 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7249 || mAnimation != null) {
7250 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7251 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7252 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7253 pw.print(" mAnimation="); pw.println(mAnimation);
7254 }
7255 if (mHasTransformation || mHasLocalTransformation) {
7256 pw.print(prefix); pw.print("XForm: has=");
7257 pw.print(mHasTransformation);
7258 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7259 pw.print(" "); mTransformation.printShortString(pw);
7260 pw.println();
7261 }
7262 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7263 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7264 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7265 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7266 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7267 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7268 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7269 pw.print(" mDestroying="); pw.print(mDestroying);
7270 pw.print(" mRemoved="); pw.println(mRemoved);
7271 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007272 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007273 pw.print(prefix); pw.print("mOrientationChanging=");
7274 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007275 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7276 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007277 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007278 if (mHScale != 1 || mVScale != 1) {
7279 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7280 pw.print(" mVScale="); pw.println(mVScale);
7281 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007282 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007283 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7284 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7285 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007286 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7287 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7288 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7289 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007290 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007291
7292 String makeInputChannelName() {
7293 return Integer.toHexString(System.identityHashCode(this))
7294 + " " + mAttrs.getTitle();
7295 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007296
7297 @Override
7298 public String toString() {
7299 return "Window{"
7300 + Integer.toHexString(System.identityHashCode(this))
7301 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7302 }
7303 }
Romain Guy06882f82009-06-10 13:36:04 -07007304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007305 // -------------------------------------------------------------
7306 // Window Token State
7307 // -------------------------------------------------------------
7308
7309 class WindowToken {
7310 // The actual token.
7311 final IBinder token;
7312
7313 // The type of window this token is for, as per WindowManager.LayoutParams.
7314 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007316 // Set if this token was explicitly added by a client, so should
7317 // not be removed when all windows are removed.
7318 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007319
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007320 // For printing.
7321 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007323 // If this is an AppWindowToken, this is non-null.
7324 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007326 // All of the windows associated with this token.
7327 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7328
7329 // Is key dispatching paused for this token?
7330 boolean paused = false;
7331
7332 // Should this token's windows be hidden?
7333 boolean hidden;
7334
7335 // Temporary for finding which tokens no longer have visible windows.
7336 boolean hasVisible;
7337
Dianne Hackborna8f60182009-09-01 19:01:50 -07007338 // Set to true when this token is in a pending transaction where it
7339 // will be shown.
7340 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007341
Dianne Hackborna8f60182009-09-01 19:01:50 -07007342 // Set to true when this token is in a pending transaction where it
7343 // will be hidden.
7344 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007345
Dianne Hackborna8f60182009-09-01 19:01:50 -07007346 // Set to true when this token is in a pending transaction where its
7347 // windows will be put to the bottom of the list.
7348 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007349
Dianne Hackborna8f60182009-09-01 19:01:50 -07007350 // Set to true when this token is in a pending transaction where its
7351 // windows will be put to the top of the list.
7352 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007354 WindowToken(IBinder _token, int type, boolean _explicit) {
7355 token = _token;
7356 windowType = type;
7357 explicit = _explicit;
7358 }
7359
7360 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007361 pw.print(prefix); pw.print("token="); pw.println(token);
7362 pw.print(prefix); pw.print("windows="); pw.println(windows);
7363 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7364 pw.print(" hidden="); pw.print(hidden);
7365 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007366 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7367 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7368 pw.print(" waitingToHide="); pw.print(waitingToHide);
7369 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7370 pw.print(" sendingToTop="); pw.println(sendingToTop);
7371 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007372 }
7373
7374 @Override
7375 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007376 if (stringName == null) {
7377 StringBuilder sb = new StringBuilder();
7378 sb.append("WindowToken{");
7379 sb.append(Integer.toHexString(System.identityHashCode(this)));
7380 sb.append(" token="); sb.append(token); sb.append('}');
7381 stringName = sb.toString();
7382 }
7383 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007384 }
7385 };
7386
7387 class AppWindowToken extends WindowToken {
7388 // Non-null only for application tokens.
7389 final IApplicationToken appToken;
7390
7391 // All of the windows and child windows that are included in this
7392 // application token. Note this list is NOT sorted!
7393 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7394
7395 int groupId = -1;
7396 boolean appFullscreen;
7397 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007398
7399 // The input dispatching timeout for this application token in nanoseconds.
7400 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007402 // These are used for determining when all windows associated with
7403 // an activity have been drawn, so they can be made visible together
7404 // at the same time.
7405 int lastTransactionSequence = mTransactionSequence-1;
7406 int numInterestingWindows;
7407 int numDrawnWindows;
7408 boolean inPendingTransaction;
7409 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007411 // Is this token going to be hidden in a little while? If so, it
7412 // won't be taken into account for setting the screen orientation.
7413 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007415 // Is this window's surface needed? This is almost like hidden, except
7416 // it will sometimes be true a little earlier: when the token has
7417 // been shown, but is still waiting for its app transition to execute
7418 // before making its windows shown.
7419 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007421 // Have we told the window clients to hide themselves?
7422 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007424 // Last visibility state we reported to the app token.
7425 boolean reportedVisible;
7426
7427 // Set to true when the token has been removed from the window mgr.
7428 boolean removed;
7429
7430 // Have we been asked to have this token keep the screen frozen?
7431 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007433 boolean animating;
7434 Animation animation;
7435 boolean hasTransformation;
7436 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007438 // Offset to the window of all layers in the token, for use by
7439 // AppWindowToken animations.
7440 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007442 // Information about an application starting window if displayed.
7443 StartingData startingData;
7444 WindowState startingWindow;
7445 View startingView;
7446 boolean startingDisplayed;
7447 boolean startingMoved;
7448 boolean firstWindowDrawn;
7449
7450 AppWindowToken(IApplicationToken _token) {
7451 super(_token.asBinder(),
7452 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7453 appWindowToken = this;
7454 appToken = _token;
7455 }
Romain Guy06882f82009-06-10 13:36:04 -07007456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007457 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007458 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007459 TAG, "Setting animation in " + this + ": " + anim);
7460 animation = anim;
7461 animating = false;
7462 anim.restrictDuration(MAX_ANIMATION_DURATION);
7463 anim.scaleCurrentDuration(mTransitionAnimationScale);
7464 int zorder = anim.getZAdjustment();
7465 int adj = 0;
7466 if (zorder == Animation.ZORDER_TOP) {
7467 adj = TYPE_LAYER_OFFSET;
7468 } else if (zorder == Animation.ZORDER_BOTTOM) {
7469 adj = -TYPE_LAYER_OFFSET;
7470 }
Romain Guy06882f82009-06-10 13:36:04 -07007471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007472 if (animLayerAdjustment != adj) {
7473 animLayerAdjustment = adj;
7474 updateLayers();
7475 }
7476 }
Romain Guy06882f82009-06-10 13:36:04 -07007477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007478 public void setDummyAnimation() {
7479 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007480 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007481 TAG, "Setting dummy animation in " + this);
7482 animation = sDummyAnimation;
7483 }
7484 }
7485
7486 public void clearAnimation() {
7487 if (animation != null) {
7488 animation = null;
7489 animating = true;
7490 }
7491 }
Romain Guy06882f82009-06-10 13:36:04 -07007492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007493 void updateLayers() {
7494 final int N = allAppWindows.size();
7495 final int adj = animLayerAdjustment;
7496 for (int i=0; i<N; i++) {
7497 WindowState w = allAppWindows.get(i);
7498 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007499 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007500 + w.mAnimLayer);
7501 if (w == mInputMethodTarget) {
7502 setInputMethodAnimLayerAdjustment(adj);
7503 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007504 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007505 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007506 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007507 }
7508 }
Romain Guy06882f82009-06-10 13:36:04 -07007509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007510 void sendAppVisibilityToClients() {
7511 final int N = allAppWindows.size();
7512 for (int i=0; i<N; i++) {
7513 WindowState win = allAppWindows.get(i);
7514 if (win == startingWindow && clientHidden) {
7515 // Don't hide the starting window.
7516 continue;
7517 }
7518 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007519 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007520 "Setting visibility of " + win + ": " + (!clientHidden));
7521 win.mClient.dispatchAppVisibility(!clientHidden);
7522 } catch (RemoteException e) {
7523 }
7524 }
7525 }
Romain Guy06882f82009-06-10 13:36:04 -07007526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007527 void showAllWindowsLocked() {
7528 final int NW = allAppWindows.size();
7529 for (int i=0; i<NW; i++) {
7530 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007531 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007532 "performing show on: " + w);
7533 w.performShowLocked();
7534 }
7535 }
Romain Guy06882f82009-06-10 13:36:04 -07007536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007537 // This must be called while inside a transaction.
7538 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007539 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007540 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007542 if (animation == sDummyAnimation) {
7543 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007544 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007545 // when it is really time to animate, this will be set to
7546 // a real animation and the next call will execute normally.
7547 return false;
7548 }
Romain Guy06882f82009-06-10 13:36:04 -07007549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007550 if ((allDrawn || animating || startingDisplayed) && animation != null) {
7551 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007552 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007553 TAG, "Starting animation in " + this +
7554 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
7555 + " scale=" + mTransitionAnimationScale
7556 + " allDrawn=" + allDrawn + " animating=" + animating);
7557 animation.initialize(dw, dh, dw, dh);
7558 animation.setStartTime(currentTime);
7559 animating = true;
7560 }
7561 transformation.clear();
7562 final boolean more = animation.getTransformation(
7563 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007564 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007565 TAG, "Stepped animation in " + this +
7566 ": more=" + more + ", xform=" + transformation);
7567 if (more) {
7568 // we're done!
7569 hasTransformation = true;
7570 return true;
7571 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007572 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007573 TAG, "Finished animation in " + this +
7574 " @ " + currentTime);
7575 animation = null;
7576 }
7577 } else if (animation != null) {
7578 // If the display is frozen, and there is a pending animation,
7579 // clear it and make sure we run the cleanup code.
7580 animating = true;
7581 animation = null;
7582 }
7583
7584 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07007585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007586 if (!animating) {
7587 return false;
7588 }
7589
7590 clearAnimation();
7591 animating = false;
7592 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
7593 moveInputMethodWindowsIfNeededLocked(true);
7594 }
Romain Guy06882f82009-06-10 13:36:04 -07007595
Joe Onorato8a9b2202010-02-26 18:56:32 -08007596 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007597 TAG, "Animation done in " + this
7598 + ": reportedVisible=" + reportedVisible);
7599
7600 transformation.clear();
7601 if (animLayerAdjustment != 0) {
7602 animLayerAdjustment = 0;
7603 updateLayers();
7604 }
Romain Guy06882f82009-06-10 13:36:04 -07007605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007606 final int N = windows.size();
7607 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007608 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007609 }
7610 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07007611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007612 return false;
7613 }
7614
7615 void updateReportedVisibilityLocked() {
7616 if (appToken == null) {
7617 return;
7618 }
Romain Guy06882f82009-06-10 13:36:04 -07007619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007620 int numInteresting = 0;
7621 int numVisible = 0;
7622 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07007623
Joe Onorato8a9b2202010-02-26 18:56:32 -08007624 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007625 final int N = allAppWindows.size();
7626 for (int i=0; i<N; i++) {
7627 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08007628 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07007629 || win.mViewVisibility != View.VISIBLE
7630 || win.mAttrs.type == TYPE_APPLICATION_STARTING) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007631 continue;
7632 }
7633 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007634 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007635 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007636 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007637 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007638 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007639 + " pv=" + win.mPolicyVisibility
7640 + " dp=" + win.mDrawPending
7641 + " cdp=" + win.mCommitDrawPending
7642 + " ah=" + win.mAttachedHidden
7643 + " th="
7644 + (win.mAppToken != null
7645 ? win.mAppToken.hiddenRequested : false)
7646 + " a=" + win.mAnimating);
7647 }
7648 }
7649 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007650 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007651 if (!win.isAnimating()) {
7652 numVisible++;
7653 }
7654 nowGone = false;
7655 } else if (win.isAnimating()) {
7656 nowGone = false;
7657 }
7658 }
Romain Guy06882f82009-06-10 13:36:04 -07007659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007660 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007661 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007662 + numInteresting + " visible=" + numVisible);
7663 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007664 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007665 TAG, "Visibility changed in " + this
7666 + ": vis=" + nowVisible);
7667 reportedVisible = nowVisible;
7668 Message m = mH.obtainMessage(
7669 H.REPORT_APPLICATION_TOKEN_WINDOWS,
7670 nowVisible ? 1 : 0,
7671 nowGone ? 1 : 0,
7672 this);
7673 mH.sendMessage(m);
7674 }
7675 }
Romain Guy06882f82009-06-10 13:36:04 -07007676
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007677 WindowState findMainWindow() {
7678 int j = windows.size();
7679 while (j > 0) {
7680 j--;
7681 WindowState win = windows.get(j);
7682 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
7683 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
7684 return win;
7685 }
7686 }
7687 return null;
7688 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007690 void dump(PrintWriter pw, String prefix) {
7691 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007692 if (appToken != null) {
7693 pw.print(prefix); pw.println("app=true");
7694 }
7695 if (allAppWindows.size() > 0) {
7696 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
7697 }
7698 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007699 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007700 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
7701 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
7702 pw.print(" clientHidden="); pw.print(clientHidden);
7703 pw.print(" willBeHidden="); pw.print(willBeHidden);
7704 pw.print(" reportedVisible="); pw.println(reportedVisible);
7705 if (paused || freezingScreen) {
7706 pw.print(prefix); pw.print("paused="); pw.print(paused);
7707 pw.print(" freezingScreen="); pw.println(freezingScreen);
7708 }
7709 if (numInterestingWindows != 0 || numDrawnWindows != 0
7710 || inPendingTransaction || allDrawn) {
7711 pw.print(prefix); pw.print("numInterestingWindows=");
7712 pw.print(numInterestingWindows);
7713 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
7714 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
7715 pw.print(" allDrawn="); pw.println(allDrawn);
7716 }
7717 if (animating || animation != null) {
7718 pw.print(prefix); pw.print("animating="); pw.print(animating);
7719 pw.print(" animation="); pw.println(animation);
7720 }
7721 if (animLayerAdjustment != 0) {
7722 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
7723 }
7724 if (hasTransformation) {
7725 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
7726 pw.print(" transformation="); transformation.printShortString(pw);
7727 pw.println();
7728 }
7729 if (startingData != null || removed || firstWindowDrawn) {
7730 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
7731 pw.print(" removed="); pw.print(removed);
7732 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
7733 }
7734 if (startingWindow != null || startingView != null
7735 || startingDisplayed || startingMoved) {
7736 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
7737 pw.print(" startingView="); pw.print(startingView);
7738 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
7739 pw.print(" startingMoved"); pw.println(startingMoved);
7740 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007741 }
7742
7743 @Override
7744 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007745 if (stringName == null) {
7746 StringBuilder sb = new StringBuilder();
7747 sb.append("AppWindowToken{");
7748 sb.append(Integer.toHexString(System.identityHashCode(this)));
7749 sb.append(" token="); sb.append(token); sb.append('}');
7750 stringName = sb.toString();
7751 }
7752 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007753 }
7754 }
Romain Guy06882f82009-06-10 13:36:04 -07007755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007756 // -------------------------------------------------------------
7757 // DummyAnimation
7758 // -------------------------------------------------------------
7759
7760 // This is an animation that does nothing: it just immediately finishes
7761 // itself every time it is called. It is used as a stub animation in cases
7762 // where we want to synchronize multiple things that may be animating.
7763 static final class DummyAnimation extends Animation {
7764 public boolean getTransformation(long currentTime, Transformation outTransformation) {
7765 return false;
7766 }
7767 }
7768 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07007769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007770 // -------------------------------------------------------------
7771 // Async Handler
7772 // -------------------------------------------------------------
7773
7774 static final class StartingData {
7775 final String pkg;
7776 final int theme;
7777 final CharSequence nonLocalizedLabel;
7778 final int labelRes;
7779 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07007780
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007781 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
7782 int _labelRes, int _icon) {
7783 pkg = _pkg;
7784 theme = _theme;
7785 nonLocalizedLabel = _nonLocalizedLabel;
7786 labelRes = _labelRes;
7787 icon = _icon;
7788 }
7789 }
7790
7791 private final class H extends Handler {
7792 public static final int REPORT_FOCUS_CHANGE = 2;
7793 public static final int REPORT_LOSING_FOCUS = 3;
7794 public static final int ANIMATE = 4;
7795 public static final int ADD_STARTING = 5;
7796 public static final int REMOVE_STARTING = 6;
7797 public static final int FINISHED_STARTING = 7;
7798 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007799 public static final int WINDOW_FREEZE_TIMEOUT = 11;
7800 public static final int HOLD_SCREEN_CHANGED = 12;
7801 public static final int APP_TRANSITION_TIMEOUT = 13;
7802 public static final int PERSIST_ANIMATION_SCALE = 14;
7803 public static final int FORCE_GC = 15;
7804 public static final int ENABLE_SCREEN = 16;
7805 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007806 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07007807 public static final int REPORT_WINDOWS_CHANGE = 19;
Romain Guy06882f82009-06-10 13:36:04 -07007808
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007809 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07007810
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007811 public H() {
7812 }
Romain Guy06882f82009-06-10 13:36:04 -07007813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007814 @Override
7815 public void handleMessage(Message msg) {
7816 switch (msg.what) {
7817 case REPORT_FOCUS_CHANGE: {
7818 WindowState lastFocus;
7819 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07007820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007821 synchronized(mWindowMap) {
7822 lastFocus = mLastFocus;
7823 newFocus = mCurrentFocus;
7824 if (lastFocus == newFocus) {
7825 // Focus is not changing, so nothing to do.
7826 return;
7827 }
7828 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007829 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007830 // + " to " + newFocus);
7831 if (newFocus != null && lastFocus != null
7832 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007833 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007834 mLosingFocus.add(lastFocus);
7835 lastFocus = null;
7836 }
7837 }
7838
7839 if (lastFocus != newFocus) {
7840 //System.out.println("Changing focus from " + lastFocus
7841 // + " to " + newFocus);
7842 if (newFocus != null) {
7843 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007844 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007845 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
7846 } catch (RemoteException e) {
7847 // Ignore if process has died.
7848 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07007849 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007850 }
7851
7852 if (lastFocus != null) {
7853 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007854 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007855 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
7856 } catch (RemoteException e) {
7857 // Ignore if process has died.
7858 }
7859 }
7860 }
7861 } break;
7862
7863 case REPORT_LOSING_FOCUS: {
7864 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07007865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007866 synchronized(mWindowMap) {
7867 losers = mLosingFocus;
7868 mLosingFocus = new ArrayList<WindowState>();
7869 }
7870
7871 final int N = losers.size();
7872 for (int i=0; i<N; i++) {
7873 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007874 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007875 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
7876 } catch (RemoteException e) {
7877 // Ignore if process has died.
7878 }
7879 }
7880 } break;
7881
7882 case ANIMATE: {
7883 synchronized(mWindowMap) {
7884 mAnimationPending = false;
7885 performLayoutAndPlaceSurfacesLocked();
7886 }
7887 } break;
7888
7889 case ADD_STARTING: {
7890 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7891 final StartingData sd = wtoken.startingData;
7892
7893 if (sd == null) {
7894 // Animation has been canceled... do nothing.
7895 return;
7896 }
Romain Guy06882f82009-06-10 13:36:04 -07007897
Joe Onorato8a9b2202010-02-26 18:56:32 -08007898 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007899 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07007900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007901 View view = null;
7902 try {
7903 view = mPolicy.addStartingWindow(
7904 wtoken.token, sd.pkg,
7905 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
7906 sd.icon);
7907 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007908 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007909 }
7910
7911 if (view != null) {
7912 boolean abort = false;
7913
7914 synchronized(mWindowMap) {
7915 if (wtoken.removed || wtoken.startingData == null) {
7916 // If the window was successfully added, then
7917 // we need to remove it.
7918 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007919 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007920 "Aborted starting " + wtoken
7921 + ": removed=" + wtoken.removed
7922 + " startingData=" + wtoken.startingData);
7923 wtoken.startingWindow = null;
7924 wtoken.startingData = null;
7925 abort = true;
7926 }
7927 } else {
7928 wtoken.startingView = view;
7929 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007930 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007931 "Added starting " + wtoken
7932 + ": startingWindow="
7933 + wtoken.startingWindow + " startingView="
7934 + wtoken.startingView);
7935 }
7936
7937 if (abort) {
7938 try {
7939 mPolicy.removeStartingWindow(wtoken.token, view);
7940 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007941 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007942 }
7943 }
7944 }
7945 } break;
7946
7947 case REMOVE_STARTING: {
7948 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7949 IBinder token = null;
7950 View view = null;
7951 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007952 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007953 + wtoken + ": startingWindow="
7954 + wtoken.startingWindow + " startingView="
7955 + wtoken.startingView);
7956 if (wtoken.startingWindow != null) {
7957 view = wtoken.startingView;
7958 token = wtoken.token;
7959 wtoken.startingData = null;
7960 wtoken.startingView = null;
7961 wtoken.startingWindow = null;
7962 }
7963 }
7964 if (view != null) {
7965 try {
7966 mPolicy.removeStartingWindow(token, view);
7967 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007968 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007969 }
7970 }
7971 } break;
7972
7973 case FINISHED_STARTING: {
7974 IBinder token = null;
7975 View view = null;
7976 while (true) {
7977 synchronized (mWindowMap) {
7978 final int N = mFinishedStarting.size();
7979 if (N <= 0) {
7980 break;
7981 }
7982 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
7983
Joe Onorato8a9b2202010-02-26 18:56:32 -08007984 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007985 "Finished starting " + wtoken
7986 + ": startingWindow=" + wtoken.startingWindow
7987 + " startingView=" + wtoken.startingView);
7988
7989 if (wtoken.startingWindow == null) {
7990 continue;
7991 }
7992
7993 view = wtoken.startingView;
7994 token = wtoken.token;
7995 wtoken.startingData = null;
7996 wtoken.startingView = null;
7997 wtoken.startingWindow = null;
7998 }
7999
8000 try {
8001 mPolicy.removeStartingWindow(token, view);
8002 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008003 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008004 }
8005 }
8006 } break;
8007
8008 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8009 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8010
8011 boolean nowVisible = msg.arg1 != 0;
8012 boolean nowGone = msg.arg2 != 0;
8013
8014 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008015 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008016 TAG, "Reporting visible in " + wtoken
8017 + " visible=" + nowVisible
8018 + " gone=" + nowGone);
8019 if (nowVisible) {
8020 wtoken.appToken.windowsVisible();
8021 } else {
8022 wtoken.appToken.windowsGone();
8023 }
8024 } catch (RemoteException ex) {
8025 }
8026 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008027
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008028 case WINDOW_FREEZE_TIMEOUT: {
8029 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008030 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008031 int i = mWindows.size();
8032 while (i > 0) {
8033 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008034 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008035 if (w.mOrientationChanging) {
8036 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008037 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008038 }
8039 }
8040 performLayoutAndPlaceSurfacesLocked();
8041 }
8042 break;
8043 }
Romain Guy06882f82009-06-10 13:36:04 -07008044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008045 case HOLD_SCREEN_CHANGED: {
8046 Session oldHold;
8047 Session newHold;
8048 synchronized (mWindowMap) {
8049 oldHold = mLastReportedHold;
8050 newHold = (Session)msg.obj;
8051 mLastReportedHold = newHold;
8052 }
Romain Guy06882f82009-06-10 13:36:04 -07008053
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008054 if (oldHold != newHold) {
8055 try {
8056 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008057 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008058 "window",
8059 BatteryStats.WAKE_TYPE_WINDOW);
8060 }
8061 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008062 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008063 "window",
8064 BatteryStats.WAKE_TYPE_WINDOW);
8065 }
8066 } catch (RemoteException e) {
8067 }
8068 }
8069 break;
8070 }
Romain Guy06882f82009-06-10 13:36:04 -07008071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008072 case APP_TRANSITION_TIMEOUT: {
8073 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008074 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008075 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008076 "*** APP TRANSITION TIMEOUT");
8077 mAppTransitionReady = true;
8078 mAppTransitionTimeout = true;
8079 performLayoutAndPlaceSurfacesLocked();
8080 }
8081 }
8082 break;
8083 }
Romain Guy06882f82009-06-10 13:36:04 -07008084
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008085 case PERSIST_ANIMATION_SCALE: {
8086 Settings.System.putFloat(mContext.getContentResolver(),
8087 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8088 Settings.System.putFloat(mContext.getContentResolver(),
8089 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8090 break;
8091 }
Romain Guy06882f82009-06-10 13:36:04 -07008092
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008093 case FORCE_GC: {
8094 synchronized(mWindowMap) {
8095 if (mAnimationPending) {
8096 // If we are animating, don't do the gc now but
8097 // delay a bit so we don't interrupt the animation.
8098 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8099 2000);
8100 return;
8101 }
8102 // If we are currently rotating the display, it will
8103 // schedule a new message when done.
8104 if (mDisplayFrozen) {
8105 return;
8106 }
8107 mFreezeGcPending = 0;
8108 }
8109 Runtime.getRuntime().gc();
8110 break;
8111 }
Romain Guy06882f82009-06-10 13:36:04 -07008112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008113 case ENABLE_SCREEN: {
8114 performEnableScreen();
8115 break;
8116 }
Romain Guy06882f82009-06-10 13:36:04 -07008117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008118 case APP_FREEZE_TIMEOUT: {
8119 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008120 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008121 int i = mAppTokens.size();
8122 while (i > 0) {
8123 i--;
8124 AppWindowToken tok = mAppTokens.get(i);
8125 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008126 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008127 unsetAppFreezingScreenLocked(tok, true, true);
8128 }
8129 }
8130 }
8131 break;
8132 }
Romain Guy06882f82009-06-10 13:36:04 -07008133
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008134 case SEND_NEW_CONFIGURATION: {
8135 removeMessages(SEND_NEW_CONFIGURATION);
8136 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008137 break;
8138 }
Romain Guy06882f82009-06-10 13:36:04 -07008139
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008140 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008141 if (mWindowsChanged) {
8142 synchronized (mWindowMap) {
8143 mWindowsChanged = false;
8144 }
8145 notifyWindowsChanged();
8146 }
8147 break;
8148 }
8149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008150 }
8151 }
8152 }
8153
8154 // -------------------------------------------------------------
8155 // IWindowManager API
8156 // -------------------------------------------------------------
8157
8158 public IWindowSession openSession(IInputMethodClient client,
8159 IInputContext inputContext) {
8160 if (client == null) throw new IllegalArgumentException("null client");
8161 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008162 Session session = new Session(client, inputContext);
8163 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008164 }
8165
8166 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8167 synchronized (mWindowMap) {
8168 // The focus for the client is the window immediately below
8169 // where we would place the input method window.
8170 int idx = findDesiredInputMethodWindowIndexLocked(false);
8171 WindowState imFocus;
8172 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008173 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008174 if (imFocus != null) {
8175 if (imFocus.mSession.mClient != null &&
8176 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8177 return true;
8178 }
8179 }
8180 }
8181 }
8182 return false;
8183 }
Romain Guy06882f82009-06-10 13:36:04 -07008184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008185 // -------------------------------------------------------------
8186 // Internals
8187 // -------------------------------------------------------------
8188
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008189 final WindowState windowForClientLocked(Session session, IWindow client,
8190 boolean throwOnError) {
8191 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008192 }
Romain Guy06882f82009-06-10 13:36:04 -07008193
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008194 final WindowState windowForClientLocked(Session session, IBinder client,
8195 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008196 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008197 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008198 TAG, "Looking up client " + client + ": " + win);
8199 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008200 RuntimeException ex = new IllegalArgumentException(
8201 "Requested window " + client + " does not exist");
8202 if (throwOnError) {
8203 throw ex;
8204 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008205 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008206 return null;
8207 }
8208 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008209 RuntimeException ex = new IllegalArgumentException(
8210 "Requested window " + client + " is in session " +
8211 win.mSession + ", not " + session);
8212 if (throwOnError) {
8213 throw ex;
8214 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008215 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008216 return null;
8217 }
8218
8219 return win;
8220 }
8221
Dianne Hackborna8f60182009-09-01 19:01:50 -07008222 final void rebuildAppWindowListLocked() {
8223 int NW = mWindows.size();
8224 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008225 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008226 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008227
Dianne Hackborna8f60182009-09-01 19:01:50 -07008228 // First remove all existing app windows.
8229 i=0;
8230 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008231 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008232 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008233 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008234 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008235 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008236 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008237 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008238 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008239 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008240 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8241 && lastWallpaper == i-1) {
8242 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008243 }
8244 i++;
8245 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008246
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008247 // The wallpaper window(s) typically live at the bottom of the stack,
8248 // so skip them before adding app tokens.
8249 lastWallpaper++;
8250 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008251
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008252 // First add all of the exiting app tokens... these are no longer
8253 // in the main app list, but still have windows shown. We put them
8254 // in the back because now that the animation is over we no longer
8255 // will care about them.
8256 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008257 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008258 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8259 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008260
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008261 // And add in the still active app tokens in Z order.
8262 NT = mAppTokens.size();
8263 for (int j=0; j<NT; j++) {
8264 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008265 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008266
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008267 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008268 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008269 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008270 + " windows but added " + i);
8271 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008272 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008274 private final void assignLayersLocked() {
8275 int N = mWindows.size();
8276 int curBaseLayer = 0;
8277 int curLayer = 0;
8278 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008280 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008281 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008282 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8283 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008284 curLayer += WINDOW_LAYER_MULTIPLIER;
8285 w.mLayer = curLayer;
8286 } else {
8287 curBaseLayer = curLayer = w.mBaseLayer;
8288 w.mLayer = curLayer;
8289 }
8290 if (w.mTargetAppToken != null) {
8291 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8292 } else if (w.mAppToken != null) {
8293 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8294 } else {
8295 w.mAnimLayer = w.mLayer;
8296 }
8297 if (w.mIsImWindow) {
8298 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008299 } else if (w.mIsWallpaper) {
8300 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008301 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008302 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008303 + w.mAnimLayer);
8304 //System.out.println(
8305 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8306 }
8307 }
8308
8309 private boolean mInLayout = false;
8310 private final void performLayoutAndPlaceSurfacesLocked() {
8311 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008312 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008313 throw new RuntimeException("Recursive call!");
8314 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008315 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008316 return;
8317 }
8318
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008319 if (mWaitingForConfig) {
8320 // Our configuration has changed (most likely rotation), but we
8321 // don't yet have the complete configuration to report to
8322 // applications. Don't do any window layout until we have it.
8323 return;
8324 }
8325
Dianne Hackbornce2ef762010-09-20 11:39:14 -07008326 if (mDisplay == null) {
8327 // Not yet initialized, nothing to do.
8328 return;
8329 }
8330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008331 boolean recoveringMemory = false;
8332 if (mForceRemoves != null) {
8333 recoveringMemory = true;
8334 // Wait a little it for things to settle down, and off we go.
8335 for (int i=0; i<mForceRemoves.size(); i++) {
8336 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008337 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008338 removeWindowInnerLocked(ws.mSession, ws);
8339 }
8340 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008341 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008342 Object tmp = new Object();
8343 synchronized (tmp) {
8344 try {
8345 tmp.wait(250);
8346 } catch (InterruptedException e) {
8347 }
8348 }
8349 }
Romain Guy06882f82009-06-10 13:36:04 -07008350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008351 mInLayout = true;
8352 try {
8353 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008355 int i = mPendingRemove.size()-1;
8356 if (i >= 0) {
8357 while (i >= 0) {
8358 WindowState w = mPendingRemove.get(i);
8359 removeWindowInnerLocked(w.mSession, w);
8360 i--;
8361 }
8362 mPendingRemove.clear();
8363
8364 mInLayout = false;
8365 assignLayersLocked();
8366 mLayoutNeeded = true;
8367 performLayoutAndPlaceSurfacesLocked();
8368
8369 } else {
8370 mInLayout = false;
8371 if (mLayoutNeeded) {
8372 requestAnimationLocked(0);
8373 }
8374 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008375 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008376 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8377 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008378 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008379 } catch (RuntimeException e) {
8380 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008381 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008382 }
8383 }
8384
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008385 private final int performLayoutLockedInner() {
8386 if (!mLayoutNeeded) {
8387 return 0;
8388 }
8389
8390 mLayoutNeeded = false;
8391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008392 final int dw = mDisplay.getWidth();
8393 final int dh = mDisplay.getHeight();
8394
8395 final int N = mWindows.size();
8396 int i;
8397
Joe Onorato8a9b2202010-02-26 18:56:32 -08008398 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008399 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8400
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008401 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008402
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008403 int seq = mLayoutSeq+1;
8404 if (seq < 0) seq = 0;
8405 mLayoutSeq = seq;
8406
8407 // First perform layout of any root windows (not attached
8408 // to another window).
8409 int topAttached = -1;
8410 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008411 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008412
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008413 // Don't do layout of a window if it is not visible, or
8414 // soon won't be visible, to avoid wasting time and funky
8415 // changes while a window is animating away.
8416 final AppWindowToken atoken = win.mAppToken;
8417 final boolean gone = win.mViewVisibility == View.GONE
8418 || !win.mRelayoutCalled
8419 || win.mRootToken.hidden
8420 || (atoken != null && atoken.hiddenRequested)
8421 || win.mAttachedHidden
8422 || win.mExiting || win.mDestroying;
8423
8424 if (!win.mLayoutAttached) {
8425 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
8426 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
8427 + " mLayoutAttached=" + win.mLayoutAttached);
8428 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
8429 + win.mViewVisibility + " mRelayoutCalled="
8430 + win.mRelayoutCalled + " hidden="
8431 + win.mRootToken.hidden + " hiddenRequested="
8432 + (atoken != null && atoken.hiddenRequested)
8433 + " mAttachedHidden=" + win.mAttachedHidden);
8434 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008435
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008436 // If this view is GONE, then skip it -- keep the current
8437 // frame, and let the caller know so they can ignore it
8438 // if they want. (We do the normal layout for INVISIBLE
8439 // windows, since that means "perform layout as normal,
8440 // just don't display").
8441 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008442 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008443 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8444 win.mLayoutSeq = seq;
8445 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8446 + win.mFrame + " mContainingFrame="
8447 + win.mContainingFrame + " mDisplayFrame="
8448 + win.mDisplayFrame);
8449 } else {
8450 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008451 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008452 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008453 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008454
8455 // Now perform layout of attached windows, which usually
8456 // depend on the position of the window they are attached to.
8457 // XXX does not deal with windows that are attached to windows
8458 // that are themselves attached.
8459 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008460 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008461
8462 // If this view is GONE, then skip it -- keep the current
8463 // frame, and let the caller know so they can ignore it
8464 // if they want. (We do the normal layout for INVISIBLE
8465 // windows, since that means "perform layout as normal,
8466 // just don't display").
8467 if (win.mLayoutAttached) {
8468 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
8469 + " mHaveFrame=" + win.mHaveFrame
8470 + " mViewVisibility=" + win.mViewVisibility
8471 + " mRelayoutCalled=" + win.mRelayoutCalled);
8472 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
8473 || !win.mHaveFrame) {
8474 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
8475 win.mLayoutSeq = seq;
8476 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8477 + win.mFrame + " mContainingFrame="
8478 + win.mContainingFrame + " mDisplayFrame="
8479 + win.mDisplayFrame);
8480 }
8481 }
8482 }
Jeff Brown349703e2010-06-22 01:27:15 -07008483
8484 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008485 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008486
8487 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008488 }
Romain Guy06882f82009-06-10 13:36:04 -07008489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008490 private final void performLayoutAndPlaceSurfacesLockedInner(
8491 boolean recoveringMemory) {
8492 final long currentTime = SystemClock.uptimeMillis();
8493 final int dw = mDisplay.getWidth();
8494 final int dh = mDisplay.getHeight();
8495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008496 int i;
8497
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008498 if (mFocusMayChange) {
8499 mFocusMayChange = false;
8500 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
8501 }
8502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008503 // Initialize state of exiting tokens.
8504 for (i=mExitingTokens.size()-1; i>=0; i--) {
8505 mExitingTokens.get(i).hasVisible = false;
8506 }
8507
8508 // Initialize state of exiting applications.
8509 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
8510 mExitingAppTokens.get(i).hasVisible = false;
8511 }
8512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008513 boolean orientationChangeComplete = true;
8514 Session holdScreen = null;
8515 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05008516 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008517 boolean focusDisplayed = false;
8518 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008519 boolean createWatermark = false;
8520
8521 if (mFxSession == null) {
8522 mFxSession = new SurfaceSession();
8523 createWatermark = true;
8524 }
8525
8526 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008527
8528 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008529
8530 if (createWatermark) {
8531 createWatermark();
8532 }
8533 if (mWatermark != null) {
8534 mWatermark.positionSurface(dw, dh);
8535 }
8536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008537 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008538 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008539 int repeats = 0;
8540 int changes = 0;
8541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008542 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008543 repeats++;
8544 if (repeats > 6) {
8545 Slog.w(TAG, "Animation repeat aborted after too many iterations");
8546 mLayoutNeeded = false;
8547 break;
8548 }
8549
8550 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
8551 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
8552 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
8553 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
8554 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
8555 assignLayersLocked();
8556 mLayoutNeeded = true;
8557 }
8558 }
8559 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
8560 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
8561 if (updateOrientationFromAppTokensLocked()) {
8562 mLayoutNeeded = true;
8563 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
8564 }
8565 }
8566 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
8567 mLayoutNeeded = true;
8568 }
8569 }
8570
8571 // FIRST LOOP: Perform a layout, if needed.
8572 if (repeats < 4) {
8573 changes = performLayoutLockedInner();
8574 if (changes != 0) {
8575 continue;
8576 }
8577 } else {
8578 Slog.w(TAG, "Layout repeat skipped after too many iterations");
8579 changes = 0;
8580 }
8581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008582 final int transactionSequence = ++mTransactionSequence;
8583
8584 // Update animations of all applications, including those
8585 // associated with exiting/removed apps
8586 boolean tokensAnimating = false;
8587 final int NAT = mAppTokens.size();
8588 for (i=0; i<NAT; i++) {
8589 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8590 tokensAnimating = true;
8591 }
8592 }
8593 final int NEAT = mExitingAppTokens.size();
8594 for (i=0; i<NEAT; i++) {
8595 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8596 tokensAnimating = true;
8597 }
8598 }
8599
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008600 // SECOND LOOP: Execute animations and update visibility of windows.
8601
Joe Onorato8a9b2202010-02-26 18:56:32 -08008602 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008603 + transactionSequence + " tokensAnimating="
8604 + tokensAnimating);
8605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008606 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008607
8608 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008609 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008610 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008611
8612 mPolicy.beginAnimationLw(dw, dh);
8613
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008614 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008615
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008616 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008617 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008618
8619 final WindowManager.LayoutParams attrs = w.mAttrs;
8620
8621 if (w.mSurface != null) {
8622 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008623 if (w.commitFinishDrawingLocked(currentTime)) {
8624 if ((w.mAttrs.flags
8625 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008626 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008627 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008628 wallpaperMayChange = true;
8629 }
8630 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008631
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008632 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008633 if (w.stepAnimationLocked(currentTime, dw, dh)) {
8634 animating = true;
8635 //w.dump(" ");
8636 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008637 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
8638 wallpaperMayChange = true;
8639 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008640
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008641 if (mPolicy.doesForceHide(w, attrs)) {
8642 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008643 if (DEBUG_VISIBILITY) Slog.v(TAG,
8644 "Animation done that could impact force hide: "
8645 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008646 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008647 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008648 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
8649 forceHiding = true;
8650 }
8651 } else if (mPolicy.canBeForceHidden(w, attrs)) {
8652 boolean changed;
8653 if (forceHiding) {
8654 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008655 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8656 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008657 } else {
8658 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008659 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8660 "Now policy shown: " + w);
8661 if (changed) {
8662 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008663 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008664 // Assume we will need to animate. If
8665 // we don't (because the wallpaper will
8666 // stay with the lock screen), then we will
8667 // clean up later.
8668 Animation a = mPolicy.createForceHideEnterAnimation();
8669 if (a != null) {
8670 w.setAnimation(a);
8671 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008672 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008673 if (mCurrentFocus == null ||
8674 mCurrentFocus.mLayer < w.mLayer) {
8675 // We are showing on to of the current
8676 // focus, so re-evaluate focus to make
8677 // sure it is correct.
8678 mFocusMayChange = true;
8679 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008680 }
8681 }
8682 if (changed && (attrs.flags
8683 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
8684 wallpaperMayChange = true;
8685 }
8686 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008688 mPolicy.animatingWindowLw(w, attrs);
8689 }
8690
8691 final AppWindowToken atoken = w.mAppToken;
8692 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
8693 if (atoken.lastTransactionSequence != transactionSequence) {
8694 atoken.lastTransactionSequence = transactionSequence;
8695 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
8696 atoken.startingDisplayed = false;
8697 }
8698 if ((w.isOnScreen() || w.mAttrs.type
8699 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
8700 && !w.mExiting && !w.mDestroying) {
8701 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008702 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008703 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008704 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008705 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008706 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008707 + " pv=" + w.mPolicyVisibility
8708 + " dp=" + w.mDrawPending
8709 + " cdp=" + w.mCommitDrawPending
8710 + " ah=" + w.mAttachedHidden
8711 + " th=" + atoken.hiddenRequested
8712 + " a=" + w.mAnimating);
8713 }
8714 }
8715 if (w != atoken.startingWindow) {
8716 if (!atoken.freezingScreen || !w.mAppFreezing) {
8717 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008718 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008719 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008720 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008721 "tokenMayBeDrawn: " + atoken
8722 + " freezingScreen=" + atoken.freezingScreen
8723 + " mAppFreezing=" + w.mAppFreezing);
8724 tokenMayBeDrawn = true;
8725 }
8726 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008727 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008728 atoken.startingDisplayed = true;
8729 }
8730 }
8731 } else if (w.mReadyToShow) {
8732 w.performShowLocked();
8733 }
8734 }
8735
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008736 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008737
8738 if (tokenMayBeDrawn) {
8739 // See if any windows have been drawn, so they (and others
8740 // associated with them) can now be shown.
8741 final int NT = mTokenList.size();
8742 for (i=0; i<NT; i++) {
8743 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
8744 if (wtoken == null) {
8745 continue;
8746 }
8747 if (wtoken.freezingScreen) {
8748 int numInteresting = wtoken.numInterestingWindows;
8749 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008750 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008751 "allDrawn: " + wtoken
8752 + " interesting=" + numInteresting
8753 + " drawn=" + wtoken.numDrawnWindows);
8754 wtoken.showAllWindowsLocked();
8755 unsetAppFreezingScreenLocked(wtoken, false, true);
8756 orientationChangeComplete = true;
8757 }
8758 } else if (!wtoken.allDrawn) {
8759 int numInteresting = wtoken.numInterestingWindows;
8760 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008761 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008762 "allDrawn: " + wtoken
8763 + " interesting=" + numInteresting
8764 + " drawn=" + wtoken.numDrawnWindows);
8765 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008766 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008767
8768 // We can now show all of the drawn windows!
8769 if (!mOpeningApps.contains(wtoken)) {
8770 wtoken.showAllWindowsLocked();
8771 }
8772 }
8773 }
8774 }
8775 }
8776
8777 // If we are ready to perform an app transition, check through
8778 // all of the app tokens to be shown and see if they are ready
8779 // to go.
8780 if (mAppTransitionReady) {
8781 int NN = mOpeningApps.size();
8782 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008783 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008784 "Checking " + NN + " opening apps (frozen="
8785 + mDisplayFrozen + " timeout="
8786 + mAppTransitionTimeout + ")...");
8787 if (!mDisplayFrozen && !mAppTransitionTimeout) {
8788 // If the display isn't frozen, wait to do anything until
8789 // all of the apps are ready. Otherwise just go because
8790 // we'll unfreeze the display when everyone is ready.
8791 for (i=0; i<NN && goodToGo; i++) {
8792 AppWindowToken wtoken = mOpeningApps.get(i);
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 "Check opening app" + wtoken + ": allDrawn="
8795 + wtoken.allDrawn + " startingDisplayed="
8796 + wtoken.startingDisplayed);
8797 if (!wtoken.allDrawn && !wtoken.startingDisplayed
8798 && !wtoken.startingMoved) {
8799 goodToGo = false;
8800 }
8801 }
8802 }
8803 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008804 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008805 int transit = mNextAppTransition;
8806 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008807 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008808 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008809 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008810 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008811 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008812 mAppTransitionTimeout = false;
8813 mStartingIconInTransition = false;
8814 mSkipAppTransitionAnimation = false;
8815
8816 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
8817
Dianne Hackborna8f60182009-09-01 19:01:50 -07008818 // If there are applications waiting to come to the
8819 // top of the stack, now is the time to move their windows.
8820 // (Note that we don't do apps going to the bottom
8821 // here -- we want to keep their windows in the old
8822 // Z-order until the animation completes.)
8823 if (mToTopApps.size() > 0) {
8824 NN = mAppTokens.size();
8825 for (i=0; i<NN; i++) {
8826 AppWindowToken wtoken = mAppTokens.get(i);
8827 if (wtoken.sendingToTop) {
8828 wtoken.sendingToTop = false;
8829 moveAppWindowsLocked(wtoken, NN, false);
8830 }
8831 }
8832 mToTopApps.clear();
8833 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008834
Dianne Hackborn25994b42009-09-04 14:21:19 -07008835 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008836
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008837 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008838 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008839
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008840 // The top-most window will supply the layout params,
8841 // and we will determine it below.
8842 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008843 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008844 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008845
Joe Onorato8a9b2202010-02-26 18:56:32 -08008846 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008847 "New wallpaper target=" + mWallpaperTarget
8848 + ", lower target=" + mLowerWallpaperTarget
8849 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07008850 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008851 // Do a first pass through the tokens for two
8852 // things:
8853 // (1) Determine if both the closing and opening
8854 // app token sets are wallpaper targets, in which
8855 // case special animations are needed
8856 // (since the wallpaper needs to stay static
8857 // behind them).
8858 // (2) Find the layout params of the top-most
8859 // application window in the tokens, which is
8860 // what will control the animation theme.
8861 final int NC = mClosingApps.size();
8862 NN = NC + mOpeningApps.size();
8863 for (i=0; i<NN; i++) {
8864 AppWindowToken wtoken;
8865 int mode;
8866 if (i < NC) {
8867 wtoken = mClosingApps.get(i);
8868 mode = 1;
8869 } else {
8870 wtoken = mOpeningApps.get(i-NC);
8871 mode = 2;
8872 }
8873 if (mLowerWallpaperTarget != null) {
8874 if (mLowerWallpaperTarget.mAppToken == wtoken
8875 || mUpperWallpaperTarget.mAppToken == wtoken) {
8876 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008877 }
8878 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008879 if (wtoken.appFullscreen) {
8880 WindowState ws = wtoken.findMainWindow();
8881 if (ws != null) {
8882 // If this is a compatibility mode
8883 // window, we will always use its anim.
8884 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
8885 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008886 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008887 bestAnimLayer = Integer.MAX_VALUE;
8888 } else if (ws.mLayer > bestAnimLayer) {
8889 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008890 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008891 bestAnimLayer = ws.mLayer;
8892 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07008893 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008894 }
8895 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008896
Dianne Hackborn25994b42009-09-04 14:21:19 -07008897 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008898 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008899 "Wallpaper animation!");
8900 switch (transit) {
8901 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
8902 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
8903 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
8904 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
8905 break;
8906 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
8907 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
8908 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
8909 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
8910 break;
8911 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008912 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008913 "New transit: " + transit);
8914 } else if (oldWallpaper != null) {
8915 // We are transitioning from an activity with
8916 // a wallpaper to one without.
8917 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008918 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008919 "New transit away from wallpaper: " + transit);
8920 } else if (mWallpaperTarget != null) {
8921 // We are transitioning from an activity without
8922 // a wallpaper to now showing the wallpaper
8923 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008924 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008925 "New transit into wallpaper: " + transit);
8926 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008927
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008928 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
8929 mLastEnterAnimToken = animToken;
8930 mLastEnterAnimParams = animLp;
8931 } else if (mLastEnterAnimParams != null) {
8932 animLp = mLastEnterAnimParams;
8933 mLastEnterAnimToken = null;
8934 mLastEnterAnimParams = null;
8935 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008936
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008937 // If all closing windows are obscured, then there is
8938 // no need to do an animation. This is the case, for
8939 // example, when this transition is being done behind
8940 // the lock screen.
8941 if (!mPolicy.allowAppAnimationsLw()) {
8942 animLp = null;
8943 }
8944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008945 NN = mOpeningApps.size();
8946 for (i=0; i<NN; i++) {
8947 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008948 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008949 "Now opening app" + wtoken);
8950 wtoken.reportedVisible = false;
8951 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008952 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008953 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008954 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008955 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008956 wtoken.showAllWindowsLocked();
8957 }
8958 NN = mClosingApps.size();
8959 for (i=0; i<NN; i++) {
8960 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008961 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008962 "Now closing app" + wtoken);
8963 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008964 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008965 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008966 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008967 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008968 // Force the allDrawn flag, because we want to start
8969 // this guy's animations regardless of whether it's
8970 // gotten drawn.
8971 wtoken.allDrawn = true;
8972 }
8973
Dianne Hackborn8b571a82009-09-25 16:09:43 -07008974 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008976 mOpeningApps.clear();
8977 mClosingApps.clear();
8978
8979 // This has changed the visibility of windows, so perform
8980 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008981 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008982 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07008983 if (!moveInputMethodWindowsIfNeededLocked(true)) {
8984 assignLayersLocked();
8985 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008986 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008987 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008988 }
8989 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008990
Dianne Hackborn16064f92010-03-25 00:47:24 -07008991 int adjResult = 0;
8992
Dianne Hackborna8f60182009-09-01 19:01:50 -07008993 if (!animating && mAppTransitionRunning) {
8994 // We have finished the animation of an app transition. To do
8995 // this, we have delayed a lot of operations like showing and
8996 // hiding apps, moving apps in Z-order, etc. The app token list
8997 // reflects the correct Z-order, but the window list may now
8998 // be out of sync with it. So here we will just rebuild the
8999 // entire app window list. Fun!
9000 mAppTransitionRunning = false;
9001 // Clear information about apps that were moving.
9002 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009003
Dianne Hackborna8f60182009-09-01 19:01:50 -07009004 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009005 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009006 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009007 moveInputMethodWindowsIfNeededLocked(false);
9008 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009009 // Since the window list has been rebuilt, focus might
9010 // have to be recomputed since the actual order of windows
9011 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009012 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009013 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009014
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009015 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009016 // At this point, there was a window with a wallpaper that
9017 // was force hiding other windows behind it, but now it
9018 // is going away. This may be simple -- just animate
9019 // away the wallpaper and its window -- or it may be
9020 // hard -- the wallpaper now needs to be shown behind
9021 // something that was hidden.
9022 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009023 if (mLowerWallpaperTarget != null
9024 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009025 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009026 "wallpaperForceHiding changed with lower="
9027 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009028 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009029 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9030 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9031 if (mLowerWallpaperTarget.mAppToken.hidden) {
9032 // The lower target has become hidden before we
9033 // actually started the animation... let's completely
9034 // re-evaluate everything.
9035 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009036 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009037 }
9038 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009039 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009040 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009041 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009042 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009043 + " NEW: " + mWallpaperTarget
9044 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009045 if (mLowerWallpaperTarget == null) {
9046 // Whoops, we don't need a special wallpaper animation.
9047 // Clear them out.
9048 forceHiding = false;
9049 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009050 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009051 if (w.mSurface != null) {
9052 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009053 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009054 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009055 forceHiding = true;
9056 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9057 if (!w.mAnimating) {
9058 // We set the animation above so it
9059 // is not yet running.
9060 w.clearAnimation();
9061 }
9062 }
9063 }
9064 }
9065 }
9066 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009067
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009068 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009069 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009070 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009071 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009072 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009073
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009074 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009075 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009076 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009077 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009078 assignLayersLocked();
9079 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009080 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009081 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009082 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009083 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009084
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009085 if (mFocusMayChange) {
9086 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009087 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009088 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009089 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009090 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009091 }
9092
9093 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009094 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009095 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009096
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009097 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9098 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009099
Jeff Browne33348b2010-07-15 23:54:05 -07009100 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009101 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009102
9103 // THIRD LOOP: Update the surfaces of all windows.
9104
9105 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9106
9107 boolean obscured = false;
9108 boolean blurring = false;
9109 boolean dimming = false;
9110 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009111 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009112 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009113
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009114 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009116 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009117 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009118
9119 boolean displayed = false;
9120 final WindowManager.LayoutParams attrs = w.mAttrs;
9121 final int attrFlags = attrs.flags;
9122
9123 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009124 // XXX NOTE: The logic here could be improved. We have
9125 // the decision about whether to resize a window separated
9126 // from whether to hide the surface. This can cause us to
9127 // resize a surface even if we are going to hide it. You
9128 // can see this by (1) holding device in landscape mode on
9129 // home screen; (2) tapping browser icon (device will rotate
9130 // to landscape; (3) tap home. The wallpaper will be resized
9131 // in step 2 but then immediately hidden, causing us to
9132 // have to resize and then redraw it again in step 3. It
9133 // would be nice to figure out how to avoid this, but it is
9134 // difficult because we do need to resize surfaces in some
9135 // cases while they are hidden such as when first showing a
9136 // window.
9137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009138 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009139 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009140 TAG, "Placing surface #" + i + " " + w.mSurface
9141 + ": new=" + w.mShownFrame + ", old="
9142 + w.mLastShownFrame);
9143
9144 boolean resize;
9145 int width, height;
9146 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9147 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9148 w.mLastRequestedHeight != w.mRequestedHeight;
9149 // for a scaled surface, we just want to use
9150 // the requested size.
9151 width = w.mRequestedWidth;
9152 height = w.mRequestedHeight;
9153 w.mLastRequestedWidth = width;
9154 w.mLastRequestedHeight = height;
9155 w.mLastShownFrame.set(w.mShownFrame);
9156 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009157 if (SHOW_TRANSACTIONS) logSurface(w,
9158 "POS " + w.mShownFrame.left
9159 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009160 w.mSurfaceX = w.mShownFrame.left;
9161 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009162 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9163 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009164 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009165 if (!recoveringMemory) {
9166 reclaimSomeSurfaceMemoryLocked(w, "position");
9167 }
9168 }
9169 } else {
9170 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9171 width = w.mShownFrame.width();
9172 height = w.mShownFrame.height();
9173 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009174 }
9175
9176 if (resize) {
9177 if (width < 1) width = 1;
9178 if (height < 1) height = 1;
9179 if (w.mSurface != null) {
9180 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009181 if (SHOW_TRANSACTIONS) logSurface(w,
9182 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009183 + w.mShownFrame.top + " SIZE "
9184 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009185 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009186 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009187 w.mSurfaceW = width;
9188 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009189 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009190 w.mSurfaceX = w.mShownFrame.left;
9191 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009192 w.mSurface.setPosition(w.mShownFrame.left,
9193 w.mShownFrame.top);
9194 } catch (RuntimeException e) {
9195 // If something goes wrong with the surface (such
9196 // as running out of memory), don't take down the
9197 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009198 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009199 + "size=(" + width + "x" + height
9200 + "), pos=(" + w.mShownFrame.left
9201 + "," + w.mShownFrame.top + ")", e);
9202 if (!recoveringMemory) {
9203 reclaimSomeSurfaceMemoryLocked(w, "size");
9204 }
9205 }
9206 }
9207 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009208 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009209 w.mContentInsetsChanged =
9210 !w.mLastContentInsets.equals(w.mContentInsets);
9211 w.mVisibleInsetsChanged =
9212 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009213 boolean configChanged =
9214 w.mConfiguration != mCurConfiguration
9215 && (w.mConfiguration == null
9216 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009217 if (DEBUG_CONFIGURATION && configChanged) {
9218 Slog.v(TAG, "Win " + w + " config changed: "
9219 + mCurConfiguration);
9220 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009221 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009222 + ": configChanged=" + configChanged
9223 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009224 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009225 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009226 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009227 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009228 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009229 w.mLastFrame.set(w.mFrame);
9230 w.mLastContentInsets.set(w.mContentInsets);
9231 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009232 // If the screen is currently frozen, then keep
9233 // it frozen until this window draws at its new
9234 // orientation.
9235 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009236 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009237 "Resizing while display frozen: " + w);
9238 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009239 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009240 mWindowsFreezingScreen = true;
9241 // XXX should probably keep timeout from
9242 // when we first froze the display.
9243 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9244 mH.sendMessageDelayed(mH.obtainMessage(
9245 H.WINDOW_FREEZE_TIMEOUT), 2000);
9246 }
9247 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009248 // If the orientation is changing, then we need to
9249 // hold off on unfreezing the display until this
9250 // window has been redrawn; to do that, we need
9251 // to go through the process of getting informed
9252 // by the application when it has finished drawing.
9253 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009254 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009255 "Orientation start waiting for draw in "
9256 + w + ", surface " + w.mSurface);
9257 w.mDrawPending = true;
9258 w.mCommitDrawPending = false;
9259 w.mReadyToShow = false;
9260 if (w.mAppToken != null) {
9261 w.mAppToken.allDrawn = false;
9262 }
9263 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009264 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009265 "Resizing window " + w + " to " + w.mFrame);
9266 mResizingWindows.add(w);
9267 } else if (w.mOrientationChanging) {
9268 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009269 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009270 "Orientation not waiting for draw in "
9271 + w + ", surface " + w.mSurface);
9272 w.mOrientationChanging = false;
9273 }
9274 }
9275 }
9276
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009277 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009278 if (!w.mLastHidden) {
9279 //dump();
Dianne Hackborn5943c202010-04-12 21:36:49 -07009280 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Window hiding: waitingToShow="
9281 + w.mRootToken.waitingToShow + " polvis="
9282 + w.mPolicyVisibility + " atthid="
9283 + w.mAttachedHidden + " tokhid="
9284 + w.mRootToken.hidden + " vis="
9285 + w.mViewVisibility);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009286 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009287 if (SHOW_TRANSACTIONS) logSurface(w,
9288 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009289 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009290 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009291 try {
9292 w.mSurface.hide();
9293 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009294 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009295 }
9296 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009297 }
9298 // If we are waiting for this window to handle an
9299 // orientation change, well, it is hidden, so
9300 // doesn't really matter. Note that this does
9301 // introduce a potential glitch if the window
9302 // becomes unhidden before it has drawn for the
9303 // new orientation.
9304 if (w.mOrientationChanging) {
9305 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009306 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009307 "Orientation change skips hidden " + w);
9308 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009309 } else if (w.mLastLayer != w.mAnimLayer
9310 || w.mLastAlpha != w.mShownAlpha
9311 || w.mLastDsDx != w.mDsDx
9312 || w.mLastDtDx != w.mDtDx
9313 || w.mLastDsDy != w.mDsDy
9314 || w.mLastDtDy != w.mDtDy
9315 || w.mLastHScale != w.mHScale
9316 || w.mLastVScale != w.mVScale
9317 || w.mLastHidden) {
9318 displayed = true;
9319 w.mLastAlpha = w.mShownAlpha;
9320 w.mLastLayer = w.mAnimLayer;
9321 w.mLastDsDx = w.mDsDx;
9322 w.mLastDtDx = w.mDtDx;
9323 w.mLastDsDy = w.mDsDy;
9324 w.mLastDtDy = w.mDtDy;
9325 w.mLastHScale = w.mHScale;
9326 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009327 if (SHOW_TRANSACTIONS) logSurface(w,
9328 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009329 + " matrix=[" + (w.mDsDx*w.mHScale)
9330 + "," + (w.mDtDx*w.mVScale)
9331 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009332 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009333 if (w.mSurface != null) {
9334 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009335 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009336 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009337 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009338 w.mSurface.setLayer(w.mAnimLayer);
9339 w.mSurface.setMatrix(
9340 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9341 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9342 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009343 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009344 if (!recoveringMemory) {
9345 reclaimSomeSurfaceMemoryLocked(w, "update");
9346 }
9347 }
9348 }
9349
9350 if (w.mLastHidden && !w.mDrawPending
9351 && !w.mCommitDrawPending
9352 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009353 if (SHOW_TRANSACTIONS) logSurface(w,
9354 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009355 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009356 + " during relayout");
9357 if (showSurfaceRobustlyLocked(w)) {
9358 w.mHasDrawn = true;
9359 w.mLastHidden = false;
9360 } else {
9361 w.mOrientationChanging = false;
9362 }
9363 }
9364 if (w.mSurface != null) {
9365 w.mToken.hasVisible = true;
9366 }
9367 } else {
9368 displayed = true;
9369 }
9370
9371 if (displayed) {
9372 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009373 if (attrs.width == LayoutParams.MATCH_PARENT
9374 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009375 covered = true;
9376 }
9377 }
9378 if (w.mOrientationChanging) {
9379 if (w.mDrawPending || w.mCommitDrawPending) {
9380 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009381 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009382 "Orientation continue waiting for draw in " + w);
9383 } else {
9384 w.mOrientationChanging = 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 change complete in " + w);
9387 }
9388 }
9389 w.mToken.hasVisible = true;
9390 }
9391 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009392 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009393 "Orientation change skips hidden " + w);
9394 w.mOrientationChanging = false;
9395 }
9396
9397 final boolean canBeSeen = w.isDisplayedLw();
9398
9399 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9400 focusDisplayed = true;
9401 }
9402
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009403 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009405 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009406 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009407 if (w.mSurface != null) {
9408 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9409 holdScreen = w.mSession;
9410 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009411 if (!syswin && w.mAttrs.screenBrightness >= 0
9412 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009413 screenBrightness = w.mAttrs.screenBrightness;
9414 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009415 if (!syswin && w.mAttrs.buttonBrightness >= 0
9416 && buttonBrightness < 0) {
9417 buttonBrightness = w.mAttrs.buttonBrightness;
9418 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05009419 if (canBeSeen
9420 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9421 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9422 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009423 syswin = true;
9424 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009425 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009426
Dianne Hackborn25994b42009-09-04 14:21:19 -07009427 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
9428 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009429 // This window completely covers everything behind it,
9430 // so we want to leave all of them as unblurred (for
9431 // performance reasons).
9432 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009433 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009434 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009435 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009436 obscured = true;
9437 if (mBackgroundFillerSurface == null) {
9438 try {
9439 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009440 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009441 0, dw, dh,
9442 PixelFormat.OPAQUE,
9443 Surface.FX_SURFACE_NORMAL);
9444 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009445 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009446 }
9447 }
9448 try {
9449 mBackgroundFillerSurface.setPosition(0, 0);
9450 mBackgroundFillerSurface.setSize(dw, dh);
9451 // Using the same layer as Dim because they will never be shown at the
9452 // same time.
9453 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9454 mBackgroundFillerSurface.show();
9455 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009456 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009457 }
9458 backgroundFillerShown = true;
9459 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009460 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009461 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009462 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009463 + ": blurring=" + blurring
9464 + " obscured=" + obscured
9465 + " displayed=" + displayed);
9466 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9467 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009468 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009469 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009470 if (mDimAnimator == null) {
9471 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009472 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009473 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009474 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009475 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009476 }
9477 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
9478 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009479 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009480 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009481 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009482 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009483 + mBlurSurface + ": CREATE");
9484 try {
Romain Guy06882f82009-06-10 13:36:04 -07009485 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009486 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009487 -1, 16, 16,
9488 PixelFormat.OPAQUE,
9489 Surface.FX_SURFACE_BLUR);
9490 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009491 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009492 }
9493 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009494 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009495 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9496 + mBlurSurface + ": pos=(0,0) (" +
9497 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009498 mBlurSurface.setPosition(0, 0);
9499 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009500 mBlurSurface.setLayer(w.mAnimLayer-2);
9501 if (!mBlurShown) {
9502 try {
9503 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9504 + mBlurSurface + ": SHOW");
9505 mBlurSurface.show();
9506 } catch (RuntimeException e) {
9507 Slog.w(TAG, "Failure showing blur surface", e);
9508 }
9509 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009510 }
9511 }
9512 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009513 }
9514 }
9515 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009516
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009517 if (obscuredChanged && mWallpaperTarget == w) {
9518 // This is the wallpaper target and its obscured state
9519 // changed... make sure the current wallaper's visibility
9520 // has been updated accordingly.
9521 updateWallpaperVisibilityLocked();
9522 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009523 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009524
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009525 if (backgroundFillerShown == false && mBackgroundFillerShown) {
9526 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009527 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009528 try {
9529 mBackgroundFillerSurface.hide();
9530 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009531 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009532 }
9533 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009534
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009535 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009536 animating |= mDimAnimator.updateSurface(dimming, currentTime,
9537 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009538 }
Romain Guy06882f82009-06-10 13:36:04 -07009539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009540 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009541 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009542 + ": HIDE");
9543 try {
9544 mBlurSurface.hide();
9545 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009546 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009547 }
9548 mBlurShown = false;
9549 }
9550
Joe Onorato8a9b2202010-02-26 18:56:32 -08009551 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009552 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009553 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009554 }
9555
Jeff Browne33348b2010-07-15 23:54:05 -07009556 mInputMonitor.updateInputWindowsLw();
9557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009558 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -07009559
Dianne Hackbornb9fb1702010-08-23 16:49:02 -07009560 if (mWatermark != null) {
9561 mWatermark.drawIfNeeded();
9562 }
9563
Joe Onorato8a9b2202010-02-26 18:56:32 -08009564 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009565 "With display frozen, orientationChangeComplete="
9566 + orientationChangeComplete);
9567 if (orientationChangeComplete) {
9568 if (mWindowsFreezingScreen) {
9569 mWindowsFreezingScreen = false;
9570 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9571 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009572 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009573 }
Romain Guy06882f82009-06-10 13:36:04 -07009574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009575 i = mResizingWindows.size();
9576 if (i > 0) {
9577 do {
9578 i--;
9579 WindowState win = mResizingWindows.get(i);
9580 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009581 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
9582 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009583 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009584 boolean configChanged =
9585 win.mConfiguration != mCurConfiguration
9586 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009587 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
9588 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
9589 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009590 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009591 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009592 + " / " + mCurConfiguration + " / 0x"
9593 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009594 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009595 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009596 win.mClient.resized(win.mFrame.width(),
9597 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009598 win.mLastVisibleInsets, win.mDrawPending,
9599 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009600 win.mContentInsetsChanged = false;
9601 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009602 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009603 } catch (RemoteException e) {
9604 win.mOrientationChanging = false;
9605 }
9606 } while (i > 0);
9607 mResizingWindows.clear();
9608 }
Romain Guy06882f82009-06-10 13:36:04 -07009609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009610 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009611 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009612 i = mDestroySurface.size();
9613 if (i > 0) {
9614 do {
9615 i--;
9616 WindowState win = mDestroySurface.get(i);
9617 win.mDestroying = false;
9618 if (mInputMethodWindow == win) {
9619 mInputMethodWindow = null;
9620 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009621 if (win == mWallpaperTarget) {
9622 wallpaperDestroyed = true;
9623 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009624 win.destroySurfaceLocked();
9625 } while (i > 0);
9626 mDestroySurface.clear();
9627 }
9628
9629 // Time to remove any exiting tokens?
9630 for (i=mExitingTokens.size()-1; i>=0; i--) {
9631 WindowToken token = mExitingTokens.get(i);
9632 if (!token.hasVisible) {
9633 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07009634 if (token.windowType == TYPE_WALLPAPER) {
9635 mWallpaperTokens.remove(token);
9636 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009637 }
9638 }
9639
9640 // Time to remove any exiting applications?
9641 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9642 AppWindowToken token = mExitingAppTokens.get(i);
9643 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009644 // Make sure there is no animation running on this token,
9645 // so any windows associated with it will be removed as
9646 // soon as their animations are complete
9647 token.animation = null;
9648 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009649 mAppTokens.remove(token);
9650 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009651 if (mLastEnterAnimToken == token) {
9652 mLastEnterAnimToken = null;
9653 mLastEnterAnimParams = null;
9654 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009655 }
9656 }
9657
Dianne Hackborna8f60182009-09-01 19:01:50 -07009658 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009659
Dianne Hackborna8f60182009-09-01 19:01:50 -07009660 if (!animating && mAppTransitionRunning) {
9661 // We have finished the animation of an app transition. To do
9662 // this, we have delayed a lot of operations like showing and
9663 // hiding apps, moving apps in Z-order, etc. The app token list
9664 // reflects the correct Z-order, but the window list may now
9665 // be out of sync with it. So here we will just rebuild the
9666 // entire app window list. Fun!
9667 mAppTransitionRunning = false;
9668 needRelayout = true;
9669 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009670 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009671 // Clear information about apps that were moving.
9672 mToBottomApps.clear();
9673 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009675 if (focusDisplayed) {
9676 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
9677 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009678 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009679 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009680 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009681 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009682 requestAnimationLocked(0);
9683 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009684 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
9685 }
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009686
Jeff Browne33348b2010-07-15 23:54:05 -07009687 mInputMonitor.updateInputWindowsLw();
9688
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009689 if (DEBUG_FREEZE) Slog.v(TAG, "Layout: mDisplayFrozen=" + mDisplayFrozen
9690 + " holdScreen=" + holdScreen);
9691 if (!mDisplayFrozen) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009692 setHoldScreenLocked(holdScreen != null);
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009693 if (screenBrightness < 0 || screenBrightness > 1.0f) {
9694 mPowerManager.setScreenBrightnessOverride(-1);
9695 } else {
9696 mPowerManager.setScreenBrightnessOverride((int)
9697 (screenBrightness * Power.BRIGHTNESS_ON));
9698 }
9699 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
9700 mPowerManager.setButtonBrightnessOverride(-1);
9701 } else {
9702 mPowerManager.setButtonBrightnessOverride((int)
9703 (buttonBrightness * Power.BRIGHTNESS_ON));
9704 }
9705 if (holdScreen != mHoldingScreenOn) {
9706 mHoldingScreenOn = holdScreen;
9707 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
9708 mH.sendMessage(m);
9709 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009710 }
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
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009998 if (DEBUG_FREEZE) Slog.v(TAG, "*** FREEZING DISPLAY", new RuntimeException());
9999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010000 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010001
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010002 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010003
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010004 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10005 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010006 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010007 mAppTransitionReady = true;
10008 }
Romain Guy06882f82009-06-10 13:36:04 -070010009
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010010 if (PROFILE_ORIENTATION) {
10011 File file = new File("/data/system/frozen");
10012 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10013 }
10014 Surface.freezeDisplay(0);
10015 }
Romain Guy06882f82009-06-10 13:36:04 -070010016
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010017 private void stopFreezingDisplayLocked() {
10018 if (!mDisplayFrozen) {
10019 return;
10020 }
Romain Guy06882f82009-06-10 13:36:04 -070010021
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010022 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10023 return;
10024 }
10025
Dianne Hackbornce73c1e2010-04-12 23:11:38 -070010026 if (DEBUG_FREEZE) Slog.v(TAG, "*** UNFREEZING DISPLAY", new RuntimeException());
10027
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010028 mDisplayFrozen = false;
10029 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10030 if (PROFILE_ORIENTATION) {
10031 Debug.stopMethodTracing();
10032 }
10033 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010034
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010035 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010036
Christopher Tateb696aee2010-04-02 19:08:30 -070010037 // While the display is frozen we don't re-compute the orientation
10038 // to avoid inconsistent states. However, something interesting
10039 // could have actually changed during that time so re-evaluate it
10040 // now to catch that.
10041 if (updateOrientationFromAppTokensLocked()) {
10042 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10043 }
10044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010045 // A little kludge: a lot could have happened while the
10046 // display was frozen, so now that we are coming back we
10047 // do a gc so that any remote references the system
10048 // processes holds on others can be released if they are
10049 // no longer needed.
10050 mH.removeMessages(H.FORCE_GC);
10051 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10052 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010053
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010054 mScreenFrozenLock.release();
10055 }
Romain Guy06882f82009-06-10 13:36:04 -070010056
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010057 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10058 DisplayMetrics dm) {
10059 if (index < tokens.length) {
10060 String str = tokens[index];
10061 if (str != null && str.length() > 0) {
10062 try {
10063 int val = Integer.parseInt(str);
10064 return val;
10065 } catch (Exception e) {
10066 }
10067 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010068 }
10069 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10070 return defDps;
10071 }
10072 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10073 return val;
10074 }
10075
10076 class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010077 final String[] mTokens;
10078 final String mText;
10079 final Paint mTextPaint;
10080 final int mTextWidth;
10081 final int mTextHeight;
10082 final int mTextAscent;
10083 final int mTextDescent;
10084 final int mDeltaX;
10085 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010086
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010087 Surface mSurface;
10088 int mLastDW;
10089 int mLastDH;
10090 boolean mDrawNeeded;
10091
10092 Watermark(SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010093 final DisplayMetrics dm = new DisplayMetrics();
10094 mDisplay.getMetrics(dm);
10095
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010096 if (false) {
10097 Log.i(TAG, "*********************** WATERMARK");
10098 for (int i=0; i<tokens.length; i++) {
10099 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10100 }
10101 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010102
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010103 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010104
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010105 StringBuilder builder = new StringBuilder(32);
10106 int len = mTokens[0].length();
10107 len = len & ~1;
10108 for (int i=0; i<len; i+=2) {
10109 int c1 = mTokens[0].charAt(i);
10110 int c2 = mTokens[0].charAt(i+1);
10111 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10112 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10113 else c1 -= '0';
10114 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10115 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10116 else c2 -= '0';
10117 builder.append((char)(255-((c1*16)+c2)));
10118 }
10119 mText = builder.toString();
10120 if (false) {
10121 Log.i(TAG, "Final text: " + mText);
10122 }
10123
10124 int fontSize = getPropertyInt(tokens, 1,
10125 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10126
10127 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10128 mTextPaint.setTextSize(fontSize);
10129 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10130
10131 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
10132 mTextWidth = (int)mTextPaint.measureText(mText);
10133 mTextAscent = fm.ascent;
10134 mTextDescent = fm.descent;
10135 mTextHeight = fm.descent - fm.ascent;
10136
10137 mDeltaX = getPropertyInt(tokens, 2,
10138 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
10139 mDeltaY = getPropertyInt(tokens, 3,
10140 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
10141 int shadowColor = getPropertyInt(tokens, 4,
10142 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
10143 int color = getPropertyInt(tokens, 5,
10144 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
10145 int shadowRadius = getPropertyInt(tokens, 6,
10146 TypedValue.COMPLEX_UNIT_PX, 7, dm);
10147 int shadowDx = getPropertyInt(tokens, 8,
10148 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10149 int shadowDy = getPropertyInt(tokens, 9,
10150 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10151
10152 mTextPaint.setColor(color);
10153 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010154
10155 try {
10156 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010157 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010158 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010159 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010160 mSurface.show();
10161 } catch (OutOfResourcesException e) {
10162 }
10163 }
10164
10165 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010166 if (mLastDW != dw || mLastDH != dh) {
10167 mLastDW = dw;
10168 mLastDH = dh;
10169 mSurface.setSize(dw, dh);
10170 mDrawNeeded = true;
10171 }
10172 }
10173
10174 void drawIfNeeded() {
10175 if (mDrawNeeded) {
10176 final int dw = mLastDW;
10177 final int dh = mLastDH;
10178
10179 mDrawNeeded = false;
10180 Rect dirty = new Rect(0, 0, dw, dh);
10181 Canvas c = null;
10182 try {
10183 c = mSurface.lockCanvas(dirty);
10184 } catch (IllegalArgumentException e) {
10185 } catch (OutOfResourcesException e) {
10186 }
10187 if (c != null) {
10188 int deltaX = mDeltaX;
10189 int deltaY = mDeltaY;
10190
10191 // deltaX shouldn't be close to a round fraction of our
10192 // x step, or else things will line up too much.
10193 int div = (dw+mTextWidth)/deltaX;
10194 int rem = (dw+mTextWidth) - (div*deltaX);
10195 int qdelta = deltaX/4;
10196 if (rem < qdelta || rem > (deltaX-qdelta)) {
10197 deltaX += deltaX/3;
10198 }
10199
10200 int y = -mTextHeight;
10201 int x = -mTextWidth;
10202 while (y < (dh+mTextHeight)) {
10203 c.drawText(mText, x, y, mTextPaint);
10204 x += deltaX;
10205 if (x >= dw) {
10206 x -= (dw+mTextWidth);
10207 y += deltaY;
10208 }
10209 }
10210 mSurface.unlockCanvasAndPost(c);
10211 }
10212 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010213 }
10214 }
10215
10216 void createWatermark() {
10217 if (mWatermark != null) {
10218 return;
10219 }
10220
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010221 File file = new File("/system/etc/setup.conf");
10222 FileInputStream in = null;
10223 try {
10224 in = new FileInputStream(file);
10225 DataInputStream ind = new DataInputStream(in);
10226 String line = ind.readLine();
10227 if (line != null) {
10228 String[] toks = line.split("%");
10229 if (toks != null && toks.length > 0) {
10230 mWatermark = new Watermark(mFxSession, toks);
10231 }
10232 }
10233 } catch (FileNotFoundException e) {
10234 } catch (IOException e) {
10235 } finally {
10236 if (in != null) {
10237 try {
10238 in.close();
10239 } catch (IOException e) {
10240 }
10241 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010242 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010243 }
10244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010245 @Override
10246 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10247 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10248 != PackageManager.PERMISSION_GRANTED) {
10249 pw.println("Permission Denial: can't dump WindowManager from from pid="
10250 + Binder.getCallingPid()
10251 + ", uid=" + Binder.getCallingUid());
10252 return;
10253 }
Romain Guy06882f82009-06-10 13:36:04 -070010254
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010255 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010256 pw.println(" ");
10257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010258 synchronized(mWindowMap) {
10259 pw.println("Current Window Manager state:");
10260 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010261 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010262 pw.print(" Window #"); pw.print(i); pw.print(' ');
10263 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010264 w.dump(pw, " ");
10265 }
10266 if (mInputMethodDialogs.size() > 0) {
10267 pw.println(" ");
10268 pw.println(" Input method dialogs:");
10269 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10270 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010271 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010272 }
10273 }
10274 if (mPendingRemove.size() > 0) {
10275 pw.println(" ");
10276 pw.println(" Remove pending for:");
10277 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10278 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010279 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10280 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010281 w.dump(pw, " ");
10282 }
10283 }
10284 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10285 pw.println(" ");
10286 pw.println(" Windows force removing:");
10287 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10288 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010289 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10290 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010291 w.dump(pw, " ");
10292 }
10293 }
10294 if (mDestroySurface.size() > 0) {
10295 pw.println(" ");
10296 pw.println(" Windows waiting to destroy their surface:");
10297 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10298 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010299 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10300 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010301 w.dump(pw, " ");
10302 }
10303 }
10304 if (mLosingFocus.size() > 0) {
10305 pw.println(" ");
10306 pw.println(" Windows losing focus:");
10307 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10308 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010309 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10310 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010311 w.dump(pw, " ");
10312 }
10313 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010314 if (mResizingWindows.size() > 0) {
10315 pw.println(" ");
10316 pw.println(" Windows waiting to resize:");
10317 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10318 WindowState w = mResizingWindows.get(i);
10319 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10320 pw.print(w); pw.println(":");
10321 w.dump(pw, " ");
10322 }
10323 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010324 if (mSessions.size() > 0) {
10325 pw.println(" ");
10326 pw.println(" All active sessions:");
10327 Iterator<Session> it = mSessions.iterator();
10328 while (it.hasNext()) {
10329 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010330 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010331 s.dump(pw, " ");
10332 }
10333 }
10334 if (mTokenMap.size() > 0) {
10335 pw.println(" ");
10336 pw.println(" All tokens:");
10337 Iterator<WindowToken> it = mTokenMap.values().iterator();
10338 while (it.hasNext()) {
10339 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010340 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010341 token.dump(pw, " ");
10342 }
10343 }
10344 if (mTokenList.size() > 0) {
10345 pw.println(" ");
10346 pw.println(" Window token list:");
10347 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010348 pw.print(" #"); pw.print(i); pw.print(": ");
10349 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010350 }
10351 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010352 if (mWallpaperTokens.size() > 0) {
10353 pw.println(" ");
10354 pw.println(" Wallpaper tokens:");
10355 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10356 WindowToken token = mWallpaperTokens.get(i);
10357 pw.print(" Wallpaper #"); pw.print(i);
10358 pw.print(' '); pw.print(token); pw.println(':');
10359 token.dump(pw, " ");
10360 }
10361 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010362 if (mAppTokens.size() > 0) {
10363 pw.println(" ");
10364 pw.println(" Application tokens in Z order:");
10365 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010366 pw.print(" App #"); pw.print(i); pw.print(": ");
10367 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010368 }
10369 }
10370 if (mFinishedStarting.size() > 0) {
10371 pw.println(" ");
10372 pw.println(" Finishing start of application tokens:");
10373 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10374 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010375 pw.print(" Finished Starting #"); pw.print(i);
10376 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010377 token.dump(pw, " ");
10378 }
10379 }
10380 if (mExitingTokens.size() > 0) {
10381 pw.println(" ");
10382 pw.println(" Exiting tokens:");
10383 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10384 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010385 pw.print(" Exiting #"); pw.print(i);
10386 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010387 token.dump(pw, " ");
10388 }
10389 }
10390 if (mExitingAppTokens.size() > 0) {
10391 pw.println(" ");
10392 pw.println(" Exiting application tokens:");
10393 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10394 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010395 pw.print(" Exiting App #"); pw.print(i);
10396 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010397 token.dump(pw, " ");
10398 }
10399 }
10400 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010401 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10402 pw.print(" mLastFocus="); pw.println(mLastFocus);
10403 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10404 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10405 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010406 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010407 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10408 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10409 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10410 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010411 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10412 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10413 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010414 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10415 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10416 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10417 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010418 if (mDimAnimator != null) {
10419 mDimAnimator.printTo(pw);
10420 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080010421 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010422 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010423 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010424 pw.print(mInputMethodAnimLayerAdjustment);
10425 pw.print(" mWallpaperAnimLayerAdjustment=");
10426 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010427 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10428 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010429 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10430 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010431 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
10432 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010433 pw.print(" mRotation="); pw.print(mRotation);
10434 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10435 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10436 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10437 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10438 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10439 pw.print(" mNextAppTransition=0x");
10440 pw.print(Integer.toHexString(mNextAppTransition));
10441 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010442 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010443 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010444 if (mNextAppTransitionPackage != null) {
10445 pw.print(" mNextAppTransitionPackage=");
10446 pw.print(mNextAppTransitionPackage);
10447 pw.print(", mNextAppTransitionEnter=0x");
10448 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10449 pw.print(", mNextAppTransitionExit=0x");
10450 pw.print(Integer.toHexString(mNextAppTransitionExit));
10451 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010452 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10453 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010454 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10455 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10456 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10457 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010458 if (mOpeningApps.size() > 0) {
10459 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10460 }
10461 if (mClosingApps.size() > 0) {
10462 pw.print(" mClosingApps="); pw.println(mClosingApps);
10463 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010464 if (mToTopApps.size() > 0) {
10465 pw.print(" mToTopApps="); pw.println(mToTopApps);
10466 }
10467 if (mToBottomApps.size() > 0) {
10468 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10469 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010470 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10471 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010472 }
10473 }
10474
Jeff Brown349703e2010-06-22 01:27:15 -070010475 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010476 public void monitor() {
10477 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010478 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070010479 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010480
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010481 /**
10482 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010483 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010484 */
10485 private static class DimAnimator {
10486 Surface mDimSurface;
10487 boolean mDimShown = false;
10488 float mDimCurrentAlpha;
10489 float mDimTargetAlpha;
10490 float mDimDeltaPerMs;
10491 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010492
10493 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010494
10495 DimAnimator (SurfaceSession session) {
10496 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010497 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010498 + mDimSurface + ": CREATE");
10499 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010500 mDimSurface = new Surface(session, 0,
10501 "DimSurface",
10502 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010503 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010010504 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010505 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010506 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010507 }
10508 }
10509 }
10510
10511 /**
10512 * Show the dim surface.
10513 */
10514 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010515 if (!mDimShown) {
10516 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
10517 dw + "x" + dh + ")");
10518 mDimShown = true;
10519 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010520 mLastDimWidth = dw;
10521 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010522 mDimSurface.setPosition(0, 0);
10523 mDimSurface.setSize(dw, dh);
10524 mDimSurface.show();
10525 } catch (RuntimeException e) {
10526 Slog.w(TAG, "Failure showing dim surface", e);
10527 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010528 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
10529 mLastDimWidth = dw;
10530 mLastDimHeight = dh;
10531 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010532 }
10533 }
10534
10535 /**
10536 * Set's the dim surface's layer and update dim parameters that will be used in
10537 * {@link updateSurface} after all windows are examined.
10538 */
10539 void updateParameters(WindowState w, long currentTime) {
10540 mDimSurface.setLayer(w.mAnimLayer-1);
10541
10542 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010543 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010544 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010545 if (mDimTargetAlpha != target) {
10546 // If the desired dim level has changed, then
10547 // start an animation to it.
10548 mLastDimAnimTime = currentTime;
10549 long duration = (w.mAnimating && w.mAnimation != null)
10550 ? w.mAnimation.computeDurationHint()
10551 : DEFAULT_DIM_DURATION;
10552 if (target > mDimTargetAlpha) {
10553 // This is happening behind the activity UI,
10554 // so we can make it run a little longer to
10555 // give a stronger impression without disrupting
10556 // the user.
10557 duration *= DIM_DURATION_MULTIPLIER;
10558 }
10559 if (duration < 1) {
10560 // Don't divide by zero
10561 duration = 1;
10562 }
10563 mDimTargetAlpha = target;
10564 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
10565 }
10566 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010567
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010568 /**
10569 * Updating the surface's alpha. Returns true if the animation continues, or returns
10570 * false when the animation is finished and the dim surface is hidden.
10571 */
10572 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
10573 if (!dimming) {
10574 if (mDimTargetAlpha != 0) {
10575 mLastDimAnimTime = currentTime;
10576 mDimTargetAlpha = 0;
10577 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
10578 }
10579 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010580
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010581 boolean animating = false;
10582 if (mLastDimAnimTime != 0) {
10583 mDimCurrentAlpha += mDimDeltaPerMs
10584 * (currentTime-mLastDimAnimTime);
10585 boolean more = true;
10586 if (displayFrozen) {
10587 // If the display is frozen, there is no reason to animate.
10588 more = false;
10589 } else if (mDimDeltaPerMs > 0) {
10590 if (mDimCurrentAlpha > mDimTargetAlpha) {
10591 more = false;
10592 }
10593 } else if (mDimDeltaPerMs < 0) {
10594 if (mDimCurrentAlpha < mDimTargetAlpha) {
10595 more = false;
10596 }
10597 } else {
10598 more = false;
10599 }
10600
10601 // Do we need to continue animating?
10602 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010603 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010604 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
10605 mLastDimAnimTime = currentTime;
10606 mDimSurface.setAlpha(mDimCurrentAlpha);
10607 animating = true;
10608 } else {
10609 mDimCurrentAlpha = mDimTargetAlpha;
10610 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010611 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010612 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
10613 mDimSurface.setAlpha(mDimCurrentAlpha);
10614 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010615 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010616 + ": HIDE");
10617 try {
10618 mDimSurface.hide();
10619 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010620 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010621 }
10622 mDimShown = false;
10623 }
10624 }
10625 }
10626 return animating;
10627 }
10628
10629 public void printTo(PrintWriter pw) {
10630 pw.print(" mDimShown="); pw.print(mDimShown);
10631 pw.print(" current="); pw.print(mDimCurrentAlpha);
10632 pw.print(" target="); pw.print(mDimTargetAlpha);
10633 pw.print(" delta="); pw.print(mDimDeltaPerMs);
10634 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
10635 }
10636 }
10637
10638 /**
10639 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
10640 * This is used for opening/closing transition for apps in compatible mode.
10641 */
10642 private static class FadeInOutAnimation extends Animation {
10643 int mWidth;
10644 boolean mFadeIn;
10645
10646 public FadeInOutAnimation(boolean fadeIn) {
10647 setInterpolator(new AccelerateInterpolator());
10648 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
10649 mFadeIn = fadeIn;
10650 }
10651
10652 @Override
10653 protected void applyTransformation(float interpolatedTime, Transformation t) {
10654 float x = interpolatedTime;
10655 if (!mFadeIn) {
10656 x = 1.0f - x; // reverse the interpolation for fade out
10657 }
10658 if (x < 0.5) {
10659 // move the window out of the screen.
10660 t.getMatrix().setTranslate(mWidth, 0);
10661 } else {
10662 t.getMatrix().setTranslate(0, 0);// show
10663 t.setAlpha((x - 0.5f) * 2);
10664 }
10665 }
10666
10667 @Override
10668 public void initialize(int width, int height, int parentWidth, int parentHeight) {
10669 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
10670 mWidth = width;
10671 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010672
10673 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070010674 public int getZAdjustment() {
10675 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010676 }
10677 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010678}