blob: 3841f75c7cc522763b3beb384e2cf486dd8039ad [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 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001485 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001486 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001487 // This window is not related to the previous one in any
1488 // interesting way, so stop here.
1489 break;
1490 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001491 foundW = wb;
1492 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001493 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001494 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001495 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001496 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001497
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001498 if (foundW == null && topCurW != null) {
1499 // There is no wallpaper target, so it goes at the bottom.
1500 // We will assume it is the same place as last time, if known.
1501 foundW = topCurW;
1502 foundI = topCurI+1;
1503 } else {
1504 // Okay i is the position immediately above the wallpaper. Look at
1505 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001506 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001507 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001508
Dianne Hackborn284ac932009-08-28 10:34:25 -07001509 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001510 if (mWallpaperTarget.mWallpaperX >= 0) {
1511 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001512 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001513 }
1514 if (mWallpaperTarget.mWallpaperY >= 0) {
1515 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001516 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001517 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001518 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001519
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001520 // Start stepping backwards from here, ensuring that our wallpaper windows
1521 // are correctly placed.
1522 int curTokenIndex = mWallpaperTokens.size();
1523 while (curTokenIndex > 0) {
1524 curTokenIndex--;
1525 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001526 if (token.hidden == visible) {
1527 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1528 token.hidden = !visible;
1529 // Need to do a layout to ensure the wallpaper now has the
1530 // correct size.
1531 mLayoutNeeded = true;
1532 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001533
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001534 int curWallpaperIndex = token.windows.size();
1535 while (curWallpaperIndex > 0) {
1536 curWallpaperIndex--;
1537 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001538
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001539 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001540 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001541 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001542
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001543 // First, make sure the client has the current visibility
1544 // state.
1545 if (wallpaper.mWallpaperVisible != visible) {
1546 wallpaper.mWallpaperVisible = visible;
1547 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001548 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001549 "Setting visibility of wallpaper " + wallpaper
1550 + ": " + visible);
1551 wallpaper.mClient.dispatchAppVisibility(visible);
1552 } catch (RemoteException e) {
1553 }
1554 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001555
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001556 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001557 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001558 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001559
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001560 // First, if this window is at the current index, then all
1561 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001562 if (wallpaper == foundW) {
1563 foundI--;
1564 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001565 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001566 continue;
1567 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001568
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001569 // The window didn't match... the current wallpaper window,
1570 // wherever it is, is in the wrong place, so make sure it is
1571 // not in the list.
1572 int oldIndex = localmWindows.indexOf(wallpaper);
1573 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001574 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001575 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001576 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001577 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001578 if (oldIndex < foundI) {
1579 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001580 }
1581 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001582
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001583 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001584 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001585 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001586 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001587
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001588 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001589 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001590 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001591 }
1592 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001593
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001594 return changed;
1595 }
1596
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001597 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001598 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001599 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001600 mWallpaperAnimLayerAdjustment = adj;
1601 int curTokenIndex = mWallpaperTokens.size();
1602 while (curTokenIndex > 0) {
1603 curTokenIndex--;
1604 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1605 int curWallpaperIndex = token.windows.size();
1606 while (curWallpaperIndex > 0) {
1607 curWallpaperIndex--;
1608 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1609 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001610 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001611 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001612 }
1613 }
1614 }
1615
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001616 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1617 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001618 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001619 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001620 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001621 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001622 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1623 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1624 changed = wallpaperWin.mXOffset != offset;
1625 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001626 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001627 + wallpaperWin + " x: " + offset);
1628 wallpaperWin.mXOffset = offset;
1629 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001630 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001631 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001632 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001633 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001634 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001635
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001636 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001637 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001638 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1639 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1640 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001641 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001642 + wallpaperWin + " y: " + offset);
1643 changed = true;
1644 wallpaperWin.mYOffset = offset;
1645 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001646 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001647 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001648 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001649 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001650 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001651
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001652 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001653 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001654 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001655 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1656 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001657 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001658 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001659 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001660 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001661 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1662 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001663 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001664 if (mWaitingOnWallpaper != null) {
1665 long start = SystemClock.uptimeMillis();
1666 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1667 < start) {
1668 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001669 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001670 "Waiting for offset complete...");
1671 mWindowMap.wait(WALLPAPER_TIMEOUT);
1672 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001673 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001674 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001675 if ((start+WALLPAPER_TIMEOUT)
1676 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001677 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001678 + wallpaperWin);
1679 mLastWallpaperTimeoutTime = start;
1680 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001681 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001682 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001683 }
1684 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001685 } catch (RemoteException e) {
1686 }
1687 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001688
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001689 return changed;
1690 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001691
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001692 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001693 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001694 if (mWaitingOnWallpaper != null &&
1695 mWaitingOnWallpaper.mClient.asBinder() == window) {
1696 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001697 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001698 }
1699 }
1700 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001701
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001702 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001703 final int dw = mDisplay.getWidth();
1704 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001705
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001706 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001707
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001708 WindowState target = mWallpaperTarget;
1709 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001710 if (target.mWallpaperX >= 0) {
1711 mLastWallpaperX = target.mWallpaperX;
1712 } else if (changingTarget.mWallpaperX >= 0) {
1713 mLastWallpaperX = changingTarget.mWallpaperX;
1714 }
1715 if (target.mWallpaperY >= 0) {
1716 mLastWallpaperY = target.mWallpaperY;
1717 } else if (changingTarget.mWallpaperY >= 0) {
1718 mLastWallpaperY = changingTarget.mWallpaperY;
1719 }
1720 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001721
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001722 int curTokenIndex = mWallpaperTokens.size();
1723 while (curTokenIndex > 0) {
1724 curTokenIndex--;
1725 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1726 int curWallpaperIndex = token.windows.size();
1727 while (curWallpaperIndex > 0) {
1728 curWallpaperIndex--;
1729 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1730 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1731 wallpaper.computeShownFrameLocked();
1732 changed = true;
1733 // We only want to be synchronous with one wallpaper.
1734 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001735 }
1736 }
1737 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001738
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001739 return changed;
1740 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001741
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001742 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001743 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001744 final int dw = mDisplay.getWidth();
1745 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001746
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001747 int curTokenIndex = mWallpaperTokens.size();
1748 while (curTokenIndex > 0) {
1749 curTokenIndex--;
1750 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001751 if (token.hidden == visible) {
1752 token.hidden = !visible;
1753 // Need to do a layout to ensure the wallpaper now has the
1754 // correct size.
1755 mLayoutNeeded = true;
1756 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001757
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001758 int curWallpaperIndex = token.windows.size();
1759 while (curWallpaperIndex > 0) {
1760 curWallpaperIndex--;
1761 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1762 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001763 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001764 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001765
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001766 if (wallpaper.mWallpaperVisible != visible) {
1767 wallpaper.mWallpaperVisible = visible;
1768 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001769 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001770 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001771 + ": " + visible);
1772 wallpaper.mClient.dispatchAppVisibility(visible);
1773 } catch (RemoteException e) {
1774 }
1775 }
1776 }
1777 }
1778 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001780 public int addWindow(Session session, IWindow client,
1781 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001782 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001783 int res = mPolicy.checkAddPermission(attrs);
1784 if (res != WindowManagerImpl.ADD_OKAY) {
1785 return res;
1786 }
Romain Guy06882f82009-06-10 13:36:04 -07001787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001788 boolean reportNewConfig = false;
1789 WindowState attachedWindow = null;
1790 WindowState win = null;
Romain Guy06882f82009-06-10 13:36:04 -07001791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001792 synchronized(mWindowMap) {
1793 // Instantiating a Display requires talking with the simulator,
1794 // so don't do it until we know the system is mostly up and
1795 // running.
1796 if (mDisplay == null) {
1797 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
1798 mDisplay = wm.getDefaultDisplay();
Christopher Tateb696aee2010-04-02 19:08:30 -07001799 mInitialDisplayWidth = mDisplay.getWidth();
1800 mInitialDisplayHeight = mDisplay.getHeight();
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001801 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001802 reportNewConfig = true;
1803 }
Romain Guy06882f82009-06-10 13:36:04 -07001804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001805 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001806 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001807 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1808 }
1809
1810 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001811 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001812 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001813 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001814 + attrs.token + ". Aborting.");
1815 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1816 }
1817 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1818 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001819 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001820 + attrs.token + ". Aborting.");
1821 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1822 }
1823 }
1824
1825 boolean addToken = false;
1826 WindowToken token = mTokenMap.get(attrs.token);
1827 if (token == null) {
1828 if (attrs.type >= FIRST_APPLICATION_WINDOW
1829 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001830 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001831 + attrs.token + ". Aborting.");
1832 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1833 }
1834 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001835 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001836 + attrs.token + ". Aborting.");
1837 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1838 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001839 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001840 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001841 + attrs.token + ". Aborting.");
1842 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1843 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001844 token = new WindowToken(attrs.token, -1, false);
1845 addToken = true;
1846 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1847 && attrs.type <= LAST_APPLICATION_WINDOW) {
1848 AppWindowToken atoken = token.appWindowToken;
1849 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001850 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001851 + token + ". Aborting.");
1852 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1853 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001854 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001855 + token + ". Aborting.");
1856 return WindowManagerImpl.ADD_APP_EXITING;
1857 }
1858 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1859 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001860 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001861 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1862 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1863 }
1864 } else if (attrs.type == TYPE_INPUT_METHOD) {
1865 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001866 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001867 + attrs.token + ". Aborting.");
1868 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1869 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001870 } else if (attrs.type == TYPE_WALLPAPER) {
1871 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001872 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001873 + attrs.token + ". Aborting.");
1874 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1875 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001876 }
1877
1878 win = new WindowState(session, client, token,
1879 attachedWindow, attrs, viewVisibility);
1880 if (win.mDeathRecipient == null) {
1881 // Client has apparently died, so there is no reason to
1882 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001883 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001884 + " that is dead, aborting.");
1885 return WindowManagerImpl.ADD_APP_EXITING;
1886 }
1887
1888 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001889
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001890 res = mPolicy.prepareAddWindowLw(win, attrs);
1891 if (res != WindowManagerImpl.ADD_OKAY) {
1892 return res;
1893 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001894
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001895 if (outInputChannel != null) {
1896 String name = win.makeInputChannelName();
1897 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1898 win.mInputChannel = inputChannels[0];
1899 inputChannels[1].transferToBinderOutParameter(outInputChannel);
1900
1901 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001902 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001903
1904 // From now on, no exceptions or errors allowed!
1905
1906 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001908 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001910 if (addToken) {
1911 mTokenMap.put(attrs.token, token);
1912 mTokenList.add(token);
1913 }
1914 win.attach();
1915 mWindowMap.put(client.asBinder(), win);
1916
1917 if (attrs.type == TYPE_APPLICATION_STARTING &&
1918 token.appWindowToken != null) {
1919 token.appWindowToken.startingWindow = win;
1920 }
1921
1922 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001924 if (attrs.type == TYPE_INPUT_METHOD) {
1925 mInputMethodWindow = win;
1926 addInputMethodWindowToListLocked(win);
1927 imMayMove = false;
1928 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1929 mInputMethodDialogs.add(win);
1930 addWindowToListInOrderLocked(win, true);
1931 adjustInputMethodDialogsLocked();
1932 imMayMove = false;
1933 } else {
1934 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001935 if (attrs.type == TYPE_WALLPAPER) {
1936 mLastWallpaperTimeoutTime = 0;
1937 adjustWallpaperWindowsLocked();
1938 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001939 adjustWallpaperWindowsLocked();
1940 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001941 }
Romain Guy06882f82009-06-10 13:36:04 -07001942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001943 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001945 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001947 if (mInTouchMode) {
1948 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1949 }
1950 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1951 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1952 }
Romain Guy06882f82009-06-10 13:36:04 -07001953
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001954 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001955 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07001956 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
1957 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001958 imMayMove = false;
1959 }
1960 }
Romain Guy06882f82009-06-10 13:36:04 -07001961
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001962 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07001963 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001964 }
Romain Guy06882f82009-06-10 13:36:04 -07001965
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001966 assignLayersLocked();
1967 // Don't do layout here, the window must call
1968 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07001969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001970 //dump();
1971
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001972 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07001973 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001974 }
Jeff Brown349703e2010-06-22 01:27:15 -07001975
Joe Onorato8a9b2202010-02-26 18:56:32 -08001976 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001977 TAG, "New client " + client.asBinder()
1978 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001979
1980 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
1981 reportNewConfig = true;
1982 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001983 }
1984
1985 // sendNewConfiguration() checks caller permissions so we must call it with
1986 // privilege. updateOrientationFromAppTokens() clears and resets the caller
1987 // identity anyway, so it's safe to just clear & restore around this whole
1988 // block.
1989 final long origId = Binder.clearCallingIdentity();
1990 if (reportNewConfig) {
1991 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001992 }
1993 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07001994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001995 return res;
1996 }
Romain Guy06882f82009-06-10 13:36:04 -07001997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001998 public void removeWindow(Session session, IWindow client) {
1999 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002000 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002001 if (win == null) {
2002 return;
2003 }
2004 removeWindowLocked(session, win);
2005 }
2006 }
Romain Guy06882f82009-06-10 13:36:04 -07002007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002008 public void removeWindowLocked(Session session, WindowState win) {
2009
Joe Onorato8a9b2202010-02-26 18:56:32 -08002010 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002011 TAG, "Remove " + win + " client="
2012 + Integer.toHexString(System.identityHashCode(
2013 win.mClient.asBinder()))
2014 + ", surface=" + win.mSurface);
2015
2016 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002017
2018 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002019
Joe Onorato8a9b2202010-02-26 18:56:32 -08002020 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002021 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2022 + " mExiting=" + win.mExiting
2023 + " isAnimating=" + win.isAnimating()
2024 + " app-animation="
2025 + (win.mAppToken != null ? win.mAppToken.animation : null)
2026 + " inPendingTransaction="
2027 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2028 + " mDisplayFrozen=" + mDisplayFrozen);
2029 // Visibility of the removed window. Will be used later to update orientation later on.
2030 boolean wasVisible = false;
2031 // First, see if we need to run an animation. If we do, we have
2032 // to hold off on removing the window until the animation is done.
2033 // If the display is frozen, just remove immediately, since the
2034 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002035 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002036 // If we are not currently running the exit animation, we
2037 // need to see about starting one.
2038 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002040 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2041 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2042 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2043 }
2044 // Try starting an animation.
2045 if (applyAnimationLocked(win, transit, false)) {
2046 win.mExiting = true;
2047 }
2048 }
2049 if (win.mExiting || win.isAnimating()) {
2050 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002051 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002052 win.mExiting = true;
2053 win.mRemoveOnExit = true;
2054 mLayoutNeeded = true;
2055 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2056 performLayoutAndPlaceSurfacesLocked();
2057 if (win.mAppToken != null) {
2058 win.mAppToken.updateReportedVisibilityLocked();
2059 }
2060 //dump();
2061 Binder.restoreCallingIdentity(origId);
2062 return;
2063 }
2064 }
2065
2066 removeWindowInnerLocked(session, win);
2067 // Removing a visible window will effect the computed orientation
2068 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002069 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002070 != mForcedAppOrientation
2071 && updateOrientationFromAppTokensLocked()) {
2072 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002073 }
2074 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2075 Binder.restoreCallingIdentity(origId);
2076 }
Romain Guy06882f82009-06-10 13:36:04 -07002077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002078 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002079 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002081 if (mInputMethodTarget == win) {
2082 moveInputMethodWindowsIfNeededLocked(false);
2083 }
Romain Guy06882f82009-06-10 13:36:04 -07002084
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002085 if (false) {
2086 RuntimeException e = new RuntimeException("here");
2087 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002088 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002089 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002091 mPolicy.removeWindowLw(win);
2092 win.removeLocked();
2093
2094 mWindowMap.remove(win.mClient.asBinder());
2095 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002096 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002097 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002098
2099 if (mInputMethodWindow == win) {
2100 mInputMethodWindow = null;
2101 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2102 mInputMethodDialogs.remove(win);
2103 }
Romain Guy06882f82009-06-10 13:36:04 -07002104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002105 final WindowToken token = win.mToken;
2106 final AppWindowToken atoken = win.mAppToken;
2107 token.windows.remove(win);
2108 if (atoken != null) {
2109 atoken.allAppWindows.remove(win);
2110 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002111 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002112 TAG, "**** Removing window " + win + ": count="
2113 + token.windows.size());
2114 if (token.windows.size() == 0) {
2115 if (!token.explicit) {
2116 mTokenMap.remove(token.token);
2117 mTokenList.remove(token);
2118 } else if (atoken != null) {
2119 atoken.firstWindowDrawn = false;
2120 }
2121 }
2122
2123 if (atoken != null) {
2124 if (atoken.startingWindow == win) {
2125 atoken.startingWindow = null;
2126 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2127 // If this is the last window and we had requested a starting
2128 // transition window, well there is no point now.
2129 atoken.startingData = null;
2130 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2131 // If this is the last window except for a starting transition
2132 // window, we need to get rid of the starting transition.
2133 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002134 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002135 + ": no more real windows");
2136 }
2137 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2138 mH.sendMessage(m);
2139 }
2140 }
Romain Guy06882f82009-06-10 13:36:04 -07002141
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002142 if (win.mAttrs.type == TYPE_WALLPAPER) {
2143 mLastWallpaperTimeoutTime = 0;
2144 adjustWallpaperWindowsLocked();
2145 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002146 adjustWallpaperWindowsLocked();
2147 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002149 if (!mInLayout) {
2150 assignLayersLocked();
2151 mLayoutNeeded = true;
2152 performLayoutAndPlaceSurfacesLocked();
2153 if (win.mAppToken != null) {
2154 win.mAppToken.updateReportedVisibilityLocked();
2155 }
2156 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002157
2158 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002159 }
2160
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002161 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2162 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2163 + ": " + msg + " / " + w.mAttrs.getTitle();
2164 if (where != null) {
2165 Slog.i(TAG, str, where);
2166 } else {
2167 Slog.i(TAG, str);
2168 }
2169 }
2170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002171 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2172 long origId = Binder.clearCallingIdentity();
2173 try {
2174 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002175 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002176 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002177 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002178 Surface.openTransaction();
2179 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002180 if (SHOW_TRANSACTIONS) logSurface(w,
2181 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002182 w.mSurface.setTransparentRegionHint(region);
2183 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002184 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002185 Surface.closeTransaction();
2186 }
2187 }
2188 }
2189 } finally {
2190 Binder.restoreCallingIdentity(origId);
2191 }
2192 }
2193
2194 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002195 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002196 Rect visibleInsets) {
2197 long origId = Binder.clearCallingIdentity();
2198 try {
2199 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002200 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002201 if (w != null) {
2202 w.mGivenInsetsPending = false;
2203 w.mGivenContentInsets.set(contentInsets);
2204 w.mGivenVisibleInsets.set(visibleInsets);
2205 w.mTouchableInsets = touchableInsets;
2206 mLayoutNeeded = true;
2207 performLayoutAndPlaceSurfacesLocked();
2208 }
2209 }
2210 } finally {
2211 Binder.restoreCallingIdentity(origId);
2212 }
2213 }
Romain Guy06882f82009-06-10 13:36:04 -07002214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002215 public void getWindowDisplayFrame(Session session, IWindow client,
2216 Rect outDisplayFrame) {
2217 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002218 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002219 if (win == null) {
2220 outDisplayFrame.setEmpty();
2221 return;
2222 }
2223 outDisplayFrame.set(win.mDisplayFrame);
2224 }
2225 }
2226
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002227 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2228 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002229 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2230 window.mWallpaperX = x;
2231 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002232 window.mWallpaperXStep = xStep;
2233 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002234 if (updateWallpaperOffsetLocked(window, true)) {
2235 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002236 }
2237 }
2238 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002239
Dianne Hackborn75804932009-10-20 20:15:20 -07002240 void wallpaperCommandComplete(IBinder window, Bundle result) {
2241 synchronized (mWindowMap) {
2242 if (mWaitingOnWallpaper != null &&
2243 mWaitingOnWallpaper.mClient.asBinder() == window) {
2244 mWaitingOnWallpaper = null;
2245 mWindowMap.notifyAll();
2246 }
2247 }
2248 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002249
Dianne Hackborn75804932009-10-20 20:15:20 -07002250 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2251 String action, int x, int y, int z, Bundle extras, boolean sync) {
2252 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2253 || window == mUpperWallpaperTarget) {
2254 boolean doWait = sync;
2255 int curTokenIndex = mWallpaperTokens.size();
2256 while (curTokenIndex > 0) {
2257 curTokenIndex--;
2258 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2259 int curWallpaperIndex = token.windows.size();
2260 while (curWallpaperIndex > 0) {
2261 curWallpaperIndex--;
2262 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2263 try {
2264 wallpaper.mClient.dispatchWallpaperCommand(action,
2265 x, y, z, extras, sync);
2266 // We only want to be synchronous with one wallpaper.
2267 sync = false;
2268 } catch (RemoteException e) {
2269 }
2270 }
2271 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002272
Dianne Hackborn75804932009-10-20 20:15:20 -07002273 if (doWait) {
2274 // XXX Need to wait for result.
2275 }
2276 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002277
Dianne Hackborn75804932009-10-20 20:15:20 -07002278 return null;
2279 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002281 public int relayoutWindow(Session session, IWindow client,
2282 WindowManager.LayoutParams attrs, int requestedWidth,
2283 int requestedHeight, int viewVisibility, boolean insetsPending,
2284 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002285 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002286 boolean displayed = false;
2287 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002288 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002289 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002291 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002292 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002293 if (win == null) {
2294 return 0;
2295 }
2296 win.mRequestedWidth = requestedWidth;
2297 win.mRequestedHeight = requestedHeight;
2298
2299 if (attrs != null) {
2300 mPolicy.adjustWindowParamsLw(attrs);
2301 }
Romain Guy06882f82009-06-10 13:36:04 -07002302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002303 int attrChanges = 0;
2304 int flagChanges = 0;
2305 if (attrs != null) {
2306 flagChanges = win.mAttrs.flags ^= attrs.flags;
2307 attrChanges = win.mAttrs.copyFrom(attrs);
2308 }
2309
Joe Onorato8a9b2202010-02-26 18:56:32 -08002310 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002311
2312 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2313 win.mAlpha = attrs.alpha;
2314 }
2315
2316 final boolean scaledWindow =
2317 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2318
2319 if (scaledWindow) {
2320 // requested{Width|Height} Surface's physical size
2321 // attrs.{width|height} Size on screen
2322 win.mHScale = (attrs.width != requestedWidth) ?
2323 (attrs.width / (float)requestedWidth) : 1.0f;
2324 win.mVScale = (attrs.height != requestedHeight) ?
2325 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002326 } else {
2327 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002328 }
2329
2330 boolean imMayMove = (flagChanges&(
2331 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2332 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002333
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002334 boolean focusMayChange = win.mViewVisibility != viewVisibility
2335 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2336 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002337
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002338 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2339 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002341 win.mRelayoutCalled = true;
2342 final int oldVisibility = win.mViewVisibility;
2343 win.mViewVisibility = viewVisibility;
2344 if (viewVisibility == View.VISIBLE &&
2345 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2346 displayed = !win.isVisibleLw();
2347 if (win.mExiting) {
2348 win.mExiting = false;
2349 win.mAnimation = null;
2350 }
2351 if (win.mDestroying) {
2352 win.mDestroying = false;
2353 mDestroySurface.remove(win);
2354 }
2355 if (oldVisibility == View.GONE) {
2356 win.mEnterAnimationPending = true;
2357 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002358 if (displayed) {
2359 if (win.mSurface != null && !win.mDrawPending
2360 && !win.mCommitDrawPending && !mDisplayFrozen
2361 && mPolicy.isScreenOn()) {
2362 applyEnterAnimationLocked(win);
2363 }
2364 if ((win.mAttrs.flags
2365 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2366 if (DEBUG_VISIBILITY) Slog.v(TAG,
2367 "Relayout window turning screen on: " + win);
2368 win.mTurnOnScreen = true;
2369 }
2370 int diff = 0;
2371 if (win.mConfiguration != mCurConfiguration
2372 && (win.mConfiguration == null
2373 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2374 win.mConfiguration = mCurConfiguration;
2375 if (DEBUG_CONFIGURATION) {
2376 Slog.i(TAG, "Window " + win + " visible with new config: "
2377 + win.mConfiguration + " / 0x"
2378 + Integer.toHexString(diff));
2379 }
2380 outConfig.setTo(mCurConfiguration);
2381 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002382 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002383 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2384 // To change the format, we need to re-build the surface.
2385 win.destroySurfaceLocked();
2386 displayed = true;
2387 }
2388 try {
2389 Surface surface = win.createSurfaceLocked();
2390 if (surface != null) {
2391 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002392 win.mReportDestroySurface = false;
2393 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002394 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002395 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002396 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002397 // For some reason there isn't a surface. Clear the
2398 // caller's object so they see the same state.
2399 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002400 }
2401 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002402 mInputMonitor.updateInputWindowsLw();
2403
Joe Onorato8a9b2202010-02-26 18:56:32 -08002404 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002405 + client + " (" + win.mAttrs.getTitle() + ")",
2406 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002407 Binder.restoreCallingIdentity(origId);
2408 return 0;
2409 }
2410 if (displayed) {
2411 focusMayChange = true;
2412 }
2413 if (win.mAttrs.type == TYPE_INPUT_METHOD
2414 && mInputMethodWindow == null) {
2415 mInputMethodWindow = win;
2416 imMayMove = true;
2417 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002418 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2419 && win.mAppToken != null
2420 && win.mAppToken.startingWindow != null) {
2421 // Special handling of starting window over the base
2422 // window of the app: propagate lock screen flags to it,
2423 // to provide the correct semantics while starting.
2424 final int mask =
2425 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002426 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2427 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002428 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2429 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2430 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002431 } else {
2432 win.mEnterAnimationPending = false;
2433 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002434 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002435 + ": mExiting=" + win.mExiting
2436 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002437 // If we are not currently running the exit animation, we
2438 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002439 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002440 // Try starting an animation; if there isn't one, we
2441 // can destroy the surface right away.
2442 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2443 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2444 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2445 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002446 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002447 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002448 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002449 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002450 } else if (win.isAnimating()) {
2451 // Currently in a hide animation... turn this into
2452 // an exit.
2453 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002454 } else if (win == mWallpaperTarget) {
2455 // If the wallpaper is currently behind this
2456 // window, we need to change both of them inside
2457 // of a transaction to avoid artifacts.
2458 win.mExiting = true;
2459 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002460 } else {
2461 if (mInputMethodWindow == win) {
2462 mInputMethodWindow = null;
2463 }
2464 win.destroySurfaceLocked();
2465 }
2466 }
2467 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002468
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002469 if (win.mSurface == null || (win.getAttrs().flags
2470 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2471 || win.mSurfacePendingDestroy) {
2472 // We are being called from a local process, which
2473 // means outSurface holds its current surface. Ensure the
2474 // surface object is cleared, but we don't want it actually
2475 // destroyed at this point.
2476 win.mSurfacePendingDestroy = false;
2477 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002478 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002479 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002480 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002481 "Keeping surface, will report destroy: " + win);
2482 win.mReportDestroySurface = true;
2483 outSurface.copyFrom(win.mSurface);
2484 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002485 }
2486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002487 if (focusMayChange) {
2488 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2489 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490 imMayMove = false;
2491 }
2492 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2493 }
Romain Guy06882f82009-06-10 13:36:04 -07002494
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002495 // updateFocusedWindowLocked() already assigned layers so we only need to
2496 // reassign them at this point if the IM window state gets shuffled
2497 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002499 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002500 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2501 // Little hack here -- we -should- be able to rely on the
2502 // function to return true if the IME has moved and needs
2503 // its layer recomputed. However, if the IME was hidden
2504 // and isn't actually moved in the list, its layer may be
2505 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002506 assignLayers = true;
2507 }
2508 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002509 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002510 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002511 assignLayers = true;
2512 }
2513 }
Romain Guy06882f82009-06-10 13:36:04 -07002514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002515 mLayoutNeeded = true;
2516 win.mGivenInsetsPending = insetsPending;
2517 if (assignLayers) {
2518 assignLayersLocked();
2519 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002520 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002521 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002522 if (displayed && win.mIsWallpaper) {
2523 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002524 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002525 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002526 if (win.mAppToken != null) {
2527 win.mAppToken.updateReportedVisibilityLocked();
2528 }
2529 outFrame.set(win.mFrame);
2530 outContentInsets.set(win.mContentInsets);
2531 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002532 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002533 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002534 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002535 + ", requestedHeight=" + requestedHeight
2536 + ", viewVisibility=" + viewVisibility
2537 + "\nRelayout returning frame=" + outFrame
2538 + ", surface=" + outSurface);
2539
Joe Onorato8a9b2202010-02-26 18:56:32 -08002540 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002541 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2542
2543 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002544
2545 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002546 }
2547
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002548 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002549 sendNewConfiguration();
2550 }
Romain Guy06882f82009-06-10 13:36:04 -07002551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002552 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002553
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002554 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2555 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2556 }
2557
2558 public void finishDrawingWindow(Session session, IWindow client) {
2559 final long origId = Binder.clearCallingIdentity();
2560 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002561 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002562 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002563 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2564 adjustWallpaperWindowsLocked();
2565 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002566 mLayoutNeeded = true;
2567 performLayoutAndPlaceSurfacesLocked();
2568 }
2569 }
2570 Binder.restoreCallingIdentity(origId);
2571 }
2572
2573 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002574 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002575 + (lp != null ? lp.packageName : null)
2576 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2577 if (lp != null && lp.windowAnimations != 0) {
2578 // If this is a system resource, don't try to load it from the
2579 // application resources. It is nice to avoid loading application
2580 // resources if we can.
2581 String packageName = lp.packageName != null ? lp.packageName : "android";
2582 int resId = lp.windowAnimations;
2583 if ((resId&0xFF000000) == 0x01000000) {
2584 packageName = "android";
2585 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002586 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002587 + packageName);
2588 return AttributeCache.instance().get(packageName, resId,
2589 com.android.internal.R.styleable.WindowAnimation);
2590 }
2591 return null;
2592 }
Romain Guy06882f82009-06-10 13:36:04 -07002593
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002594 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002595 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002596 + packageName + " resId=0x" + Integer.toHexString(resId));
2597 if (packageName != null) {
2598 if ((resId&0xFF000000) == 0x01000000) {
2599 packageName = "android";
2600 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002601 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002602 + packageName);
2603 return AttributeCache.instance().get(packageName, resId,
2604 com.android.internal.R.styleable.WindowAnimation);
2605 }
2606 return null;
2607 }
2608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002609 private void applyEnterAnimationLocked(WindowState win) {
2610 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2611 if (win.mEnterAnimationPending) {
2612 win.mEnterAnimationPending = false;
2613 transit = WindowManagerPolicy.TRANSIT_ENTER;
2614 }
2615
2616 applyAnimationLocked(win, transit, true);
2617 }
2618
2619 private boolean applyAnimationLocked(WindowState win,
2620 int transit, boolean isEntrance) {
2621 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2622 // If we are trying to apply an animation, but already running
2623 // an animation of the same type, then just leave that one alone.
2624 return true;
2625 }
Romain Guy06882f82009-06-10 13:36:04 -07002626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002627 // Only apply an animation if the display isn't frozen. If it is
2628 // frozen, there is no reason to animate and it can cause strange
2629 // artifacts when we unfreeze the display if some different animation
2630 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002631 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002632 int anim = mPolicy.selectAnimationLw(win, transit);
2633 int attr = -1;
2634 Animation a = null;
2635 if (anim != 0) {
2636 a = AnimationUtils.loadAnimation(mContext, anim);
2637 } else {
2638 switch (transit) {
2639 case WindowManagerPolicy.TRANSIT_ENTER:
2640 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2641 break;
2642 case WindowManagerPolicy.TRANSIT_EXIT:
2643 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2644 break;
2645 case WindowManagerPolicy.TRANSIT_SHOW:
2646 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2647 break;
2648 case WindowManagerPolicy.TRANSIT_HIDE:
2649 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2650 break;
2651 }
2652 if (attr >= 0) {
2653 a = loadAnimation(win.mAttrs, attr);
2654 }
2655 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002656 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002657 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2658 + " mAnimation=" + win.mAnimation
2659 + " isEntrance=" + isEntrance);
2660 if (a != null) {
2661 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002662 RuntimeException e = null;
2663 if (!HIDE_STACK_CRAWLS) {
2664 e = new RuntimeException();
2665 e.fillInStackTrace();
2666 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002667 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002668 }
2669 win.setAnimation(a);
2670 win.mAnimationIsEntrance = isEntrance;
2671 }
2672 } else {
2673 win.clearAnimation();
2674 }
2675
2676 return win.mAnimation != null;
2677 }
2678
2679 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2680 int anim = 0;
2681 Context context = mContext;
2682 if (animAttr >= 0) {
2683 AttributeCache.Entry ent = getCachedAnimations(lp);
2684 if (ent != null) {
2685 context = ent.context;
2686 anim = ent.array.getResourceId(animAttr, 0);
2687 }
2688 }
2689 if (anim != 0) {
2690 return AnimationUtils.loadAnimation(context, anim);
2691 }
2692 return null;
2693 }
Romain Guy06882f82009-06-10 13:36:04 -07002694
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002695 private Animation loadAnimation(String packageName, int resId) {
2696 int anim = 0;
2697 Context context = mContext;
2698 if (resId >= 0) {
2699 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2700 if (ent != null) {
2701 context = ent.context;
2702 anim = resId;
2703 }
2704 }
2705 if (anim != 0) {
2706 return AnimationUtils.loadAnimation(context, anim);
2707 }
2708 return null;
2709 }
2710
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002711 private boolean applyAnimationLocked(AppWindowToken wtoken,
2712 WindowManager.LayoutParams lp, int transit, boolean enter) {
2713 // Only apply an animation if the display isn't frozen. If it is
2714 // frozen, there is no reason to animate and it can cause strange
2715 // artifacts when we unfreeze the display if some different animation
2716 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002717 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002718 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002719 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002720 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002721 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002722 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002723 } else if (mNextAppTransitionPackage != null) {
2724 a = loadAnimation(mNextAppTransitionPackage, enter ?
2725 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002726 } else {
2727 int animAttr = 0;
2728 switch (transit) {
2729 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2730 animAttr = enter
2731 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2732 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2733 break;
2734 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2735 animAttr = enter
2736 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2737 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2738 break;
2739 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2740 animAttr = enter
2741 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2742 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2743 break;
2744 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2745 animAttr = enter
2746 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2747 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2748 break;
2749 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2750 animAttr = enter
2751 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2752 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2753 break;
2754 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2755 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002756 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002757 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2758 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002759 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002760 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002761 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2762 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002763 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002764 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002765 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002766 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2767 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2768 break;
2769 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2770 animAttr = enter
2771 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2772 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2773 break;
2774 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2775 animAttr = enter
2776 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2777 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002778 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002779 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002780 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002781 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002782 + " anim=" + a
2783 + " animAttr=0x" + Integer.toHexString(animAttr)
2784 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002785 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002786 if (a != null) {
2787 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002788 RuntimeException e = null;
2789 if (!HIDE_STACK_CRAWLS) {
2790 e = new RuntimeException();
2791 e.fillInStackTrace();
2792 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002793 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002794 }
2795 wtoken.setAnimation(a);
2796 }
2797 } else {
2798 wtoken.clearAnimation();
2799 }
2800
2801 return wtoken.animation != null;
2802 }
2803
2804 // -------------------------------------------------------------
2805 // Application Window Tokens
2806 // -------------------------------------------------------------
2807
2808 public void validateAppTokens(List tokens) {
2809 int v = tokens.size()-1;
2810 int m = mAppTokens.size()-1;
2811 while (v >= 0 && m >= 0) {
2812 AppWindowToken wtoken = mAppTokens.get(m);
2813 if (wtoken.removed) {
2814 m--;
2815 continue;
2816 }
2817 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002818 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002819 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2820 }
2821 v--;
2822 m--;
2823 }
2824 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002825 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002826 v--;
2827 }
2828 while (m >= 0) {
2829 AppWindowToken wtoken = mAppTokens.get(m);
2830 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002831 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002832 }
2833 m--;
2834 }
2835 }
2836
2837 boolean checkCallingPermission(String permission, String func) {
2838 // Quick check: if the calling permission is me, it's all okay.
2839 if (Binder.getCallingPid() == Process.myPid()) {
2840 return true;
2841 }
Romain Guy06882f82009-06-10 13:36:04 -07002842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002843 if (mContext.checkCallingPermission(permission)
2844 == PackageManager.PERMISSION_GRANTED) {
2845 return true;
2846 }
2847 String msg = "Permission Denial: " + func + " from pid="
2848 + Binder.getCallingPid()
2849 + ", uid=" + Binder.getCallingUid()
2850 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002851 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852 return false;
2853 }
Romain Guy06882f82009-06-10 13:36:04 -07002854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002855 AppWindowToken findAppWindowToken(IBinder token) {
2856 WindowToken wtoken = mTokenMap.get(token);
2857 if (wtoken == null) {
2858 return null;
2859 }
2860 return wtoken.appWindowToken;
2861 }
Romain Guy06882f82009-06-10 13:36:04 -07002862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002863 public void addWindowToken(IBinder token, int type) {
2864 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2865 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002866 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002867 }
Romain Guy06882f82009-06-10 13:36:04 -07002868
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002869 synchronized(mWindowMap) {
2870 WindowToken wtoken = mTokenMap.get(token);
2871 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002872 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002873 return;
2874 }
2875 wtoken = new WindowToken(token, type, true);
2876 mTokenMap.put(token, wtoken);
2877 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002878 if (type == TYPE_WALLPAPER) {
2879 mWallpaperTokens.add(wtoken);
2880 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002881 }
2882 }
Romain Guy06882f82009-06-10 13:36:04 -07002883
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002884 public void removeWindowToken(IBinder token) {
2885 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2886 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002887 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002888 }
2889
2890 final long origId = Binder.clearCallingIdentity();
2891 synchronized(mWindowMap) {
2892 WindowToken wtoken = mTokenMap.remove(token);
2893 mTokenList.remove(wtoken);
2894 if (wtoken != null) {
2895 boolean delayed = false;
2896 if (!wtoken.hidden) {
2897 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002899 final int N = wtoken.windows.size();
2900 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002902 for (int i=0; i<N; i++) {
2903 WindowState win = wtoken.windows.get(i);
2904
2905 if (win.isAnimating()) {
2906 delayed = true;
2907 }
Romain Guy06882f82009-06-10 13:36:04 -07002908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002909 if (win.isVisibleNow()) {
2910 applyAnimationLocked(win,
2911 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002912 changed = true;
2913 }
2914 }
2915
2916 if (changed) {
2917 mLayoutNeeded = true;
2918 performLayoutAndPlaceSurfacesLocked();
2919 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2920 }
Romain Guy06882f82009-06-10 13:36:04 -07002921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002922 if (delayed) {
2923 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002924 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2925 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002926 }
2927 }
Romain Guy06882f82009-06-10 13:36:04 -07002928
Jeff Brownc5ed5912010-07-14 18:48:53 -07002929 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002930 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002931 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002932 }
2933 }
2934 Binder.restoreCallingIdentity(origId);
2935 }
2936
2937 public void addAppToken(int addPos, IApplicationToken token,
2938 int groupId, int requestedOrientation, boolean fullscreen) {
2939 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2940 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002941 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002942 }
Jeff Brown349703e2010-06-22 01:27:15 -07002943
2944 // Get the dispatching timeout here while we are not holding any locks so that it
2945 // can be cached by the AppWindowToken. The timeout value is used later by the
2946 // input dispatcher in code that does hold locks. If we did not cache the value
2947 // here we would run the chance of introducing a deadlock between the window manager
2948 // (which holds locks while updating the input dispatcher state) and the activity manager
2949 // (which holds locks while querying the application token).
2950 long inputDispatchingTimeoutNanos;
2951 try {
2952 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
2953 } catch (RemoteException ex) {
2954 Slog.w(TAG, "Could not get dispatching timeout.", ex);
2955 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
2956 }
Romain Guy06882f82009-06-10 13:36:04 -07002957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002958 synchronized(mWindowMap) {
2959 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2960 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002961 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002962 return;
2963 }
2964 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07002965 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002966 wtoken.groupId = groupId;
2967 wtoken.appFullscreen = fullscreen;
2968 wtoken.requestedOrientation = requestedOrientation;
2969 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002970 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002971 mTokenMap.put(token.asBinder(), wtoken);
2972 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002973
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002974 // Application tokens start out hidden.
2975 wtoken.hidden = true;
2976 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07002977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002978 //dump();
2979 }
2980 }
Romain Guy06882f82009-06-10 13:36:04 -07002981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002982 public void setAppGroupId(IBinder token, int groupId) {
2983 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2984 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002985 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002986 }
2987
2988 synchronized(mWindowMap) {
2989 AppWindowToken wtoken = findAppWindowToken(token);
2990 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002991 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002992 return;
2993 }
2994 wtoken.groupId = groupId;
2995 }
2996 }
Romain Guy06882f82009-06-10 13:36:04 -07002997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002998 public int getOrientationFromWindowsLocked() {
2999 int pos = mWindows.size() - 1;
3000 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003001 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003002 pos--;
3003 if (wtoken.mAppToken != null) {
3004 // We hit an application window. so the orientation will be determined by the
3005 // app window. No point in continuing further.
3006 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3007 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003008 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003009 continue;
3010 }
3011 int req = wtoken.mAttrs.screenOrientation;
3012 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3013 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3014 continue;
3015 } else {
3016 return req;
3017 }
3018 }
3019 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3020 }
Romain Guy06882f82009-06-10 13:36:04 -07003021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003022 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003023 int pos = mAppTokens.size() - 1;
3024 int curGroup = 0;
3025 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3026 boolean findingBehind = false;
3027 boolean haveGroup = false;
3028 boolean lastFullscreen = false;
3029 while (pos >= 0) {
3030 AppWindowToken wtoken = mAppTokens.get(pos);
3031 pos--;
3032 // if we're about to tear down this window and not seek for
3033 // the behind activity, don't use it for orientation
3034 if (!findingBehind
3035 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3036 continue;
3037 }
3038
3039 if (!haveGroup) {
3040 // We ignore any hidden applications on the top.
3041 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003042 continue;
3043 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003044 haveGroup = true;
3045 curGroup = wtoken.groupId;
3046 lastOrientation = wtoken.requestedOrientation;
3047 } else if (curGroup != wtoken.groupId) {
3048 // If we have hit a new application group, and the bottom
3049 // of the previous group didn't explicitly say to use
3050 // the orientation behind it, and the last app was
3051 // full screen, then we'll stick with the
3052 // user's orientation.
3053 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3054 && lastFullscreen) {
3055 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003056 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003057 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003058 int or = wtoken.requestedOrientation;
3059 // If this application is fullscreen, and didn't explicitly say
3060 // to use the orientation behind it, then just take whatever
3061 // orientation it has and ignores whatever is under it.
3062 lastFullscreen = wtoken.appFullscreen;
3063 if (lastFullscreen
3064 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3065 return or;
3066 }
3067 // If this application has requested an explicit orientation,
3068 // then use it.
3069 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
3070 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
3071 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
3072 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
3073 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
3074 return or;
3075 }
3076 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3077 }
3078 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003079 }
Romain Guy06882f82009-06-10 13:36:04 -07003080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003081 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003082 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003083 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3084 "updateOrientationFromAppTokens()")) {
3085 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3086 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003087
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003088 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003089 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003090
3091 synchronized(mWindowMap) {
3092 if (updateOrientationFromAppTokensLocked()) {
3093 if (freezeThisOneIfNeeded != null) {
3094 AppWindowToken wtoken = findAppWindowToken(
3095 freezeThisOneIfNeeded);
3096 if (wtoken != null) {
3097 startAppFreezingScreenLocked(wtoken,
3098 ActivityInfo.CONFIG_ORIENTATION);
3099 }
3100 }
3101 config = computeNewConfigurationLocked();
3102
3103 } else if (currentConfig != null) {
3104 // No obvious action we need to take, but if our current
3105 // state mismatches the activity maanager's, update it
3106 mTempConfiguration.setToDefaults();
3107 if (computeNewConfigurationLocked(mTempConfiguration)) {
3108 if (currentConfig.diff(mTempConfiguration) != 0) {
3109 mWaitingForConfig = true;
3110 mLayoutNeeded = true;
3111 startFreezingDisplayLocked();
3112 config = new Configuration(mTempConfiguration);
3113 }
3114 }
3115 }
3116 }
3117
Dianne Hackborncfaef692009-06-15 14:24:44 -07003118 Binder.restoreCallingIdentity(ident);
3119 return config;
3120 }
3121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003122 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003123 * Determine the new desired orientation of the display, returning
3124 * a non-null new Configuration if it has changed from the current
3125 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3126 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3127 * SCREEN. This will typically be done for you if you call
3128 * sendNewConfiguration().
3129 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003130 * The orientation is computed from non-application windows first. If none of
3131 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003132 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003133 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3134 * android.os.IBinder)
3135 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003136 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003137 if (mDisplayFrozen) {
3138 // If the display is frozen, some activities may be in the middle
3139 // of restarting, and thus have removed their old window. If the
3140 // window has the flag to hide the lock screen, then the lock screen
3141 // can re-appear and inflict its own orientation on us. Keep the
3142 // orientation stable until this all settles down.
3143 return false;
3144 }
3145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003146 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003147 long ident = Binder.clearCallingIdentity();
3148 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003149 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003151 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003152 mForcedAppOrientation = req;
3153 //send a message to Policy indicating orientation change to take
3154 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003155 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003156 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3157 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3158 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003159 }
3160 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003161
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003162 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003163 } finally {
3164 Binder.restoreCallingIdentity(ident);
3165 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003166 }
Romain Guy06882f82009-06-10 13:36:04 -07003167
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003168 int computeForcedAppOrientationLocked() {
3169 int req = getOrientationFromWindowsLocked();
3170 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3171 req = getOrientationFromAppTokensLocked();
3172 }
3173 return req;
3174 }
Romain Guy06882f82009-06-10 13:36:04 -07003175
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003176 public void setNewConfiguration(Configuration config) {
3177 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3178 "setNewConfiguration()")) {
3179 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3180 }
3181
3182 synchronized(mWindowMap) {
3183 mCurConfiguration = new Configuration(config);
3184 mWaitingForConfig = false;
3185 performLayoutAndPlaceSurfacesLocked();
3186 }
3187 }
3188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003189 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3190 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3191 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003192 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003193 }
Romain Guy06882f82009-06-10 13:36:04 -07003194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003195 synchronized(mWindowMap) {
3196 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3197 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003198 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003199 return;
3200 }
Romain Guy06882f82009-06-10 13:36:04 -07003201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003202 wtoken.requestedOrientation = requestedOrientation;
3203 }
3204 }
Romain Guy06882f82009-06-10 13:36:04 -07003205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003206 public int getAppOrientation(IApplicationToken token) {
3207 synchronized(mWindowMap) {
3208 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3209 if (wtoken == null) {
3210 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3211 }
Romain Guy06882f82009-06-10 13:36:04 -07003212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003213 return wtoken.requestedOrientation;
3214 }
3215 }
Romain Guy06882f82009-06-10 13:36:04 -07003216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003217 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3218 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3219 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003220 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003221 }
3222
3223 synchronized(mWindowMap) {
3224 boolean changed = false;
3225 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003226 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003227 changed = mFocusedApp != null;
3228 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003229 if (changed) {
3230 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003231 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003232 } else {
3233 AppWindowToken newFocus = findAppWindowToken(token);
3234 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003235 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003236 return;
3237 }
3238 changed = mFocusedApp != newFocus;
3239 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003240 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003241 if (changed) {
3242 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003243 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003244 }
3245
3246 if (moveFocusNow && changed) {
3247 final long origId = Binder.clearCallingIdentity();
3248 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3249 Binder.restoreCallingIdentity(origId);
3250 }
3251 }
3252 }
3253
3254 public void prepareAppTransition(int transit) {
3255 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3256 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003257 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003258 }
Romain Guy06882f82009-06-10 13:36:04 -07003259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003260 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003261 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003262 TAG, "Prepare app transition: transit=" + transit
3263 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003264 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003265 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3266 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003267 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003268 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3269 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3270 // Opening a new task always supersedes a close for the anim.
3271 mNextAppTransition = transit;
3272 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3273 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3274 // Opening a new activity always supersedes a close for the anim.
3275 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003276 }
3277 mAppTransitionReady = false;
3278 mAppTransitionTimeout = false;
3279 mStartingIconInTransition = false;
3280 mSkipAppTransitionAnimation = false;
3281 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3282 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3283 5000);
3284 }
3285 }
3286 }
3287
3288 public int getPendingAppTransition() {
3289 return mNextAppTransition;
3290 }
Romain Guy06882f82009-06-10 13:36:04 -07003291
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003292 public void overridePendingAppTransition(String packageName,
3293 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003294 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003295 mNextAppTransitionPackage = packageName;
3296 mNextAppTransitionEnter = enterAnim;
3297 mNextAppTransitionExit = exitAnim;
3298 }
3299 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003301 public void executeAppTransition() {
3302 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3303 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003304 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003305 }
Romain Guy06882f82009-06-10 13:36:04 -07003306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003307 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003308 if (DEBUG_APP_TRANSITIONS) {
3309 RuntimeException e = new RuntimeException("here");
3310 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003311 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003312 + mNextAppTransition, e);
3313 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003314 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003315 mAppTransitionReady = true;
3316 final long origId = Binder.clearCallingIdentity();
3317 performLayoutAndPlaceSurfacesLocked();
3318 Binder.restoreCallingIdentity(origId);
3319 }
3320 }
3321 }
3322
3323 public void setAppStartingWindow(IBinder token, String pkg,
3324 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3325 IBinder transferFrom, boolean createIfNeeded) {
3326 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3327 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003328 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003329 }
3330
3331 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003332 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003333 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3334 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003336 AppWindowToken wtoken = findAppWindowToken(token);
3337 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003338 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003339 return;
3340 }
3341
3342 // If the display is frozen, we won't do anything until the
3343 // actual window is displayed so there is no reason to put in
3344 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003345 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003346 return;
3347 }
Romain Guy06882f82009-06-10 13:36:04 -07003348
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003349 if (wtoken.startingData != null) {
3350 return;
3351 }
Romain Guy06882f82009-06-10 13:36:04 -07003352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003353 if (transferFrom != null) {
3354 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3355 if (ttoken != null) {
3356 WindowState startingWindow = ttoken.startingWindow;
3357 if (startingWindow != null) {
3358 if (mStartingIconInTransition) {
3359 // In this case, the starting icon has already
3360 // been displayed, so start letting windows get
3361 // shown immediately without any more transitions.
3362 mSkipAppTransitionAnimation = true;
3363 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003364 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003365 "Moving existing starting from " + ttoken
3366 + " to " + wtoken);
3367 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003369 // Transfer the starting window over to the new
3370 // token.
3371 wtoken.startingData = ttoken.startingData;
3372 wtoken.startingView = ttoken.startingView;
3373 wtoken.startingWindow = startingWindow;
3374 ttoken.startingData = null;
3375 ttoken.startingView = null;
3376 ttoken.startingWindow = null;
3377 ttoken.startingMoved = true;
3378 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003379 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003380 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003381 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003382 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003383 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003384 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003385 ttoken.windows.remove(startingWindow);
3386 ttoken.allAppWindows.remove(startingWindow);
3387 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003389 // Propagate other interesting state between the
3390 // tokens. If the old token is displayed, we should
3391 // immediately force the new one to be displayed. If
3392 // it is animating, we need to move that animation to
3393 // the new one.
3394 if (ttoken.allDrawn) {
3395 wtoken.allDrawn = true;
3396 }
3397 if (ttoken.firstWindowDrawn) {
3398 wtoken.firstWindowDrawn = true;
3399 }
3400 if (!ttoken.hidden) {
3401 wtoken.hidden = false;
3402 wtoken.hiddenRequested = false;
3403 wtoken.willBeHidden = false;
3404 }
3405 if (wtoken.clientHidden != ttoken.clientHidden) {
3406 wtoken.clientHidden = ttoken.clientHidden;
3407 wtoken.sendAppVisibilityToClients();
3408 }
3409 if (ttoken.animation != null) {
3410 wtoken.animation = ttoken.animation;
3411 wtoken.animating = ttoken.animating;
3412 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3413 ttoken.animation = null;
3414 ttoken.animLayerAdjustment = 0;
3415 wtoken.updateLayers();
3416 ttoken.updateLayers();
3417 }
Romain Guy06882f82009-06-10 13:36:04 -07003418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003419 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003420 mLayoutNeeded = true;
3421 performLayoutAndPlaceSurfacesLocked();
3422 Binder.restoreCallingIdentity(origId);
3423 return;
3424 } else if (ttoken.startingData != null) {
3425 // The previous app was getting ready to show a
3426 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003427 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003428 "Moving pending starting from " + ttoken
3429 + " to " + wtoken);
3430 wtoken.startingData = ttoken.startingData;
3431 ttoken.startingData = null;
3432 ttoken.startingMoved = true;
3433 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3434 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3435 // want to process the message ASAP, before any other queued
3436 // messages.
3437 mH.sendMessageAtFrontOfQueue(m);
3438 return;
3439 }
3440 }
3441 }
3442
3443 // There is no existing starting window, and the caller doesn't
3444 // want us to create one, so that's it!
3445 if (!createIfNeeded) {
3446 return;
3447 }
Romain Guy06882f82009-06-10 13:36:04 -07003448
Dianne Hackborn284ac932009-08-28 10:34:25 -07003449 // If this is a translucent or wallpaper window, then don't
3450 // show a starting window -- the current effect (a full-screen
3451 // opaque starting window that fades away to the real contents
3452 // when it is ready) does not work for this.
3453 if (theme != 0) {
3454 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3455 com.android.internal.R.styleable.Window);
3456 if (ent.array.getBoolean(
3457 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3458 return;
3459 }
3460 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003461 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3462 return;
3463 }
3464 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003465 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3466 return;
3467 }
3468 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003469
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003470 mStartingIconInTransition = true;
3471 wtoken.startingData = new StartingData(
3472 pkg, theme, nonLocalizedLabel,
3473 labelRes, icon);
3474 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3475 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3476 // want to process the message ASAP, before any other queued
3477 // messages.
3478 mH.sendMessageAtFrontOfQueue(m);
3479 }
3480 }
3481
3482 public void setAppWillBeHidden(IBinder token) {
3483 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3484 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003485 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003486 }
3487
3488 AppWindowToken wtoken;
3489
3490 synchronized(mWindowMap) {
3491 wtoken = findAppWindowToken(token);
3492 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003493 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 -08003494 return;
3495 }
3496 wtoken.willBeHidden = true;
3497 }
3498 }
Romain Guy06882f82009-06-10 13:36:04 -07003499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003500 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3501 boolean visible, int transit, boolean performLayout) {
3502 boolean delayed = false;
3503
3504 if (wtoken.clientHidden == visible) {
3505 wtoken.clientHidden = !visible;
3506 wtoken.sendAppVisibilityToClients();
3507 }
Romain Guy06882f82009-06-10 13:36:04 -07003508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003509 wtoken.willBeHidden = false;
3510 if (wtoken.hidden == visible) {
3511 final int N = wtoken.allAppWindows.size();
3512 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003513 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003514 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3515 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003517 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003518
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003519 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003520 if (wtoken.animation == sDummyAnimation) {
3521 wtoken.animation = null;
3522 }
3523 applyAnimationLocked(wtoken, lp, transit, visible);
3524 changed = true;
3525 if (wtoken.animation != null) {
3526 delayed = runningAppAnimation = true;
3527 }
3528 }
Romain Guy06882f82009-06-10 13:36:04 -07003529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003530 for (int i=0; i<N; i++) {
3531 WindowState win = wtoken.allAppWindows.get(i);
3532 if (win == wtoken.startingWindow) {
3533 continue;
3534 }
3535
3536 if (win.isAnimating()) {
3537 delayed = true;
3538 }
Romain Guy06882f82009-06-10 13:36:04 -07003539
Joe Onorato8a9b2202010-02-26 18:56:32 -08003540 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003541 //win.dump(" ");
3542 if (visible) {
3543 if (!win.isVisibleNow()) {
3544 if (!runningAppAnimation) {
3545 applyAnimationLocked(win,
3546 WindowManagerPolicy.TRANSIT_ENTER, true);
3547 }
3548 changed = true;
3549 }
3550 } else if (win.isVisibleNow()) {
3551 if (!runningAppAnimation) {
3552 applyAnimationLocked(win,
3553 WindowManagerPolicy.TRANSIT_EXIT, false);
3554 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003555 changed = true;
3556 }
3557 }
3558
3559 wtoken.hidden = wtoken.hiddenRequested = !visible;
3560 if (!visible) {
3561 unsetAppFreezingScreenLocked(wtoken, true, true);
3562 } else {
3563 // If we are being set visible, and the starting window is
3564 // not yet displayed, then make sure it doesn't get displayed.
3565 WindowState swin = wtoken.startingWindow;
3566 if (swin != null && (swin.mDrawPending
3567 || swin.mCommitDrawPending)) {
3568 swin.mPolicyVisibility = false;
3569 swin.mPolicyVisibilityAfterAnim = false;
3570 }
3571 }
Romain Guy06882f82009-06-10 13:36:04 -07003572
Joe Onorato8a9b2202010-02-26 18:56:32 -08003573 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003574 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3575 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003576
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003577 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003578 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003579 if (performLayout) {
3580 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3581 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003582 } else {
3583 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003584 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003585 }
3586 }
3587
3588 if (wtoken.animation != null) {
3589 delayed = true;
3590 }
Romain Guy06882f82009-06-10 13:36:04 -07003591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003592 return delayed;
3593 }
3594
3595 public void setAppVisibility(IBinder token, boolean visible) {
3596 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3597 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003598 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003599 }
3600
3601 AppWindowToken wtoken;
3602
3603 synchronized(mWindowMap) {
3604 wtoken = findAppWindowToken(token);
3605 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003606 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003607 return;
3608 }
3609
3610 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003611 RuntimeException e = null;
3612 if (!HIDE_STACK_CRAWLS) {
3613 e = new RuntimeException();
3614 e.fillInStackTrace();
3615 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003616 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003617 + "): mNextAppTransition=" + mNextAppTransition
3618 + " hidden=" + wtoken.hidden
3619 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3620 }
Romain Guy06882f82009-06-10 13:36:04 -07003621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003622 // If we are preparing an app transition, then delay changing
3623 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003624 if (!mDisplayFrozen && mPolicy.isScreenOn()
3625 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003626 // Already in requested state, don't do anything more.
3627 if (wtoken.hiddenRequested != visible) {
3628 return;
3629 }
3630 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003631
Joe Onorato8a9b2202010-02-26 18:56:32 -08003632 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003633 TAG, "Setting dummy animation on: " + wtoken);
3634 wtoken.setDummyAnimation();
3635 mOpeningApps.remove(wtoken);
3636 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003637 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003638 wtoken.inPendingTransaction = true;
3639 if (visible) {
3640 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003641 wtoken.startingDisplayed = false;
3642 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003643
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003644 // If the token is currently hidden (should be the
3645 // common case), then we need to set up to wait for
3646 // its windows to be ready.
3647 if (wtoken.hidden) {
3648 wtoken.allDrawn = false;
3649 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003650
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003651 if (wtoken.clientHidden) {
3652 // In the case where we are making an app visible
3653 // but holding off for a transition, we still need
3654 // to tell the client to make its windows visible so
3655 // they get drawn. Otherwise, we will wait on
3656 // performing the transition until all windows have
3657 // been drawn, they never will be, and we are sad.
3658 wtoken.clientHidden = false;
3659 wtoken.sendAppVisibilityToClients();
3660 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003661 }
3662 } else {
3663 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003664
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003665 // If the token is currently visible (should be the
3666 // common case), then set up to wait for it to be hidden.
3667 if (!wtoken.hidden) {
3668 wtoken.waitingToHide = true;
3669 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003670 }
3671 return;
3672 }
Romain Guy06882f82009-06-10 13:36:04 -07003673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003674 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003675 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003676 wtoken.updateReportedVisibilityLocked();
3677 Binder.restoreCallingIdentity(origId);
3678 }
3679 }
3680
3681 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3682 boolean unfreezeSurfaceNow, boolean force) {
3683 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003684 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003685 + " force=" + force);
3686 final int N = wtoken.allAppWindows.size();
3687 boolean unfrozeWindows = false;
3688 for (int i=0; i<N; i++) {
3689 WindowState w = wtoken.allAppWindows.get(i);
3690 if (w.mAppFreezing) {
3691 w.mAppFreezing = false;
3692 if (w.mSurface != null && !w.mOrientationChanging) {
3693 w.mOrientationChanging = true;
3694 }
3695 unfrozeWindows = true;
3696 }
3697 }
3698 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003699 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003700 wtoken.freezingScreen = false;
3701 mAppsFreezingScreen--;
3702 }
3703 if (unfreezeSurfaceNow) {
3704 if (unfrozeWindows) {
3705 mLayoutNeeded = true;
3706 performLayoutAndPlaceSurfacesLocked();
3707 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003708 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003709 }
3710 }
3711 }
Romain Guy06882f82009-06-10 13:36:04 -07003712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003713 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3714 int configChanges) {
3715 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003716 RuntimeException e = null;
3717 if (!HIDE_STACK_CRAWLS) {
3718 e = new RuntimeException();
3719 e.fillInStackTrace();
3720 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003721 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003722 + ": hidden=" + wtoken.hidden + " freezing="
3723 + wtoken.freezingScreen, e);
3724 }
3725 if (!wtoken.hiddenRequested) {
3726 if (!wtoken.freezingScreen) {
3727 wtoken.freezingScreen = true;
3728 mAppsFreezingScreen++;
3729 if (mAppsFreezingScreen == 1) {
3730 startFreezingDisplayLocked();
3731 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3732 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3733 5000);
3734 }
3735 }
3736 final int N = wtoken.allAppWindows.size();
3737 for (int i=0; i<N; i++) {
3738 WindowState w = wtoken.allAppWindows.get(i);
3739 w.mAppFreezing = true;
3740 }
3741 }
3742 }
Romain Guy06882f82009-06-10 13:36:04 -07003743
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003744 public void startAppFreezingScreen(IBinder token, int configChanges) {
3745 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3746 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003747 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003748 }
3749
3750 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003751 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003752 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003753 return;
3754 }
Romain Guy06882f82009-06-10 13:36:04 -07003755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003756 AppWindowToken wtoken = findAppWindowToken(token);
3757 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003758 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003759 return;
3760 }
3761 final long origId = Binder.clearCallingIdentity();
3762 startAppFreezingScreenLocked(wtoken, configChanges);
3763 Binder.restoreCallingIdentity(origId);
3764 }
3765 }
Romain Guy06882f82009-06-10 13:36:04 -07003766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003767 public void stopAppFreezingScreen(IBinder token, boolean force) {
3768 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3769 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003770 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003771 }
3772
3773 synchronized(mWindowMap) {
3774 AppWindowToken wtoken = findAppWindowToken(token);
3775 if (wtoken == null || wtoken.appToken == null) {
3776 return;
3777 }
3778 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003779 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003780 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3781 unsetAppFreezingScreenLocked(wtoken, true, force);
3782 Binder.restoreCallingIdentity(origId);
3783 }
3784 }
Romain Guy06882f82009-06-10 13:36:04 -07003785
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003786 public void removeAppToken(IBinder token) {
3787 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3788 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003789 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003790 }
3791
3792 AppWindowToken wtoken = null;
3793 AppWindowToken startingToken = null;
3794 boolean delayed = false;
3795
3796 final long origId = Binder.clearCallingIdentity();
3797 synchronized(mWindowMap) {
3798 WindowToken basewtoken = mTokenMap.remove(token);
3799 mTokenList.remove(basewtoken);
3800 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003801 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003802 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003803 wtoken.inPendingTransaction = false;
3804 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003805 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003806 if (mClosingApps.contains(wtoken)) {
3807 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003808 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003809 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003810 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003811 delayed = true;
3812 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003813 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003814 TAG, "Removing app " + wtoken + " delayed=" + delayed
3815 + " animation=" + wtoken.animation
3816 + " animating=" + wtoken.animating);
3817 if (delayed) {
3818 // set the token aside because it has an active animation to be finished
3819 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003820 } else {
3821 // Make sure there is no animation running on this token,
3822 // so any windows associated with it will be removed as
3823 // soon as their animations are complete
3824 wtoken.animation = null;
3825 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003826 }
3827 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003828 if (mLastEnterAnimToken == wtoken) {
3829 mLastEnterAnimToken = null;
3830 mLastEnterAnimParams = null;
3831 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003832 wtoken.removed = true;
3833 if (wtoken.startingData != null) {
3834 startingToken = wtoken;
3835 }
3836 unsetAppFreezingScreenLocked(wtoken, true, true);
3837 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003838 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003839 mFocusedApp = null;
3840 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003841 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003842 }
3843 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003844 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003845 }
Romain Guy06882f82009-06-10 13:36:04 -07003846
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003847 if (!delayed && wtoken != null) {
3848 wtoken.updateReportedVisibilityLocked();
3849 }
3850 }
3851 Binder.restoreCallingIdentity(origId);
3852
3853 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003854 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003855 + startingToken + ": app token removed");
3856 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3857 mH.sendMessage(m);
3858 }
3859 }
3860
3861 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3862 final int NW = token.windows.size();
3863 for (int i=0; i<NW; i++) {
3864 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003865 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003866 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003867 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003868 int j = win.mChildWindows.size();
3869 while (j > 0) {
3870 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003871 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003872 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003873 "Tmp removing child window " + cwin);
3874 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003875 }
3876 }
3877 return NW > 0;
3878 }
3879
3880 void dumpAppTokensLocked() {
3881 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003882 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003883 }
3884 }
Romain Guy06882f82009-06-10 13:36:04 -07003885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003886 void dumpWindowsLocked() {
3887 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003888 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003889 }
3890 }
Romain Guy06882f82009-06-10 13:36:04 -07003891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003892 private int findWindowOffsetLocked(int tokenPos) {
3893 final int NW = mWindows.size();
3894
3895 if (tokenPos >= mAppTokens.size()) {
3896 int i = NW;
3897 while (i > 0) {
3898 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07003899 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003900 if (win.getAppToken() != null) {
3901 return i+1;
3902 }
3903 }
3904 }
3905
3906 while (tokenPos > 0) {
3907 // Find the first app token below the new position that has
3908 // a window displayed.
3909 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003910 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003911 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003912 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003913 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07003914 "Skipping token -- currently sending to bottom");
3915 tokenPos--;
3916 continue;
3917 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003918 int i = wtoken.windows.size();
3919 while (i > 0) {
3920 i--;
3921 WindowState win = wtoken.windows.get(i);
3922 int j = win.mChildWindows.size();
3923 while (j > 0) {
3924 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003925 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003926 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003927 for (int pos=NW-1; pos>=0; pos--) {
3928 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003929 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003930 "Found child win @" + (pos+1));
3931 return pos+1;
3932 }
3933 }
3934 }
3935 }
3936 for (int pos=NW-1; pos>=0; pos--) {
3937 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003938 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003939 return pos+1;
3940 }
3941 }
3942 }
3943 tokenPos--;
3944 }
3945
3946 return 0;
3947 }
3948
3949 private final int reAddWindowLocked(int index, WindowState win) {
3950 final int NCW = win.mChildWindows.size();
3951 boolean added = false;
3952 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07003953 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003954 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003955 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003956 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003957 mWindows.add(index, win);
3958 index++;
3959 added = true;
3960 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003961 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003962 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003963 mWindows.add(index, cwin);
3964 index++;
3965 }
3966 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003967 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003968 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003969 mWindows.add(index, win);
3970 index++;
3971 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003972 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003973 return index;
3974 }
Romain Guy06882f82009-06-10 13:36:04 -07003975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003976 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3977 final int NW = token.windows.size();
3978 for (int i=0; i<NW; i++) {
3979 index = reAddWindowLocked(index, token.windows.get(i));
3980 }
3981 return index;
3982 }
3983
3984 public void moveAppToken(int index, IBinder token) {
3985 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3986 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003987 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003988 }
3989
3990 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003991 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003992 if (DEBUG_REORDER) dumpAppTokensLocked();
3993 final AppWindowToken wtoken = findAppWindowToken(token);
3994 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003995 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003996 + token + " (" + wtoken + ")");
3997 return;
3998 }
3999 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004000 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004001 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004003 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004004 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004005 if (DEBUG_REORDER) dumpWindowsLocked();
4006 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004007 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004008 if (DEBUG_REORDER) dumpWindowsLocked();
4009 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004010 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004011 if (DEBUG_REORDER) dumpWindowsLocked();
4012 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004013 mLayoutNeeded = true;
4014 performLayoutAndPlaceSurfacesLocked();
4015 }
4016 Binder.restoreCallingIdentity(origId);
4017 }
4018 }
4019
4020 private void removeAppTokensLocked(List<IBinder> tokens) {
4021 // XXX This should be done more efficiently!
4022 // (take advantage of the fact that both lists should be
4023 // ordered in the same way.)
4024 int N = tokens.size();
4025 for (int i=0; i<N; i++) {
4026 IBinder token = tokens.get(i);
4027 final AppWindowToken wtoken = findAppWindowToken(token);
4028 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004029 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004030 + token + " (" + wtoken + ")");
4031 i--;
4032 N--;
4033 }
4034 }
4035 }
4036
Dianne Hackborna8f60182009-09-01 19:01:50 -07004037 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4038 boolean updateFocusAndLayout) {
4039 // First remove all of the windows from the list.
4040 tmpRemoveAppWindowsLocked(wtoken);
4041
4042 // Where to start adding?
4043 int pos = findWindowOffsetLocked(tokenPos);
4044
4045 // And now add them back at the correct place.
4046 pos = reAddAppWindowsLocked(pos, wtoken);
4047
4048 if (updateFocusAndLayout) {
4049 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4050 assignLayersLocked();
4051 }
4052 mLayoutNeeded = true;
4053 performLayoutAndPlaceSurfacesLocked();
4054 }
4055 }
4056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004057 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4058 // First remove all of the windows from the list.
4059 final int N = tokens.size();
4060 int i;
4061 for (i=0; i<N; i++) {
4062 WindowToken token = mTokenMap.get(tokens.get(i));
4063 if (token != null) {
4064 tmpRemoveAppWindowsLocked(token);
4065 }
4066 }
4067
4068 // Where to start adding?
4069 int pos = findWindowOffsetLocked(tokenPos);
4070
4071 // And now add them back at the correct place.
4072 for (i=0; i<N; i++) {
4073 WindowToken token = mTokenMap.get(tokens.get(i));
4074 if (token != null) {
4075 pos = reAddAppWindowsLocked(pos, token);
4076 }
4077 }
4078
Dianne Hackborna8f60182009-09-01 19:01:50 -07004079 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4080 assignLayersLocked();
4081 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004082 mLayoutNeeded = true;
4083 performLayoutAndPlaceSurfacesLocked();
4084
4085 //dump();
4086 }
4087
4088 public void moveAppTokensToTop(List<IBinder> tokens) {
4089 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4090 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004091 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004092 }
4093
4094 final long origId = Binder.clearCallingIdentity();
4095 synchronized(mWindowMap) {
4096 removeAppTokensLocked(tokens);
4097 final int N = tokens.size();
4098 for (int i=0; i<N; i++) {
4099 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4100 if (wt != null) {
4101 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004102 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004103 mToTopApps.remove(wt);
4104 mToBottomApps.remove(wt);
4105 mToTopApps.add(wt);
4106 wt.sendingToBottom = false;
4107 wt.sendingToTop = true;
4108 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004109 }
4110 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004111
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004112 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004113 moveAppWindowsLocked(tokens, mAppTokens.size());
4114 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004115 }
4116 Binder.restoreCallingIdentity(origId);
4117 }
4118
4119 public void moveAppTokensToBottom(List<IBinder> tokens) {
4120 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4121 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004122 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004123 }
4124
4125 final long origId = Binder.clearCallingIdentity();
4126 synchronized(mWindowMap) {
4127 removeAppTokensLocked(tokens);
4128 final int N = tokens.size();
4129 int pos = 0;
4130 for (int i=0; i<N; i++) {
4131 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4132 if (wt != null) {
4133 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004134 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004135 mToTopApps.remove(wt);
4136 mToBottomApps.remove(wt);
4137 mToBottomApps.add(i, wt);
4138 wt.sendingToTop = false;
4139 wt.sendingToBottom = true;
4140 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004141 pos++;
4142 }
4143 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004144
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004145 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004146 moveAppWindowsLocked(tokens, 0);
4147 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004148 }
4149 Binder.restoreCallingIdentity(origId);
4150 }
4151
4152 // -------------------------------------------------------------
4153 // Misc IWindowSession methods
4154 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004155
Jim Miller284b62e2010-06-08 14:27:42 -07004156 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004157 {
Jim Miller284b62e2010-06-08 14:27:42 -07004158 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4159 // called before DevicePolicyManagerService has started.
4160 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4161 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4162 Context.DEVICE_POLICY_SERVICE);
4163 if (dpm != null) {
4164 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4165 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4166 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4167 }
Jim Millerd6b57052010-06-07 17:52:42 -07004168 }
Jim Miller284b62e2010-06-08 14:27:42 -07004169 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004170 }
4171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004172 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004173 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004174 != PackageManager.PERMISSION_GRANTED) {
4175 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4176 }
Jim Millerd6b57052010-06-07 17:52:42 -07004177
Jim Miller284b62e2010-06-08 14:27:42 -07004178 synchronized (mKeyguardTokenWatcher) {
4179 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004180 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004181 }
4182
4183 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004184 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004185 != PackageManager.PERMISSION_GRANTED) {
4186 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4187 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004188
Jim Miller284b62e2010-06-08 14:27:42 -07004189 synchronized (mKeyguardTokenWatcher) {
4190 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004191
Jim Miller284b62e2010-06-08 14:27:42 -07004192 if (!mKeyguardTokenWatcher.isAcquired()) {
4193 // If we are the last one to reenable the keyguard wait until
4194 // we have actually finished reenabling until returning.
4195 // It is possible that reenableKeyguard() can be called before
4196 // the previous disableKeyguard() is handled, in which case
4197 // neither mKeyguardTokenWatcher.acquired() or released() would
4198 // be called. In that case mKeyguardDisabled will be false here
4199 // and we have nothing to wait for.
4200 while (mKeyguardDisabled) {
4201 try {
4202 mKeyguardTokenWatcher.wait();
4203 } catch (InterruptedException e) {
4204 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004205 }
4206 }
4207 }
4208 }
4209 }
4210
4211 /**
4212 * @see android.app.KeyguardManager#exitKeyguardSecurely
4213 */
4214 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004215 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004216 != PackageManager.PERMISSION_GRANTED) {
4217 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4218 }
4219 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4220 public void onKeyguardExitResult(boolean success) {
4221 try {
4222 callback.onKeyguardExitResult(success);
4223 } catch (RemoteException e) {
4224 // Client has died, we don't care.
4225 }
4226 }
4227 });
4228 }
4229
4230 public boolean inKeyguardRestrictedInputMode() {
4231 return mPolicy.inKeyguardRestrictedKeyInputMode();
4232 }
Romain Guy06882f82009-06-10 13:36:04 -07004233
Dianne Hackbornffa42482009-09-23 22:20:11 -07004234 public void closeSystemDialogs(String reason) {
4235 synchronized(mWindowMap) {
4236 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004237 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004238 if (w.mSurface != null) {
4239 try {
4240 w.mClient.closeSystemDialogs(reason);
4241 } catch (RemoteException e) {
4242 }
4243 }
4244 }
4245 }
4246 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004248 static float fixScale(float scale) {
4249 if (scale < 0) scale = 0;
4250 else if (scale > 20) scale = 20;
4251 return Math.abs(scale);
4252 }
Romain Guy06882f82009-06-10 13:36:04 -07004253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004254 public void setAnimationScale(int which, float scale) {
4255 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4256 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004257 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004258 }
4259
4260 if (scale < 0) scale = 0;
4261 else if (scale > 20) scale = 20;
4262 scale = Math.abs(scale);
4263 switch (which) {
4264 case 0: mWindowAnimationScale = fixScale(scale); break;
4265 case 1: mTransitionAnimationScale = fixScale(scale); break;
4266 }
Romain Guy06882f82009-06-10 13:36:04 -07004267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004268 // Persist setting
4269 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4270 }
Romain Guy06882f82009-06-10 13:36:04 -07004271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004272 public void setAnimationScales(float[] scales) {
4273 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4274 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004275 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004276 }
4277
4278 if (scales != null) {
4279 if (scales.length >= 1) {
4280 mWindowAnimationScale = fixScale(scales[0]);
4281 }
4282 if (scales.length >= 2) {
4283 mTransitionAnimationScale = fixScale(scales[1]);
4284 }
4285 }
Romain Guy06882f82009-06-10 13:36:04 -07004286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004287 // Persist setting
4288 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4289 }
Romain Guy06882f82009-06-10 13:36:04 -07004290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004291 public float getAnimationScale(int which) {
4292 switch (which) {
4293 case 0: return mWindowAnimationScale;
4294 case 1: return mTransitionAnimationScale;
4295 }
4296 return 0;
4297 }
Romain Guy06882f82009-06-10 13:36:04 -07004298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004299 public float[] getAnimationScales() {
4300 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4301 }
Romain Guy06882f82009-06-10 13:36:04 -07004302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004303 public int getSwitchState(int sw) {
4304 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4305 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004306 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004307 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004308 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004309 }
Romain Guy06882f82009-06-10 13:36:04 -07004310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004311 public int getSwitchStateForDevice(int devid, int sw) {
4312 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4313 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004314 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004315 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004316 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004317 }
Romain Guy06882f82009-06-10 13:36:04 -07004318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004319 public int getScancodeState(int sw) {
4320 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4321 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004322 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004323 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004324 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004325 }
Romain Guy06882f82009-06-10 13:36:04 -07004326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004327 public int getScancodeStateForDevice(int devid, int sw) {
4328 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4329 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004330 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004331 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004332 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004333 }
Romain Guy06882f82009-06-10 13:36:04 -07004334
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004335 public int getTrackballScancodeState(int sw) {
4336 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4337 "getTrackballScancodeState()")) {
4338 throw new SecurityException("Requires READ_INPUT_STATE permission");
4339 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004340 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004341 }
4342
4343 public int getDPadScancodeState(int sw) {
4344 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4345 "getDPadScancodeState()")) {
4346 throw new SecurityException("Requires READ_INPUT_STATE permission");
4347 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004348 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004349 }
4350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004351 public int getKeycodeState(int sw) {
4352 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4353 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004354 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004355 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004356 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004357 }
Romain Guy06882f82009-06-10 13:36:04 -07004358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004359 public int getKeycodeStateForDevice(int devid, int sw) {
4360 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4361 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004362 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004363 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004364 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004365 }
Romain Guy06882f82009-06-10 13:36:04 -07004366
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004367 public int getTrackballKeycodeState(int sw) {
4368 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4369 "getTrackballKeycodeState()")) {
4370 throw new SecurityException("Requires READ_INPUT_STATE permission");
4371 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004372 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004373 }
4374
4375 public int getDPadKeycodeState(int sw) {
4376 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4377 "getDPadKeycodeState()")) {
4378 throw new SecurityException("Requires READ_INPUT_STATE permission");
4379 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004380 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004381 }
Jeff Browna41ca772010-08-11 14:46:32 -07004382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004383 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004384 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004385 }
Romain Guy06882f82009-06-10 13:36:04 -07004386
Jeff Browna41ca772010-08-11 14:46:32 -07004387 public InputChannel monitorInput(String inputChannelName) {
4388 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4389 "monitorInput()")) {
4390 throw new SecurityException("Requires READ_INPUT_STATE permission");
4391 }
4392 return mInputManager.monitorInput(inputChannelName);
4393 }
4394
Jeff Brown8d608662010-08-30 03:02:23 -07004395 public InputDevice getInputDevice(int deviceId) {
4396 return mInputManager.getInputDevice(deviceId);
4397 }
4398
4399 public int[] getInputDeviceIds() {
4400 return mInputManager.getInputDeviceIds();
4401 }
4402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004403 public void enableScreenAfterBoot() {
4404 synchronized(mWindowMap) {
4405 if (mSystemBooted) {
4406 return;
4407 }
4408 mSystemBooted = true;
4409 }
Romain Guy06882f82009-06-10 13:36:04 -07004410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004411 performEnableScreen();
4412 }
Romain Guy06882f82009-06-10 13:36:04 -07004413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004414 public void enableScreenIfNeededLocked() {
4415 if (mDisplayEnabled) {
4416 return;
4417 }
4418 if (!mSystemBooted) {
4419 return;
4420 }
4421 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4422 }
Romain Guy06882f82009-06-10 13:36:04 -07004423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004424 public void performEnableScreen() {
4425 synchronized(mWindowMap) {
4426 if (mDisplayEnabled) {
4427 return;
4428 }
4429 if (!mSystemBooted) {
4430 return;
4431 }
Romain Guy06882f82009-06-10 13:36:04 -07004432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004433 // Don't enable the screen until all existing windows
4434 // have been drawn.
4435 final int N = mWindows.size();
4436 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004437 WindowState w = mWindows.get(i);
Dianne Hackborn5943c202010-04-12 21:36:49 -07004438 if (w.isVisibleLw() && !w.mObscured
4439 && (w.mOrientationChanging || !w.isDrawnLw())) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004440 return;
4441 }
4442 }
Romain Guy06882f82009-06-10 13:36:04 -07004443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004444 mDisplayEnabled = true;
4445 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004446 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004447 StringWriter sw = new StringWriter();
4448 PrintWriter pw = new PrintWriter(sw);
4449 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004450 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004451 }
4452 try {
4453 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4454 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004455 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004456 Parcel data = Parcel.obtain();
4457 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4458 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4459 data, null, 0);
4460 data.recycle();
4461 }
4462 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004463 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004464 }
4465 }
Romain Guy06882f82009-06-10 13:36:04 -07004466
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004467 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004469 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004470 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4471 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004472 }
Romain Guy06882f82009-06-10 13:36:04 -07004473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004474 public void setInTouchMode(boolean mode) {
4475 synchronized(mWindowMap) {
4476 mInTouchMode = mode;
4477 }
4478 }
4479
Romain Guy06882f82009-06-10 13:36:04 -07004480 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004481 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004482 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004483 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004484 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004485 }
4486
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004487 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004488 }
Romain Guy06882f82009-06-10 13:36:04 -07004489
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004490 public void setRotationUnchecked(int rotation,
4491 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004492 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004493 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004495 long origId = Binder.clearCallingIdentity();
4496 boolean changed;
4497 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004498 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004499 }
Romain Guy06882f82009-06-10 13:36:04 -07004500
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004501 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004502 sendNewConfiguration();
4503 }
Romain Guy06882f82009-06-10 13:36:04 -07004504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004505 Binder.restoreCallingIdentity(origId);
4506 }
Romain Guy06882f82009-06-10 13:36:04 -07004507
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004508 /**
4509 * Apply a new rotation to the screen, respecting the requests of
4510 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4511 * re-evaluate the desired rotation.
4512 *
4513 * Returns null if the rotation has been changed. In this case YOU
4514 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4515 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004516 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004517 boolean changed;
4518 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4519 rotation = mRequestedRotation;
4520 } else {
4521 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004522 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004523 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004524 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004525 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004526 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004527 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004528 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004530 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004531 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004532 "Rotation changed to " + rotation
4533 + " from " + mRotation
4534 + " (forceApp=" + mForcedAppOrientation
4535 + ", req=" + mRequestedRotation + ")");
4536 mRotation = rotation;
4537 mWindowsFreezingScreen = true;
4538 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4539 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4540 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004541 mWaitingForConfig = true;
4542 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004543 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004544 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004545 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004546 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004547 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004548 }
4549 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004550 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004551 if (w.mSurface != null) {
4552 w.mOrientationChanging = true;
4553 }
4554 }
4555 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4556 try {
4557 mRotationWatchers.get(i).onRotationChanged(rotation);
4558 } catch (RemoteException e) {
4559 }
4560 }
4561 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004563 return changed;
4564 }
Romain Guy06882f82009-06-10 13:36:04 -07004565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004566 public int getRotation() {
4567 return mRotation;
4568 }
4569
4570 public int watchRotation(IRotationWatcher watcher) {
4571 final IBinder watcherBinder = watcher.asBinder();
4572 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4573 public void binderDied() {
4574 synchronized (mWindowMap) {
4575 for (int i=0; i<mRotationWatchers.size(); i++) {
4576 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004577 IRotationWatcher removed = mRotationWatchers.remove(i);
4578 if (removed != null) {
4579 removed.asBinder().unlinkToDeath(this, 0);
4580 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004581 i--;
4582 }
4583 }
4584 }
4585 }
4586 };
Romain Guy06882f82009-06-10 13:36:04 -07004587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004588 synchronized (mWindowMap) {
4589 try {
4590 watcher.asBinder().linkToDeath(dr, 0);
4591 mRotationWatchers.add(watcher);
4592 } catch (RemoteException e) {
4593 // Client died, no cleanup needed.
4594 }
Romain Guy06882f82009-06-10 13:36:04 -07004595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004596 return mRotation;
4597 }
4598 }
4599
4600 /**
4601 * Starts the view server on the specified port.
4602 *
4603 * @param port The port to listener to.
4604 *
4605 * @return True if the server was successfully started, false otherwise.
4606 *
4607 * @see com.android.server.ViewServer
4608 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4609 */
4610 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004611 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004612 return false;
4613 }
4614
4615 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4616 return false;
4617 }
4618
4619 if (port < 1024) {
4620 return false;
4621 }
4622
4623 if (mViewServer != null) {
4624 if (!mViewServer.isRunning()) {
4625 try {
4626 return mViewServer.start();
4627 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004628 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004629 }
4630 }
4631 return false;
4632 }
4633
4634 try {
4635 mViewServer = new ViewServer(this, port);
4636 return mViewServer.start();
4637 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004638 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004639 }
4640 return false;
4641 }
4642
Romain Guy06882f82009-06-10 13:36:04 -07004643 private boolean isSystemSecure() {
4644 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4645 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4646 }
4647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004648 /**
4649 * Stops the view server if it exists.
4650 *
4651 * @return True if the server stopped, false if it wasn't started or
4652 * couldn't be stopped.
4653 *
4654 * @see com.android.server.ViewServer
4655 */
4656 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004657 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004658 return false;
4659 }
4660
4661 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4662 return false;
4663 }
4664
4665 if (mViewServer != null) {
4666 return mViewServer.stop();
4667 }
4668 return false;
4669 }
4670
4671 /**
4672 * Indicates whether the view server is running.
4673 *
4674 * @return True if the server is running, false otherwise.
4675 *
4676 * @see com.android.server.ViewServer
4677 */
4678 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004679 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004680 return false;
4681 }
4682
4683 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4684 return false;
4685 }
4686
4687 return mViewServer != null && mViewServer.isRunning();
4688 }
4689
4690 /**
4691 * Lists all availble windows in the system. The listing is written in the
4692 * specified Socket's output stream with the following syntax:
4693 * windowHashCodeInHexadecimal windowName
4694 * Each line of the ouput represents a different window.
4695 *
4696 * @param client The remote client to send the listing to.
4697 * @return False if an error occured, true otherwise.
4698 */
4699 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004700 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004701 return false;
4702 }
4703
4704 boolean result = true;
4705
Jeff Browne33348b2010-07-15 23:54:05 -07004706 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004707 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004708 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07004709 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004710 }
4711
4712 BufferedWriter out = null;
4713
4714 // Any uncaught exception will crash the system process
4715 try {
4716 OutputStream clientStream = client.getOutputStream();
4717 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4718
4719 final int count = windows.length;
4720 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004721 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004722 out.write(Integer.toHexString(System.identityHashCode(w)));
4723 out.write(' ');
4724 out.append(w.mAttrs.getTitle());
4725 out.write('\n');
4726 }
4727
4728 out.write("DONE.\n");
4729 out.flush();
4730 } catch (Exception e) {
4731 result = false;
4732 } finally {
4733 if (out != null) {
4734 try {
4735 out.close();
4736 } catch (IOException e) {
4737 result = false;
4738 }
4739 }
4740 }
4741
4742 return result;
4743 }
4744
4745 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07004746 * Returns the focused window in the following format:
4747 * windowHashCodeInHexadecimal windowName
4748 *
4749 * @param client The remote client to send the listing to.
4750 * @return False if an error occurred, true otherwise.
4751 */
4752 boolean viewServerGetFocusedWindow(Socket client) {
4753 if (isSystemSecure()) {
4754 return false;
4755 }
4756
4757 boolean result = true;
4758
4759 WindowState focusedWindow = getFocusedWindow();
4760
4761 BufferedWriter out = null;
4762
4763 // Any uncaught exception will crash the system process
4764 try {
4765 OutputStream clientStream = client.getOutputStream();
4766 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4767
4768 if(focusedWindow != null) {
4769 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
4770 out.write(' ');
4771 out.append(focusedWindow.mAttrs.getTitle());
4772 }
4773 out.write('\n');
4774 out.flush();
4775 } catch (Exception e) {
4776 result = false;
4777 } finally {
4778 if (out != null) {
4779 try {
4780 out.close();
4781 } catch (IOException e) {
4782 result = false;
4783 }
4784 }
4785 }
4786
4787 return result;
4788 }
4789
4790 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004791 * Sends a command to a target window. The result of the command, if any, will be
4792 * written in the output stream of the specified socket.
4793 *
4794 * The parameters must follow this syntax:
4795 * windowHashcode extra
4796 *
4797 * Where XX is the length in characeters of the windowTitle.
4798 *
4799 * The first parameter is the target window. The window with the specified hashcode
4800 * will be the target. If no target can be found, nothing happens. The extra parameters
4801 * will be delivered to the target window and as parameters to the command itself.
4802 *
4803 * @param client The remote client to sent the result, if any, to.
4804 * @param command The command to execute.
4805 * @param parameters The command parameters.
4806 *
4807 * @return True if the command was successfully delivered, false otherwise. This does
4808 * not indicate whether the command itself was successful.
4809 */
4810 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004811 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004812 return false;
4813 }
4814
4815 boolean success = true;
4816 Parcel data = null;
4817 Parcel reply = null;
4818
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07004819 BufferedWriter out = null;
4820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004821 // Any uncaught exception will crash the system process
4822 try {
4823 // Find the hashcode of the window
4824 int index = parameters.indexOf(' ');
4825 if (index == -1) {
4826 index = parameters.length();
4827 }
4828 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004829 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004830
4831 // Extract the command's parameter after the window description
4832 if (index < parameters.length()) {
4833 parameters = parameters.substring(index + 1);
4834 } else {
4835 parameters = "";
4836 }
4837
4838 final WindowManagerService.WindowState window = findWindow(hashCode);
4839 if (window == null) {
4840 return false;
4841 }
4842
4843 data = Parcel.obtain();
4844 data.writeInterfaceToken("android.view.IWindow");
4845 data.writeString(command);
4846 data.writeString(parameters);
4847 data.writeInt(1);
4848 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4849
4850 reply = Parcel.obtain();
4851
4852 final IBinder binder = window.mClient.asBinder();
4853 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4854 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4855
4856 reply.readException();
4857
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07004858 if (!client.isOutputShutdown()) {
4859 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
4860 out.write("DONE\n");
4861 out.flush();
4862 }
4863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004864 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004865 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004866 success = false;
4867 } finally {
4868 if (data != null) {
4869 data.recycle();
4870 }
4871 if (reply != null) {
4872 reply.recycle();
4873 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07004874 if (out != null) {
4875 try {
4876 out.close();
4877 } catch (IOException e) {
4878
4879 }
4880 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004881 }
4882
4883 return success;
4884 }
4885
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004886 public void addWindowChangeListener(WindowChangeListener listener) {
4887 synchronized(mWindowMap) {
4888 mWindowChangeListeners.add(listener);
4889 }
4890 }
4891
4892 public void removeWindowChangeListener(WindowChangeListener listener) {
4893 synchronized(mWindowMap) {
4894 mWindowChangeListeners.remove(listener);
4895 }
4896 }
4897
4898 private void notifyWindowsChanged() {
4899 WindowChangeListener[] windowChangeListeners;
4900 synchronized(mWindowMap) {
4901 if(mWindowChangeListeners.isEmpty()) {
4902 return;
4903 }
4904 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4905 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4906 }
4907 int N = windowChangeListeners.length;
4908 for(int i = 0; i < N; i++) {
4909 windowChangeListeners[i].windowsChanged();
4910 }
4911 }
4912
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07004913 private void notifyFocusChanged() {
4914 WindowChangeListener[] windowChangeListeners;
4915 synchronized(mWindowMap) {
4916 if(mWindowChangeListeners.isEmpty()) {
4917 return;
4918 }
4919 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4920 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4921 }
4922 int N = windowChangeListeners.length;
4923 for(int i = 0; i < N; i++) {
4924 windowChangeListeners[i].focusChanged();
4925 }
4926 }
4927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004928 private WindowState findWindow(int hashCode) {
4929 if (hashCode == -1) {
4930 return getFocusedWindow();
4931 }
4932
4933 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07004934 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004935 final int count = windows.size();
4936
4937 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004938 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004939 if (System.identityHashCode(w) == hashCode) {
4940 return w;
4941 }
4942 }
4943 }
4944
4945 return null;
4946 }
4947
4948 /*
4949 * Instruct the Activity Manager to fetch the current configuration and broadcast
4950 * that to config-changed listeners if appropriate.
4951 */
4952 void sendNewConfiguration() {
4953 try {
4954 mActivityManager.updateConfiguration(null);
4955 } catch (RemoteException e) {
4956 }
4957 }
Romain Guy06882f82009-06-10 13:36:04 -07004958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004959 public Configuration computeNewConfiguration() {
4960 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004961 return computeNewConfigurationLocked();
4962 }
4963 }
Romain Guy06882f82009-06-10 13:36:04 -07004964
Dianne Hackbornc485a602009-03-24 22:39:49 -07004965 Configuration computeNewConfigurationLocked() {
4966 Configuration config = new Configuration();
4967 if (!computeNewConfigurationLocked(config)) {
4968 return null;
4969 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004970 return config;
4971 }
Romain Guy06882f82009-06-10 13:36:04 -07004972
Dianne Hackbornc485a602009-03-24 22:39:49 -07004973 boolean computeNewConfigurationLocked(Configuration config) {
4974 if (mDisplay == null) {
4975 return false;
4976 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004977
4978 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07004979
4980 // Use the effective "visual" dimensions based on current rotation
4981 final boolean rotated = (mRotation == Surface.ROTATION_90
4982 || mRotation == Surface.ROTATION_270);
4983 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
4984 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
4985
Dianne Hackbornc485a602009-03-24 22:39:49 -07004986 int orientation = Configuration.ORIENTATION_SQUARE;
4987 if (dw < dh) {
4988 orientation = Configuration.ORIENTATION_PORTRAIT;
4989 } else if (dw > dh) {
4990 orientation = Configuration.ORIENTATION_LANDSCAPE;
4991 }
4992 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004993
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004994 DisplayMetrics dm = new DisplayMetrics();
4995 mDisplay.getMetrics(dm);
4996 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4997
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004998 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004999 // Note we only do this once because at this point we don't
5000 // expect the screen to change in this way at runtime, and want
5001 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005002 int longSize = dw;
5003 int shortSize = dh;
5004 if (longSize < shortSize) {
5005 int tmp = longSize;
5006 longSize = shortSize;
5007 shortSize = tmp;
5008 }
5009 longSize = (int)(longSize/dm.density);
5010 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005011
Dianne Hackborn723738c2009-06-25 19:48:04 -07005012 // These semi-magic numbers define our compatibility modes for
5013 // applications with different screens. Don't change unless you
5014 // make sure to test lots and lots of apps!
5015 if (longSize < 470) {
5016 // This is shorter than an HVGA normal density screen (which
5017 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005018 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5019 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005020 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005021 // What size is this screen screen?
5022 if (longSize >= 800 && shortSize >= 600) {
5023 // SVGA or larger screens at medium density are the point
5024 // at which we consider it to be an extra large screen.
5025 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
5026 } else if (longSize >= 640 && shortSize >= 480) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005027 // VGA or larger screens at medium density are the point
5028 // at which we consider it to be a large screen.
5029 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5030 } else {
5031 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005032
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005033 // If this screen is wider than normal HVGA, or taller
5034 // than FWVGA, then for old apps we want to run in size
5035 // compatibility mode.
5036 if (shortSize > 321 || longSize > 570) {
5037 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5038 }
5039 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005040
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005041 // Is this a long screen?
5042 if (((longSize*3)/5) >= (shortSize-1)) {
5043 // Anything wider than WVGA (5:3) is considering to be long.
5044 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5045 } else {
5046 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5047 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005048 }
5049 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005050 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005051
Dianne Hackbornc485a602009-03-24 22:39:49 -07005052 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5053 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5054 mPolicy.adjustConfigurationLw(config);
5055 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005056 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005058 // -------------------------------------------------------------
5059 // Input Events and Focus Management
5060 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005061
Jeff Brown349703e2010-06-22 01:27:15 -07005062 InputMonitor mInputMonitor = new InputMonitor();
5063
5064 /* Tracks the progress of input dispatch and ensures that input dispatch state
5065 * is kept in sync with changes in window focus, visibility, registration, and
5066 * other relevant Window Manager state transitions. */
5067 final class InputMonitor {
5068 // Current window with input focus for keys and other non-touch events. May be null.
5069 private WindowState mInputFocus;
5070
5071 // When true, prevents input dispatch from proceeding until set to false again.
5072 private boolean mInputDispatchFrozen;
5073
5074 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5075 private boolean mInputDispatchEnabled = true;
5076
5077 // Temporary list of windows information to provide to the input dispatcher.
5078 private InputWindowList mTempInputWindows = new InputWindowList();
5079
5080 // Temporary input application object to provide to the input dispatcher.
5081 private InputApplication mTempInputApplication = new InputApplication();
5082
5083 /* Notifies the window manager about a broken input channel.
5084 *
5085 * Called by the InputManager.
5086 */
5087 public void notifyInputChannelBroken(InputChannel inputChannel) {
5088 synchronized (mWindowMap) {
5089 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5090 if (windowState == null) {
5091 return; // irrelevant
5092 }
5093
5094 Slog.i(TAG, "WINDOW DIED " + windowState);
5095 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005096 }
5097 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005098
Jeff Brown349703e2010-06-22 01:27:15 -07005099 /* Notifies the window manager about an input channel that is not responding.
5100 * The method can either cause dispatching to be aborted by returning -2 or
5101 * return a new timeout in nanoseconds.
5102 *
5103 * Called by the InputManager.
5104 */
5105 public long notifyInputChannelANR(InputChannel inputChannel) {
5106 AppWindowToken token;
5107 synchronized (mWindowMap) {
5108 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5109 if (windowState == null) {
5110 return -2; // irrelevant, abort dispatching (-2)
5111 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005112
Jeff Brown349703e2010-06-22 01:27:15 -07005113 Slog.i(TAG, "Input event dispatching timed out sending to "
5114 + windowState.mAttrs.getTitle());
5115 token = windowState.mAppToken;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005116 }
5117
Jeff Brown349703e2010-06-22 01:27:15 -07005118 return notifyANRInternal(token);
5119 }
5120
5121 /* Notifies the window manager about an input channel spontaneously recovering from ANR
5122 * by successfully delivering the event that originally timed out.
5123 *
5124 * Called by the InputManager.
5125 */
5126 public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) {
5127 // Nothing to do just now.
5128 // Just wait for the user to dismiss the ANR dialog.
5129 }
5130
5131 /* Notifies the window manager about an application that is not responding
5132 * in general rather than with respect to a particular input channel.
5133 * The method can either cause dispatching to be aborted by returning -2 or
5134 * return a new timeout in nanoseconds.
5135 *
5136 * Called by the InputManager.
5137 */
5138 public long notifyANR(Object token) {
5139 AppWindowToken appWindowToken = (AppWindowToken) token;
5140
5141 Slog.i(TAG, "Input event dispatching timed out sending to application "
5142 + appWindowToken.stringName);
5143 return notifyANRInternal(appWindowToken);
5144 }
5145
5146 private long notifyANRInternal(AppWindowToken token) {
5147 if (token != null && token.appToken != null) {
5148 try {
5149 // Notify the activity manager about the timeout and let it decide whether
5150 // to abort dispatching or keep waiting.
5151 boolean abort = token.appToken.keyDispatchingTimedOut();
5152 if (! abort) {
5153 // The activity manager declined to abort dispatching.
5154 // Wait a bit longer and timeout again later.
5155 return token.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005156 }
Jeff Brown349703e2010-06-22 01:27:15 -07005157 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005158 }
5159 }
Jeff Brown349703e2010-06-22 01:27:15 -07005160 return -2; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005161 }
5162
Jeff Brown349703e2010-06-22 01:27:15 -07005163 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5164 synchronized (mWindowMap) {
5165 return getWindowStateForInputChannelLocked(inputChannel);
5166 }
5167 }
5168
5169 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5170 int windowCount = mWindows.size();
5171 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005172 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005173 if (windowState.mInputChannel == inputChannel) {
5174 return windowState;
5175 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005176 }
5177
Jeff Brown349703e2010-06-22 01:27:15 -07005178 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005179 }
5180
Jeff Brown349703e2010-06-22 01:27:15 -07005181 /* Updates the cached window information provided to the input dispatcher. */
5182 public void updateInputWindowsLw() {
5183 // Populate the input window list with information about all of the windows that
5184 // could potentially receive input.
5185 // As an optimization, we could try to prune the list of windows but this turns
5186 // out to be difficult because only the native code knows for sure which window
5187 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005188 final ArrayList<WindowState> windows = mWindows;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005189 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005190 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005191 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005192 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005193 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005194 continue;
5195 }
5196
Jeff Brown349703e2010-06-22 01:27:15 -07005197 final int flags = child.mAttrs.flags;
5198 final int type = child.mAttrs.type;
5199
5200 final boolean hasFocus = (child == mInputFocus);
5201 final boolean isVisible = child.isVisibleLw();
5202 final boolean hasWallpaper = (child == mWallpaperTarget)
5203 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
5204
5205 // Add a window to our list of input windows.
5206 final InputWindow inputWindow = mTempInputWindows.add();
5207 inputWindow.inputChannel = child.mInputChannel;
5208 inputWindow.layoutParamsFlags = flags;
5209 inputWindow.layoutParamsType = type;
5210 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5211 inputWindow.visible = isVisible;
5212 inputWindow.hasFocus = hasFocus;
5213 inputWindow.hasWallpaper = hasWallpaper;
5214 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
5215 inputWindow.ownerPid = child.mSession.mPid;
5216 inputWindow.ownerUid = child.mSession.mUid;
5217
5218 final Rect frame = child.mFrame;
5219 inputWindow.frameLeft = frame.left;
5220 inputWindow.frameTop = frame.top;
5221
5222 switch (child.mTouchableInsets) {
5223 default:
5224 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5225 inputWindow.touchableAreaLeft = frame.left;
5226 inputWindow.touchableAreaTop = frame.top;
5227 inputWindow.touchableAreaRight = frame.right;
5228 inputWindow.touchableAreaBottom = frame.bottom;
5229 break;
5230
5231 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5232 Rect inset = child.mGivenContentInsets;
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;
5237 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005238 }
Jeff Brown349703e2010-06-22 01:27:15 -07005239
5240 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5241 Rect inset = child.mGivenVisibleInsets;
5242 inputWindow.touchableAreaLeft = frame.left + inset.left;
5243 inputWindow.touchableAreaTop = frame.top + inset.top;
5244 inputWindow.touchableAreaRight = frame.right - inset.right;
5245 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005246 break;
5247 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005248 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005249 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005250
Jeff Brown349703e2010-06-22 01:27:15 -07005251 // Send windows to native code.
5252 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005253
Jeff Brown349703e2010-06-22 01:27:15 -07005254 // Clear the list in preparation for the next round.
5255 // Also avoids keeping InputChannel objects referenced unnecessarily.
5256 mTempInputWindows.clear();
5257 }
5258
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005259 /* Provides feedback for a virtual key down. */
5260 public void virtualKeyDownFeedback() {
5261 synchronized (mWindowMap) {
5262 mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5263 }
5264 }
5265
Jeff Brown349703e2010-06-22 01:27:15 -07005266 /* Notifies that an app switch key (BACK / HOME) has just been pressed.
5267 * This essentially starts a .5 second timeout for the application to process
5268 * subsequent input events while waiting for the app switch to occur. If it takes longer
5269 * than this, the pending events will be dropped.
5270 */
5271 public void notifyAppSwitchComing() {
5272 // TODO Not implemented yet. Should go in the native side.
5273 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005274
5275 /* Notifies that the lid switch changed state. */
5276 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5277 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5278 }
5279
Jeff Brown349703e2010-06-22 01:27:15 -07005280 /* Provides an opportunity for the window manager policy to intercept early key
5281 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005282 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5283 int policyFlags, boolean isScreenOn) {
5284 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5285 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005286 }
5287
5288 /* Provides an opportunity for the window manager policy to process a key before
5289 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005290 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5291 int action, int flags, int keyCode, int metaState, int repeatCount,
5292 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005293 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005294 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5295 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005296 }
5297
5298 /* Called when the current input focus changes.
5299 * Layer assignment is assumed to be complete by the time this is called.
5300 */
5301 public void setInputFocusLw(WindowState newWindow) {
5302 if (DEBUG_INPUT) {
5303 Slog.d(TAG, "Input focus has changed to " + newWindow);
5304 }
5305
5306 if (newWindow != mInputFocus) {
5307 if (newWindow != null && newWindow.canReceiveKeys()) {
5308 // If the new input focus is an error window or appears above the current
5309 // input focus, preempt any pending synchronous dispatch so that we can
5310 // start delivering events to the new input focus as soon as possible.
5311 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
5312 if (DEBUG_INPUT) {
5313 Slog.v(TAG, "New SYSTEM_ERROR window; resetting state");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005314 }
Jeff Brown349703e2010-06-22 01:27:15 -07005315 preemptInputDispatchLw();
5316 } else if (mInputFocus != null && newWindow.mLayer > mInputFocus.mLayer) {
5317 if (DEBUG_INPUT) {
5318 Slog.v(TAG, "Transferring focus to new window at higher layer: "
5319 + "old win layer=" + mInputFocus.mLayer
5320 + ", new win layer=" + newWindow.mLayer);
5321 }
5322 preemptInputDispatchLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005323 }
Jeff Brown349703e2010-06-22 01:27:15 -07005324
5325 // Displaying a window implicitly causes dispatching to be unpaused.
5326 // This is to protect against bugs if someone pauses dispatching but
5327 // forgets to resume.
5328 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005329 }
Jeff Brown349703e2010-06-22 01:27:15 -07005330
5331 mInputFocus = newWindow;
5332 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005333 }
5334 }
5335
Jeff Brown349703e2010-06-22 01:27:15 -07005336 /* Tells the dispatcher to stop waiting for its current synchronous event targets.
5337 * Essentially, just makes those dispatches asynchronous so a new dispatch cycle
5338 * can begin.
5339 */
5340 private void preemptInputDispatchLw() {
5341 mInputManager.preemptInputDispatch();
5342 }
5343
5344 public void setFocusedAppLw(AppWindowToken newApp) {
5345 // Focused app has changed.
5346 if (newApp == null) {
5347 mInputManager.setFocusedApplication(null);
5348 } else {
5349 mTempInputApplication.name = newApp.toString();
5350 mTempInputApplication.dispatchingTimeoutNanos =
5351 newApp.inputDispatchingTimeoutNanos;
5352 mTempInputApplication.token = newApp;
5353
5354 mInputManager.setFocusedApplication(mTempInputApplication);
5355 }
5356 }
5357
Jeff Brown349703e2010-06-22 01:27:15 -07005358 public void pauseDispatchingLw(WindowToken window) {
5359 if (! window.paused) {
5360 if (DEBUG_INPUT) {
5361 Slog.v(TAG, "Pausing WindowToken " + window);
5362 }
5363
5364 window.paused = true;
5365 updateInputWindowsLw();
5366 }
5367 }
5368
5369 public void resumeDispatchingLw(WindowToken window) {
5370 if (window.paused) {
5371 if (DEBUG_INPUT) {
5372 Slog.v(TAG, "Resuming WindowToken " + window);
5373 }
5374
5375 window.paused = false;
5376 updateInputWindowsLw();
5377 }
5378 }
5379
5380 public void freezeInputDispatchingLw() {
5381 if (! mInputDispatchFrozen) {
5382 if (DEBUG_INPUT) {
5383 Slog.v(TAG, "Freezing input dispatching");
5384 }
5385
5386 mInputDispatchFrozen = true;
5387 updateInputDispatchModeLw();
5388 }
5389 }
5390
5391 public void thawInputDispatchingLw() {
5392 if (mInputDispatchFrozen) {
5393 if (DEBUG_INPUT) {
5394 Slog.v(TAG, "Thawing input dispatching");
5395 }
5396
5397 mInputDispatchFrozen = false;
5398 updateInputDispatchModeLw();
5399 }
5400 }
5401
5402 public void setEventDispatchingLw(boolean enabled) {
5403 if (mInputDispatchEnabled != enabled) {
5404 if (DEBUG_INPUT) {
5405 Slog.v(TAG, "Setting event dispatching to " + enabled);
5406 }
5407
5408 mInputDispatchEnabled = enabled;
5409 updateInputDispatchModeLw();
5410 }
5411 }
5412
5413 private void updateInputDispatchModeLw() {
5414 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5415 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005416 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005418 public void pauseKeyDispatching(IBinder _token) {
5419 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5420 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005421 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005422 }
5423
5424 synchronized (mWindowMap) {
5425 WindowToken token = mTokenMap.get(_token);
5426 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005427 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005428 }
5429 }
5430 }
5431
5432 public void resumeKeyDispatching(IBinder _token) {
5433 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5434 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005435 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005436 }
5437
5438 synchronized (mWindowMap) {
5439 WindowToken token = mTokenMap.get(_token);
5440 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005441 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005442 }
5443 }
5444 }
5445
5446 public void setEventDispatching(boolean enabled) {
5447 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5448 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005449 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005450 }
5451
5452 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005453 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005454 }
5455 }
Romain Guy06882f82009-06-10 13:36:04 -07005456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005457 /**
5458 * Injects a keystroke event into the UI.
Jeff Brown6ec402b2010-07-28 15:48:59 -07005459 * Even when sync is false, this method may block while waiting for current
5460 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005461 *
5462 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005463 * {@link SystemClock#uptimeMillis()} as the timebase.)
5464 * @param sync If true, wait for the event to be completed before returning to the caller.
5465 * @return Returns true if event was dispatched, false if it was dropped for any reason
5466 */
5467 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5468 long downTime = ev.getDownTime();
5469 long eventTime = ev.getEventTime();
5470
5471 int action = ev.getAction();
5472 int code = ev.getKeyCode();
5473 int repeatCount = ev.getRepeatCount();
5474 int metaState = ev.getMetaState();
5475 int deviceId = ev.getDeviceId();
5476 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005477 int source = ev.getSource();
5478
5479 if (source == InputDevice.SOURCE_UNKNOWN) {
5480 source = InputDevice.SOURCE_KEYBOARD;
5481 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005482
5483 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5484 if (downTime == 0) downTime = eventTime;
5485
5486 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005487 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005488
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005489 final int pid = Binder.getCallingPid();
5490 final int uid = Binder.getCallingUid();
5491 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005492
Jeff Brown6ec402b2010-07-28 15:48:59 -07005493 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5494 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5495 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5496 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005497
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005498 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005499 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005500 }
5501
5502 /**
5503 * Inject a pointer (touch) event into the UI.
Jeff Brown6ec402b2010-07-28 15:48:59 -07005504 * Even when sync is false, this method may block while waiting for current
5505 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005506 *
5507 * @param ev A motion event describing the pointer (touch) action. (As noted in
5508 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005509 * {@link SystemClock#uptimeMillis()} as the timebase.)
5510 * @param sync If true, wait for the event to be completed before returning to the caller.
5511 * @return Returns true if event was dispatched, false if it was dropped for any reason
5512 */
5513 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005514 final int pid = Binder.getCallingPid();
5515 final int uid = Binder.getCallingUid();
5516 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005517
Jeff Brownc5ed5912010-07-14 18:48:53 -07005518 MotionEvent newEvent = MotionEvent.obtain(ev);
5519 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5520 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5521 }
5522
Jeff Brown6ec402b2010-07-28 15:48:59 -07005523 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5524 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5525 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5526 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005527
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005528 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005529 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005530 }
Romain Guy06882f82009-06-10 13:36:04 -07005531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005532 /**
5533 * Inject a trackball (navigation device) event into the UI.
Jeff Brown6ec402b2010-07-28 15:48:59 -07005534 * Even when sync is false, this method may block while waiting for current
5535 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005536 *
5537 * @param ev A motion event describing the trackball action. (As noted in
5538 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005539 * {@link SystemClock#uptimeMillis()} as the timebase.)
5540 * @param sync If true, wait for the event to be completed before returning to the caller.
5541 * @return Returns true if event was dispatched, false if it was dropped for any reason
5542 */
5543 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005544 final int pid = Binder.getCallingPid();
5545 final int uid = Binder.getCallingUid();
5546 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005547
Jeff Brownc5ed5912010-07-14 18:48:53 -07005548 MotionEvent newEvent = MotionEvent.obtain(ev);
5549 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5550 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5551 }
5552
Jeff Brown6ec402b2010-07-28 15:48:59 -07005553 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5554 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5555 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5556 INJECTION_TIMEOUT_MILLIS);
5557
5558 Binder.restoreCallingIdentity(ident);
5559 return reportInjectionResult(result);
5560 }
5561
5562 /**
5563 * Inject an input event into the UI without waiting for dispatch to commence.
5564 * This variant is useful for fire-and-forget input event injection. It does not
5565 * block any longer than it takes to enqueue the input event.
5566 *
5567 * @param ev An input event. (Be sure to set the input source correctly.)
5568 * @return Returns true if event was dispatched, false if it was dropped for any reason
5569 */
5570 public boolean injectInputEventNoWait(InputEvent ev) {
5571 final int pid = Binder.getCallingPid();
5572 final int uid = Binder.getCallingUid();
5573 final long ident = Binder.clearCallingIdentity();
5574
5575 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5576 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5577 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005578
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005579 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005580 return reportInjectionResult(result);
5581 }
5582
5583 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005584 switch (result) {
5585 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5586 Slog.w(TAG, "Input event injection permission denied.");
5587 throw new SecurityException(
5588 "Injecting to another application requires INJECT_EVENTS permission");
5589 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07005590 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005591 return true;
5592 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5593 Slog.w(TAG, "Input event injection timed out.");
5594 return false;
5595 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5596 default:
5597 Slog.w(TAG, "Input event injection failed.");
5598 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005599 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005600 }
Romain Guy06882f82009-06-10 13:36:04 -07005601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005602 private WindowState getFocusedWindow() {
5603 synchronized (mWindowMap) {
5604 return getFocusedWindowLocked();
5605 }
5606 }
5607
5608 private WindowState getFocusedWindowLocked() {
5609 return mCurrentFocus;
5610 }
Romain Guy06882f82009-06-10 13:36:04 -07005611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005612 public boolean detectSafeMode() {
5613 mSafeMode = mPolicy.detectSafeMode();
5614 return mSafeMode;
5615 }
Romain Guy06882f82009-06-10 13:36:04 -07005616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005617 public void systemReady() {
5618 mPolicy.systemReady();
5619 }
Romain Guy06882f82009-06-10 13:36:04 -07005620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005621 // -------------------------------------------------------------
5622 // Client Session State
5623 // -------------------------------------------------------------
5624
5625 private final class Session extends IWindowSession.Stub
5626 implements IBinder.DeathRecipient {
5627 final IInputMethodClient mClient;
5628 final IInputContext mInputContext;
5629 final int mUid;
5630 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005631 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005632 SurfaceSession mSurfaceSession;
5633 int mNumWindow = 0;
5634 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07005635
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005636 public Session(IInputMethodClient client, IInputContext inputContext) {
5637 mClient = client;
5638 mInputContext = inputContext;
5639 mUid = Binder.getCallingUid();
5640 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005641 StringBuilder sb = new StringBuilder();
5642 sb.append("Session{");
5643 sb.append(Integer.toHexString(System.identityHashCode(this)));
5644 sb.append(" uid ");
5645 sb.append(mUid);
5646 sb.append("}");
5647 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07005648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005649 synchronized (mWindowMap) {
5650 if (mInputMethodManager == null && mHaveInputMethods) {
5651 IBinder b = ServiceManager.getService(
5652 Context.INPUT_METHOD_SERVICE);
5653 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
5654 }
5655 }
5656 long ident = Binder.clearCallingIdentity();
5657 try {
5658 // Note: it is safe to call in to the input method manager
5659 // here because we are not holding our lock.
5660 if (mInputMethodManager != null) {
5661 mInputMethodManager.addClient(client, inputContext,
5662 mUid, mPid);
5663 } else {
5664 client.setUsingInputMethod(false);
5665 }
5666 client.asBinder().linkToDeath(this, 0);
5667 } catch (RemoteException e) {
5668 // The caller has died, so we can just forget about this.
5669 try {
5670 if (mInputMethodManager != null) {
5671 mInputMethodManager.removeClient(client);
5672 }
5673 } catch (RemoteException ee) {
5674 }
5675 } finally {
5676 Binder.restoreCallingIdentity(ident);
5677 }
5678 }
Romain Guy06882f82009-06-10 13:36:04 -07005679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005680 @Override
5681 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
5682 throws RemoteException {
5683 try {
5684 return super.onTransact(code, data, reply, flags);
5685 } catch (RuntimeException e) {
5686 // Log all 'real' exceptions thrown to the caller
5687 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005688 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005689 }
5690 throw e;
5691 }
5692 }
5693
5694 public void binderDied() {
5695 // Note: it is safe to call in to the input method manager
5696 // here because we are not holding our lock.
5697 try {
5698 if (mInputMethodManager != null) {
5699 mInputMethodManager.removeClient(mClient);
5700 }
5701 } catch (RemoteException e) {
5702 }
5703 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005704 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005705 mClientDead = true;
5706 killSessionLocked();
5707 }
5708 }
5709
5710 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005711 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
5712 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
5713 outInputChannel);
5714 }
5715
5716 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005717 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005718 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005719 }
Romain Guy06882f82009-06-10 13:36:04 -07005720
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005721 public void remove(IWindow window) {
5722 removeWindow(this, window);
5723 }
Romain Guy06882f82009-06-10 13:36:04 -07005724
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005725 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
5726 int requestedWidth, int requestedHeight, int viewFlags,
5727 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005728 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005729 return relayoutWindow(this, window, attrs,
5730 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005731 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005732 }
Romain Guy06882f82009-06-10 13:36:04 -07005733
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005734 public void setTransparentRegion(IWindow window, Region region) {
5735 setTransparentRegionWindow(this, window, region);
5736 }
Romain Guy06882f82009-06-10 13:36:04 -07005737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005738 public void setInsets(IWindow window, int touchableInsets,
5739 Rect contentInsets, Rect visibleInsets) {
5740 setInsetsWindow(this, window, touchableInsets, contentInsets,
5741 visibleInsets);
5742 }
Romain Guy06882f82009-06-10 13:36:04 -07005743
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005744 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
5745 getWindowDisplayFrame(this, window, outDisplayFrame);
5746 }
Romain Guy06882f82009-06-10 13:36:04 -07005747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005748 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005749 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005750 TAG, "IWindow finishDrawing called for " + window);
5751 finishDrawingWindow(this, window);
5752 }
5753
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005754 public void setInTouchMode(boolean mode) {
5755 synchronized(mWindowMap) {
5756 mInTouchMode = mode;
5757 }
5758 }
5759
5760 public boolean getInTouchMode() {
5761 synchronized(mWindowMap) {
5762 return mInTouchMode;
5763 }
5764 }
5765
5766 public boolean performHapticFeedback(IWindow window, int effectId,
5767 boolean always) {
5768 synchronized(mWindowMap) {
5769 long ident = Binder.clearCallingIdentity();
5770 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005771 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005772 windowForClientLocked(this, window, true),
5773 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005774 } finally {
5775 Binder.restoreCallingIdentity(ident);
5776 }
5777 }
5778 }
Romain Guy06882f82009-06-10 13:36:04 -07005779
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005780 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005781 synchronized(mWindowMap) {
5782 long ident = Binder.clearCallingIdentity();
5783 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005784 setWindowWallpaperPositionLocked(
5785 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005786 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005787 } finally {
5788 Binder.restoreCallingIdentity(ident);
5789 }
5790 }
5791 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005792
Dianne Hackborn19382ac2009-09-11 21:13:37 -07005793 public void wallpaperOffsetsComplete(IBinder window) {
5794 WindowManagerService.this.wallpaperOffsetsComplete(window);
5795 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005796
Dianne Hackborn75804932009-10-20 20:15:20 -07005797 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
5798 int z, Bundle extras, boolean sync) {
5799 synchronized(mWindowMap) {
5800 long ident = Binder.clearCallingIdentity();
5801 try {
5802 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005803 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07005804 action, x, y, z, extras, sync);
5805 } finally {
5806 Binder.restoreCallingIdentity(ident);
5807 }
5808 }
5809 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005810
Dianne Hackborn75804932009-10-20 20:15:20 -07005811 public void wallpaperCommandComplete(IBinder window, Bundle result) {
5812 WindowManagerService.this.wallpaperCommandComplete(window, result);
5813 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005814
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005815 void windowAddedLocked() {
5816 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005817 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005818 TAG, "First window added to " + this + ", creating SurfaceSession");
5819 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08005820 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005821 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005822 mSessions.add(this);
5823 }
5824 mNumWindow++;
5825 }
5826
5827 void windowRemovedLocked() {
5828 mNumWindow--;
5829 killSessionLocked();
5830 }
Romain Guy06882f82009-06-10 13:36:04 -07005831
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005832 void killSessionLocked() {
5833 if (mNumWindow <= 0 && mClientDead) {
5834 mSessions.remove(this);
5835 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005836 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005837 TAG, "Last window removed from " + this
5838 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005839 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005840 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005841 try {
5842 mSurfaceSession.kill();
5843 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005844 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005845 + mSurfaceSession + " in session " + this
5846 + ": " + e.toString());
5847 }
5848 mSurfaceSession = null;
5849 }
5850 }
5851 }
Romain Guy06882f82009-06-10 13:36:04 -07005852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005853 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005854 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
5855 pw.print(" mClientDead="); pw.print(mClientDead);
5856 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005857 }
5858
5859 @Override
5860 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005861 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005862 }
5863 }
5864
5865 // -------------------------------------------------------------
5866 // Client Window State
5867 // -------------------------------------------------------------
5868
5869 private final class WindowState implements WindowManagerPolicy.WindowState {
5870 final Session mSession;
5871 final IWindow mClient;
5872 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07005873 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005874 AppWindowToken mAppToken;
5875 AppWindowToken mTargetAppToken;
5876 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
5877 final DeathRecipient mDeathRecipient;
5878 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07005879 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005880 final int mBaseLayer;
5881 final int mSubLayer;
5882 final boolean mLayoutAttached;
5883 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005884 final boolean mIsWallpaper;
5885 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005886 int mViewVisibility;
5887 boolean mPolicyVisibility = true;
5888 boolean mPolicyVisibilityAfterAnim = true;
5889 boolean mAppFreezing;
5890 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07005891 boolean mReportDestroySurface;
5892 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005893 boolean mAttachedHidden; // is our parent window hidden?
5894 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07005895 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005896 int mRequestedWidth;
5897 int mRequestedHeight;
5898 int mLastRequestedWidth;
5899 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005900 int mLayer;
5901 int mAnimLayer;
5902 int mLastLayer;
5903 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07005904 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07005905 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005906
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005907 int mLayoutSeq = -1;
5908
5909 Configuration mConfiguration = null;
5910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005911 // Actual frame shown on-screen (may be modified by animation)
5912 final Rect mShownFrame = new Rect();
5913 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005915 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08005916 * Set when we have changed the size of the surface, to know that
5917 * we must tell them application to resize (and thus redraw itself).
5918 */
5919 boolean mSurfaceResized;
5920
5921 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005922 * Insets that determine the actually visible area
5923 */
5924 final Rect mVisibleInsets = new Rect();
5925 final Rect mLastVisibleInsets = new Rect();
5926 boolean mVisibleInsetsChanged;
5927
5928 /**
5929 * Insets that are covered by system windows
5930 */
5931 final Rect mContentInsets = new Rect();
5932 final Rect mLastContentInsets = new Rect();
5933 boolean mContentInsetsChanged;
5934
5935 /**
5936 * Set to true if we are waiting for this window to receive its
5937 * given internal insets before laying out other windows based on it.
5938 */
5939 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07005940
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005941 /**
5942 * These are the content insets that were given during layout for
5943 * this window, to be applied to windows behind it.
5944 */
5945 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005947 /**
5948 * These are the visible insets that were given during layout for
5949 * this window, to be applied to windows behind it.
5950 */
5951 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005953 /**
5954 * Flag indicating whether the touchable region should be adjusted by
5955 * the visible insets; if false the area outside the visible insets is
5956 * NOT touchable, so we must use those to adjust the frame during hit
5957 * tests.
5958 */
5959 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07005960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005961 // Current transformation being applied.
5962 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
5963 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
5964 float mHScale=1, mVScale=1;
5965 float mLastHScale=1, mLastVScale=1;
5966 final Matrix mTmpMatrix = new Matrix();
5967
5968 // "Real" frame that the application sees.
5969 final Rect mFrame = new Rect();
5970 final Rect mLastFrame = new Rect();
5971
5972 final Rect mContainingFrame = new Rect();
5973 final Rect mDisplayFrame = new Rect();
5974 final Rect mContentFrame = new Rect();
5975 final Rect mVisibleFrame = new Rect();
5976
5977 float mShownAlpha = 1;
5978 float mAlpha = 1;
5979 float mLastAlpha = 1;
5980
5981 // Set to true if, when the window gets displayed, it should perform
5982 // an enter animation.
5983 boolean mEnterAnimationPending;
5984
5985 // Currently running animation.
5986 boolean mAnimating;
5987 boolean mLocalAnimating;
5988 Animation mAnimation;
5989 boolean mAnimationIsEntrance;
5990 boolean mHasTransformation;
5991 boolean mHasLocalTransformation;
5992 final Transformation mTransformation = new Transformation();
5993
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005994 // If a window showing a wallpaper: the requested offset for the
5995 // wallpaper; if a wallpaper window: the currently applied offset.
5996 float mWallpaperX = -1;
5997 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005998
5999 // If a window showing a wallpaper: what fraction of the offset
6000 // range corresponds to a full virtual screen.
6001 float mWallpaperXStep = -1;
6002 float mWallpaperYStep = -1;
6003
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006004 // Wallpaper windows: pixels offset based on above variables.
6005 int mXOffset;
6006 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006008 // This is set after IWindowSession.relayout() has been called at
6009 // least once for the window. It allows us to detect the situation
6010 // where we don't yet have a surface, but should have one soon, so
6011 // we can give the window focus before waiting for the relayout.
6012 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006014 // This is set after the Surface has been created but before the
6015 // window has been drawn. During this time the surface is hidden.
6016 boolean mDrawPending;
6017
6018 // This is set after the window has finished drawing for the first
6019 // time but before its surface is shown. The surface will be
6020 // displayed when the next layout is run.
6021 boolean mCommitDrawPending;
6022
6023 // This is set during the time after the window's drawing has been
6024 // committed, and before its surface is actually shown. It is used
6025 // to delay showing the surface until all windows in a token are ready
6026 // to be shown.
6027 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006029 // Set when the window has been shown in the screen the first time.
6030 boolean mHasDrawn;
6031
6032 // Currently running an exit animation?
6033 boolean mExiting;
6034
6035 // Currently on the mDestroySurface list?
6036 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006038 // Completely remove from window manager after exit animation?
6039 boolean mRemoveOnExit;
6040
6041 // Set when the orientation is changing and this window has not yet
6042 // been updated for the new orientation.
6043 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006045 // Is this window now (or just being) removed?
6046 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006047
Dianne Hackborn16064f92010-03-25 00:47:24 -07006048 // For debugging, this is the last information given to the surface flinger.
6049 boolean mSurfaceShown;
6050 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6051 int mSurfaceLayer;
6052 float mSurfaceAlpha;
6053
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006054 // Input channel
6055 InputChannel mInputChannel;
6056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006057 WindowState(Session s, IWindow c, WindowToken token,
6058 WindowState attachedWindow, WindowManager.LayoutParams a,
6059 int viewVisibility) {
6060 mSession = s;
6061 mClient = c;
6062 mToken = token;
6063 mAttrs.copyFrom(a);
6064 mViewVisibility = viewVisibility;
6065 DeathRecipient deathRecipient = new DeathRecipient();
6066 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006067 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006068 TAG, "Window " + this + " client=" + c.asBinder()
6069 + " token=" + token + " (" + mAttrs.token + ")");
6070 try {
6071 c.asBinder().linkToDeath(deathRecipient, 0);
6072 } catch (RemoteException e) {
6073 mDeathRecipient = null;
6074 mAttachedWindow = null;
6075 mLayoutAttached = false;
6076 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006077 mIsWallpaper = false;
6078 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006079 mBaseLayer = 0;
6080 mSubLayer = 0;
6081 return;
6082 }
6083 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006084
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006085 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6086 mAttrs.type <= LAST_SUB_WINDOW)) {
6087 // The multiplier here is to reserve space for multiple
6088 // windows in the same type layer.
6089 mBaseLayer = mPolicy.windowTypeToLayerLw(
6090 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6091 + TYPE_LAYER_OFFSET;
6092 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6093 mAttachedWindow = attachedWindow;
6094 mAttachedWindow.mChildWindows.add(this);
6095 mLayoutAttached = mAttrs.type !=
6096 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6097 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6098 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006099 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6100 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006101 } else {
6102 // The multiplier here is to reserve space for multiple
6103 // windows in the same type layer.
6104 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6105 * TYPE_LAYER_MULTIPLIER
6106 + TYPE_LAYER_OFFSET;
6107 mSubLayer = 0;
6108 mAttachedWindow = null;
6109 mLayoutAttached = false;
6110 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6111 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006112 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6113 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006114 }
6115
6116 WindowState appWin = this;
6117 while (appWin.mAttachedWindow != null) {
6118 appWin = mAttachedWindow;
6119 }
6120 WindowToken appToken = appWin.mToken;
6121 while (appToken.appWindowToken == null) {
6122 WindowToken parent = mTokenMap.get(appToken.token);
6123 if (parent == null || appToken == parent) {
6124 break;
6125 }
6126 appToken = parent;
6127 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006128 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006129 mAppToken = appToken.appWindowToken;
6130
6131 mSurface = null;
6132 mRequestedWidth = 0;
6133 mRequestedHeight = 0;
6134 mLastRequestedWidth = 0;
6135 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006136 mXOffset = 0;
6137 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006138 mLayer = 0;
6139 mAnimLayer = 0;
6140 mLastLayer = 0;
6141 }
6142
6143 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006144 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006145 TAG, "Attaching " + this + " token=" + mToken
6146 + ", list=" + mToken.windows);
6147 mSession.windowAddedLocked();
6148 }
6149
6150 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6151 mHaveFrame = true;
6152
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006153 final Rect container = mContainingFrame;
6154 container.set(pf);
6155
6156 final Rect display = mDisplayFrame;
6157 display.set(df);
6158
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006159 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006160 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006161 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6162 display.intersect(mCompatibleScreenFrame);
6163 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006164 }
6165
6166 final int pw = container.right - container.left;
6167 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006168
6169 int w,h;
6170 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6171 w = mAttrs.width < 0 ? pw : mAttrs.width;
6172 h = mAttrs.height< 0 ? ph : mAttrs.height;
6173 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006174 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6175 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006176 }
Romain Guy06882f82009-06-10 13:36:04 -07006177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006178 final Rect content = mContentFrame;
6179 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006181 final Rect visible = mVisibleFrame;
6182 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006184 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006185 final int fw = frame.width();
6186 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006188 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6189 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6190
6191 Gravity.apply(mAttrs.gravity, w, h, container,
6192 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6193 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6194
6195 //System.out.println("Out: " + mFrame);
6196
6197 // Now make sure the window fits in the overall display.
6198 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006200 // Make sure the content and visible frames are inside of the
6201 // final window frame.
6202 if (content.left < frame.left) content.left = frame.left;
6203 if (content.top < frame.top) content.top = frame.top;
6204 if (content.right > frame.right) content.right = frame.right;
6205 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6206 if (visible.left < frame.left) visible.left = frame.left;
6207 if (visible.top < frame.top) visible.top = frame.top;
6208 if (visible.right > frame.right) visible.right = frame.right;
6209 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006211 final Rect contentInsets = mContentInsets;
6212 contentInsets.left = content.left-frame.left;
6213 contentInsets.top = content.top-frame.top;
6214 contentInsets.right = frame.right-content.right;
6215 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006217 final Rect visibleInsets = mVisibleInsets;
6218 visibleInsets.left = visible.left-frame.left;
6219 visibleInsets.top = visible.top-frame.top;
6220 visibleInsets.right = frame.right-visible.right;
6221 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006222
Dianne Hackborn284ac932009-08-28 10:34:25 -07006223 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6224 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006225 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006226 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006228 if (localLOGV) {
6229 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6230 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006231 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006232 + mRequestedWidth + ", mRequestedheight="
6233 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6234 + "): frame=" + mFrame.toShortString()
6235 + " ci=" + contentInsets.toShortString()
6236 + " vi=" + visibleInsets.toShortString());
6237 //}
6238 }
6239 }
Romain Guy06882f82009-06-10 13:36:04 -07006240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006241 public Rect getFrameLw() {
6242 return mFrame;
6243 }
6244
6245 public Rect getShownFrameLw() {
6246 return mShownFrame;
6247 }
6248
6249 public Rect getDisplayFrameLw() {
6250 return mDisplayFrame;
6251 }
6252
6253 public Rect getContentFrameLw() {
6254 return mContentFrame;
6255 }
6256
6257 public Rect getVisibleFrameLw() {
6258 return mVisibleFrame;
6259 }
6260
6261 public boolean getGivenInsetsPendingLw() {
6262 return mGivenInsetsPending;
6263 }
6264
6265 public Rect getGivenContentInsetsLw() {
6266 return mGivenContentInsets;
6267 }
Romain Guy06882f82009-06-10 13:36:04 -07006268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006269 public Rect getGivenVisibleInsetsLw() {
6270 return mGivenVisibleInsets;
6271 }
Romain Guy06882f82009-06-10 13:36:04 -07006272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006273 public WindowManager.LayoutParams getAttrs() {
6274 return mAttrs;
6275 }
6276
6277 public int getSurfaceLayer() {
6278 return mLayer;
6279 }
Romain Guy06882f82009-06-10 13:36:04 -07006280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006281 public IApplicationToken getAppToken() {
6282 return mAppToken != null ? mAppToken.appToken : null;
6283 }
Jeff Brown349703e2010-06-22 01:27:15 -07006284
6285 public long getInputDispatchingTimeoutNanos() {
6286 return mAppToken != null
6287 ? mAppToken.inputDispatchingTimeoutNanos
6288 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6289 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006290
6291 public boolean hasAppShownWindows() {
6292 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6293 }
6294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006295 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006296 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006297 TAG, "Setting animation in " + this + ": " + anim);
6298 mAnimating = false;
6299 mLocalAnimating = false;
6300 mAnimation = anim;
6301 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6302 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6303 }
6304
6305 public void clearAnimation() {
6306 if (mAnimation != null) {
6307 mAnimating = true;
6308 mLocalAnimating = false;
6309 mAnimation = null;
6310 }
6311 }
Romain Guy06882f82009-06-10 13:36:04 -07006312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006313 Surface createSurfaceLocked() {
6314 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006315 mReportDestroySurface = false;
6316 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006317 mDrawPending = true;
6318 mCommitDrawPending = false;
6319 mReadyToShow = false;
6320 if (mAppToken != null) {
6321 mAppToken.allDrawn = false;
6322 }
6323
6324 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006325 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006326 flags |= Surface.PUSH_BUFFERS;
6327 }
6328
6329 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6330 flags |= Surface.SECURE;
6331 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006332 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006333 TAG, "Creating surface in session "
6334 + mSession.mSurfaceSession + " window " + this
6335 + " w=" + mFrame.width()
6336 + " h=" + mFrame.height() + " format="
6337 + mAttrs.format + " flags=" + flags);
6338
6339 int w = mFrame.width();
6340 int h = mFrame.height();
6341 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6342 // for a scaled surface, we always want the requested
6343 // size.
6344 w = mRequestedWidth;
6345 h = mRequestedHeight;
6346 }
6347
Romain Guy9825ec62009-10-01 00:58:09 -07006348 // Something is wrong and SurfaceFlinger will not like this,
6349 // try to revert to sane values
6350 if (w <= 0) w = 1;
6351 if (h <= 0) h = 1;
6352
Dianne Hackborn16064f92010-03-25 00:47:24 -07006353 mSurfaceShown = false;
6354 mSurfaceLayer = 0;
6355 mSurfaceAlpha = 1;
6356 mSurfaceX = 0;
6357 mSurfaceY = 0;
6358 mSurfaceW = w;
6359 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006360 try {
6361 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006362 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006363 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006364 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006365 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006366 + mSurface + " IN SESSION "
6367 + mSession.mSurfaceSession
6368 + ": pid=" + mSession.mPid + " format="
6369 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006370 + Integer.toHexString(flags)
6371 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006372 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006373 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006374 reclaimSomeSurfaceMemoryLocked(this, "create");
6375 return null;
6376 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006377 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006378 return null;
6379 }
Romain Guy06882f82009-06-10 13:36:04 -07006380
Joe Onorato8a9b2202010-02-26 18:56:32 -08006381 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006382 TAG, "Got surface: " + mSurface
6383 + ", set left=" + mFrame.left + " top=" + mFrame.top
6384 + ", animLayer=" + mAnimLayer);
6385 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006386 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006387 if (SHOW_TRANSACTIONS) logSurface(this,
6388 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6389 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6390 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006391 }
6392 Surface.openTransaction();
6393 try {
6394 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006395 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006396 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006397 mSurface.setPosition(mSurfaceX, mSurfaceY);
6398 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006399 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006400 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006401 mSurface.hide();
6402 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006403 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006404 mSurface.setFlags(Surface.SURFACE_DITHER,
6405 Surface.SURFACE_DITHER);
6406 }
6407 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006408 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006409 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6410 }
6411 mLastHidden = true;
6412 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006413 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006414 Surface.closeTransaction();
6415 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006416 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006417 TAG, "Created surface " + this);
6418 }
6419 return mSurface;
6420 }
Romain Guy06882f82009-06-10 13:36:04 -07006421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006422 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006423 if (mAppToken != null && this == mAppToken.startingWindow) {
6424 mAppToken.startingDisplayed = false;
6425 }
Romain Guy06882f82009-06-10 13:36:04 -07006426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006427 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006428 mDrawPending = false;
6429 mCommitDrawPending = false;
6430 mReadyToShow = false;
6431
6432 int i = mChildWindows.size();
6433 while (i > 0) {
6434 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006435 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006436 c.mAttachedHidden = true;
6437 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006438
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006439 if (mReportDestroySurface) {
6440 mReportDestroySurface = false;
6441 mSurfacePendingDestroy = true;
6442 try {
6443 mClient.dispatchGetNewSurface();
6444 // We'll really destroy on the next time around.
6445 return;
6446 } catch (RemoteException e) {
6447 }
6448 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006450 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006451 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006452 RuntimeException e = null;
6453 if (!HIDE_STACK_CRAWLS) {
6454 e = new RuntimeException();
6455 e.fillInStackTrace();
6456 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006457 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006458 + mSurface + ", session " + mSession, e);
6459 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006460 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006461 RuntimeException e = null;
6462 if (!HIDE_STACK_CRAWLS) {
6463 e = new RuntimeException();
6464 e.fillInStackTrace();
6465 }
6466 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006467 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006468 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006469 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006470 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006471 + " surface " + mSurface + " session " + mSession
6472 + ": " + e.toString());
6473 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006474
Dianne Hackborn16064f92010-03-25 00:47:24 -07006475 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006476 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006477 }
6478 }
6479
6480 boolean finishDrawingLocked() {
6481 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006482 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006483 TAG, "finishDrawingLocked: " + mSurface);
6484 mCommitDrawPending = true;
6485 mDrawPending = false;
6486 return true;
6487 }
6488 return false;
6489 }
6490
6491 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006492 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006493 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006494 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006495 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006496 }
6497 mCommitDrawPending = false;
6498 mReadyToShow = true;
6499 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6500 final AppWindowToken atoken = mAppToken;
6501 if (atoken == null || atoken.allDrawn || starting) {
6502 performShowLocked();
6503 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006504 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006505 }
6506
6507 // This must be called while inside a transaction.
6508 boolean performShowLocked() {
6509 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006510 RuntimeException e = null;
6511 if (!HIDE_STACK_CRAWLS) {
6512 e = new RuntimeException();
6513 e.fillInStackTrace();
6514 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006515 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006516 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
6517 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
6518 }
6519 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006520 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
6521 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006522 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006523 + " during animation: policyVis=" + mPolicyVisibility
6524 + " attHidden=" + mAttachedHidden
6525 + " tok.hiddenRequested="
6526 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07006527 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006528 + (mAppToken != null ? mAppToken.hidden : false)
6529 + " animating=" + mAnimating
6530 + " tok animating="
6531 + (mAppToken != null ? mAppToken.animating : false));
6532 if (!showSurfaceRobustlyLocked(this)) {
6533 return false;
6534 }
6535 mLastAlpha = -1;
6536 mHasDrawn = true;
6537 mLastHidden = false;
6538 mReadyToShow = false;
6539 enableScreenIfNeededLocked();
6540
6541 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07006542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006543 int i = mChildWindows.size();
6544 while (i > 0) {
6545 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006546 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006547 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006548 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006549 if (c.mSurface != null) {
6550 c.performShowLocked();
6551 // It hadn't been shown, which means layout not
6552 // performed on it, so now we want to make sure to
6553 // do a layout. If called from within the transaction
6554 // loop, this will cause it to restart with a new
6555 // layout.
6556 mLayoutNeeded = true;
6557 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006558 }
6559 }
Romain Guy06882f82009-06-10 13:36:04 -07006560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006561 if (mAttrs.type != TYPE_APPLICATION_STARTING
6562 && mAppToken != null) {
6563 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006564
Dianne Hackborn248b1882009-09-16 16:46:44 -07006565 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006566 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006567 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006568 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07006569 // If this initial window is animating, stop it -- we
6570 // will do an animation to reveal it from behind the
6571 // starting window, so there is no need for it to also
6572 // be doing its own stuff.
6573 if (mAnimation != null) {
6574 mAnimation = null;
6575 // Make sure we clean up the animation.
6576 mAnimating = true;
6577 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006578 mFinishedStarting.add(mAppToken);
6579 mH.sendEmptyMessage(H.FINISHED_STARTING);
6580 }
6581 mAppToken.updateReportedVisibilityLocked();
6582 }
6583 }
6584 return true;
6585 }
Romain Guy06882f82009-06-10 13:36:04 -07006586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006587 // This must be called while inside a transaction. Returns true if
6588 // there is more animation to run.
6589 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08006590 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006591 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07006592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006593 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
6594 mHasTransformation = true;
6595 mHasLocalTransformation = true;
6596 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006597 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006598 TAG, "Starting animation in " + this +
6599 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
6600 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
6601 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
6602 mAnimation.setStartTime(currentTime);
6603 mLocalAnimating = true;
6604 mAnimating = true;
6605 }
6606 mTransformation.clear();
6607 final boolean more = mAnimation.getTransformation(
6608 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006609 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006610 TAG, "Stepped animation in " + this +
6611 ": more=" + more + ", xform=" + mTransformation);
6612 if (more) {
6613 // we're not done!
6614 return true;
6615 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006616 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006617 TAG, "Finished animation in " + this +
6618 " @ " + currentTime);
6619 mAnimation = null;
6620 //WindowManagerService.this.dump();
6621 }
6622 mHasLocalTransformation = false;
6623 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006624 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006625 // When our app token is animating, we kind-of pretend like
6626 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
6627 // part of this check means that we will only do this if
6628 // our window is not currently exiting, or it is not
6629 // locally animating itself. The idea being that one that
6630 // is exiting and doing a local animation should be removed
6631 // once that animation is done.
6632 mAnimating = true;
6633 mHasTransformation = true;
6634 mTransformation.clear();
6635 return false;
6636 } else if (mHasTransformation) {
6637 // Little trick to get through the path below to act like
6638 // we have finished an animation.
6639 mAnimating = true;
6640 } else if (isAnimating()) {
6641 mAnimating = true;
6642 }
6643 } else if (mAnimation != null) {
6644 // If the display is frozen, and there is a pending animation,
6645 // clear it and make sure we run the cleanup code.
6646 mAnimating = true;
6647 mLocalAnimating = true;
6648 mAnimation = null;
6649 }
Romain Guy06882f82009-06-10 13:36:04 -07006650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006651 if (!mAnimating && !mLocalAnimating) {
6652 return false;
6653 }
6654
Joe Onorato8a9b2202010-02-26 18:56:32 -08006655 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006656 TAG, "Animation done in " + this + ": exiting=" + mExiting
6657 + ", reportedVisible="
6658 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07006659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006660 mAnimating = false;
6661 mLocalAnimating = false;
6662 mAnimation = null;
6663 mAnimLayer = mLayer;
6664 if (mIsImWindow) {
6665 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006666 } else if (mIsWallpaper) {
6667 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006668 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006669 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006670 + " anim layer: " + mAnimLayer);
6671 mHasTransformation = false;
6672 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006673 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
6674 if (DEBUG_VISIBILITY) {
6675 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
6676 + mPolicyVisibilityAfterAnim);
6677 }
6678 mPolicyVisibility = mPolicyVisibilityAfterAnim;
6679 if (!mPolicyVisibility) {
6680 if (mCurrentFocus == this) {
6681 mFocusMayChange = true;
6682 }
6683 // Window is no longer visible -- make sure if we were waiting
6684 // for it to be displayed before enabling the display, that
6685 // we allow the display to be enabled now.
6686 enableScreenIfNeededLocked();
6687 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08006688 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006689 mTransformation.clear();
6690 if (mHasDrawn
6691 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
6692 && mAppToken != null
6693 && mAppToken.firstWindowDrawn
6694 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006695 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006696 + mToken + ": first real window done animating");
6697 mFinishedStarting.add(mAppToken);
6698 mH.sendEmptyMessage(H.FINISHED_STARTING);
6699 }
Romain Guy06882f82009-06-10 13:36:04 -07006700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006701 finishExit();
6702
6703 if (mAppToken != null) {
6704 mAppToken.updateReportedVisibilityLocked();
6705 }
6706
6707 return false;
6708 }
6709
6710 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006711 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006712 TAG, "finishExit in " + this
6713 + ": exiting=" + mExiting
6714 + " remove=" + mRemoveOnExit
6715 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07006716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006717 final int N = mChildWindows.size();
6718 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07006719 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006720 }
Romain Guy06882f82009-06-10 13:36:04 -07006721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006722 if (!mExiting) {
6723 return;
6724 }
Romain Guy06882f82009-06-10 13:36:04 -07006725
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006726 if (isWindowAnimating()) {
6727 return;
6728 }
6729
Joe Onorato8a9b2202010-02-26 18:56:32 -08006730 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006731 TAG, "Exit animation finished in " + this
6732 + ": remove=" + mRemoveOnExit);
6733 if (mSurface != null) {
6734 mDestroySurface.add(this);
6735 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006736 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006737 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006738 try {
6739 mSurface.hide();
6740 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006741 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006742 }
6743 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006744 }
6745 mExiting = false;
6746 if (mRemoveOnExit) {
6747 mPendingRemove.add(this);
6748 mRemoveOnExit = false;
6749 }
6750 }
Romain Guy06882f82009-06-10 13:36:04 -07006751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006752 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
6753 if (dsdx < .99999f || dsdx > 1.00001f) return false;
6754 if (dtdy < .99999f || dtdy > 1.00001f) return false;
6755 if (dtdx < -.000001f || dtdx > .000001f) return false;
6756 if (dsdy < -.000001f || dsdy > .000001f) return false;
6757 return true;
6758 }
Romain Guy06882f82009-06-10 13:36:04 -07006759
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006760 void computeShownFrameLocked() {
6761 final boolean selfTransformation = mHasLocalTransformation;
6762 Transformation attachedTransformation =
6763 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
6764 ? mAttachedWindow.mTransformation : null;
6765 Transformation appTransformation =
6766 (mAppToken != null && mAppToken.hasTransformation)
6767 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006768
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006769 // Wallpapers are animated based on the "real" window they
6770 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006771 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07006772 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07006773 if (mWallpaperTarget.mHasLocalTransformation &&
6774 mWallpaperTarget.mAnimation != null &&
6775 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006776 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006777 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006778 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006779 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006780 }
6781 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07006782 mWallpaperTarget.mAppToken.hasTransformation &&
6783 mWallpaperTarget.mAppToken.animation != null &&
6784 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006785 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006786 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006787 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006788 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006789 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006790 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006792 if (selfTransformation || attachedTransformation != null
6793 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07006794 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006795 final Rect frame = mFrame;
6796 final float tmpFloats[] = mTmpFloats;
6797 final Matrix tmpMatrix = mTmpMatrix;
6798
6799 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07006800 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006801 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006802 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006803 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07006804 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006805 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006806 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006807 }
6808 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006809 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006810 }
6811
6812 // "convert" it into SurfaceFlinger's format
6813 // (a 2x2 matrix + an offset)
6814 // Here we must not transform the position of the surface
6815 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006816 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07006817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006818 tmpMatrix.getValues(tmpFloats);
6819 mDsDx = tmpFloats[Matrix.MSCALE_X];
6820 mDtDx = tmpFloats[Matrix.MSKEW_X];
6821 mDsDy = tmpFloats[Matrix.MSKEW_Y];
6822 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006823 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
6824 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006825 int w = frame.width();
6826 int h = frame.height();
6827 mShownFrame.set(x, y, x+w, y+h);
6828
6829 // Now set the alpha... but because our current hardware
6830 // can't do alpha transformation on a non-opaque surface,
6831 // turn it off if we are running an animation that is also
6832 // transforming since it is more important to have that
6833 // animation be smooth.
6834 mShownAlpha = mAlpha;
6835 if (!mLimitedAlphaCompositing
6836 || (!PixelFormat.formatHasAlpha(mAttrs.format)
6837 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
6838 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006839 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006840 if (selfTransformation) {
6841 mShownAlpha *= mTransformation.getAlpha();
6842 }
6843 if (attachedTransformation != null) {
6844 mShownAlpha *= attachedTransformation.getAlpha();
6845 }
6846 if (appTransformation != null) {
6847 mShownAlpha *= appTransformation.getAlpha();
6848 }
6849 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006850 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006851 }
Romain Guy06882f82009-06-10 13:36:04 -07006852
Joe Onorato8a9b2202010-02-26 18:56:32 -08006853 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006854 TAG, "Continuing animation in " + this +
6855 ": " + mShownFrame +
6856 ", alpha=" + mTransformation.getAlpha());
6857 return;
6858 }
Romain Guy06882f82009-06-10 13:36:04 -07006859
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006860 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006861 if (mXOffset != 0 || mYOffset != 0) {
6862 mShownFrame.offset(mXOffset, mYOffset);
6863 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006864 mShownAlpha = mAlpha;
6865 mDsDx = 1;
6866 mDtDx = 0;
6867 mDsDy = 0;
6868 mDtDy = 1;
6869 }
Romain Guy06882f82009-06-10 13:36:04 -07006870
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006871 /**
6872 * Is this window visible? It is not visible if there is no
6873 * surface, or we are in the process of running an exit animation
6874 * that will remove the surface, or its app token has been hidden.
6875 */
6876 public boolean isVisibleLw() {
6877 final AppWindowToken atoken = mAppToken;
6878 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6879 && (atoken == null || !atoken.hiddenRequested)
6880 && !mExiting && !mDestroying;
6881 }
6882
6883 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006884 * Like {@link #isVisibleLw}, but also counts a window that is currently
6885 * "hidden" behind the keyguard as visible. This allows us to apply
6886 * things like window flags that impact the keyguard.
6887 * XXX I am starting to think we need to have ANOTHER visibility flag
6888 * for this "hidden behind keyguard" state rather than overloading
6889 * mPolicyVisibility. Ungh.
6890 */
6891 public boolean isVisibleOrBehindKeyguardLw() {
6892 final AppWindowToken atoken = mAppToken;
6893 return mSurface != null && !mAttachedHidden
6894 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackborn5943c202010-04-12 21:36:49 -07006895 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending))
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006896 && !mExiting && !mDestroying;
6897 }
6898
6899 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006900 * Is this window visible, ignoring its app token? It is not visible
6901 * if there is no surface, or we are in the process of running an exit animation
6902 * that will remove the surface.
6903 */
6904 public boolean isWinVisibleLw() {
6905 final AppWindowToken atoken = mAppToken;
6906 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6907 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
6908 && !mExiting && !mDestroying;
6909 }
6910
6911 /**
6912 * The same as isVisible(), but follows the current hidden state of
6913 * the associated app token, not the pending requested hidden state.
6914 */
6915 boolean isVisibleNow() {
6916 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07006917 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006918 }
6919
6920 /**
6921 * Same as isVisible(), but we also count it as visible between the
6922 * call to IWindowSession.add() and the first relayout().
6923 */
6924 boolean isVisibleOrAdding() {
6925 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006926 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006927 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
6928 && mPolicyVisibility && !mAttachedHidden
6929 && (atoken == null || !atoken.hiddenRequested)
6930 && !mExiting && !mDestroying;
6931 }
6932
6933 /**
6934 * Is this window currently on-screen? It is on-screen either if it
6935 * is visible or it is currently running an animation before no longer
6936 * being visible.
6937 */
6938 boolean isOnScreen() {
6939 final AppWindowToken atoken = mAppToken;
6940 if (atoken != null) {
6941 return mSurface != null && mPolicyVisibility && !mDestroying
6942 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006943 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006944 } else {
6945 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006946 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006947 }
6948 }
Romain Guy06882f82009-06-10 13:36:04 -07006949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006950 /**
6951 * Like isOnScreen(), but we don't return true if the window is part
6952 * of a transition that has not yet been started.
6953 */
6954 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006955 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07006956 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006957 return false;
6958 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006959 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006960 final boolean animating = atoken != null
6961 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006962 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006963 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
6964 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006965 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006966 }
6967
6968 /** Is the window or its container currently animating? */
6969 boolean isAnimating() {
6970 final WindowState attached = mAttachedWindow;
6971 final AppWindowToken atoken = mAppToken;
6972 return mAnimation != null
6973 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07006974 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006975 (atoken.animation != null
6976 || atoken.inPendingTransaction));
6977 }
6978
6979 /** Is this window currently animating? */
6980 boolean isWindowAnimating() {
6981 return mAnimation != null;
6982 }
6983
6984 /**
6985 * Like isOnScreen, but returns false if the surface hasn't yet
6986 * been drawn.
6987 */
6988 public boolean isDisplayedLw() {
6989 final AppWindowToken atoken = mAppToken;
6990 return mSurface != null && mPolicyVisibility && !mDestroying
6991 && !mDrawPending && !mCommitDrawPending
6992 && ((!mAttachedHidden &&
6993 (atoken == null || !atoken.hiddenRequested))
6994 || mAnimating);
6995 }
6996
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006997 /**
6998 * Returns true if the window has a surface that it has drawn a
Dianne Hackborn5943c202010-04-12 21:36:49 -07006999 * complete UI in to. Note that this returns true if the orientation
7000 * is changing even if the window hasn't redrawn because we don't want
7001 * to stop things from executing during that time.
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007002 */
7003 public boolean isDrawnLw() {
7004 final AppWindowToken atoken = mAppToken;
7005 return mSurface != null && !mDestroying
Dianne Hackborn5943c202010-04-12 21:36:49 -07007006 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending));
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007007 }
7008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007009 public boolean fillsScreenLw(int screenWidth, int screenHeight,
7010 boolean shownFrame, boolean onlyOpaque) {
7011 if (mSurface == null) {
7012 return false;
7013 }
7014 if (mAppToken != null && !mAppToken.appFullscreen) {
7015 return false;
7016 }
7017 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
7018 return false;
7019 }
7020 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007021
7022 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
7023 return frame.left <= mCompatibleScreenFrame.left &&
7024 frame.top <= mCompatibleScreenFrame.top &&
7025 frame.right >= mCompatibleScreenFrame.right &&
7026 frame.bottom >= mCompatibleScreenFrame.bottom;
7027 } else {
7028 return frame.left <= 0 && frame.top <= 0
7029 && frame.right >= screenWidth
7030 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007031 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007032 }
Romain Guy06882f82009-06-10 13:36:04 -07007033
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007034 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007035 * Return true if the window is opaque and fully drawn. This indicates
7036 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007037 */
7038 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007039 return (mAttrs.format == PixelFormat.OPAQUE
7040 || mAttrs.type == TYPE_WALLPAPER)
7041 && mSurface != null && mAnimation == null
7042 && (mAppToken == null || mAppToken.animation == null)
7043 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007044 }
7045
7046 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7047 return
7048 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007049 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7050 // only if it's visible
7051 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007052 // and only if the application fills the compatible screen
7053 mFrame.left <= mCompatibleScreenFrame.left &&
7054 mFrame.top <= mCompatibleScreenFrame.top &&
7055 mFrame.right >= mCompatibleScreenFrame.right &&
7056 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007057 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007058 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007059 }
7060
7061 boolean isFullscreen(int screenWidth, int screenHeight) {
7062 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007063 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007064 }
7065
7066 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007067 disposeInputChannel();
7068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007069 if (mAttachedWindow != null) {
7070 mAttachedWindow.mChildWindows.remove(this);
7071 }
7072 destroySurfaceLocked();
7073 mSession.windowRemovedLocked();
7074 try {
7075 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7076 } catch (RuntimeException e) {
7077 // Ignore if it has already been removed (usually because
7078 // we are doing this as part of processing a death note.)
7079 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007080 }
7081
7082 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007083 if (mInputChannel != null) {
7084 mInputManager.unregisterInputChannel(mInputChannel);
7085
7086 mInputChannel.dispose();
7087 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007088 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007089 }
7090
7091 private class DeathRecipient implements IBinder.DeathRecipient {
7092 public void binderDied() {
7093 try {
7094 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007095 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007096 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007097 if (win != null) {
7098 removeWindowLocked(mSession, win);
7099 }
7100 }
7101 } catch (IllegalArgumentException ex) {
7102 // This will happen if the window has already been
7103 // removed.
7104 }
7105 }
7106 }
7107
7108 /** Returns true if this window desires key events. */
7109 public final boolean canReceiveKeys() {
7110 return isVisibleOrAdding()
7111 && (mViewVisibility == View.VISIBLE)
7112 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7113 }
7114
7115 public boolean hasDrawnLw() {
7116 return mHasDrawn;
7117 }
7118
7119 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007120 return showLw(doAnimation, true);
7121 }
7122
7123 boolean showLw(boolean doAnimation, boolean requestAnim) {
7124 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7125 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007126 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007127 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007128 if (doAnimation) {
7129 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7130 + mPolicyVisibility + " mAnimation=" + mAnimation);
7131 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7132 doAnimation = false;
7133 } else if (mPolicyVisibility && mAnimation == null) {
7134 // Check for the case where we are currently visible and
7135 // not animating; we do not want to do animation at such a
7136 // point to become visible when we already are.
7137 doAnimation = false;
7138 }
7139 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007140 mPolicyVisibility = true;
7141 mPolicyVisibilityAfterAnim = true;
7142 if (doAnimation) {
7143 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7144 }
7145 if (requestAnim) {
7146 requestAnimationLocked(0);
7147 }
7148 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007149 }
7150
7151 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007152 return hideLw(doAnimation, true);
7153 }
7154
7155 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007156 if (doAnimation) {
7157 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7158 doAnimation = false;
7159 }
7160 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007161 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7162 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007163 if (!current) {
7164 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007165 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007166 if (doAnimation) {
7167 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7168 if (mAnimation == null) {
7169 doAnimation = false;
7170 }
7171 }
7172 if (doAnimation) {
7173 mPolicyVisibilityAfterAnim = false;
7174 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007175 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007176 mPolicyVisibilityAfterAnim = false;
7177 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007178 // Window is no longer visible -- make sure if we were waiting
7179 // for it to be displayed before enabling the display, that
7180 // we allow the display to be enabled now.
7181 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007182 if (mCurrentFocus == this) {
7183 mFocusMayChange = true;
7184 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007185 }
7186 if (requestAnim) {
7187 requestAnimationLocked(0);
7188 }
7189 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007190 }
7191
7192 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007193 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7194 pw.print(" mClient="); pw.println(mClient.asBinder());
7195 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7196 if (mAttachedWindow != null || mLayoutAttached) {
7197 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7198 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7199 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007200 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7201 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7202 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007203 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7204 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007205 }
7206 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7207 pw.print(" mSubLayer="); pw.print(mSubLayer);
7208 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7209 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7210 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7211 pw.print("="); pw.print(mAnimLayer);
7212 pw.print(" mLastLayer="); pw.println(mLastLayer);
7213 if (mSurface != null) {
7214 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007215 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7216 pw.print(" layer="); pw.print(mSurfaceLayer);
7217 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7218 pw.print(" rect=("); pw.print(mSurfaceX);
7219 pw.print(","); pw.print(mSurfaceY);
7220 pw.print(") "); pw.print(mSurfaceW);
7221 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007222 }
7223 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7224 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7225 if (mAppToken != null) {
7226 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7227 }
7228 if (mTargetAppToken != null) {
7229 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7230 }
7231 pw.print(prefix); pw.print("mViewVisibility=0x");
7232 pw.print(Integer.toHexString(mViewVisibility));
7233 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007234 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7235 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007236 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7237 pw.print(prefix); pw.print("mPolicyVisibility=");
7238 pw.print(mPolicyVisibility);
7239 pw.print(" mPolicyVisibilityAfterAnim=");
7240 pw.print(mPolicyVisibilityAfterAnim);
7241 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7242 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007243 if (!mRelayoutCalled) {
7244 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7245 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007246 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007247 pw.print(" h="); pw.print(mRequestedHeight);
7248 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007249 if (mXOffset != 0 || mYOffset != 0) {
7250 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7251 pw.print(" y="); pw.println(mYOffset);
7252 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007253 pw.print(prefix); pw.print("mGivenContentInsets=");
7254 mGivenContentInsets.printShortString(pw);
7255 pw.print(" mGivenVisibleInsets=");
7256 mGivenVisibleInsets.printShortString(pw);
7257 pw.println();
7258 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7259 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7260 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7261 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007262 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007263 pw.print(prefix); pw.print("mShownFrame=");
7264 mShownFrame.printShortString(pw);
7265 pw.print(" last="); mLastShownFrame.printShortString(pw);
7266 pw.println();
7267 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7268 pw.print(" last="); mLastFrame.printShortString(pw);
7269 pw.println();
7270 pw.print(prefix); pw.print("mContainingFrame=");
7271 mContainingFrame.printShortString(pw);
7272 pw.print(" mDisplayFrame=");
7273 mDisplayFrame.printShortString(pw);
7274 pw.println();
7275 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7276 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7277 pw.println();
7278 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7279 pw.print(" last="); mLastContentInsets.printShortString(pw);
7280 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7281 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7282 pw.println();
7283 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7284 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7285 pw.print(" mAlpha="); pw.print(mAlpha);
7286 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7287 }
7288 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7289 || mAnimation != null) {
7290 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7291 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7292 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7293 pw.print(" mAnimation="); pw.println(mAnimation);
7294 }
7295 if (mHasTransformation || mHasLocalTransformation) {
7296 pw.print(prefix); pw.print("XForm: has=");
7297 pw.print(mHasTransformation);
7298 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7299 pw.print(" "); mTransformation.printShortString(pw);
7300 pw.println();
7301 }
7302 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7303 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7304 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7305 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7306 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7307 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7308 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7309 pw.print(" mDestroying="); pw.print(mDestroying);
7310 pw.print(" mRemoved="); pw.println(mRemoved);
7311 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007312 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007313 pw.print(prefix); pw.print("mOrientationChanging=");
7314 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007315 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7316 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007317 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007318 if (mHScale != 1 || mVScale != 1) {
7319 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7320 pw.print(" mVScale="); pw.println(mVScale);
7321 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007322 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007323 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7324 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7325 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007326 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7327 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7328 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7329 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007330 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007331
7332 String makeInputChannelName() {
7333 return Integer.toHexString(System.identityHashCode(this))
7334 + " " + mAttrs.getTitle();
7335 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007336
7337 @Override
7338 public String toString() {
7339 return "Window{"
7340 + Integer.toHexString(System.identityHashCode(this))
7341 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7342 }
7343 }
Romain Guy06882f82009-06-10 13:36:04 -07007344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007345 // -------------------------------------------------------------
7346 // Window Token State
7347 // -------------------------------------------------------------
7348
7349 class WindowToken {
7350 // The actual token.
7351 final IBinder token;
7352
7353 // The type of window this token is for, as per WindowManager.LayoutParams.
7354 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007356 // Set if this token was explicitly added by a client, so should
7357 // not be removed when all windows are removed.
7358 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007359
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007360 // For printing.
7361 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007363 // If this is an AppWindowToken, this is non-null.
7364 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007366 // All of the windows associated with this token.
7367 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7368
7369 // Is key dispatching paused for this token?
7370 boolean paused = false;
7371
7372 // Should this token's windows be hidden?
7373 boolean hidden;
7374
7375 // Temporary for finding which tokens no longer have visible windows.
7376 boolean hasVisible;
7377
Dianne Hackborna8f60182009-09-01 19:01:50 -07007378 // Set to true when this token is in a pending transaction where it
7379 // will be shown.
7380 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007381
Dianne Hackborna8f60182009-09-01 19:01:50 -07007382 // Set to true when this token is in a pending transaction where it
7383 // will be hidden.
7384 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007385
Dianne Hackborna8f60182009-09-01 19:01:50 -07007386 // Set to true when this token is in a pending transaction where its
7387 // windows will be put to the bottom of the list.
7388 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007389
Dianne Hackborna8f60182009-09-01 19:01:50 -07007390 // Set to true when this token is in a pending transaction where its
7391 // windows will be put to the top of the list.
7392 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007394 WindowToken(IBinder _token, int type, boolean _explicit) {
7395 token = _token;
7396 windowType = type;
7397 explicit = _explicit;
7398 }
7399
7400 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007401 pw.print(prefix); pw.print("token="); pw.println(token);
7402 pw.print(prefix); pw.print("windows="); pw.println(windows);
7403 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7404 pw.print(" hidden="); pw.print(hidden);
7405 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007406 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7407 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7408 pw.print(" waitingToHide="); pw.print(waitingToHide);
7409 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7410 pw.print(" sendingToTop="); pw.println(sendingToTop);
7411 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007412 }
7413
7414 @Override
7415 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007416 if (stringName == null) {
7417 StringBuilder sb = new StringBuilder();
7418 sb.append("WindowToken{");
7419 sb.append(Integer.toHexString(System.identityHashCode(this)));
7420 sb.append(" token="); sb.append(token); sb.append('}');
7421 stringName = sb.toString();
7422 }
7423 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007424 }
7425 };
7426
7427 class AppWindowToken extends WindowToken {
7428 // Non-null only for application tokens.
7429 final IApplicationToken appToken;
7430
7431 // All of the windows and child windows that are included in this
7432 // application token. Note this list is NOT sorted!
7433 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7434
7435 int groupId = -1;
7436 boolean appFullscreen;
7437 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007438
7439 // The input dispatching timeout for this application token in nanoseconds.
7440 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007442 // These are used for determining when all windows associated with
7443 // an activity have been drawn, so they can be made visible together
7444 // at the same time.
7445 int lastTransactionSequence = mTransactionSequence-1;
7446 int numInterestingWindows;
7447 int numDrawnWindows;
7448 boolean inPendingTransaction;
7449 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007451 // Is this token going to be hidden in a little while? If so, it
7452 // won't be taken into account for setting the screen orientation.
7453 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007455 // Is this window's surface needed? This is almost like hidden, except
7456 // it will sometimes be true a little earlier: when the token has
7457 // been shown, but is still waiting for its app transition to execute
7458 // before making its windows shown.
7459 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007461 // Have we told the window clients to hide themselves?
7462 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007464 // Last visibility state we reported to the app token.
7465 boolean reportedVisible;
7466
7467 // Set to true when the token has been removed from the window mgr.
7468 boolean removed;
7469
7470 // Have we been asked to have this token keep the screen frozen?
7471 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007473 boolean animating;
7474 Animation animation;
7475 boolean hasTransformation;
7476 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007478 // Offset to the window of all layers in the token, for use by
7479 // AppWindowToken animations.
7480 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007482 // Information about an application starting window if displayed.
7483 StartingData startingData;
7484 WindowState startingWindow;
7485 View startingView;
7486 boolean startingDisplayed;
7487 boolean startingMoved;
7488 boolean firstWindowDrawn;
7489
7490 AppWindowToken(IApplicationToken _token) {
7491 super(_token.asBinder(),
7492 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7493 appWindowToken = this;
7494 appToken = _token;
7495 }
Romain Guy06882f82009-06-10 13:36:04 -07007496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007497 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007498 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007499 TAG, "Setting animation in " + this + ": " + anim);
7500 animation = anim;
7501 animating = false;
7502 anim.restrictDuration(MAX_ANIMATION_DURATION);
7503 anim.scaleCurrentDuration(mTransitionAnimationScale);
7504 int zorder = anim.getZAdjustment();
7505 int adj = 0;
7506 if (zorder == Animation.ZORDER_TOP) {
7507 adj = TYPE_LAYER_OFFSET;
7508 } else if (zorder == Animation.ZORDER_BOTTOM) {
7509 adj = -TYPE_LAYER_OFFSET;
7510 }
Romain Guy06882f82009-06-10 13:36:04 -07007511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007512 if (animLayerAdjustment != adj) {
7513 animLayerAdjustment = adj;
7514 updateLayers();
7515 }
7516 }
Romain Guy06882f82009-06-10 13:36:04 -07007517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007518 public void setDummyAnimation() {
7519 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007520 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007521 TAG, "Setting dummy animation in " + this);
7522 animation = sDummyAnimation;
7523 }
7524 }
7525
7526 public void clearAnimation() {
7527 if (animation != null) {
7528 animation = null;
7529 animating = true;
7530 }
7531 }
Romain Guy06882f82009-06-10 13:36:04 -07007532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007533 void updateLayers() {
7534 final int N = allAppWindows.size();
7535 final int adj = animLayerAdjustment;
7536 for (int i=0; i<N; i++) {
7537 WindowState w = allAppWindows.get(i);
7538 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007539 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007540 + w.mAnimLayer);
7541 if (w == mInputMethodTarget) {
7542 setInputMethodAnimLayerAdjustment(adj);
7543 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007544 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007545 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007546 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007547 }
7548 }
Romain Guy06882f82009-06-10 13:36:04 -07007549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007550 void sendAppVisibilityToClients() {
7551 final int N = allAppWindows.size();
7552 for (int i=0; i<N; i++) {
7553 WindowState win = allAppWindows.get(i);
7554 if (win == startingWindow && clientHidden) {
7555 // Don't hide the starting window.
7556 continue;
7557 }
7558 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007559 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007560 "Setting visibility of " + win + ": " + (!clientHidden));
7561 win.mClient.dispatchAppVisibility(!clientHidden);
7562 } catch (RemoteException e) {
7563 }
7564 }
7565 }
Romain Guy06882f82009-06-10 13:36:04 -07007566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007567 void showAllWindowsLocked() {
7568 final int NW = allAppWindows.size();
7569 for (int i=0; i<NW; i++) {
7570 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007571 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007572 "performing show on: " + w);
7573 w.performShowLocked();
7574 }
7575 }
Romain Guy06882f82009-06-10 13:36:04 -07007576
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007577 // This must be called while inside a transaction.
7578 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007579 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007580 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007582 if (animation == sDummyAnimation) {
7583 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007584 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007585 // when it is really time to animate, this will be set to
7586 // a real animation and the next call will execute normally.
7587 return false;
7588 }
Romain Guy06882f82009-06-10 13:36:04 -07007589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007590 if ((allDrawn || animating || startingDisplayed) && animation != null) {
7591 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007592 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007593 TAG, "Starting animation in " + this +
7594 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
7595 + " scale=" + mTransitionAnimationScale
7596 + " allDrawn=" + allDrawn + " animating=" + animating);
7597 animation.initialize(dw, dh, dw, dh);
7598 animation.setStartTime(currentTime);
7599 animating = true;
7600 }
7601 transformation.clear();
7602 final boolean more = animation.getTransformation(
7603 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007604 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007605 TAG, "Stepped animation in " + this +
7606 ": more=" + more + ", xform=" + transformation);
7607 if (more) {
7608 // we're done!
7609 hasTransformation = true;
7610 return true;
7611 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007612 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007613 TAG, "Finished animation in " + this +
7614 " @ " + currentTime);
7615 animation = null;
7616 }
7617 } else if (animation != null) {
7618 // If the display is frozen, and there is a pending animation,
7619 // clear it and make sure we run the cleanup code.
7620 animating = true;
7621 animation = null;
7622 }
7623
7624 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07007625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007626 if (!animating) {
7627 return false;
7628 }
7629
7630 clearAnimation();
7631 animating = false;
7632 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
7633 moveInputMethodWindowsIfNeededLocked(true);
7634 }
Romain Guy06882f82009-06-10 13:36:04 -07007635
Joe Onorato8a9b2202010-02-26 18:56:32 -08007636 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007637 TAG, "Animation done in " + this
7638 + ": reportedVisible=" + reportedVisible);
7639
7640 transformation.clear();
7641 if (animLayerAdjustment != 0) {
7642 animLayerAdjustment = 0;
7643 updateLayers();
7644 }
Romain Guy06882f82009-06-10 13:36:04 -07007645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007646 final int N = windows.size();
7647 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007648 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007649 }
7650 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07007651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007652 return false;
7653 }
7654
7655 void updateReportedVisibilityLocked() {
7656 if (appToken == null) {
7657 return;
7658 }
Romain Guy06882f82009-06-10 13:36:04 -07007659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007660 int numInteresting = 0;
7661 int numVisible = 0;
7662 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07007663
Joe Onorato8a9b2202010-02-26 18:56:32 -08007664 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007665 final int N = allAppWindows.size();
7666 for (int i=0; i<N; i++) {
7667 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08007668 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07007669 || win.mViewVisibility != View.VISIBLE
7670 || win.mAttrs.type == TYPE_APPLICATION_STARTING) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007671 continue;
7672 }
7673 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007674 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007675 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007676 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007677 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007678 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007679 + " pv=" + win.mPolicyVisibility
7680 + " dp=" + win.mDrawPending
7681 + " cdp=" + win.mCommitDrawPending
7682 + " ah=" + win.mAttachedHidden
7683 + " th="
7684 + (win.mAppToken != null
7685 ? win.mAppToken.hiddenRequested : false)
7686 + " a=" + win.mAnimating);
7687 }
7688 }
7689 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007690 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007691 if (!win.isAnimating()) {
7692 numVisible++;
7693 }
7694 nowGone = false;
7695 } else if (win.isAnimating()) {
7696 nowGone = false;
7697 }
7698 }
Romain Guy06882f82009-06-10 13:36:04 -07007699
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007700 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007701 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007702 + numInteresting + " visible=" + numVisible);
7703 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007704 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007705 TAG, "Visibility changed in " + this
7706 + ": vis=" + nowVisible);
7707 reportedVisible = nowVisible;
7708 Message m = mH.obtainMessage(
7709 H.REPORT_APPLICATION_TOKEN_WINDOWS,
7710 nowVisible ? 1 : 0,
7711 nowGone ? 1 : 0,
7712 this);
7713 mH.sendMessage(m);
7714 }
7715 }
Romain Guy06882f82009-06-10 13:36:04 -07007716
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007717 WindowState findMainWindow() {
7718 int j = windows.size();
7719 while (j > 0) {
7720 j--;
7721 WindowState win = windows.get(j);
7722 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
7723 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
7724 return win;
7725 }
7726 }
7727 return null;
7728 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007730 void dump(PrintWriter pw, String prefix) {
7731 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007732 if (appToken != null) {
7733 pw.print(prefix); pw.println("app=true");
7734 }
7735 if (allAppWindows.size() > 0) {
7736 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
7737 }
7738 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007739 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007740 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
7741 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
7742 pw.print(" clientHidden="); pw.print(clientHidden);
7743 pw.print(" willBeHidden="); pw.print(willBeHidden);
7744 pw.print(" reportedVisible="); pw.println(reportedVisible);
7745 if (paused || freezingScreen) {
7746 pw.print(prefix); pw.print("paused="); pw.print(paused);
7747 pw.print(" freezingScreen="); pw.println(freezingScreen);
7748 }
7749 if (numInterestingWindows != 0 || numDrawnWindows != 0
7750 || inPendingTransaction || allDrawn) {
7751 pw.print(prefix); pw.print("numInterestingWindows=");
7752 pw.print(numInterestingWindows);
7753 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
7754 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
7755 pw.print(" allDrawn="); pw.println(allDrawn);
7756 }
7757 if (animating || animation != null) {
7758 pw.print(prefix); pw.print("animating="); pw.print(animating);
7759 pw.print(" animation="); pw.println(animation);
7760 }
7761 if (animLayerAdjustment != 0) {
7762 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
7763 }
7764 if (hasTransformation) {
7765 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
7766 pw.print(" transformation="); transformation.printShortString(pw);
7767 pw.println();
7768 }
7769 if (startingData != null || removed || firstWindowDrawn) {
7770 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
7771 pw.print(" removed="); pw.print(removed);
7772 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
7773 }
7774 if (startingWindow != null || startingView != null
7775 || startingDisplayed || startingMoved) {
7776 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
7777 pw.print(" startingView="); pw.print(startingView);
7778 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
7779 pw.print(" startingMoved"); pw.println(startingMoved);
7780 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007781 }
7782
7783 @Override
7784 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007785 if (stringName == null) {
7786 StringBuilder sb = new StringBuilder();
7787 sb.append("AppWindowToken{");
7788 sb.append(Integer.toHexString(System.identityHashCode(this)));
7789 sb.append(" token="); sb.append(token); sb.append('}');
7790 stringName = sb.toString();
7791 }
7792 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007793 }
7794 }
Romain Guy06882f82009-06-10 13:36:04 -07007795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007796 // -------------------------------------------------------------
7797 // DummyAnimation
7798 // -------------------------------------------------------------
7799
7800 // This is an animation that does nothing: it just immediately finishes
7801 // itself every time it is called. It is used as a stub animation in cases
7802 // where we want to synchronize multiple things that may be animating.
7803 static final class DummyAnimation extends Animation {
7804 public boolean getTransformation(long currentTime, Transformation outTransformation) {
7805 return false;
7806 }
7807 }
7808 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07007809
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007810 // -------------------------------------------------------------
7811 // Async Handler
7812 // -------------------------------------------------------------
7813
7814 static final class StartingData {
7815 final String pkg;
7816 final int theme;
7817 final CharSequence nonLocalizedLabel;
7818 final int labelRes;
7819 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07007820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007821 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
7822 int _labelRes, int _icon) {
7823 pkg = _pkg;
7824 theme = _theme;
7825 nonLocalizedLabel = _nonLocalizedLabel;
7826 labelRes = _labelRes;
7827 icon = _icon;
7828 }
7829 }
7830
7831 private final class H extends Handler {
7832 public static final int REPORT_FOCUS_CHANGE = 2;
7833 public static final int REPORT_LOSING_FOCUS = 3;
7834 public static final int ANIMATE = 4;
7835 public static final int ADD_STARTING = 5;
7836 public static final int REMOVE_STARTING = 6;
7837 public static final int FINISHED_STARTING = 7;
7838 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007839 public static final int WINDOW_FREEZE_TIMEOUT = 11;
7840 public static final int HOLD_SCREEN_CHANGED = 12;
7841 public static final int APP_TRANSITION_TIMEOUT = 13;
7842 public static final int PERSIST_ANIMATION_SCALE = 14;
7843 public static final int FORCE_GC = 15;
7844 public static final int ENABLE_SCREEN = 16;
7845 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007846 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07007847 public static final int REPORT_WINDOWS_CHANGE = 19;
Romain Guy06882f82009-06-10 13:36:04 -07007848
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007849 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07007850
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007851 public H() {
7852 }
Romain Guy06882f82009-06-10 13:36:04 -07007853
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007854 @Override
7855 public void handleMessage(Message msg) {
7856 switch (msg.what) {
7857 case REPORT_FOCUS_CHANGE: {
7858 WindowState lastFocus;
7859 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07007860
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007861 synchronized(mWindowMap) {
7862 lastFocus = mLastFocus;
7863 newFocus = mCurrentFocus;
7864 if (lastFocus == newFocus) {
7865 // Focus is not changing, so nothing to do.
7866 return;
7867 }
7868 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007869 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007870 // + " to " + newFocus);
7871 if (newFocus != null && lastFocus != null
7872 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007873 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007874 mLosingFocus.add(lastFocus);
7875 lastFocus = null;
7876 }
7877 }
7878
7879 if (lastFocus != newFocus) {
7880 //System.out.println("Changing focus from " + lastFocus
7881 // + " to " + newFocus);
7882 if (newFocus != null) {
7883 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007884 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007885 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
7886 } catch (RemoteException e) {
7887 // Ignore if process has died.
7888 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07007889 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007890 }
7891
7892 if (lastFocus != null) {
7893 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007894 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007895 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
7896 } catch (RemoteException e) {
7897 // Ignore if process has died.
7898 }
7899 }
7900 }
7901 } break;
7902
7903 case REPORT_LOSING_FOCUS: {
7904 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07007905
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007906 synchronized(mWindowMap) {
7907 losers = mLosingFocus;
7908 mLosingFocus = new ArrayList<WindowState>();
7909 }
7910
7911 final int N = losers.size();
7912 for (int i=0; i<N; i++) {
7913 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007914 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007915 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
7916 } catch (RemoteException e) {
7917 // Ignore if process has died.
7918 }
7919 }
7920 } break;
7921
7922 case ANIMATE: {
7923 synchronized(mWindowMap) {
7924 mAnimationPending = false;
7925 performLayoutAndPlaceSurfacesLocked();
7926 }
7927 } break;
7928
7929 case ADD_STARTING: {
7930 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7931 final StartingData sd = wtoken.startingData;
7932
7933 if (sd == null) {
7934 // Animation has been canceled... do nothing.
7935 return;
7936 }
Romain Guy06882f82009-06-10 13:36:04 -07007937
Joe Onorato8a9b2202010-02-26 18:56:32 -08007938 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007939 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07007940
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007941 View view = null;
7942 try {
7943 view = mPolicy.addStartingWindow(
7944 wtoken.token, sd.pkg,
7945 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
7946 sd.icon);
7947 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007948 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007949 }
7950
7951 if (view != null) {
7952 boolean abort = false;
7953
7954 synchronized(mWindowMap) {
7955 if (wtoken.removed || wtoken.startingData == null) {
7956 // If the window was successfully added, then
7957 // we need to remove it.
7958 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007959 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007960 "Aborted starting " + wtoken
7961 + ": removed=" + wtoken.removed
7962 + " startingData=" + wtoken.startingData);
7963 wtoken.startingWindow = null;
7964 wtoken.startingData = null;
7965 abort = true;
7966 }
7967 } else {
7968 wtoken.startingView = view;
7969 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007970 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007971 "Added starting " + wtoken
7972 + ": startingWindow="
7973 + wtoken.startingWindow + " startingView="
7974 + wtoken.startingView);
7975 }
7976
7977 if (abort) {
7978 try {
7979 mPolicy.removeStartingWindow(wtoken.token, view);
7980 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007981 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007982 }
7983 }
7984 }
7985 } break;
7986
7987 case REMOVE_STARTING: {
7988 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7989 IBinder token = null;
7990 View view = null;
7991 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007992 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007993 + wtoken + ": startingWindow="
7994 + wtoken.startingWindow + " startingView="
7995 + wtoken.startingView);
7996 if (wtoken.startingWindow != null) {
7997 view = wtoken.startingView;
7998 token = wtoken.token;
7999 wtoken.startingData = null;
8000 wtoken.startingView = null;
8001 wtoken.startingWindow = null;
8002 }
8003 }
8004 if (view != null) {
8005 try {
8006 mPolicy.removeStartingWindow(token, view);
8007 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008008 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008009 }
8010 }
8011 } break;
8012
8013 case FINISHED_STARTING: {
8014 IBinder token = null;
8015 View view = null;
8016 while (true) {
8017 synchronized (mWindowMap) {
8018 final int N = mFinishedStarting.size();
8019 if (N <= 0) {
8020 break;
8021 }
8022 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8023
Joe Onorato8a9b2202010-02-26 18:56:32 -08008024 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008025 "Finished starting " + wtoken
8026 + ": startingWindow=" + wtoken.startingWindow
8027 + " startingView=" + wtoken.startingView);
8028
8029 if (wtoken.startingWindow == null) {
8030 continue;
8031 }
8032
8033 view = wtoken.startingView;
8034 token = wtoken.token;
8035 wtoken.startingData = null;
8036 wtoken.startingView = null;
8037 wtoken.startingWindow = null;
8038 }
8039
8040 try {
8041 mPolicy.removeStartingWindow(token, view);
8042 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008043 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008044 }
8045 }
8046 } break;
8047
8048 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8049 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8050
8051 boolean nowVisible = msg.arg1 != 0;
8052 boolean nowGone = msg.arg2 != 0;
8053
8054 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008055 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008056 TAG, "Reporting visible in " + wtoken
8057 + " visible=" + nowVisible
8058 + " gone=" + nowGone);
8059 if (nowVisible) {
8060 wtoken.appToken.windowsVisible();
8061 } else {
8062 wtoken.appToken.windowsGone();
8063 }
8064 } catch (RemoteException ex) {
8065 }
8066 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008068 case WINDOW_FREEZE_TIMEOUT: {
8069 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008070 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008071 int i = mWindows.size();
8072 while (i > 0) {
8073 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008074 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008075 if (w.mOrientationChanging) {
8076 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008077 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008078 }
8079 }
8080 performLayoutAndPlaceSurfacesLocked();
8081 }
8082 break;
8083 }
Romain Guy06882f82009-06-10 13:36:04 -07008084
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008085 case HOLD_SCREEN_CHANGED: {
8086 Session oldHold;
8087 Session newHold;
8088 synchronized (mWindowMap) {
8089 oldHold = mLastReportedHold;
8090 newHold = (Session)msg.obj;
8091 mLastReportedHold = newHold;
8092 }
Romain Guy06882f82009-06-10 13:36:04 -07008093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008094 if (oldHold != newHold) {
8095 try {
8096 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008097 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008098 "window",
8099 BatteryStats.WAKE_TYPE_WINDOW);
8100 }
8101 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008102 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008103 "window",
8104 BatteryStats.WAKE_TYPE_WINDOW);
8105 }
8106 } catch (RemoteException e) {
8107 }
8108 }
8109 break;
8110 }
Romain Guy06882f82009-06-10 13:36:04 -07008111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008112 case APP_TRANSITION_TIMEOUT: {
8113 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008114 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008115 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008116 "*** APP TRANSITION TIMEOUT");
8117 mAppTransitionReady = true;
8118 mAppTransitionTimeout = true;
8119 performLayoutAndPlaceSurfacesLocked();
8120 }
8121 }
8122 break;
8123 }
Romain Guy06882f82009-06-10 13:36:04 -07008124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008125 case PERSIST_ANIMATION_SCALE: {
8126 Settings.System.putFloat(mContext.getContentResolver(),
8127 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8128 Settings.System.putFloat(mContext.getContentResolver(),
8129 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8130 break;
8131 }
Romain Guy06882f82009-06-10 13:36:04 -07008132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008133 case FORCE_GC: {
8134 synchronized(mWindowMap) {
8135 if (mAnimationPending) {
8136 // If we are animating, don't do the gc now but
8137 // delay a bit so we don't interrupt the animation.
8138 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8139 2000);
8140 return;
8141 }
8142 // If we are currently rotating the display, it will
8143 // schedule a new message when done.
8144 if (mDisplayFrozen) {
8145 return;
8146 }
8147 mFreezeGcPending = 0;
8148 }
8149 Runtime.getRuntime().gc();
8150 break;
8151 }
Romain Guy06882f82009-06-10 13:36:04 -07008152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008153 case ENABLE_SCREEN: {
8154 performEnableScreen();
8155 break;
8156 }
Romain Guy06882f82009-06-10 13:36:04 -07008157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008158 case APP_FREEZE_TIMEOUT: {
8159 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008160 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008161 int i = mAppTokens.size();
8162 while (i > 0) {
8163 i--;
8164 AppWindowToken tok = mAppTokens.get(i);
8165 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008166 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008167 unsetAppFreezingScreenLocked(tok, true, true);
8168 }
8169 }
8170 }
8171 break;
8172 }
Romain Guy06882f82009-06-10 13:36:04 -07008173
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008174 case SEND_NEW_CONFIGURATION: {
8175 removeMessages(SEND_NEW_CONFIGURATION);
8176 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008177 break;
8178 }
Romain Guy06882f82009-06-10 13:36:04 -07008179
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008180 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008181 if (mWindowsChanged) {
8182 synchronized (mWindowMap) {
8183 mWindowsChanged = false;
8184 }
8185 notifyWindowsChanged();
8186 }
8187 break;
8188 }
8189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008190 }
8191 }
8192 }
8193
8194 // -------------------------------------------------------------
8195 // IWindowManager API
8196 // -------------------------------------------------------------
8197
8198 public IWindowSession openSession(IInputMethodClient client,
8199 IInputContext inputContext) {
8200 if (client == null) throw new IllegalArgumentException("null client");
8201 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008202 Session session = new Session(client, inputContext);
8203 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008204 }
8205
8206 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8207 synchronized (mWindowMap) {
8208 // The focus for the client is the window immediately below
8209 // where we would place the input method window.
8210 int idx = findDesiredInputMethodWindowIndexLocked(false);
8211 WindowState imFocus;
8212 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008213 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008214 if (imFocus != null) {
8215 if (imFocus.mSession.mClient != null &&
8216 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8217 return true;
8218 }
8219 }
8220 }
8221 }
8222 return false;
8223 }
Romain Guy06882f82009-06-10 13:36:04 -07008224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008225 // -------------------------------------------------------------
8226 // Internals
8227 // -------------------------------------------------------------
8228
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008229 final WindowState windowForClientLocked(Session session, IWindow client,
8230 boolean throwOnError) {
8231 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008232 }
Romain Guy06882f82009-06-10 13:36:04 -07008233
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008234 final WindowState windowForClientLocked(Session session, IBinder client,
8235 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008236 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008237 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008238 TAG, "Looking up client " + client + ": " + win);
8239 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008240 RuntimeException ex = new IllegalArgumentException(
8241 "Requested window " + client + " does not exist");
8242 if (throwOnError) {
8243 throw ex;
8244 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008245 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008246 return null;
8247 }
8248 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008249 RuntimeException ex = new IllegalArgumentException(
8250 "Requested window " + client + " is in session " +
8251 win.mSession + ", not " + session);
8252 if (throwOnError) {
8253 throw ex;
8254 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008255 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008256 return null;
8257 }
8258
8259 return win;
8260 }
8261
Dianne Hackborna8f60182009-09-01 19:01:50 -07008262 final void rebuildAppWindowListLocked() {
8263 int NW = mWindows.size();
8264 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008265 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008266 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008267
Dianne Hackborna8f60182009-09-01 19:01:50 -07008268 // First remove all existing app windows.
8269 i=0;
8270 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008271 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008272 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008273 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008274 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008275 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008276 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008277 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008278 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008279 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008280 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8281 && lastWallpaper == i-1) {
8282 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008283 }
8284 i++;
8285 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008286
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008287 // The wallpaper window(s) typically live at the bottom of the stack,
8288 // so skip them before adding app tokens.
8289 lastWallpaper++;
8290 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008291
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008292 // First add all of the exiting app tokens... these are no longer
8293 // in the main app list, but still have windows shown. We put them
8294 // in the back because now that the animation is over we no longer
8295 // will care about them.
8296 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008297 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008298 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8299 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008300
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008301 // And add in the still active app tokens in Z order.
8302 NT = mAppTokens.size();
8303 for (int j=0; j<NT; j++) {
8304 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008305 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008306
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008307 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008308 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008309 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008310 + " windows but added " + i);
8311 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008312 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008314 private final void assignLayersLocked() {
8315 int N = mWindows.size();
8316 int curBaseLayer = 0;
8317 int curLayer = 0;
8318 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008320 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008321 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008322 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8323 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008324 curLayer += WINDOW_LAYER_MULTIPLIER;
8325 w.mLayer = curLayer;
8326 } else {
8327 curBaseLayer = curLayer = w.mBaseLayer;
8328 w.mLayer = curLayer;
8329 }
8330 if (w.mTargetAppToken != null) {
8331 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8332 } else if (w.mAppToken != null) {
8333 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8334 } else {
8335 w.mAnimLayer = w.mLayer;
8336 }
8337 if (w.mIsImWindow) {
8338 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008339 } else if (w.mIsWallpaper) {
8340 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008341 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008342 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008343 + w.mAnimLayer);
8344 //System.out.println(
8345 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8346 }
8347 }
8348
8349 private boolean mInLayout = false;
8350 private final void performLayoutAndPlaceSurfacesLocked() {
8351 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008352 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008353 throw new RuntimeException("Recursive call!");
8354 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008355 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008356 return;
8357 }
8358
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008359 if (mWaitingForConfig) {
8360 // Our configuration has changed (most likely rotation), but we
8361 // don't yet have the complete configuration to report to
8362 // applications. Don't do any window layout until we have it.
8363 return;
8364 }
8365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008366 boolean recoveringMemory = false;
8367 if (mForceRemoves != null) {
8368 recoveringMemory = true;
8369 // Wait a little it for things to settle down, and off we go.
8370 for (int i=0; i<mForceRemoves.size(); i++) {
8371 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008372 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008373 removeWindowInnerLocked(ws.mSession, ws);
8374 }
8375 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008376 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008377 Object tmp = new Object();
8378 synchronized (tmp) {
8379 try {
8380 tmp.wait(250);
8381 } catch (InterruptedException e) {
8382 }
8383 }
8384 }
Romain Guy06882f82009-06-10 13:36:04 -07008385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008386 mInLayout = true;
8387 try {
8388 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008390 int i = mPendingRemove.size()-1;
8391 if (i >= 0) {
8392 while (i >= 0) {
8393 WindowState w = mPendingRemove.get(i);
8394 removeWindowInnerLocked(w.mSession, w);
8395 i--;
8396 }
8397 mPendingRemove.clear();
8398
8399 mInLayout = false;
8400 assignLayersLocked();
8401 mLayoutNeeded = true;
8402 performLayoutAndPlaceSurfacesLocked();
8403
8404 } else {
8405 mInLayout = false;
8406 if (mLayoutNeeded) {
8407 requestAnimationLocked(0);
8408 }
8409 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008410 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008411 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8412 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008413 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008414 } catch (RuntimeException e) {
8415 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008416 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008417 }
8418 }
8419
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008420 private final int performLayoutLockedInner() {
8421 if (!mLayoutNeeded) {
8422 return 0;
8423 }
8424
8425 mLayoutNeeded = false;
8426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008427 final int dw = mDisplay.getWidth();
8428 final int dh = mDisplay.getHeight();
8429
8430 final int N = mWindows.size();
8431 int i;
8432
Joe Onorato8a9b2202010-02-26 18:56:32 -08008433 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008434 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8435
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008436 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008437
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008438 int seq = mLayoutSeq+1;
8439 if (seq < 0) seq = 0;
8440 mLayoutSeq = seq;
8441
8442 // First perform layout of any root windows (not attached
8443 // to another window).
8444 int topAttached = -1;
8445 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008446 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008447
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008448 // Don't do layout of a window if it is not visible, or
8449 // soon won't be visible, to avoid wasting time and funky
8450 // changes while a window is animating away.
8451 final AppWindowToken atoken = win.mAppToken;
8452 final boolean gone = win.mViewVisibility == View.GONE
8453 || !win.mRelayoutCalled
8454 || win.mRootToken.hidden
8455 || (atoken != null && atoken.hiddenRequested)
8456 || win.mAttachedHidden
8457 || win.mExiting || win.mDestroying;
8458
8459 if (!win.mLayoutAttached) {
8460 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
8461 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
8462 + " mLayoutAttached=" + win.mLayoutAttached);
8463 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
8464 + win.mViewVisibility + " mRelayoutCalled="
8465 + win.mRelayoutCalled + " hidden="
8466 + win.mRootToken.hidden + " hiddenRequested="
8467 + (atoken != null && atoken.hiddenRequested)
8468 + " mAttachedHidden=" + win.mAttachedHidden);
8469 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008470
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008471 // If this view is GONE, then skip it -- keep the current
8472 // frame, and let the caller know so they can ignore it
8473 // if they want. (We do the normal layout for INVISIBLE
8474 // windows, since that means "perform layout as normal,
8475 // just don't display").
8476 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008477 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008478 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8479 win.mLayoutSeq = seq;
8480 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8481 + win.mFrame + " mContainingFrame="
8482 + win.mContainingFrame + " mDisplayFrame="
8483 + win.mDisplayFrame);
8484 } else {
8485 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008486 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008487 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008488 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008489
8490 // Now perform layout of attached windows, which usually
8491 // depend on the position of the window they are attached to.
8492 // XXX does not deal with windows that are attached to windows
8493 // that are themselves attached.
8494 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008495 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008496
8497 // If this view is GONE, then skip it -- keep the current
8498 // frame, and let the caller know so they can ignore it
8499 // if they want. (We do the normal layout for INVISIBLE
8500 // windows, since that means "perform layout as normal,
8501 // just don't display").
8502 if (win.mLayoutAttached) {
8503 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
8504 + " mHaveFrame=" + win.mHaveFrame
8505 + " mViewVisibility=" + win.mViewVisibility
8506 + " mRelayoutCalled=" + win.mRelayoutCalled);
8507 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
8508 || !win.mHaveFrame) {
8509 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
8510 win.mLayoutSeq = seq;
8511 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8512 + win.mFrame + " mContainingFrame="
8513 + win.mContainingFrame + " mDisplayFrame="
8514 + win.mDisplayFrame);
8515 }
8516 }
8517 }
Jeff Brown349703e2010-06-22 01:27:15 -07008518
8519 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008520 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008521
8522 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008523 }
Romain Guy06882f82009-06-10 13:36:04 -07008524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008525 private final void performLayoutAndPlaceSurfacesLockedInner(
8526 boolean recoveringMemory) {
8527 final long currentTime = SystemClock.uptimeMillis();
8528 final int dw = mDisplay.getWidth();
8529 final int dh = mDisplay.getHeight();
8530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008531 int i;
8532
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008533 if (mFocusMayChange) {
8534 mFocusMayChange = false;
8535 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
8536 }
8537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008538 // Initialize state of exiting tokens.
8539 for (i=mExitingTokens.size()-1; i>=0; i--) {
8540 mExitingTokens.get(i).hasVisible = false;
8541 }
8542
8543 // Initialize state of exiting applications.
8544 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
8545 mExitingAppTokens.get(i).hasVisible = false;
8546 }
8547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008548 boolean orientationChangeComplete = true;
8549 Session holdScreen = null;
8550 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05008551 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008552 boolean focusDisplayed = false;
8553 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008554 boolean createWatermark = false;
8555
8556 if (mFxSession == null) {
8557 mFxSession = new SurfaceSession();
8558 createWatermark = true;
8559 }
8560
8561 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008562
8563 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008564
8565 if (createWatermark) {
8566 createWatermark();
8567 }
8568 if (mWatermark != null) {
8569 mWatermark.positionSurface(dw, dh);
8570 }
8571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008572 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008573 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008574 int repeats = 0;
8575 int changes = 0;
8576
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008577 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008578 repeats++;
8579 if (repeats > 6) {
8580 Slog.w(TAG, "Animation repeat aborted after too many iterations");
8581 mLayoutNeeded = false;
8582 break;
8583 }
8584
8585 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
8586 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
8587 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
8588 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
8589 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
8590 assignLayersLocked();
8591 mLayoutNeeded = true;
8592 }
8593 }
8594 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
8595 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
8596 if (updateOrientationFromAppTokensLocked()) {
8597 mLayoutNeeded = true;
8598 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
8599 }
8600 }
8601 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
8602 mLayoutNeeded = true;
8603 }
8604 }
8605
8606 // FIRST LOOP: Perform a layout, if needed.
8607 if (repeats < 4) {
8608 changes = performLayoutLockedInner();
8609 if (changes != 0) {
8610 continue;
8611 }
8612 } else {
8613 Slog.w(TAG, "Layout repeat skipped after too many iterations");
8614 changes = 0;
8615 }
8616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008617 final int transactionSequence = ++mTransactionSequence;
8618
8619 // Update animations of all applications, including those
8620 // associated with exiting/removed apps
8621 boolean tokensAnimating = false;
8622 final int NAT = mAppTokens.size();
8623 for (i=0; i<NAT; i++) {
8624 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8625 tokensAnimating = true;
8626 }
8627 }
8628 final int NEAT = mExitingAppTokens.size();
8629 for (i=0; i<NEAT; i++) {
8630 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8631 tokensAnimating = true;
8632 }
8633 }
8634
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008635 // SECOND LOOP: Execute animations and update visibility of windows.
8636
Joe Onorato8a9b2202010-02-26 18:56:32 -08008637 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008638 + transactionSequence + " tokensAnimating="
8639 + tokensAnimating);
8640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008641 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008642
8643 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008644 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008645 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008646
8647 mPolicy.beginAnimationLw(dw, dh);
8648
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008649 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008651 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008652 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008653
8654 final WindowManager.LayoutParams attrs = w.mAttrs;
8655
8656 if (w.mSurface != null) {
8657 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008658 if (w.commitFinishDrawingLocked(currentTime)) {
8659 if ((w.mAttrs.flags
8660 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008661 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008662 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008663 wallpaperMayChange = true;
8664 }
8665 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008666
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008667 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008668 if (w.stepAnimationLocked(currentTime, dw, dh)) {
8669 animating = true;
8670 //w.dump(" ");
8671 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008672 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
8673 wallpaperMayChange = true;
8674 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008675
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008676 if (mPolicy.doesForceHide(w, attrs)) {
8677 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008678 if (DEBUG_VISIBILITY) Slog.v(TAG,
8679 "Animation done that could impact force hide: "
8680 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008681 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008682 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008683 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
8684 forceHiding = true;
8685 }
8686 } else if (mPolicy.canBeForceHidden(w, attrs)) {
8687 boolean changed;
8688 if (forceHiding) {
8689 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008690 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8691 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008692 } else {
8693 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008694 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8695 "Now policy shown: " + w);
8696 if (changed) {
8697 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008698 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008699 // Assume we will need to animate. If
8700 // we don't (because the wallpaper will
8701 // stay with the lock screen), then we will
8702 // clean up later.
8703 Animation a = mPolicy.createForceHideEnterAnimation();
8704 if (a != null) {
8705 w.setAnimation(a);
8706 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008707 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008708 if (mCurrentFocus == null ||
8709 mCurrentFocus.mLayer < w.mLayer) {
8710 // We are showing on to of the current
8711 // focus, so re-evaluate focus to make
8712 // sure it is correct.
8713 mFocusMayChange = true;
8714 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008715 }
8716 }
8717 if (changed && (attrs.flags
8718 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
8719 wallpaperMayChange = true;
8720 }
8721 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008722
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008723 mPolicy.animatingWindowLw(w, attrs);
8724 }
8725
8726 final AppWindowToken atoken = w.mAppToken;
8727 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
8728 if (atoken.lastTransactionSequence != transactionSequence) {
8729 atoken.lastTransactionSequence = transactionSequence;
8730 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
8731 atoken.startingDisplayed = false;
8732 }
8733 if ((w.isOnScreen() || w.mAttrs.type
8734 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
8735 && !w.mExiting && !w.mDestroying) {
8736 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008737 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008738 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008739 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008740 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008741 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008742 + " pv=" + w.mPolicyVisibility
8743 + " dp=" + w.mDrawPending
8744 + " cdp=" + w.mCommitDrawPending
8745 + " ah=" + w.mAttachedHidden
8746 + " th=" + atoken.hiddenRequested
8747 + " a=" + w.mAnimating);
8748 }
8749 }
8750 if (w != atoken.startingWindow) {
8751 if (!atoken.freezingScreen || !w.mAppFreezing) {
8752 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008753 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008754 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008755 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008756 "tokenMayBeDrawn: " + atoken
8757 + " freezingScreen=" + atoken.freezingScreen
8758 + " mAppFreezing=" + w.mAppFreezing);
8759 tokenMayBeDrawn = true;
8760 }
8761 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008762 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008763 atoken.startingDisplayed = true;
8764 }
8765 }
8766 } else if (w.mReadyToShow) {
8767 w.performShowLocked();
8768 }
8769 }
8770
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008771 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008772
8773 if (tokenMayBeDrawn) {
8774 // See if any windows have been drawn, so they (and others
8775 // associated with them) can now be shown.
8776 final int NT = mTokenList.size();
8777 for (i=0; i<NT; i++) {
8778 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
8779 if (wtoken == null) {
8780 continue;
8781 }
8782 if (wtoken.freezingScreen) {
8783 int numInteresting = wtoken.numInterestingWindows;
8784 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008785 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008786 "allDrawn: " + wtoken
8787 + " interesting=" + numInteresting
8788 + " drawn=" + wtoken.numDrawnWindows);
8789 wtoken.showAllWindowsLocked();
8790 unsetAppFreezingScreenLocked(wtoken, false, true);
8791 orientationChangeComplete = true;
8792 }
8793 } else if (!wtoken.allDrawn) {
8794 int numInteresting = wtoken.numInterestingWindows;
8795 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008796 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008797 "allDrawn: " + wtoken
8798 + " interesting=" + numInteresting
8799 + " drawn=" + wtoken.numDrawnWindows);
8800 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008801 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008802
8803 // We can now show all of the drawn windows!
8804 if (!mOpeningApps.contains(wtoken)) {
8805 wtoken.showAllWindowsLocked();
8806 }
8807 }
8808 }
8809 }
8810 }
8811
8812 // If we are ready to perform an app transition, check through
8813 // all of the app tokens to be shown and see if they are ready
8814 // to go.
8815 if (mAppTransitionReady) {
8816 int NN = mOpeningApps.size();
8817 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008818 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008819 "Checking " + NN + " opening apps (frozen="
8820 + mDisplayFrozen + " timeout="
8821 + mAppTransitionTimeout + ")...");
8822 if (!mDisplayFrozen && !mAppTransitionTimeout) {
8823 // If the display isn't frozen, wait to do anything until
8824 // all of the apps are ready. Otherwise just go because
8825 // we'll unfreeze the display when everyone is ready.
8826 for (i=0; i<NN && goodToGo; i++) {
8827 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008828 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008829 "Check opening app" + wtoken + ": allDrawn="
8830 + wtoken.allDrawn + " startingDisplayed="
8831 + wtoken.startingDisplayed);
8832 if (!wtoken.allDrawn && !wtoken.startingDisplayed
8833 && !wtoken.startingMoved) {
8834 goodToGo = false;
8835 }
8836 }
8837 }
8838 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008839 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008840 int transit = mNextAppTransition;
8841 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008842 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008843 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008844 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008845 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008846 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008847 mAppTransitionTimeout = false;
8848 mStartingIconInTransition = false;
8849 mSkipAppTransitionAnimation = false;
8850
8851 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
8852
Dianne Hackborna8f60182009-09-01 19:01:50 -07008853 // If there are applications waiting to come to the
8854 // top of the stack, now is the time to move their windows.
8855 // (Note that we don't do apps going to the bottom
8856 // here -- we want to keep their windows in the old
8857 // Z-order until the animation completes.)
8858 if (mToTopApps.size() > 0) {
8859 NN = mAppTokens.size();
8860 for (i=0; i<NN; i++) {
8861 AppWindowToken wtoken = mAppTokens.get(i);
8862 if (wtoken.sendingToTop) {
8863 wtoken.sendingToTop = false;
8864 moveAppWindowsLocked(wtoken, NN, false);
8865 }
8866 }
8867 mToTopApps.clear();
8868 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008869
Dianne Hackborn25994b42009-09-04 14:21:19 -07008870 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008871
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008872 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008873 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008874
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008875 // The top-most window will supply the layout params,
8876 // and we will determine it below.
8877 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008878 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008879 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008880
Joe Onorato8a9b2202010-02-26 18:56:32 -08008881 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008882 "New wallpaper target=" + mWallpaperTarget
8883 + ", lower target=" + mLowerWallpaperTarget
8884 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07008885 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008886 // Do a first pass through the tokens for two
8887 // things:
8888 // (1) Determine if both the closing and opening
8889 // app token sets are wallpaper targets, in which
8890 // case special animations are needed
8891 // (since the wallpaper needs to stay static
8892 // behind them).
8893 // (2) Find the layout params of the top-most
8894 // application window in the tokens, which is
8895 // what will control the animation theme.
8896 final int NC = mClosingApps.size();
8897 NN = NC + mOpeningApps.size();
8898 for (i=0; i<NN; i++) {
8899 AppWindowToken wtoken;
8900 int mode;
8901 if (i < NC) {
8902 wtoken = mClosingApps.get(i);
8903 mode = 1;
8904 } else {
8905 wtoken = mOpeningApps.get(i-NC);
8906 mode = 2;
8907 }
8908 if (mLowerWallpaperTarget != null) {
8909 if (mLowerWallpaperTarget.mAppToken == wtoken
8910 || mUpperWallpaperTarget.mAppToken == wtoken) {
8911 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008912 }
8913 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008914 if (wtoken.appFullscreen) {
8915 WindowState ws = wtoken.findMainWindow();
8916 if (ws != null) {
8917 // If this is a compatibility mode
8918 // window, we will always use its anim.
8919 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
8920 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008921 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008922 bestAnimLayer = Integer.MAX_VALUE;
8923 } else if (ws.mLayer > bestAnimLayer) {
8924 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008925 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008926 bestAnimLayer = ws.mLayer;
8927 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07008928 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008929 }
8930 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008931
Dianne Hackborn25994b42009-09-04 14:21:19 -07008932 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008933 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008934 "Wallpaper animation!");
8935 switch (transit) {
8936 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
8937 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
8938 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
8939 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
8940 break;
8941 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
8942 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
8943 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
8944 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
8945 break;
8946 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008947 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008948 "New transit: " + transit);
8949 } else if (oldWallpaper != null) {
8950 // We are transitioning from an activity with
8951 // a wallpaper to one without.
8952 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008953 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008954 "New transit away from wallpaper: " + transit);
8955 } else if (mWallpaperTarget != null) {
8956 // We are transitioning from an activity without
8957 // a wallpaper to now showing the wallpaper
8958 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008959 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008960 "New transit into wallpaper: " + transit);
8961 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008962
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008963 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
8964 mLastEnterAnimToken = animToken;
8965 mLastEnterAnimParams = animLp;
8966 } else if (mLastEnterAnimParams != null) {
8967 animLp = mLastEnterAnimParams;
8968 mLastEnterAnimToken = null;
8969 mLastEnterAnimParams = null;
8970 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008971
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008972 // If all closing windows are obscured, then there is
8973 // no need to do an animation. This is the case, for
8974 // example, when this transition is being done behind
8975 // the lock screen.
8976 if (!mPolicy.allowAppAnimationsLw()) {
8977 animLp = null;
8978 }
8979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008980 NN = mOpeningApps.size();
8981 for (i=0; i<NN; i++) {
8982 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008983 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008984 "Now opening app" + wtoken);
8985 wtoken.reportedVisible = false;
8986 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008987 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008988 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008989 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008990 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008991 wtoken.showAllWindowsLocked();
8992 }
8993 NN = mClosingApps.size();
8994 for (i=0; i<NN; i++) {
8995 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008996 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008997 "Now closing app" + wtoken);
8998 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008999 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009000 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009001 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009002 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009003 // Force the allDrawn flag, because we want to start
9004 // this guy's animations regardless of whether it's
9005 // gotten drawn.
9006 wtoken.allDrawn = true;
9007 }
9008
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009009 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009010
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009011 mOpeningApps.clear();
9012 mClosingApps.clear();
9013
9014 // This has changed the visibility of windows, so perform
9015 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009016 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009017 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009018 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9019 assignLayersLocked();
9020 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009021 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009022 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009023 }
9024 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009025
Dianne Hackborn16064f92010-03-25 00:47:24 -07009026 int adjResult = 0;
9027
Dianne Hackborna8f60182009-09-01 19:01:50 -07009028 if (!animating && mAppTransitionRunning) {
9029 // We have finished the animation of an app transition. To do
9030 // this, we have delayed a lot of operations like showing and
9031 // hiding apps, moving apps in Z-order, etc. The app token list
9032 // reflects the correct Z-order, but the window list may now
9033 // be out of sync with it. So here we will just rebuild the
9034 // entire app window list. Fun!
9035 mAppTransitionRunning = false;
9036 // Clear information about apps that were moving.
9037 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009038
Dianne Hackborna8f60182009-09-01 19:01:50 -07009039 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009040 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009041 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009042 moveInputMethodWindowsIfNeededLocked(false);
9043 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009044 // Since the window list has been rebuilt, focus might
9045 // have to be recomputed since the actual order of windows
9046 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009047 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009048 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009049
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009050 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009051 // At this point, there was a window with a wallpaper that
9052 // was force hiding other windows behind it, but now it
9053 // is going away. This may be simple -- just animate
9054 // away the wallpaper and its window -- or it may be
9055 // hard -- the wallpaper now needs to be shown behind
9056 // something that was hidden.
9057 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009058 if (mLowerWallpaperTarget != null
9059 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009060 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009061 "wallpaperForceHiding changed with lower="
9062 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009063 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009064 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9065 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9066 if (mLowerWallpaperTarget.mAppToken.hidden) {
9067 // The lower target has become hidden before we
9068 // actually started the animation... let's completely
9069 // re-evaluate everything.
9070 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009071 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009072 }
9073 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009074 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009075 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009076 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009077 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009078 + " NEW: " + mWallpaperTarget
9079 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009080 if (mLowerWallpaperTarget == null) {
9081 // Whoops, we don't need a special wallpaper animation.
9082 // Clear them out.
9083 forceHiding = false;
9084 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009085 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009086 if (w.mSurface != null) {
9087 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009088 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009089 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009090 forceHiding = true;
9091 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9092 if (!w.mAnimating) {
9093 // We set the animation above so it
9094 // is not yet running.
9095 w.clearAnimation();
9096 }
9097 }
9098 }
9099 }
9100 }
9101 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009102
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009103 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009104 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009105 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009106 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009107 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009108
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009109 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009110 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009111 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009112 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009113 assignLayersLocked();
9114 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009115 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009116 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009117 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009118 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009119
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009120 if (mFocusMayChange) {
9121 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009122 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009123 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009124 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009125 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009126 }
9127
9128 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009129 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009130 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009131
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009132 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9133 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009134
Jeff Browne33348b2010-07-15 23:54:05 -07009135 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009136 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009137
9138 // THIRD LOOP: Update the surfaces of all windows.
9139
9140 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9141
9142 boolean obscured = false;
9143 boolean blurring = false;
9144 boolean dimming = false;
9145 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009146 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009147 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009148
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009149 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009151 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009152 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009153
9154 boolean displayed = false;
9155 final WindowManager.LayoutParams attrs = w.mAttrs;
9156 final int attrFlags = attrs.flags;
9157
9158 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009159 // XXX NOTE: The logic here could be improved. We have
9160 // the decision about whether to resize a window separated
9161 // from whether to hide the surface. This can cause us to
9162 // resize a surface even if we are going to hide it. You
9163 // can see this by (1) holding device in landscape mode on
9164 // home screen; (2) tapping browser icon (device will rotate
9165 // to landscape; (3) tap home. The wallpaper will be resized
9166 // in step 2 but then immediately hidden, causing us to
9167 // have to resize and then redraw it again in step 3. It
9168 // would be nice to figure out how to avoid this, but it is
9169 // difficult because we do need to resize surfaces in some
9170 // cases while they are hidden such as when first showing a
9171 // window.
9172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009173 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009174 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009175 TAG, "Placing surface #" + i + " " + w.mSurface
9176 + ": new=" + w.mShownFrame + ", old="
9177 + w.mLastShownFrame);
9178
9179 boolean resize;
9180 int width, height;
9181 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9182 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9183 w.mLastRequestedHeight != w.mRequestedHeight;
9184 // for a scaled surface, we just want to use
9185 // the requested size.
9186 width = w.mRequestedWidth;
9187 height = w.mRequestedHeight;
9188 w.mLastRequestedWidth = width;
9189 w.mLastRequestedHeight = height;
9190 w.mLastShownFrame.set(w.mShownFrame);
9191 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009192 if (SHOW_TRANSACTIONS) logSurface(w,
9193 "POS " + w.mShownFrame.left
9194 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009195 w.mSurfaceX = w.mShownFrame.left;
9196 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009197 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9198 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009199 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009200 if (!recoveringMemory) {
9201 reclaimSomeSurfaceMemoryLocked(w, "position");
9202 }
9203 }
9204 } else {
9205 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9206 width = w.mShownFrame.width();
9207 height = w.mShownFrame.height();
9208 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009209 }
9210
9211 if (resize) {
9212 if (width < 1) width = 1;
9213 if (height < 1) height = 1;
9214 if (w.mSurface != null) {
9215 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009216 if (SHOW_TRANSACTIONS) logSurface(w,
9217 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009218 + w.mShownFrame.top + " SIZE "
9219 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009220 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009221 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009222 w.mSurfaceW = width;
9223 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009224 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009225 w.mSurfaceX = w.mShownFrame.left;
9226 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009227 w.mSurface.setPosition(w.mShownFrame.left,
9228 w.mShownFrame.top);
9229 } catch (RuntimeException e) {
9230 // If something goes wrong with the surface (such
9231 // as running out of memory), don't take down the
9232 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009233 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009234 + "size=(" + width + "x" + height
9235 + "), pos=(" + w.mShownFrame.left
9236 + "," + w.mShownFrame.top + ")", e);
9237 if (!recoveringMemory) {
9238 reclaimSomeSurfaceMemoryLocked(w, "size");
9239 }
9240 }
9241 }
9242 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009243 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009244 w.mContentInsetsChanged =
9245 !w.mLastContentInsets.equals(w.mContentInsets);
9246 w.mVisibleInsetsChanged =
9247 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009248 boolean configChanged =
9249 w.mConfiguration != mCurConfiguration
9250 && (w.mConfiguration == null
9251 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009252 if (DEBUG_CONFIGURATION && configChanged) {
9253 Slog.v(TAG, "Win " + w + " config changed: "
9254 + mCurConfiguration);
9255 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009256 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009257 + ": configChanged=" + configChanged
9258 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009259 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009260 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009261 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009262 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009263 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009264 w.mLastFrame.set(w.mFrame);
9265 w.mLastContentInsets.set(w.mContentInsets);
9266 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009267 // If the screen is currently frozen, then keep
9268 // it frozen until this window draws at its new
9269 // orientation.
9270 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009271 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009272 "Resizing while display frozen: " + w);
9273 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009274 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009275 mWindowsFreezingScreen = true;
9276 // XXX should probably keep timeout from
9277 // when we first froze the display.
9278 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9279 mH.sendMessageDelayed(mH.obtainMessage(
9280 H.WINDOW_FREEZE_TIMEOUT), 2000);
9281 }
9282 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009283 // If the orientation is changing, then we need to
9284 // hold off on unfreezing the display until this
9285 // window has been redrawn; to do that, we need
9286 // to go through the process of getting informed
9287 // by the application when it has finished drawing.
9288 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009289 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009290 "Orientation start waiting for draw in "
9291 + w + ", surface " + w.mSurface);
9292 w.mDrawPending = true;
9293 w.mCommitDrawPending = false;
9294 w.mReadyToShow = false;
9295 if (w.mAppToken != null) {
9296 w.mAppToken.allDrawn = false;
9297 }
9298 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009299 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009300 "Resizing window " + w + " to " + w.mFrame);
9301 mResizingWindows.add(w);
9302 } else if (w.mOrientationChanging) {
9303 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009304 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009305 "Orientation not waiting for draw in "
9306 + w + ", surface " + w.mSurface);
9307 w.mOrientationChanging = false;
9308 }
9309 }
9310 }
9311
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009312 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009313 if (!w.mLastHidden) {
9314 //dump();
Dianne Hackborn5943c202010-04-12 21:36:49 -07009315 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Window hiding: waitingToShow="
9316 + w.mRootToken.waitingToShow + " polvis="
9317 + w.mPolicyVisibility + " atthid="
9318 + w.mAttachedHidden + " tokhid="
9319 + w.mRootToken.hidden + " vis="
9320 + w.mViewVisibility);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009321 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009322 if (SHOW_TRANSACTIONS) logSurface(w,
9323 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009324 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009325 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009326 try {
9327 w.mSurface.hide();
9328 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009329 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009330 }
9331 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009332 }
9333 // If we are waiting for this window to handle an
9334 // orientation change, well, it is hidden, so
9335 // doesn't really matter. Note that this does
9336 // introduce a potential glitch if the window
9337 // becomes unhidden before it has drawn for the
9338 // new orientation.
9339 if (w.mOrientationChanging) {
9340 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009341 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009342 "Orientation change skips hidden " + w);
9343 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009344 } else if (w.mLastLayer != w.mAnimLayer
9345 || w.mLastAlpha != w.mShownAlpha
9346 || w.mLastDsDx != w.mDsDx
9347 || w.mLastDtDx != w.mDtDx
9348 || w.mLastDsDy != w.mDsDy
9349 || w.mLastDtDy != w.mDtDy
9350 || w.mLastHScale != w.mHScale
9351 || w.mLastVScale != w.mVScale
9352 || w.mLastHidden) {
9353 displayed = true;
9354 w.mLastAlpha = w.mShownAlpha;
9355 w.mLastLayer = w.mAnimLayer;
9356 w.mLastDsDx = w.mDsDx;
9357 w.mLastDtDx = w.mDtDx;
9358 w.mLastDsDy = w.mDsDy;
9359 w.mLastDtDy = w.mDtDy;
9360 w.mLastHScale = w.mHScale;
9361 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009362 if (SHOW_TRANSACTIONS) logSurface(w,
9363 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009364 + " matrix=[" + (w.mDsDx*w.mHScale)
9365 + "," + (w.mDtDx*w.mVScale)
9366 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009367 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009368 if (w.mSurface != null) {
9369 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009370 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009371 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009372 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009373 w.mSurface.setLayer(w.mAnimLayer);
9374 w.mSurface.setMatrix(
9375 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9376 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9377 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009378 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009379 if (!recoveringMemory) {
9380 reclaimSomeSurfaceMemoryLocked(w, "update");
9381 }
9382 }
9383 }
9384
9385 if (w.mLastHidden && !w.mDrawPending
9386 && !w.mCommitDrawPending
9387 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009388 if (SHOW_TRANSACTIONS) logSurface(w,
9389 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009390 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009391 + " during relayout");
9392 if (showSurfaceRobustlyLocked(w)) {
9393 w.mHasDrawn = true;
9394 w.mLastHidden = false;
9395 } else {
9396 w.mOrientationChanging = false;
9397 }
9398 }
9399 if (w.mSurface != null) {
9400 w.mToken.hasVisible = true;
9401 }
9402 } else {
9403 displayed = true;
9404 }
9405
9406 if (displayed) {
9407 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009408 if (attrs.width == LayoutParams.MATCH_PARENT
9409 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009410 covered = true;
9411 }
9412 }
9413 if (w.mOrientationChanging) {
9414 if (w.mDrawPending || w.mCommitDrawPending) {
9415 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009416 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009417 "Orientation continue waiting for draw in " + w);
9418 } else {
9419 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009420 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009421 "Orientation change complete in " + w);
9422 }
9423 }
9424 w.mToken.hasVisible = true;
9425 }
9426 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009427 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009428 "Orientation change skips hidden " + w);
9429 w.mOrientationChanging = false;
9430 }
9431
9432 final boolean canBeSeen = w.isDisplayedLw();
9433
9434 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9435 focusDisplayed = true;
9436 }
9437
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009438 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009440 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009441 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009442 if (w.mSurface != null) {
9443 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9444 holdScreen = w.mSession;
9445 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009446 if (!syswin && w.mAttrs.screenBrightness >= 0
9447 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009448 screenBrightness = w.mAttrs.screenBrightness;
9449 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009450 if (!syswin && w.mAttrs.buttonBrightness >= 0
9451 && buttonBrightness < 0) {
9452 buttonBrightness = w.mAttrs.buttonBrightness;
9453 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05009454 if (canBeSeen
9455 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9456 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9457 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009458 syswin = true;
9459 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009460 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009461
Dianne Hackborn25994b42009-09-04 14:21:19 -07009462 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
9463 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009464 // This window completely covers everything behind it,
9465 // so we want to leave all of them as unblurred (for
9466 // performance reasons).
9467 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009468 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009469 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009470 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009471 obscured = true;
9472 if (mBackgroundFillerSurface == null) {
9473 try {
9474 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009475 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009476 0, dw, dh,
9477 PixelFormat.OPAQUE,
9478 Surface.FX_SURFACE_NORMAL);
9479 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009480 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009481 }
9482 }
9483 try {
9484 mBackgroundFillerSurface.setPosition(0, 0);
9485 mBackgroundFillerSurface.setSize(dw, dh);
9486 // Using the same layer as Dim because they will never be shown at the
9487 // same time.
9488 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9489 mBackgroundFillerSurface.show();
9490 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009491 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009492 }
9493 backgroundFillerShown = true;
9494 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009495 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009496 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009497 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009498 + ": blurring=" + blurring
9499 + " obscured=" + obscured
9500 + " displayed=" + displayed);
9501 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9502 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009503 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009504 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009505 if (mDimAnimator == null) {
9506 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009507 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009508 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009509 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009510 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009511 }
9512 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
9513 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009514 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009515 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009516 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009517 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009518 + mBlurSurface + ": CREATE");
9519 try {
Romain Guy06882f82009-06-10 13:36:04 -07009520 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009521 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009522 -1, 16, 16,
9523 PixelFormat.OPAQUE,
9524 Surface.FX_SURFACE_BLUR);
9525 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009526 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009527 }
9528 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009529 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009530 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9531 + mBlurSurface + ": pos=(0,0) (" +
9532 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009533 mBlurSurface.setPosition(0, 0);
9534 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009535 mBlurSurface.setLayer(w.mAnimLayer-2);
9536 if (!mBlurShown) {
9537 try {
9538 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9539 + mBlurSurface + ": SHOW");
9540 mBlurSurface.show();
9541 } catch (RuntimeException e) {
9542 Slog.w(TAG, "Failure showing blur surface", e);
9543 }
9544 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009545 }
9546 }
9547 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009548 }
9549 }
9550 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009551
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009552 if (obscuredChanged && mWallpaperTarget == w) {
9553 // This is the wallpaper target and its obscured state
9554 // changed... make sure the current wallaper's visibility
9555 // has been updated accordingly.
9556 updateWallpaperVisibilityLocked();
9557 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009558 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009559
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009560 if (backgroundFillerShown == false && mBackgroundFillerShown) {
9561 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009562 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009563 try {
9564 mBackgroundFillerSurface.hide();
9565 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009566 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009567 }
9568 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009569
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009570 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009571 animating |= mDimAnimator.updateSurface(dimming, currentTime,
9572 mDisplayFrozen || !mPolicy.isScreenOn());
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 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009576 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009577 + ": HIDE");
9578 try {
9579 mBlurSurface.hide();
9580 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009581 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009582 }
9583 mBlurShown = false;
9584 }
9585
Joe Onorato8a9b2202010-02-26 18:56:32 -08009586 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009587 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009588 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009589 }
9590
Jeff Browne33348b2010-07-15 23:54:05 -07009591 mInputMonitor.updateInputWindowsLw();
9592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009593 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -07009594
Dianne Hackbornb9fb1702010-08-23 16:49:02 -07009595 if (mWatermark != null) {
9596 mWatermark.drawIfNeeded();
9597 }
9598
Joe Onorato8a9b2202010-02-26 18:56:32 -08009599 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009600 "With display frozen, orientationChangeComplete="
9601 + orientationChangeComplete);
9602 if (orientationChangeComplete) {
9603 if (mWindowsFreezingScreen) {
9604 mWindowsFreezingScreen = false;
9605 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9606 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009607 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009608 }
Romain Guy06882f82009-06-10 13:36:04 -07009609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009610 i = mResizingWindows.size();
9611 if (i > 0) {
9612 do {
9613 i--;
9614 WindowState win = mResizingWindows.get(i);
9615 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009616 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
9617 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009618 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009619 boolean configChanged =
9620 win.mConfiguration != mCurConfiguration
9621 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009622 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
9623 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
9624 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009625 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009626 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009627 + " / " + mCurConfiguration + " / 0x"
9628 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009629 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009630 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009631 win.mClient.resized(win.mFrame.width(),
9632 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009633 win.mLastVisibleInsets, win.mDrawPending,
9634 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009635 win.mContentInsetsChanged = false;
9636 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009637 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009638 } catch (RemoteException e) {
9639 win.mOrientationChanging = false;
9640 }
9641 } while (i > 0);
9642 mResizingWindows.clear();
9643 }
Romain Guy06882f82009-06-10 13:36:04 -07009644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009645 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009646 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009647 i = mDestroySurface.size();
9648 if (i > 0) {
9649 do {
9650 i--;
9651 WindowState win = mDestroySurface.get(i);
9652 win.mDestroying = false;
9653 if (mInputMethodWindow == win) {
9654 mInputMethodWindow = null;
9655 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009656 if (win == mWallpaperTarget) {
9657 wallpaperDestroyed = true;
9658 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009659 win.destroySurfaceLocked();
9660 } while (i > 0);
9661 mDestroySurface.clear();
9662 }
9663
9664 // Time to remove any exiting tokens?
9665 for (i=mExitingTokens.size()-1; i>=0; i--) {
9666 WindowToken token = mExitingTokens.get(i);
9667 if (!token.hasVisible) {
9668 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07009669 if (token.windowType == TYPE_WALLPAPER) {
9670 mWallpaperTokens.remove(token);
9671 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009672 }
9673 }
9674
9675 // Time to remove any exiting applications?
9676 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9677 AppWindowToken token = mExitingAppTokens.get(i);
9678 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009679 // Make sure there is no animation running on this token,
9680 // so any windows associated with it will be removed as
9681 // soon as their animations are complete
9682 token.animation = null;
9683 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009684 mAppTokens.remove(token);
9685 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009686 if (mLastEnterAnimToken == token) {
9687 mLastEnterAnimToken = null;
9688 mLastEnterAnimParams = null;
9689 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009690 }
9691 }
9692
Dianne Hackborna8f60182009-09-01 19:01:50 -07009693 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009694
Dianne Hackborna8f60182009-09-01 19:01:50 -07009695 if (!animating && mAppTransitionRunning) {
9696 // We have finished the animation of an app transition. To do
9697 // this, we have delayed a lot of operations like showing and
9698 // hiding apps, moving apps in Z-order, etc. The app token list
9699 // reflects the correct Z-order, but the window list may now
9700 // be out of sync with it. So here we will just rebuild the
9701 // entire app window list. Fun!
9702 mAppTransitionRunning = false;
9703 needRelayout = true;
9704 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009705 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009706 // Clear information about apps that were moving.
9707 mToBottomApps.clear();
9708 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009710 if (focusDisplayed) {
9711 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
9712 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009713 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009714 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009715 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009716 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009717 requestAnimationLocked(0);
9718 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009719 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
9720 }
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009721
Jeff Browne33348b2010-07-15 23:54:05 -07009722 mInputMonitor.updateInputWindowsLw();
9723
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009724 if (DEBUG_FREEZE) Slog.v(TAG, "Layout: mDisplayFrozen=" + mDisplayFrozen
9725 + " holdScreen=" + holdScreen);
9726 if (!mDisplayFrozen) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009727 setHoldScreenLocked(holdScreen != null);
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009728 if (screenBrightness < 0 || screenBrightness > 1.0f) {
9729 mPowerManager.setScreenBrightnessOverride(-1);
9730 } else {
9731 mPowerManager.setScreenBrightnessOverride((int)
9732 (screenBrightness * Power.BRIGHTNESS_ON));
9733 }
9734 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
9735 mPowerManager.setButtonBrightnessOverride(-1);
9736 } else {
9737 mPowerManager.setButtonBrightnessOverride((int)
9738 (buttonBrightness * Power.BRIGHTNESS_ON));
9739 }
9740 if (holdScreen != mHoldingScreenOn) {
9741 mHoldingScreenOn = holdScreen;
9742 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
9743 mH.sendMessage(m);
9744 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009745 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009746
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009747 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009748 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009749 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
9750 LocalPowerManager.BUTTON_EVENT, true);
9751 mTurnOnScreen = false;
9752 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08009753
9754 // Check to see if we are now in a state where the screen should
9755 // be enabled, because the window obscured flags have changed.
9756 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009757 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009758
9759 /**
9760 * Must be called with the main window manager lock held.
9761 */
9762 void setHoldScreenLocked(boolean holding) {
9763 boolean state = mHoldingScreenWakeLock.isHeld();
9764 if (holding != state) {
9765 if (holding) {
9766 mHoldingScreenWakeLock.acquire();
9767 } else {
9768 mPolicy.screenOnStoppedLw();
9769 mHoldingScreenWakeLock.release();
9770 }
9771 }
9772 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009773
9774 void requestAnimationLocked(long delay) {
9775 if (!mAnimationPending) {
9776 mAnimationPending = true;
9777 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
9778 }
9779 }
Romain Guy06882f82009-06-10 13:36:04 -07009780
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009781 /**
9782 * Have the surface flinger show a surface, robustly dealing with
9783 * error conditions. In particular, if there is not enough memory
9784 * to show the surface, then we will try to get rid of other surfaces
9785 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -07009786 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009787 * @return Returns true if the surface was successfully shown.
9788 */
9789 boolean showSurfaceRobustlyLocked(WindowState win) {
9790 try {
9791 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009792 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009793 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009794 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009795 if (DEBUG_VISIBILITY) Slog.v(TAG,
9796 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009797 win.mTurnOnScreen = false;
9798 mTurnOnScreen = true;
9799 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009800 }
9801 return true;
9802 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009803 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009804 }
Romain Guy06882f82009-06-10 13:36:04 -07009805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009806 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -07009807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009808 return false;
9809 }
Romain Guy06882f82009-06-10 13:36:04 -07009810
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009811 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
9812 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -07009813
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009814 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009815 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -07009816
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009817 if (mForceRemoves == null) {
9818 mForceRemoves = new ArrayList<WindowState>();
9819 }
Romain Guy06882f82009-06-10 13:36:04 -07009820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009821 long callingIdentity = Binder.clearCallingIdentity();
9822 try {
9823 // There was some problem... first, do a sanity check of the
9824 // window list to make sure we haven't left any dangling surfaces
9825 // around.
9826 int N = mWindows.size();
9827 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009828 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009829 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009830 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009831 if (ws.mSurface != null) {
9832 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009833 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009834 + ws + " surface=" + ws.mSurface
9835 + " token=" + win.mToken
9836 + " pid=" + ws.mSession.mPid
9837 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009838 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009839 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009840 ws.mSurface = null;
9841 mForceRemoves.add(ws);
9842 i--;
9843 N--;
9844 leakedSurface = true;
9845 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009846 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009847 + ws + " surface=" + ws.mSurface
9848 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009849 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009850 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009851 ws.mSurface = null;
9852 leakedSurface = true;
9853 }
9854 }
9855 }
Romain Guy06882f82009-06-10 13:36:04 -07009856
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009857 boolean killedApps = false;
9858 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009859 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009860 SparseIntArray pidCandidates = new SparseIntArray();
9861 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009862 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009863 if (ws.mSurface != null) {
9864 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
9865 }
9866 }
9867 if (pidCandidates.size() > 0) {
9868 int[] pids = new int[pidCandidates.size()];
9869 for (int i=0; i<pids.length; i++) {
9870 pids[i] = pidCandidates.keyAt(i);
9871 }
9872 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -07009873 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009874 killedApps = true;
9875 }
9876 } catch (RemoteException e) {
9877 }
9878 }
9879 }
Romain Guy06882f82009-06-10 13:36:04 -07009880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009881 if (leakedSurface || killedApps) {
9882 // We managed to reclaim some memory, so get rid of the trouble
9883 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009884 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009885 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009886 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009887 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009888 win.mSurface = null;
9889 }
Romain Guy06882f82009-06-10 13:36:04 -07009890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009891 try {
9892 win.mClient.dispatchGetNewSurface();
9893 } catch (RemoteException e) {
9894 }
9895 }
9896 } finally {
9897 Binder.restoreCallingIdentity(callingIdentity);
9898 }
9899 }
Romain Guy06882f82009-06-10 13:36:04 -07009900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009901 private boolean updateFocusedWindowLocked(int mode) {
9902 WindowState newFocus = computeFocusedWindowLocked();
9903 if (mCurrentFocus != newFocus) {
9904 // This check makes sure that we don't already have the focus
9905 // change message pending.
9906 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
9907 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009908 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009909 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
9910 final WindowState oldFocus = mCurrentFocus;
9911 mCurrentFocus = newFocus;
9912 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -07009913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009914 final WindowState imWindow = mInputMethodWindow;
9915 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009916 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009917 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009918 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
9919 mLayoutNeeded = true;
9920 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009921 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
9922 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009923 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
9924 // Client will do the layout, but we need to assign layers
9925 // for handleNewWindowLocked() below.
9926 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009927 }
9928 }
Jeff Brown349703e2010-06-22 01:27:15 -07009929
9930 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
9931 // If we defer assigning layers, then the caller is responsible for
9932 // doing this part.
9933 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009934 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009935 return true;
9936 }
9937 return false;
9938 }
Jeff Brown349703e2010-06-22 01:27:15 -07009939
9940 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009941 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07009942 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009943
9944 private WindowState computeFocusedWindowLocked() {
9945 WindowState result = null;
9946 WindowState win;
9947
9948 int i = mWindows.size() - 1;
9949 int nextAppIndex = mAppTokens.size()-1;
9950 WindowToken nextApp = nextAppIndex >= 0
9951 ? mAppTokens.get(nextAppIndex) : null;
9952
9953 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009954 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009955
Joe Onorato8a9b2202010-02-26 18:56:32 -08009956 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009957 TAG, "Looking for focus: " + i
9958 + " = " + win
9959 + ", flags=" + win.mAttrs.flags
9960 + ", canReceive=" + win.canReceiveKeys());
9961
9962 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -07009963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009964 // If this window's application has been removed, just skip it.
9965 if (thisApp != null && thisApp.removed) {
9966 i--;
9967 continue;
9968 }
Romain Guy06882f82009-06-10 13:36:04 -07009969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009970 // If there is a focused app, don't allow focus to go to any
9971 // windows below it. If this is an application window, step
9972 // through the app tokens until we find its app.
9973 if (thisApp != null && nextApp != null && thisApp != nextApp
9974 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
9975 int origAppIndex = nextAppIndex;
9976 while (nextAppIndex > 0) {
9977 if (nextApp == mFocusedApp) {
9978 // Whoops, we are below the focused app... no focus
9979 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -08009980 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009981 TAG, "Reached focused app: " + mFocusedApp);
9982 return null;
9983 }
9984 nextAppIndex--;
9985 nextApp = mAppTokens.get(nextAppIndex);
9986 if (nextApp == thisApp) {
9987 break;
9988 }
9989 }
9990 if (thisApp != nextApp) {
9991 // Uh oh, the app token doesn't exist! This shouldn't
9992 // happen, but if it does we can get totally hosed...
9993 // so restart at the original app.
9994 nextAppIndex = origAppIndex;
9995 nextApp = mAppTokens.get(nextAppIndex);
9996 }
9997 }
9998
9999 // Dispatch to this window if it is wants key events.
10000 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010001 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010002 TAG, "Found focus @ " + i + " = " + win);
10003 result = win;
10004 break;
10005 }
10006
10007 i--;
10008 }
10009
10010 return result;
10011 }
10012
10013 private void startFreezingDisplayLocked() {
10014 if (mDisplayFrozen) {
10015 return;
10016 }
Romain Guy06882f82009-06-10 13:36:04 -070010017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010018 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010019
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010020 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010021 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010022 if (mFreezeGcPending != 0) {
10023 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010024 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010025 mH.removeMessages(H.FORCE_GC);
10026 Runtime.getRuntime().gc();
10027 mFreezeGcPending = now;
10028 }
10029 } else {
10030 mFreezeGcPending = now;
10031 }
Romain Guy06882f82009-06-10 13:36:04 -070010032
Dianne Hackbornce73c1e2010-04-12 23:11:38 -070010033 if (DEBUG_FREEZE) Slog.v(TAG, "*** FREEZING DISPLAY", new RuntimeException());
10034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010035 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010036
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010037 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010038
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010039 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10040 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010041 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010042 mAppTransitionReady = true;
10043 }
Romain Guy06882f82009-06-10 13:36:04 -070010044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010045 if (PROFILE_ORIENTATION) {
10046 File file = new File("/data/system/frozen");
10047 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10048 }
10049 Surface.freezeDisplay(0);
10050 }
Romain Guy06882f82009-06-10 13:36:04 -070010051
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010052 private void stopFreezingDisplayLocked() {
10053 if (!mDisplayFrozen) {
10054 return;
10055 }
Romain Guy06882f82009-06-10 13:36:04 -070010056
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010057 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10058 return;
10059 }
10060
Dianne Hackbornce73c1e2010-04-12 23:11:38 -070010061 if (DEBUG_FREEZE) Slog.v(TAG, "*** UNFREEZING DISPLAY", new RuntimeException());
10062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010063 mDisplayFrozen = false;
10064 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10065 if (PROFILE_ORIENTATION) {
10066 Debug.stopMethodTracing();
10067 }
10068 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010069
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010070 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010071
Christopher Tateb696aee2010-04-02 19:08:30 -070010072 // While the display is frozen we don't re-compute the orientation
10073 // to avoid inconsistent states. However, something interesting
10074 // could have actually changed during that time so re-evaluate it
10075 // now to catch that.
10076 if (updateOrientationFromAppTokensLocked()) {
10077 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10078 }
10079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010080 // A little kludge: a lot could have happened while the
10081 // display was frozen, so now that we are coming back we
10082 // do a gc so that any remote references the system
10083 // processes holds on others can be released if they are
10084 // no longer needed.
10085 mH.removeMessages(H.FORCE_GC);
10086 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10087 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010089 mScreenFrozenLock.release();
10090 }
Romain Guy06882f82009-06-10 13:36:04 -070010091
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010092 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10093 DisplayMetrics dm) {
10094 if (index < tokens.length) {
10095 String str = tokens[index];
10096 if (str != null && str.length() > 0) {
10097 try {
10098 int val = Integer.parseInt(str);
10099 return val;
10100 } catch (Exception e) {
10101 }
10102 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010103 }
10104 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10105 return defDps;
10106 }
10107 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10108 return val;
10109 }
10110
10111 class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010112 final String[] mTokens;
10113 final String mText;
10114 final Paint mTextPaint;
10115 final int mTextWidth;
10116 final int mTextHeight;
10117 final int mTextAscent;
10118 final int mTextDescent;
10119 final int mDeltaX;
10120 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010121
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010122 Surface mSurface;
10123 int mLastDW;
10124 int mLastDH;
10125 boolean mDrawNeeded;
10126
10127 Watermark(SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010128 final DisplayMetrics dm = new DisplayMetrics();
10129 mDisplay.getMetrics(dm);
10130
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010131 if (false) {
10132 Log.i(TAG, "*********************** WATERMARK");
10133 for (int i=0; i<tokens.length; i++) {
10134 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10135 }
10136 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010137
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010138 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010139
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010140 StringBuilder builder = new StringBuilder(32);
10141 int len = mTokens[0].length();
10142 len = len & ~1;
10143 for (int i=0; i<len; i+=2) {
10144 int c1 = mTokens[0].charAt(i);
10145 int c2 = mTokens[0].charAt(i+1);
10146 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10147 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10148 else c1 -= '0';
10149 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10150 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10151 else c2 -= '0';
10152 builder.append((char)(255-((c1*16)+c2)));
10153 }
10154 mText = builder.toString();
10155 if (false) {
10156 Log.i(TAG, "Final text: " + mText);
10157 }
10158
10159 int fontSize = getPropertyInt(tokens, 1,
10160 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10161
10162 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10163 mTextPaint.setTextSize(fontSize);
10164 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10165
10166 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
10167 mTextWidth = (int)mTextPaint.measureText(mText);
10168 mTextAscent = fm.ascent;
10169 mTextDescent = fm.descent;
10170 mTextHeight = fm.descent - fm.ascent;
10171
10172 mDeltaX = getPropertyInt(tokens, 2,
10173 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
10174 mDeltaY = getPropertyInt(tokens, 3,
10175 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
10176 int shadowColor = getPropertyInt(tokens, 4,
10177 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
10178 int color = getPropertyInt(tokens, 5,
10179 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
10180 int shadowRadius = getPropertyInt(tokens, 6,
10181 TypedValue.COMPLEX_UNIT_PX, 7, dm);
10182 int shadowDx = getPropertyInt(tokens, 8,
10183 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10184 int shadowDy = getPropertyInt(tokens, 9,
10185 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10186
10187 mTextPaint.setColor(color);
10188 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010189
10190 try {
10191 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010192 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010193 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010194 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010195 mSurface.show();
10196 } catch (OutOfResourcesException e) {
10197 }
10198 }
10199
10200 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010201 if (mLastDW != dw || mLastDH != dh) {
10202 mLastDW = dw;
10203 mLastDH = dh;
10204 mSurface.setSize(dw, dh);
10205 mDrawNeeded = true;
10206 }
10207 }
10208
10209 void drawIfNeeded() {
10210 if (mDrawNeeded) {
10211 final int dw = mLastDW;
10212 final int dh = mLastDH;
10213
10214 mDrawNeeded = false;
10215 Rect dirty = new Rect(0, 0, dw, dh);
10216 Canvas c = null;
10217 try {
10218 c = mSurface.lockCanvas(dirty);
10219 } catch (IllegalArgumentException e) {
10220 } catch (OutOfResourcesException e) {
10221 }
10222 if (c != null) {
10223 int deltaX = mDeltaX;
10224 int deltaY = mDeltaY;
10225
10226 // deltaX shouldn't be close to a round fraction of our
10227 // x step, or else things will line up too much.
10228 int div = (dw+mTextWidth)/deltaX;
10229 int rem = (dw+mTextWidth) - (div*deltaX);
10230 int qdelta = deltaX/4;
10231 if (rem < qdelta || rem > (deltaX-qdelta)) {
10232 deltaX += deltaX/3;
10233 }
10234
10235 int y = -mTextHeight;
10236 int x = -mTextWidth;
10237 while (y < (dh+mTextHeight)) {
10238 c.drawText(mText, x, y, mTextPaint);
10239 x += deltaX;
10240 if (x >= dw) {
10241 x -= (dw+mTextWidth);
10242 y += deltaY;
10243 }
10244 }
10245 mSurface.unlockCanvasAndPost(c);
10246 }
10247 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010248 }
10249 }
10250
10251 void createWatermark() {
10252 if (mWatermark != null) {
10253 return;
10254 }
10255
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010256 File file = new File("/system/etc/setup.conf");
10257 FileInputStream in = null;
10258 try {
10259 in = new FileInputStream(file);
10260 DataInputStream ind = new DataInputStream(in);
10261 String line = ind.readLine();
10262 if (line != null) {
10263 String[] toks = line.split("%");
10264 if (toks != null && toks.length > 0) {
10265 mWatermark = new Watermark(mFxSession, toks);
10266 }
10267 }
10268 } catch (FileNotFoundException e) {
10269 } catch (IOException e) {
10270 } finally {
10271 if (in != null) {
10272 try {
10273 in.close();
10274 } catch (IOException e) {
10275 }
10276 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010277 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010278 }
10279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010280 @Override
10281 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10282 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10283 != PackageManager.PERMISSION_GRANTED) {
10284 pw.println("Permission Denial: can't dump WindowManager from from pid="
10285 + Binder.getCallingPid()
10286 + ", uid=" + Binder.getCallingUid());
10287 return;
10288 }
Romain Guy06882f82009-06-10 13:36:04 -070010289
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010290 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010291 pw.println(" ");
10292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010293 synchronized(mWindowMap) {
10294 pw.println("Current Window Manager state:");
10295 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010296 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010297 pw.print(" Window #"); pw.print(i); pw.print(' ');
10298 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010299 w.dump(pw, " ");
10300 }
10301 if (mInputMethodDialogs.size() > 0) {
10302 pw.println(" ");
10303 pw.println(" Input method dialogs:");
10304 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10305 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010306 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010307 }
10308 }
10309 if (mPendingRemove.size() > 0) {
10310 pw.println(" ");
10311 pw.println(" Remove pending for:");
10312 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10313 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010314 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10315 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010316 w.dump(pw, " ");
10317 }
10318 }
10319 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10320 pw.println(" ");
10321 pw.println(" Windows force removing:");
10322 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10323 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010324 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10325 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010326 w.dump(pw, " ");
10327 }
10328 }
10329 if (mDestroySurface.size() > 0) {
10330 pw.println(" ");
10331 pw.println(" Windows waiting to destroy their surface:");
10332 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10333 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010334 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10335 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010336 w.dump(pw, " ");
10337 }
10338 }
10339 if (mLosingFocus.size() > 0) {
10340 pw.println(" ");
10341 pw.println(" Windows losing focus:");
10342 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10343 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010344 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10345 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010346 w.dump(pw, " ");
10347 }
10348 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010349 if (mResizingWindows.size() > 0) {
10350 pw.println(" ");
10351 pw.println(" Windows waiting to resize:");
10352 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10353 WindowState w = mResizingWindows.get(i);
10354 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10355 pw.print(w); pw.println(":");
10356 w.dump(pw, " ");
10357 }
10358 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010359 if (mSessions.size() > 0) {
10360 pw.println(" ");
10361 pw.println(" All active sessions:");
10362 Iterator<Session> it = mSessions.iterator();
10363 while (it.hasNext()) {
10364 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010365 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010366 s.dump(pw, " ");
10367 }
10368 }
10369 if (mTokenMap.size() > 0) {
10370 pw.println(" ");
10371 pw.println(" All tokens:");
10372 Iterator<WindowToken> it = mTokenMap.values().iterator();
10373 while (it.hasNext()) {
10374 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010375 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010376 token.dump(pw, " ");
10377 }
10378 }
10379 if (mTokenList.size() > 0) {
10380 pw.println(" ");
10381 pw.println(" Window token list:");
10382 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010383 pw.print(" #"); pw.print(i); pw.print(": ");
10384 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010385 }
10386 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010387 if (mWallpaperTokens.size() > 0) {
10388 pw.println(" ");
10389 pw.println(" Wallpaper tokens:");
10390 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10391 WindowToken token = mWallpaperTokens.get(i);
10392 pw.print(" Wallpaper #"); pw.print(i);
10393 pw.print(' '); pw.print(token); pw.println(':');
10394 token.dump(pw, " ");
10395 }
10396 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010397 if (mAppTokens.size() > 0) {
10398 pw.println(" ");
10399 pw.println(" Application tokens in Z order:");
10400 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010401 pw.print(" App #"); pw.print(i); pw.print(": ");
10402 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010403 }
10404 }
10405 if (mFinishedStarting.size() > 0) {
10406 pw.println(" ");
10407 pw.println(" Finishing start of application tokens:");
10408 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10409 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010410 pw.print(" Finished Starting #"); pw.print(i);
10411 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010412 token.dump(pw, " ");
10413 }
10414 }
10415 if (mExitingTokens.size() > 0) {
10416 pw.println(" ");
10417 pw.println(" Exiting tokens:");
10418 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10419 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010420 pw.print(" Exiting #"); pw.print(i);
10421 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010422 token.dump(pw, " ");
10423 }
10424 }
10425 if (mExitingAppTokens.size() > 0) {
10426 pw.println(" ");
10427 pw.println(" Exiting application tokens:");
10428 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10429 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010430 pw.print(" Exiting App #"); pw.print(i);
10431 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010432 token.dump(pw, " ");
10433 }
10434 }
10435 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010436 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10437 pw.print(" mLastFocus="); pw.println(mLastFocus);
10438 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10439 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10440 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010441 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010442 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10443 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10444 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10445 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010446 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10447 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10448 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010449 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10450 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10451 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10452 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010453 if (mDimAnimator != null) {
10454 mDimAnimator.printTo(pw);
10455 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080010456 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010457 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010458 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010459 pw.print(mInputMethodAnimLayerAdjustment);
10460 pw.print(" mWallpaperAnimLayerAdjustment=");
10461 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010462 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10463 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010464 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10465 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010466 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
10467 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010468 pw.print(" mRotation="); pw.print(mRotation);
10469 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10470 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10471 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10472 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10473 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10474 pw.print(" mNextAppTransition=0x");
10475 pw.print(Integer.toHexString(mNextAppTransition));
10476 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010477 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010478 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010479 if (mNextAppTransitionPackage != null) {
10480 pw.print(" mNextAppTransitionPackage=");
10481 pw.print(mNextAppTransitionPackage);
10482 pw.print(", mNextAppTransitionEnter=0x");
10483 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10484 pw.print(", mNextAppTransitionExit=0x");
10485 pw.print(Integer.toHexString(mNextAppTransitionExit));
10486 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010487 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10488 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010489 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10490 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10491 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10492 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010493 if (mOpeningApps.size() > 0) {
10494 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10495 }
10496 if (mClosingApps.size() > 0) {
10497 pw.print(" mClosingApps="); pw.println(mClosingApps);
10498 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010499 if (mToTopApps.size() > 0) {
10500 pw.print(" mToTopApps="); pw.println(mToTopApps);
10501 }
10502 if (mToBottomApps.size() > 0) {
10503 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10504 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010505 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10506 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010507 }
10508 }
10509
Jeff Brown349703e2010-06-22 01:27:15 -070010510 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010511 public void monitor() {
10512 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010513 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070010514 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010515
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010516 /**
10517 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010518 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010519 */
10520 private static class DimAnimator {
10521 Surface mDimSurface;
10522 boolean mDimShown = false;
10523 float mDimCurrentAlpha;
10524 float mDimTargetAlpha;
10525 float mDimDeltaPerMs;
10526 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010527
10528 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010529
10530 DimAnimator (SurfaceSession session) {
10531 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010532 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010533 + mDimSurface + ": CREATE");
10534 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010535 mDimSurface = new Surface(session, 0,
10536 "DimSurface",
10537 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010538 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010010539 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010540 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010541 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010542 }
10543 }
10544 }
10545
10546 /**
10547 * Show the dim surface.
10548 */
10549 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010550 if (!mDimShown) {
10551 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
10552 dw + "x" + dh + ")");
10553 mDimShown = true;
10554 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010555 mLastDimWidth = dw;
10556 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010557 mDimSurface.setPosition(0, 0);
10558 mDimSurface.setSize(dw, dh);
10559 mDimSurface.show();
10560 } catch (RuntimeException e) {
10561 Slog.w(TAG, "Failure showing dim surface", e);
10562 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010563 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
10564 mLastDimWidth = dw;
10565 mLastDimHeight = dh;
10566 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010567 }
10568 }
10569
10570 /**
10571 * Set's the dim surface's layer and update dim parameters that will be used in
10572 * {@link updateSurface} after all windows are examined.
10573 */
10574 void updateParameters(WindowState w, long currentTime) {
10575 mDimSurface.setLayer(w.mAnimLayer-1);
10576
10577 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010578 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010579 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010580 if (mDimTargetAlpha != target) {
10581 // If the desired dim level has changed, then
10582 // start an animation to it.
10583 mLastDimAnimTime = currentTime;
10584 long duration = (w.mAnimating && w.mAnimation != null)
10585 ? w.mAnimation.computeDurationHint()
10586 : DEFAULT_DIM_DURATION;
10587 if (target > mDimTargetAlpha) {
10588 // This is happening behind the activity UI,
10589 // so we can make it run a little longer to
10590 // give a stronger impression without disrupting
10591 // the user.
10592 duration *= DIM_DURATION_MULTIPLIER;
10593 }
10594 if (duration < 1) {
10595 // Don't divide by zero
10596 duration = 1;
10597 }
10598 mDimTargetAlpha = target;
10599 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
10600 }
10601 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010602
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010603 /**
10604 * Updating the surface's alpha. Returns true if the animation continues, or returns
10605 * false when the animation is finished and the dim surface is hidden.
10606 */
10607 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
10608 if (!dimming) {
10609 if (mDimTargetAlpha != 0) {
10610 mLastDimAnimTime = currentTime;
10611 mDimTargetAlpha = 0;
10612 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
10613 }
10614 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010615
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010616 boolean animating = false;
10617 if (mLastDimAnimTime != 0) {
10618 mDimCurrentAlpha += mDimDeltaPerMs
10619 * (currentTime-mLastDimAnimTime);
10620 boolean more = true;
10621 if (displayFrozen) {
10622 // If the display is frozen, there is no reason to animate.
10623 more = false;
10624 } else if (mDimDeltaPerMs > 0) {
10625 if (mDimCurrentAlpha > mDimTargetAlpha) {
10626 more = false;
10627 }
10628 } else if (mDimDeltaPerMs < 0) {
10629 if (mDimCurrentAlpha < mDimTargetAlpha) {
10630 more = false;
10631 }
10632 } else {
10633 more = false;
10634 }
10635
10636 // Do we need to continue animating?
10637 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010638 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010639 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
10640 mLastDimAnimTime = currentTime;
10641 mDimSurface.setAlpha(mDimCurrentAlpha);
10642 animating = true;
10643 } else {
10644 mDimCurrentAlpha = mDimTargetAlpha;
10645 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010646 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010647 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
10648 mDimSurface.setAlpha(mDimCurrentAlpha);
10649 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010650 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010651 + ": HIDE");
10652 try {
10653 mDimSurface.hide();
10654 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010655 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010656 }
10657 mDimShown = false;
10658 }
10659 }
10660 }
10661 return animating;
10662 }
10663
10664 public void printTo(PrintWriter pw) {
10665 pw.print(" mDimShown="); pw.print(mDimShown);
10666 pw.print(" current="); pw.print(mDimCurrentAlpha);
10667 pw.print(" target="); pw.print(mDimTargetAlpha);
10668 pw.print(" delta="); pw.print(mDimDeltaPerMs);
10669 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
10670 }
10671 }
10672
10673 /**
10674 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
10675 * This is used for opening/closing transition for apps in compatible mode.
10676 */
10677 private static class FadeInOutAnimation extends Animation {
10678 int mWidth;
10679 boolean mFadeIn;
10680
10681 public FadeInOutAnimation(boolean fadeIn) {
10682 setInterpolator(new AccelerateInterpolator());
10683 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
10684 mFadeIn = fadeIn;
10685 }
10686
10687 @Override
10688 protected void applyTransformation(float interpolatedTime, Transformation t) {
10689 float x = interpolatedTime;
10690 if (!mFadeIn) {
10691 x = 1.0f - x; // reverse the interpolation for fade out
10692 }
10693 if (x < 0.5) {
10694 // move the window out of the screen.
10695 t.getMatrix().setTranslate(mWidth, 0);
10696 } else {
10697 t.getMatrix().setTranslate(0, 0);// show
10698 t.setAlpha((x - 0.5f) * 2);
10699 }
10700 }
10701
10702 @Override
10703 public void initialize(int width, int height, int parentWidth, int parentHeight) {
10704 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
10705 mWidth = width;
10706 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010707
10708 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070010709 public int getZAdjustment() {
10710 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010711 }
10712 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010713}