The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server; |
| 18 | |
| 19 | import static android.os.LocalPowerManager.CHEEK_EVENT; |
| 20 | import static android.os.LocalPowerManager.OTHER_EVENT; |
| 21 | import static android.os.LocalPowerManager.TOUCH_EVENT; |
Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 22 | import static android.os.LocalPowerManager.LONG_TOUCH_EVENT; |
| 23 | import static android.os.LocalPowerManager.TOUCH_UP_EVENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
| 25 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
| 26 | import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 27 | import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND; |
| 29 | import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 30 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR; |
| 32 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 33 | import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
| 34 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 35 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
| 36 | import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_GPU; |
| 37 | import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_HARDWARE; |
| 38 | import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS; |
| 39 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 40 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 41 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 42 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
| 43 | |
| 44 | import com.android.internal.app.IBatteryStats; |
| 45 | import com.android.internal.policy.PolicyManager; |
| 46 | import com.android.internal.view.IInputContext; |
| 47 | import com.android.internal.view.IInputMethodClient; |
| 48 | import com.android.internal.view.IInputMethodManager; |
| 49 | import com.android.server.KeyInputQueue.QueuedEvent; |
| 50 | import com.android.server.am.BatteryStatsService; |
| 51 | |
| 52 | import android.Manifest; |
| 53 | import android.app.ActivityManagerNative; |
| 54 | import android.app.IActivityManager; |
| 55 | import android.content.Context; |
| 56 | import android.content.pm.ActivityInfo; |
| 57 | import android.content.pm.PackageManager; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 58 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import android.content.res.Configuration; |
| 60 | import android.graphics.Matrix; |
| 61 | import android.graphics.PixelFormat; |
| 62 | import android.graphics.Rect; |
| 63 | import android.graphics.Region; |
| 64 | import android.os.BatteryStats; |
| 65 | import android.os.Binder; |
| 66 | import android.os.Debug; |
| 67 | import android.os.Handler; |
| 68 | import android.os.IBinder; |
| 69 | import android.os.LocalPowerManager; |
| 70 | import android.os.Looper; |
| 71 | import android.os.Message; |
| 72 | import android.os.Parcel; |
| 73 | import android.os.ParcelFileDescriptor; |
| 74 | import android.os.Power; |
| 75 | import android.os.PowerManager; |
| 76 | import android.os.Process; |
| 77 | import android.os.RemoteException; |
| 78 | import android.os.ServiceManager; |
| 79 | import android.os.SystemClock; |
| 80 | import android.os.SystemProperties; |
| 81 | import android.os.TokenWatcher; |
| 82 | import android.provider.Settings; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 83 | import android.util.DisplayMetrics; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | import android.util.EventLog; |
| 85 | import android.util.Log; |
| 86 | import android.util.SparseIntArray; |
| 87 | import android.view.Display; |
| 88 | import android.view.Gravity; |
| 89 | import android.view.IApplicationToken; |
| 90 | import android.view.IOnKeyguardExitResult; |
| 91 | import android.view.IRotationWatcher; |
| 92 | import android.view.IWindow; |
| 93 | import android.view.IWindowManager; |
| 94 | import android.view.IWindowSession; |
| 95 | import android.view.KeyEvent; |
| 96 | import android.view.MotionEvent; |
| 97 | import android.view.RawInputEvent; |
| 98 | import android.view.Surface; |
| 99 | import android.view.SurfaceSession; |
| 100 | import android.view.View; |
| 101 | import android.view.ViewTreeObserver; |
| 102 | import android.view.WindowManager; |
| 103 | import android.view.WindowManagerImpl; |
| 104 | import android.view.WindowManagerPolicy; |
| 105 | import android.view.WindowManager.LayoutParams; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 106 | import android.view.animation.AccelerateInterpolator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | import android.view.animation.Animation; |
| 108 | import android.view.animation.AnimationUtils; |
| 109 | import android.view.animation.Transformation; |
| 110 | |
| 111 | import java.io.BufferedWriter; |
| 112 | import java.io.File; |
| 113 | import java.io.FileDescriptor; |
| 114 | import java.io.IOException; |
| 115 | import java.io.OutputStream; |
| 116 | import java.io.OutputStreamWriter; |
| 117 | import java.io.PrintWriter; |
| 118 | import java.io.StringWriter; |
| 119 | import java.net.Socket; |
| 120 | import java.util.ArrayList; |
| 121 | import java.util.HashMap; |
| 122 | import java.util.HashSet; |
| 123 | import java.util.Iterator; |
| 124 | import java.util.List; |
| 125 | |
| 126 | /** {@hide} */ |
| 127 | public class WindowManagerService extends IWindowManager.Stub implements Watchdog.Monitor { |
| 128 | static final String TAG = "WindowManager"; |
| 129 | static final boolean DEBUG = false; |
| 130 | static final boolean DEBUG_FOCUS = false; |
| 131 | static final boolean DEBUG_ANIM = false; |
| 132 | static final boolean DEBUG_LAYERS = false; |
| 133 | static final boolean DEBUG_INPUT = false; |
| 134 | static final boolean DEBUG_INPUT_METHOD = false; |
| 135 | static final boolean DEBUG_VISIBILITY = false; |
| 136 | static final boolean DEBUG_ORIENTATION = false; |
| 137 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 138 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 139 | static final boolean DEBUG_REORDER = false; |
| 140 | static final boolean SHOW_TRANSACTIONS = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 141 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | static final boolean PROFILE_ORIENTATION = false; |
| 143 | static final boolean BLUR = true; |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 144 | static final boolean localLOGV = DEBUG; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 145 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | static final int LOG_WM_NO_SURFACE_MEMORY = 31000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 147 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | /** How long to wait for first key repeat, in milliseconds */ |
| 149 | static final int KEY_REPEAT_FIRST_DELAY = 750; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 150 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | /** How long to wait for subsequent key repeats, in milliseconds */ |
| 152 | static final int KEY_REPEAT_DELAY = 50; |
| 153 | |
| 154 | /** How much to multiply the policy's type layer, to reserve room |
| 155 | * for multiple windows of the same type and Z-ordering adjustment |
| 156 | * with TYPE_LAYER_OFFSET. */ |
| 157 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 158 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 160 | * or below others in the same layer. */ |
| 161 | static final int TYPE_LAYER_OFFSET = 1000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 162 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | /** How much to increment the layer for each window, to reserve room |
| 164 | * for effect surfaces between them. |
| 165 | */ |
| 166 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 167 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | /** The maximum length we will accept for a loaded animation duration: |
| 169 | * this is 10 seconds. |
| 170 | */ |
| 171 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 172 | |
| 173 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 174 | * value to another, when no window animation is driving it. |
| 175 | */ |
| 176 | static final int DEFAULT_DIM_DURATION = 200; |
| 177 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 178 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 179 | * compatible windows. |
| 180 | */ |
| 181 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 182 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | /** Adjustment to time to perform a dim, to make it more dramatic. |
| 184 | */ |
| 185 | static final int DIM_DURATION_MULTIPLIER = 6; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 186 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 187 | static final int INJECT_FAILED = 0; |
| 188 | static final int INJECT_SUCCEEDED = 1; |
| 189 | static final int INJECT_NO_PERMISSION = -1; |
| 190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 192 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 193 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 194 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 195 | |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 196 | /** The minimum time between dispatching touch events. */ |
| 197 | int mMinWaitTimeBetweenTouchEvents = 1000 / 35; |
| 198 | |
| 199 | // Last touch event time |
| 200 | long mLastTouchEventTime = 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 201 | |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 202 | // Last touch event type |
| 203 | int mLastTouchEventType = OTHER_EVENT; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 204 | |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 205 | // Time to wait before calling useractivity again. This saves CPU usage |
| 206 | // when we get a flood of touch events. |
| 207 | static final int MIN_TIME_BETWEEN_USERACTIVITIES = 1000; |
| 208 | |
| 209 | // Last time we call user activity |
| 210 | long mLastUserActivityCallTime = 0; |
| 211 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 212 | // Last time we updated battery stats |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 213 | long mLastBatteryStatsCallTime = 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 214 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | private static final String SYSTEM_SECURE = "ro.secure"; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 216 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | |
| 218 | /** |
| 219 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 220 | * the window policy has finished. |
| 221 | */ |
| 222 | private boolean mWaitingUntilKeyguardReenabled = false; |
| 223 | |
| 224 | |
| 225 | final TokenWatcher mKeyguardDisabled = new TokenWatcher( |
| 226 | new Handler(), "WindowManagerService.mKeyguardDisabled") { |
| 227 | public void acquired() { |
| 228 | mPolicy.enableKeyguard(false); |
| 229 | } |
| 230 | public void released() { |
| 231 | synchronized (mKeyguardDisabled) { |
| 232 | mPolicy.enableKeyguard(true); |
| 233 | mWaitingUntilKeyguardReenabled = false; |
| 234 | mKeyguardDisabled.notifyAll(); |
| 235 | } |
| 236 | } |
| 237 | }; |
| 238 | |
| 239 | final Context mContext; |
| 240 | |
| 241 | final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 242 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | final boolean mLimitedAlphaCompositing; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 244 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 245 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 246 | |
| 247 | final IActivityManager mActivityManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 248 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 249 | final IBatteryStats mBatteryStats; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 250 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | /** |
| 252 | * All currently active sessions with clients. |
| 253 | */ |
| 254 | final HashSet<Session> mSessions = new HashSet<Session>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 255 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 256 | /** |
| 257 | * Mapping from an IWindow IBinder to the server's Window object. |
| 258 | * This is also used as the lock for all of our state. |
| 259 | */ |
| 260 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 261 | |
| 262 | /** |
| 263 | * Mapping from a token IBinder to a WindowToken object. |
| 264 | */ |
| 265 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 266 | new HashMap<IBinder, WindowToken>(); |
| 267 | |
| 268 | /** |
| 269 | * The same tokens as mTokenMap, stored in a list for efficient iteration |
| 270 | * over them. |
| 271 | */ |
| 272 | final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 273 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 274 | /** |
| 275 | * Window tokens that are in the process of exiting, but still |
| 276 | * on screen for animations. |
| 277 | */ |
| 278 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 279 | |
| 280 | /** |
| 281 | * Z-ordered (bottom-most first) list of all application tokens, for |
| 282 | * controlling the ordering of windows in different applications. This |
| 283 | * contains WindowToken objects. |
| 284 | */ |
| 285 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 286 | |
| 287 | /** |
| 288 | * Application tokens that are in the process of exiting, but still |
| 289 | * on screen for animations. |
| 290 | */ |
| 291 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 292 | |
| 293 | /** |
| 294 | * List of window tokens that have finished starting their application, |
| 295 | * and now need to have the policy remove their windows. |
| 296 | */ |
| 297 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 298 | |
| 299 | /** |
| 300 | * Z-ordered (bottom-most first) list of all Window objects. |
| 301 | */ |
| 302 | final ArrayList mWindows = new ArrayList(); |
| 303 | |
| 304 | /** |
| 305 | * Windows that are being resized. Used so we can tell the client about |
| 306 | * the resize after closing the transaction in which we resized the |
| 307 | * underlying surface. |
| 308 | */ |
| 309 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 310 | |
| 311 | /** |
| 312 | * Windows whose animations have ended and now must be removed. |
| 313 | */ |
| 314 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 315 | |
| 316 | /** |
| 317 | * Windows whose surface should be destroyed. |
| 318 | */ |
| 319 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 320 | |
| 321 | /** |
| 322 | * Windows that have lost input focus and are waiting for the new |
| 323 | * focus window to be displayed before they are told about this. |
| 324 | */ |
| 325 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 326 | |
| 327 | /** |
| 328 | * This is set when we have run out of memory, and will either be an empty |
| 329 | * list or contain windows that need to be force removed. |
| 330 | */ |
| 331 | ArrayList<WindowState> mForceRemoves; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 332 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | IInputMethodManager mInputMethodManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 334 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | SurfaceSession mFxSession; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 336 | private DimAnimator mDimAnimator = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | Surface mBlurSurface; |
| 338 | boolean mBlurShown; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 339 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 340 | int mTransactionSequence = 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 341 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | final float[] mTmpFloats = new float[9]; |
| 343 | |
| 344 | boolean mSafeMode; |
| 345 | boolean mDisplayEnabled = false; |
| 346 | boolean mSystemBooted = false; |
| 347 | int mRotation = 0; |
| 348 | int mRequestedRotation = 0; |
| 349 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 350 | int mLastRotationFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 351 | ArrayList<IRotationWatcher> mRotationWatchers |
| 352 | = new ArrayList<IRotationWatcher>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 353 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 354 | boolean mLayoutNeeded = true; |
| 355 | boolean mAnimationPending = false; |
| 356 | boolean mDisplayFrozen = false; |
| 357 | boolean mWindowsFreezingScreen = false; |
| 358 | long mFreezeGcPending = 0; |
| 359 | int mAppsFreezingScreen = 0; |
| 360 | |
| 361 | // This is held as long as we have the screen frozen, to give us time to |
| 362 | // perform a rotation animation when turning off shows the lock screen which |
| 363 | // changes the orientation. |
| 364 | PowerManager.WakeLock mScreenFrozenLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 365 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 366 | // State management of app transitions. When we are preparing for a |
| 367 | // transition, mNextAppTransition will be the kind of transition to |
| 368 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 369 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 370 | // made visible or hidden at the next transition. |
| 371 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_NONE; |
| 372 | boolean mAppTransitionReady = false; |
| 373 | boolean mAppTransitionTimeout = false; |
| 374 | boolean mStartingIconInTransition = false; |
| 375 | boolean mSkipAppTransitionAnimation = false; |
| 376 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 377 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 378 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 379 | //flag to detect fat touch events |
| 380 | boolean mFatTouch = false; |
| 381 | Display mDisplay; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 382 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | H mH = new H(); |
| 384 | |
| 385 | WindowState mCurrentFocus = null; |
| 386 | WindowState mLastFocus = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 387 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | // This just indicates the window the input method is on top of, not |
| 389 | // necessarily the window its input is going to. |
| 390 | WindowState mInputMethodTarget = null; |
| 391 | WindowState mUpcomingInputMethodTarget = null; |
| 392 | boolean mInputMethodTargetWaitingAnim; |
| 393 | int mInputMethodAnimLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 394 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 395 | WindowState mInputMethodWindow = null; |
| 396 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 397 | |
| 398 | AppWindowToken mFocusedApp = null; |
| 399 | |
| 400 | PowerManagerService mPowerManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 401 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | float mWindowAnimationScale = 1.0f; |
| 403 | float mTransitionAnimationScale = 1.0f; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 404 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 405 | final KeyWaiter mKeyWaiter = new KeyWaiter(); |
| 406 | final KeyQ mQueue; |
| 407 | final InputDispatcherThread mInputThread; |
| 408 | |
| 409 | // Who is holding the screen on. |
| 410 | Session mHoldingScreenOn; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 411 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 412 | /** |
| 413 | * Whether the UI is currently running in touch mode (not showing |
| 414 | * navigational focus because the user is directly pressing the screen). |
| 415 | */ |
| 416 | boolean mInTouchMode = false; |
| 417 | |
| 418 | private ViewServer mViewServer; |
| 419 | |
| 420 | final Rect mTempRect = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 421 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 422 | final Configuration mTempConfiguration = new Configuration(); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 423 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 424 | |
| 425 | // The frame use to limit the size of the app running in compatibility mode. |
| 426 | Rect mCompatibleScreenFrame = new Rect(); |
| 427 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 428 | Surface mBackgroundFillerSurface = null; |
| 429 | boolean mBackgroundFillerShown = false; |
| 430 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | public static WindowManagerService main(Context context, |
| 432 | PowerManagerService pm, boolean haveInputMethods) { |
| 433 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 434 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 435 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 436 | synchronized (thr) { |
| 437 | while (thr.mService == null) { |
| 438 | try { |
| 439 | thr.wait(); |
| 440 | } catch (InterruptedException e) { |
| 441 | } |
| 442 | } |
| 443 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 444 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 445 | return thr.mService; |
| 446 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 447 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | static class WMThread extends Thread { |
| 449 | WindowManagerService mService; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | private final Context mContext; |
| 452 | private final PowerManagerService mPM; |
| 453 | private final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 454 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | public WMThread(Context context, PowerManagerService pm, |
| 456 | boolean haveInputMethods) { |
| 457 | super("WindowManager"); |
| 458 | mContext = context; |
| 459 | mPM = pm; |
| 460 | mHaveInputMethods = haveInputMethods; |
| 461 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 462 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 463 | public void run() { |
| 464 | Looper.prepare(); |
| 465 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 466 | mHaveInputMethods); |
| 467 | android.os.Process.setThreadPriority( |
| 468 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 469 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 470 | synchronized (this) { |
| 471 | mService = s; |
| 472 | notifyAll(); |
| 473 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 474 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 475 | Looper.loop(); |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | static class PolicyThread extends Thread { |
| 480 | private final WindowManagerPolicy mPolicy; |
| 481 | private final WindowManagerService mService; |
| 482 | private final Context mContext; |
| 483 | private final PowerManagerService mPM; |
| 484 | boolean mRunning = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 485 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 486 | public PolicyThread(WindowManagerPolicy policy, |
| 487 | WindowManagerService service, Context context, |
| 488 | PowerManagerService pm) { |
| 489 | super("WindowManagerPolicy"); |
| 490 | mPolicy = policy; |
| 491 | mService = service; |
| 492 | mContext = context; |
| 493 | mPM = pm; |
| 494 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 495 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | public void run() { |
| 497 | Looper.prepare(); |
| 498 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
| 499 | // Log.VERBOSE, "WindowManagerPolicy")); |
| 500 | android.os.Process.setThreadPriority( |
| 501 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
| 502 | mPolicy.init(mContext, mService, mPM); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 503 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 504 | synchronized (this) { |
| 505 | mRunning = true; |
| 506 | notifyAll(); |
| 507 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 508 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 509 | Looper.loop(); |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | private WindowManagerService(Context context, PowerManagerService pm, |
| 514 | boolean haveInputMethods) { |
| 515 | mContext = context; |
| 516 | mHaveInputMethods = haveInputMethods; |
| 517 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 518 | com.android.internal.R.bool.config_sf_limitedAlpha); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 519 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 520 | mPowerManager = pm; |
| 521 | mPowerManager.setPolicy(mPolicy); |
| 522 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 523 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 524 | "SCREEN_FROZEN"); |
| 525 | mScreenFrozenLock.setReferenceCounted(false); |
| 526 | |
| 527 | mActivityManager = ActivityManagerNative.getDefault(); |
| 528 | mBatteryStats = BatteryStatsService.getService(); |
| 529 | |
| 530 | // Get persisted window scale setting |
| 531 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 532 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 533 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 534 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 535 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 536 | mQueue = new KeyQ(); |
| 537 | |
| 538 | mInputThread = new InputDispatcherThread(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 539 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 540 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 541 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 542 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 543 | synchronized (thr) { |
| 544 | while (!thr.mRunning) { |
| 545 | try { |
| 546 | thr.wait(); |
| 547 | } catch (InterruptedException e) { |
| 548 | } |
| 549 | } |
| 550 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 551 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 552 | mInputThread.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 553 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 554 | // Add ourself to the Watchdog monitors. |
| 555 | Watchdog.getInstance().addMonitor(this); |
| 556 | } |
| 557 | |
| 558 | @Override |
| 559 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 560 | throws RemoteException { |
| 561 | try { |
| 562 | return super.onTransact(code, data, reply, flags); |
| 563 | } catch (RuntimeException e) { |
| 564 | // The window manager only throws security exceptions, so let's |
| 565 | // log all others. |
| 566 | if (!(e instanceof SecurityException)) { |
| 567 | Log.e(TAG, "Window Manager Crash", e); |
| 568 | } |
| 569 | throw e; |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | private void placeWindowAfter(Object pos, WindowState window) { |
| 574 | final int i = mWindows.indexOf(pos); |
| 575 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 576 | TAG, "Adding window " + window + " at " |
| 577 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 578 | mWindows.add(i+1, window); |
| 579 | } |
| 580 | |
| 581 | private void placeWindowBefore(Object pos, WindowState window) { |
| 582 | final int i = mWindows.indexOf(pos); |
| 583 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 584 | TAG, "Adding window " + window + " at " |
| 585 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 586 | mWindows.add(i, window); |
| 587 | } |
| 588 | |
| 589 | //This method finds out the index of a window that has the same app token as |
| 590 | //win. used for z ordering the windows in mWindows |
| 591 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 592 | //use a local variable to cache mWindows |
| 593 | ArrayList localmWindows = mWindows; |
| 594 | int jmax = localmWindows.size(); |
| 595 | if(jmax == 0) { |
| 596 | return -1; |
| 597 | } |
| 598 | for(int j = (jmax-1); j >= 0; j--) { |
| 599 | WindowState wentry = (WindowState)localmWindows.get(j); |
| 600 | if(wentry.mAppToken == win.mAppToken) { |
| 601 | return j; |
| 602 | } |
| 603 | } |
| 604 | return -1; |
| 605 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 606 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 607 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 608 | final IWindow client = win.mClient; |
| 609 | final WindowToken token = win.mToken; |
| 610 | final ArrayList localmWindows = mWindows; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 611 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 612 | final int N = localmWindows.size(); |
| 613 | final WindowState attached = win.mAttachedWindow; |
| 614 | int i; |
| 615 | if (attached == null) { |
| 616 | int tokenWindowsPos = token.windows.size(); |
| 617 | if (token.appWindowToken != null) { |
| 618 | int index = tokenWindowsPos-1; |
| 619 | if (index >= 0) { |
| 620 | // If this application has existing windows, we |
| 621 | // simply place the new window on top of them... but |
| 622 | // keep the starting window on top. |
| 623 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 624 | // Base windows go behind everything else. |
| 625 | placeWindowBefore(token.windows.get(0), win); |
| 626 | tokenWindowsPos = 0; |
| 627 | } else { |
| 628 | AppWindowToken atoken = win.mAppToken; |
| 629 | if (atoken != null && |
| 630 | token.windows.get(index) == atoken.startingWindow) { |
| 631 | placeWindowBefore(token.windows.get(index), win); |
| 632 | tokenWindowsPos--; |
| 633 | } else { |
| 634 | int newIdx = findIdxBasedOnAppTokens(win); |
| 635 | if(newIdx != -1) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 636 | //there is a window above this one associated with the same |
| 637 | //apptoken note that the window could be a floating window |
| 638 | //that was created later or a window at the top of the list of |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 639 | //windows associated with this token. |
| 640 | localmWindows.add(newIdx+1, win); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 641 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 642 | } |
| 643 | } |
| 644 | } else { |
| 645 | if (localLOGV) Log.v( |
| 646 | TAG, "Figuring out where to add app window " |
| 647 | + client.asBinder() + " (token=" + token + ")"); |
| 648 | // Figure out where the window should go, based on the |
| 649 | // order of applications. |
| 650 | final int NA = mAppTokens.size(); |
| 651 | Object pos = null; |
| 652 | for (i=NA-1; i>=0; i--) { |
| 653 | AppWindowToken t = mAppTokens.get(i); |
| 654 | if (t == token) { |
| 655 | i--; |
| 656 | break; |
| 657 | } |
| 658 | if (t.windows.size() > 0) { |
| 659 | pos = t.windows.get(0); |
| 660 | } |
| 661 | } |
| 662 | // We now know the index into the apps. If we found |
| 663 | // an app window above, that gives us the position; else |
| 664 | // we need to look some more. |
| 665 | if (pos != null) { |
| 666 | // Move behind any windows attached to this one. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 667 | WindowToken atoken = |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 668 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 669 | if (atoken != null) { |
| 670 | final int NC = atoken.windows.size(); |
| 671 | if (NC > 0) { |
| 672 | WindowState bottom = atoken.windows.get(0); |
| 673 | if (bottom.mSubLayer < 0) { |
| 674 | pos = bottom; |
| 675 | } |
| 676 | } |
| 677 | } |
| 678 | placeWindowBefore(pos, win); |
| 679 | } else { |
| 680 | while (i >= 0) { |
| 681 | AppWindowToken t = mAppTokens.get(i); |
| 682 | final int NW = t.windows.size(); |
| 683 | if (NW > 0) { |
| 684 | pos = t.windows.get(NW-1); |
| 685 | break; |
| 686 | } |
| 687 | i--; |
| 688 | } |
| 689 | if (pos != null) { |
| 690 | // Move in front of any windows attached to this |
| 691 | // one. |
| 692 | WindowToken atoken = |
| 693 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 694 | if (atoken != null) { |
| 695 | final int NC = atoken.windows.size(); |
| 696 | if (NC > 0) { |
| 697 | WindowState top = atoken.windows.get(NC-1); |
| 698 | if (top.mSubLayer >= 0) { |
| 699 | pos = top; |
| 700 | } |
| 701 | } |
| 702 | } |
| 703 | placeWindowAfter(pos, win); |
| 704 | } else { |
| 705 | // Just search for the start of this layer. |
| 706 | final int myLayer = win.mBaseLayer; |
| 707 | for (i=0; i<N; i++) { |
| 708 | WindowState w = (WindowState)localmWindows.get(i); |
| 709 | if (w.mBaseLayer > myLayer) { |
| 710 | break; |
| 711 | } |
| 712 | } |
| 713 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 714 | TAG, "Adding window " + win + " at " |
| 715 | + i + " of " + N); |
| 716 | localmWindows.add(i, win); |
| 717 | } |
| 718 | } |
| 719 | } |
| 720 | } else { |
| 721 | // Figure out where window should go, based on layer. |
| 722 | final int myLayer = win.mBaseLayer; |
| 723 | for (i=N-1; i>=0; i--) { |
| 724 | if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) { |
| 725 | i++; |
| 726 | break; |
| 727 | } |
| 728 | } |
| 729 | if (i < 0) i = 0; |
| 730 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 731 | TAG, "Adding window " + win + " at " |
| 732 | + i + " of " + N); |
| 733 | localmWindows.add(i, win); |
| 734 | } |
| 735 | if (addToToken) { |
| 736 | token.windows.add(tokenWindowsPos, win); |
| 737 | } |
| 738 | |
| 739 | } else { |
| 740 | // Figure out this window's ordering relative to the window |
| 741 | // it is attached to. |
| 742 | final int NA = token.windows.size(); |
| 743 | final int sublayer = win.mSubLayer; |
| 744 | int largestSublayer = Integer.MIN_VALUE; |
| 745 | WindowState windowWithLargestSublayer = null; |
| 746 | for (i=0; i<NA; i++) { |
| 747 | WindowState w = token.windows.get(i); |
| 748 | final int wSublayer = w.mSubLayer; |
| 749 | if (wSublayer >= largestSublayer) { |
| 750 | largestSublayer = wSublayer; |
| 751 | windowWithLargestSublayer = w; |
| 752 | } |
| 753 | if (sublayer < 0) { |
| 754 | // For negative sublayers, we go below all windows |
| 755 | // in the same sublayer. |
| 756 | if (wSublayer >= sublayer) { |
| 757 | if (addToToken) { |
| 758 | token.windows.add(i, win); |
| 759 | } |
| 760 | placeWindowBefore( |
| 761 | wSublayer >= 0 ? attached : w, win); |
| 762 | break; |
| 763 | } |
| 764 | } else { |
| 765 | // For positive sublayers, we go above all windows |
| 766 | // in the same sublayer. |
| 767 | if (wSublayer > sublayer) { |
| 768 | if (addToToken) { |
| 769 | token.windows.add(i, win); |
| 770 | } |
| 771 | placeWindowBefore(w, win); |
| 772 | break; |
| 773 | } |
| 774 | } |
| 775 | } |
| 776 | if (i >= NA) { |
| 777 | if (addToToken) { |
| 778 | token.windows.add(win); |
| 779 | } |
| 780 | if (sublayer < 0) { |
| 781 | placeWindowBefore(attached, win); |
| 782 | } else { |
| 783 | placeWindowAfter(largestSublayer >= 0 |
| 784 | ? windowWithLargestSublayer |
| 785 | : attached, |
| 786 | win); |
| 787 | } |
| 788 | } |
| 789 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 790 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 791 | if (win.mAppToken != null && addToToken) { |
| 792 | win.mAppToken.allAppWindows.add(win); |
| 793 | } |
| 794 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 795 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 796 | static boolean canBeImeTarget(WindowState w) { |
| 797 | final int fl = w.mAttrs.flags |
| 798 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 799 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 800 | return w.isVisibleOrAdding(); |
| 801 | } |
| 802 | return false; |
| 803 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 804 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 805 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
| 806 | final ArrayList localmWindows = mWindows; |
| 807 | final int N = localmWindows.size(); |
| 808 | WindowState w = null; |
| 809 | int i = N; |
| 810 | while (i > 0) { |
| 811 | i--; |
| 812 | w = (WindowState)localmWindows.get(i); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 813 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 814 | //Log.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
| 815 | // + Integer.toHexString(w.mAttrs.flags)); |
| 816 | if (canBeImeTarget(w)) { |
| 817 | //Log.i(TAG, "Putting input method here!"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 818 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 819 | // Yet more tricksyness! If this window is a "starting" |
| 820 | // window, we do actually want to be on top of it, but |
| 821 | // it is not -really- where input will go. So if the caller |
| 822 | // is not actually looking to move the IME, look down below |
| 823 | // for a real window to target... |
| 824 | if (!willMove |
| 825 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 826 | && i > 0) { |
| 827 | WindowState wb = (WindowState)localmWindows.get(i-1); |
| 828 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 829 | i--; |
| 830 | w = wb; |
| 831 | } |
| 832 | } |
| 833 | break; |
| 834 | } |
| 835 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 836 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 837 | mUpcomingInputMethodTarget = w; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 838 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 839 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Desired input method target=" |
| 840 | + w + " willMove=" + willMove); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 841 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 842 | if (willMove && w != null) { |
| 843 | final WindowState curTarget = mInputMethodTarget; |
| 844 | if (curTarget != null && curTarget.mAppToken != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 845 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 846 | // Now some fun for dealing with window animations that |
| 847 | // modify the Z order. We need to look at all windows below |
| 848 | // the current target that are in this app, finding the highest |
| 849 | // visible one in layering. |
| 850 | AppWindowToken token = curTarget.mAppToken; |
| 851 | WindowState highestTarget = null; |
| 852 | int highestPos = 0; |
| 853 | if (token.animating || token.animation != null) { |
| 854 | int pos = 0; |
| 855 | pos = localmWindows.indexOf(curTarget); |
| 856 | while (pos >= 0) { |
| 857 | WindowState win = (WindowState)localmWindows.get(pos); |
| 858 | if (win.mAppToken != token) { |
| 859 | break; |
| 860 | } |
| 861 | if (!win.mRemoved) { |
| 862 | if (highestTarget == null || win.mAnimLayer > |
| 863 | highestTarget.mAnimLayer) { |
| 864 | highestTarget = win; |
| 865 | highestPos = pos; |
| 866 | } |
| 867 | } |
| 868 | pos--; |
| 869 | } |
| 870 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 871 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 872 | if (highestTarget != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 873 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "mNextAppTransition=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 874 | + mNextAppTransition + " " + highestTarget |
| 875 | + " animating=" + highestTarget.isAnimating() |
| 876 | + " layer=" + highestTarget.mAnimLayer |
| 877 | + " new layer=" + w.mAnimLayer); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 878 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 879 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) { |
| 880 | // If we are currently setting up for an animation, |
| 881 | // hold everything until we can find out what will happen. |
| 882 | mInputMethodTargetWaitingAnim = true; |
| 883 | mInputMethodTarget = highestTarget; |
| 884 | return highestPos + 1; |
| 885 | } else if (highestTarget.isAnimating() && |
| 886 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 887 | // If the window we are currently targeting is involved |
| 888 | // with an animation, and it is on top of the next target |
| 889 | // we will be over, then hold off on moving until |
| 890 | // that is done. |
| 891 | mInputMethodTarget = highestTarget; |
| 892 | return highestPos + 1; |
| 893 | } |
| 894 | } |
| 895 | } |
| 896 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 897 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 898 | //Log.i(TAG, "Placing input method @" + (i+1)); |
| 899 | if (w != null) { |
| 900 | if (willMove) { |
| 901 | RuntimeException e = new RuntimeException(); |
| 902 | e.fillInStackTrace(); |
| 903 | if (DEBUG_INPUT_METHOD) Log.w(TAG, "Moving IM target from " |
| 904 | + mInputMethodTarget + " to " + w, e); |
| 905 | mInputMethodTarget = w; |
| 906 | if (w.mAppToken != null) { |
| 907 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 908 | } else { |
| 909 | setInputMethodAnimLayerAdjustment(0); |
| 910 | } |
| 911 | } |
| 912 | return i+1; |
| 913 | } |
| 914 | if (willMove) { |
| 915 | RuntimeException e = new RuntimeException(); |
| 916 | e.fillInStackTrace(); |
| 917 | if (DEBUG_INPUT_METHOD) Log.w(TAG, "Moving IM target from " |
| 918 | + mInputMethodTarget + " to null", e); |
| 919 | mInputMethodTarget = null; |
| 920 | setInputMethodAnimLayerAdjustment(0); |
| 921 | } |
| 922 | return -1; |
| 923 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 924 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 925 | void addInputMethodWindowToListLocked(WindowState win) { |
| 926 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 927 | if (pos >= 0) { |
| 928 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 929 | mWindows.add(pos, win); |
| 930 | moveInputMethodDialogsLocked(pos+1); |
| 931 | return; |
| 932 | } |
| 933 | win.mTargetAppToken = null; |
| 934 | addWindowToListInOrderLocked(win, true); |
| 935 | moveInputMethodDialogsLocked(pos); |
| 936 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 937 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 938 | void setInputMethodAnimLayerAdjustment(int adj) { |
| 939 | if (DEBUG_LAYERS) Log.v(TAG, "Setting im layer adj to " + adj); |
| 940 | mInputMethodAnimLayerAdjustment = adj; |
| 941 | WindowState imw = mInputMethodWindow; |
| 942 | if (imw != null) { |
| 943 | imw.mAnimLayer = imw.mLayer + adj; |
| 944 | if (DEBUG_LAYERS) Log.v(TAG, "IM win " + imw |
| 945 | + " anim layer: " + imw.mAnimLayer); |
| 946 | int wi = imw.mChildWindows.size(); |
| 947 | while (wi > 0) { |
| 948 | wi--; |
| 949 | WindowState cw = (WindowState)imw.mChildWindows.get(wi); |
| 950 | cw.mAnimLayer = cw.mLayer + adj; |
| 951 | if (DEBUG_LAYERS) Log.v(TAG, "IM win " + cw |
| 952 | + " anim layer: " + cw.mAnimLayer); |
| 953 | } |
| 954 | } |
| 955 | int di = mInputMethodDialogs.size(); |
| 956 | while (di > 0) { |
| 957 | di --; |
| 958 | imw = mInputMethodDialogs.get(di); |
| 959 | imw.mAnimLayer = imw.mLayer + adj; |
| 960 | if (DEBUG_LAYERS) Log.v(TAG, "IM win " + imw |
| 961 | + " anim layer: " + imw.mAnimLayer); |
| 962 | } |
| 963 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 964 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 965 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 966 | int wpos = mWindows.indexOf(win); |
| 967 | if (wpos >= 0) { |
| 968 | if (wpos < interestingPos) interestingPos--; |
| 969 | mWindows.remove(wpos); |
| 970 | int NC = win.mChildWindows.size(); |
| 971 | while (NC > 0) { |
| 972 | NC--; |
| 973 | WindowState cw = (WindowState)win.mChildWindows.get(NC); |
| 974 | int cpos = mWindows.indexOf(cw); |
| 975 | if (cpos >= 0) { |
| 976 | if (cpos < interestingPos) interestingPos--; |
| 977 | mWindows.remove(cpos); |
| 978 | } |
| 979 | } |
| 980 | } |
| 981 | return interestingPos; |
| 982 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 983 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 984 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 985 | addWindowToListInOrderLocked(win, false); |
| 986 | // This is a hack to get all of the child windows added as well |
| 987 | // at the right position. Child windows should be rare and |
| 988 | // this case should be rare, so it shouldn't be that big a deal. |
| 989 | int wpos = mWindows.indexOf(win); |
| 990 | if (wpos >= 0) { |
| 991 | mWindows.remove(wpos); |
| 992 | reAddWindowLocked(wpos, win); |
| 993 | } |
| 994 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 995 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 996 | void logWindowList(String prefix) { |
| 997 | int N = mWindows.size(); |
| 998 | while (N > 0) { |
| 999 | N--; |
| 1000 | Log.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
| 1001 | } |
| 1002 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1003 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1004 | void moveInputMethodDialogsLocked(int pos) { |
| 1005 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1006 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1007 | final int N = dialogs.size(); |
| 1008 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Removing " + N + " dialogs w/pos=" + pos); |
| 1009 | for (int i=0; i<N; i++) { |
| 1010 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1011 | } |
| 1012 | if (DEBUG_INPUT_METHOD) { |
| 1013 | Log.v(TAG, "Window list w/pos=" + pos); |
| 1014 | logWindowList(" "); |
| 1015 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1016 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1017 | if (pos >= 0) { |
| 1018 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1019 | if (pos < mWindows.size()) { |
| 1020 | WindowState wp = (WindowState)mWindows.get(pos); |
| 1021 | if (wp == mInputMethodWindow) { |
| 1022 | pos++; |
| 1023 | } |
| 1024 | } |
| 1025 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Adding " + N + " dialogs at pos=" + pos); |
| 1026 | for (int i=0; i<N; i++) { |
| 1027 | WindowState win = dialogs.get(i); |
| 1028 | win.mTargetAppToken = targetAppToken; |
| 1029 | pos = reAddWindowLocked(pos, win); |
| 1030 | } |
| 1031 | if (DEBUG_INPUT_METHOD) { |
| 1032 | Log.v(TAG, "Final window list:"); |
| 1033 | logWindowList(" "); |
| 1034 | } |
| 1035 | return; |
| 1036 | } |
| 1037 | for (int i=0; i<N; i++) { |
| 1038 | WindowState win = dialogs.get(i); |
| 1039 | win.mTargetAppToken = null; |
| 1040 | reAddWindowToListInOrderLocked(win); |
| 1041 | if (DEBUG_INPUT_METHOD) { |
| 1042 | Log.v(TAG, "No IM target, final list:"); |
| 1043 | logWindowList(" "); |
| 1044 | } |
| 1045 | } |
| 1046 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1047 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1048 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1049 | final WindowState imWin = mInputMethodWindow; |
| 1050 | final int DN = mInputMethodDialogs.size(); |
| 1051 | if (imWin == null && DN == 0) { |
| 1052 | return false; |
| 1053 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1054 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1055 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1056 | if (imPos >= 0) { |
| 1057 | // In this case, the input method windows are to be placed |
| 1058 | // immediately above the window they are targeting. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1059 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1060 | // First check to see if the input method windows are already |
| 1061 | // located here, and contiguous. |
| 1062 | final int N = mWindows.size(); |
| 1063 | WindowState firstImWin = imPos < N |
| 1064 | ? (WindowState)mWindows.get(imPos) : null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1065 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1066 | // Figure out the actual input method window that should be |
| 1067 | // at the bottom of their stack. |
| 1068 | WindowState baseImWin = imWin != null |
| 1069 | ? imWin : mInputMethodDialogs.get(0); |
| 1070 | if (baseImWin.mChildWindows.size() > 0) { |
| 1071 | WindowState cw = (WindowState)baseImWin.mChildWindows.get(0); |
| 1072 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1073 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1074 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1075 | if (firstImWin == baseImWin) { |
| 1076 | // The windows haven't moved... but are they still contiguous? |
| 1077 | // First find the top IM window. |
| 1078 | int pos = imPos+1; |
| 1079 | while (pos < N) { |
| 1080 | if (!((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1081 | break; |
| 1082 | } |
| 1083 | pos++; |
| 1084 | } |
| 1085 | pos++; |
| 1086 | // Now there should be no more input method windows above. |
| 1087 | while (pos < N) { |
| 1088 | if (((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1089 | break; |
| 1090 | } |
| 1091 | pos++; |
| 1092 | } |
| 1093 | if (pos >= N) { |
| 1094 | // All is good! |
| 1095 | return false; |
| 1096 | } |
| 1097 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1098 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1099 | if (imWin != null) { |
| 1100 | if (DEBUG_INPUT_METHOD) { |
| 1101 | Log.v(TAG, "Moving IM from " + imPos); |
| 1102 | logWindowList(" "); |
| 1103 | } |
| 1104 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1105 | if (DEBUG_INPUT_METHOD) { |
| 1106 | Log.v(TAG, "List after moving with new pos " + imPos + ":"); |
| 1107 | logWindowList(" "); |
| 1108 | } |
| 1109 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1110 | reAddWindowLocked(imPos, imWin); |
| 1111 | if (DEBUG_INPUT_METHOD) { |
| 1112 | Log.v(TAG, "List after moving IM to " + imPos + ":"); |
| 1113 | logWindowList(" "); |
| 1114 | } |
| 1115 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1116 | } else { |
| 1117 | moveInputMethodDialogsLocked(imPos); |
| 1118 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1119 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1120 | } else { |
| 1121 | // In this case, the input method windows go in a fixed layer, |
| 1122 | // because they aren't currently associated with a focus window. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1123 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1124 | if (imWin != null) { |
| 1125 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Moving IM from " + imPos); |
| 1126 | tmpRemoveWindowLocked(0, imWin); |
| 1127 | imWin.mTargetAppToken = null; |
| 1128 | reAddWindowToListInOrderLocked(imWin); |
| 1129 | if (DEBUG_INPUT_METHOD) { |
| 1130 | Log.v(TAG, "List with no IM target:"); |
| 1131 | logWindowList(" "); |
| 1132 | } |
| 1133 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1134 | } else { |
| 1135 | moveInputMethodDialogsLocked(-1);; |
| 1136 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1137 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1138 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1139 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1140 | if (needAssignLayers) { |
| 1141 | assignLayersLocked(); |
| 1142 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1143 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1144 | return true; |
| 1145 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1146 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1147 | void adjustInputMethodDialogsLocked() { |
| 1148 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1149 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1150 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1151 | public int addWindow(Session session, IWindow client, |
| 1152 | WindowManager.LayoutParams attrs, int viewVisibility, |
| 1153 | Rect outContentInsets) { |
| 1154 | int res = mPolicy.checkAddPermission(attrs); |
| 1155 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1156 | return res; |
| 1157 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1158 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1159 | boolean reportNewConfig = false; |
| 1160 | WindowState attachedWindow = null; |
| 1161 | WindowState win = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1162 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1163 | synchronized(mWindowMap) { |
| 1164 | // Instantiating a Display requires talking with the simulator, |
| 1165 | // so don't do it until we know the system is mostly up and |
| 1166 | // running. |
| 1167 | if (mDisplay == null) { |
| 1168 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 1169 | mDisplay = wm.getDefaultDisplay(); |
| 1170 | mQueue.setDisplay(mDisplay); |
| 1171 | reportNewConfig = true; |
| 1172 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1174 | if (mWindowMap.containsKey(client.asBinder())) { |
| 1175 | Log.w(TAG, "Window " + client + " is already added"); |
| 1176 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 1177 | } |
| 1178 | |
| 1179 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1180 | attachedWindow = windowForClientLocked(null, attrs.token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1181 | if (attachedWindow == null) { |
| 1182 | Log.w(TAG, "Attempted to add window with token that is not a window: " |
| 1183 | + attrs.token + ". Aborting."); |
| 1184 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1185 | } |
| 1186 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 1187 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
| 1188 | Log.w(TAG, "Attempted to add window with token that is a sub-window: " |
| 1189 | + attrs.token + ". Aborting."); |
| 1190 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1191 | } |
| 1192 | } |
| 1193 | |
| 1194 | boolean addToken = false; |
| 1195 | WindowToken token = mTokenMap.get(attrs.token); |
| 1196 | if (token == null) { |
| 1197 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1198 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1199 | Log.w(TAG, "Attempted to add application window with unknown token " |
| 1200 | + attrs.token + ". Aborting."); |
| 1201 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1202 | } |
| 1203 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 1204 | Log.w(TAG, "Attempted to add input method window with unknown token " |
| 1205 | + attrs.token + ". Aborting."); |
| 1206 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1207 | } |
| 1208 | token = new WindowToken(attrs.token, -1, false); |
| 1209 | addToken = true; |
| 1210 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1211 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1212 | AppWindowToken atoken = token.appWindowToken; |
| 1213 | if (atoken == null) { |
| 1214 | Log.w(TAG, "Attempted to add window with non-application token " |
| 1215 | + token + ". Aborting."); |
| 1216 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 1217 | } else if (atoken.removed) { |
| 1218 | Log.w(TAG, "Attempted to add window with exiting application token " |
| 1219 | + token + ". Aborting."); |
| 1220 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1221 | } |
| 1222 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 1223 | // No need for this guy! |
| 1224 | if (localLOGV) Log.v( |
| 1225 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 1226 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 1227 | } |
| 1228 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 1229 | if (token.windowType != TYPE_INPUT_METHOD) { |
| 1230 | Log.w(TAG, "Attempted to add input method window with bad token " |
| 1231 | + attrs.token + ". Aborting."); |
| 1232 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | win = new WindowState(session, client, token, |
| 1237 | attachedWindow, attrs, viewVisibility); |
| 1238 | if (win.mDeathRecipient == null) { |
| 1239 | // Client has apparently died, so there is no reason to |
| 1240 | // continue. |
| 1241 | Log.w(TAG, "Adding window client " + client.asBinder() |
| 1242 | + " that is dead, aborting."); |
| 1243 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1244 | } |
| 1245 | |
| 1246 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1247 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1248 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 1249 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1250 | return res; |
| 1251 | } |
| 1252 | |
| 1253 | // From now on, no exceptions or errors allowed! |
| 1254 | |
| 1255 | res = WindowManagerImpl.ADD_OKAY; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1256 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1257 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1258 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1259 | if (addToken) { |
| 1260 | mTokenMap.put(attrs.token, token); |
| 1261 | mTokenList.add(token); |
| 1262 | } |
| 1263 | win.attach(); |
| 1264 | mWindowMap.put(client.asBinder(), win); |
| 1265 | |
| 1266 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 1267 | token.appWindowToken != null) { |
| 1268 | token.appWindowToken.startingWindow = win; |
| 1269 | } |
| 1270 | |
| 1271 | boolean imMayMove = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1272 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1273 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 1274 | mInputMethodWindow = win; |
| 1275 | addInputMethodWindowToListLocked(win); |
| 1276 | imMayMove = false; |
| 1277 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 1278 | mInputMethodDialogs.add(win); |
| 1279 | addWindowToListInOrderLocked(win, true); |
| 1280 | adjustInputMethodDialogsLocked(); |
| 1281 | imMayMove = false; |
| 1282 | } else { |
| 1283 | addWindowToListInOrderLocked(win, true); |
| 1284 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1285 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1286 | win.mEnterAnimationPending = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1287 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1288 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1289 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1290 | if (mInTouchMode) { |
| 1291 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 1292 | } |
| 1293 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 1294 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 1295 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1296 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1297 | boolean focusChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1298 | if (win.canReceiveKeys()) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1299 | if ((focusChanged=updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS)) |
| 1300 | == true) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1301 | imMayMove = false; |
| 1302 | } |
| 1303 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1304 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1305 | if (imMayMove) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1306 | moveInputMethodWindowsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1307 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1308 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1309 | assignLayersLocked(); |
| 1310 | // Don't do layout here, the window must call |
| 1311 | // relayout to be displayed, so we'll do it there. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1312 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1313 | //dump(); |
| 1314 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1315 | if (focusChanged) { |
| 1316 | if (mCurrentFocus != null) { |
| 1317 | mKeyWaiter.handleNewWindowLocked(mCurrentFocus); |
| 1318 | } |
| 1319 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1320 | if (localLOGV) Log.v( |
| 1321 | TAG, "New client " + client.asBinder() |
| 1322 | + ": window=" + win); |
| 1323 | } |
| 1324 | |
| 1325 | // sendNewConfiguration() checks caller permissions so we must call it with |
| 1326 | // privilege. updateOrientationFromAppTokens() clears and resets the caller |
| 1327 | // identity anyway, so it's safe to just clear & restore around this whole |
| 1328 | // block. |
| 1329 | final long origId = Binder.clearCallingIdentity(); |
| 1330 | if (reportNewConfig) { |
| 1331 | sendNewConfiguration(); |
| 1332 | } else { |
| 1333 | // Update Orientation after adding a window, only if the window needs to be |
| 1334 | // displayed right away |
| 1335 | if (win.isVisibleOrAdding()) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 1336 | if (updateOrientationFromAppTokensUnchecked(null, null) != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1337 | sendNewConfiguration(); |
| 1338 | } |
| 1339 | } |
| 1340 | } |
| 1341 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1342 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1343 | return res; |
| 1344 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1345 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1346 | public void removeWindow(Session session, IWindow client) { |
| 1347 | synchronized(mWindowMap) { |
| 1348 | WindowState win = windowForClientLocked(session, client); |
| 1349 | if (win == null) { |
| 1350 | return; |
| 1351 | } |
| 1352 | removeWindowLocked(session, win); |
| 1353 | } |
| 1354 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1355 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1356 | public void removeWindowLocked(Session session, WindowState win) { |
| 1357 | |
| 1358 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 1359 | TAG, "Remove " + win + " client=" |
| 1360 | + Integer.toHexString(System.identityHashCode( |
| 1361 | win.mClient.asBinder())) |
| 1362 | + ", surface=" + win.mSurface); |
| 1363 | |
| 1364 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1365 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1366 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 1367 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 1368 | + " mExiting=" + win.mExiting |
| 1369 | + " isAnimating=" + win.isAnimating() |
| 1370 | + " app-animation=" |
| 1371 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 1372 | + " inPendingTransaction=" |
| 1373 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 1374 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 1375 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 1376 | boolean wasVisible = false; |
| 1377 | // First, see if we need to run an animation. If we do, we have |
| 1378 | // to hold off on removing the window until the animation is done. |
| 1379 | // If the display is frozen, just remove immediately, since the |
| 1380 | // animation wouldn't be seen. |
| 1381 | if (win.mSurface != null && !mDisplayFrozen) { |
| 1382 | // If we are not currently running the exit animation, we |
| 1383 | // need to see about starting one. |
| 1384 | if (wasVisible=win.isWinVisibleLw()) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1385 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1386 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 1387 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 1388 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 1389 | } |
| 1390 | // Try starting an animation. |
| 1391 | if (applyAnimationLocked(win, transit, false)) { |
| 1392 | win.mExiting = true; |
| 1393 | } |
| 1394 | } |
| 1395 | if (win.mExiting || win.isAnimating()) { |
| 1396 | // The exit animation is running... wait for it! |
| 1397 | //Log.i(TAG, "*** Running exit animation..."); |
| 1398 | win.mExiting = true; |
| 1399 | win.mRemoveOnExit = true; |
| 1400 | mLayoutNeeded = true; |
| 1401 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 1402 | performLayoutAndPlaceSurfacesLocked(); |
| 1403 | if (win.mAppToken != null) { |
| 1404 | win.mAppToken.updateReportedVisibilityLocked(); |
| 1405 | } |
| 1406 | //dump(); |
| 1407 | Binder.restoreCallingIdentity(origId); |
| 1408 | return; |
| 1409 | } |
| 1410 | } |
| 1411 | |
| 1412 | removeWindowInnerLocked(session, win); |
| 1413 | // Removing a visible window will effect the computed orientation |
| 1414 | // So just update orientation if needed. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1415 | if (wasVisible && computeForcedAppOrientationLocked() |
| 1416 | != mForcedAppOrientation) { |
| 1417 | mH.sendMessage(mH.obtainMessage(H.COMPUTE_AND_SEND_NEW_CONFIGURATION)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1418 | } |
| 1419 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 1420 | Binder.restoreCallingIdentity(origId); |
| 1421 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1422 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1423 | private void removeWindowInnerLocked(Session session, WindowState win) { |
| 1424 | mKeyWaiter.releasePendingPointerLocked(win.mSession); |
| 1425 | mKeyWaiter.releasePendingTrackballLocked(win.mSession); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1427 | win.mRemoved = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1428 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1429 | if (mInputMethodTarget == win) { |
| 1430 | moveInputMethodWindowsIfNeededLocked(false); |
| 1431 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1432 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1433 | mPolicy.removeWindowLw(win); |
| 1434 | win.removeLocked(); |
| 1435 | |
| 1436 | mWindowMap.remove(win.mClient.asBinder()); |
| 1437 | mWindows.remove(win); |
| 1438 | |
| 1439 | if (mInputMethodWindow == win) { |
| 1440 | mInputMethodWindow = null; |
| 1441 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 1442 | mInputMethodDialogs.remove(win); |
| 1443 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1444 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1445 | final WindowToken token = win.mToken; |
| 1446 | final AppWindowToken atoken = win.mAppToken; |
| 1447 | token.windows.remove(win); |
| 1448 | if (atoken != null) { |
| 1449 | atoken.allAppWindows.remove(win); |
| 1450 | } |
| 1451 | if (localLOGV) Log.v( |
| 1452 | TAG, "**** Removing window " + win + ": count=" |
| 1453 | + token.windows.size()); |
| 1454 | if (token.windows.size() == 0) { |
| 1455 | if (!token.explicit) { |
| 1456 | mTokenMap.remove(token.token); |
| 1457 | mTokenList.remove(token); |
| 1458 | } else if (atoken != null) { |
| 1459 | atoken.firstWindowDrawn = false; |
| 1460 | } |
| 1461 | } |
| 1462 | |
| 1463 | if (atoken != null) { |
| 1464 | if (atoken.startingWindow == win) { |
| 1465 | atoken.startingWindow = null; |
| 1466 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 1467 | // If this is the last window and we had requested a starting |
| 1468 | // transition window, well there is no point now. |
| 1469 | atoken.startingData = null; |
| 1470 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 1471 | // If this is the last window except for a starting transition |
| 1472 | // window, we need to get rid of the starting transition. |
| 1473 | if (DEBUG_STARTING_WINDOW) { |
| 1474 | Log.v(TAG, "Schedule remove starting " + token |
| 1475 | + ": no more real windows"); |
| 1476 | } |
| 1477 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 1478 | mH.sendMessage(m); |
| 1479 | } |
| 1480 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1481 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1482 | if (!mInLayout) { |
| 1483 | assignLayersLocked(); |
| 1484 | mLayoutNeeded = true; |
| 1485 | performLayoutAndPlaceSurfacesLocked(); |
| 1486 | if (win.mAppToken != null) { |
| 1487 | win.mAppToken.updateReportedVisibilityLocked(); |
| 1488 | } |
| 1489 | } |
| 1490 | } |
| 1491 | |
| 1492 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 1493 | long origId = Binder.clearCallingIdentity(); |
| 1494 | try { |
| 1495 | synchronized (mWindowMap) { |
| 1496 | WindowState w = windowForClientLocked(session, client); |
| 1497 | if ((w != null) && (w.mSurface != null)) { |
| 1498 | Surface.openTransaction(); |
| 1499 | try { |
| 1500 | w.mSurface.setTransparentRegionHint(region); |
| 1501 | } finally { |
| 1502 | Surface.closeTransaction(); |
| 1503 | } |
| 1504 | } |
| 1505 | } |
| 1506 | } finally { |
| 1507 | Binder.restoreCallingIdentity(origId); |
| 1508 | } |
| 1509 | } |
| 1510 | |
| 1511 | void setInsetsWindow(Session session, IWindow client, |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1512 | int touchableInsets, Rect contentInsets, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1513 | Rect visibleInsets) { |
| 1514 | long origId = Binder.clearCallingIdentity(); |
| 1515 | try { |
| 1516 | synchronized (mWindowMap) { |
| 1517 | WindowState w = windowForClientLocked(session, client); |
| 1518 | if (w != null) { |
| 1519 | w.mGivenInsetsPending = false; |
| 1520 | w.mGivenContentInsets.set(contentInsets); |
| 1521 | w.mGivenVisibleInsets.set(visibleInsets); |
| 1522 | w.mTouchableInsets = touchableInsets; |
| 1523 | mLayoutNeeded = true; |
| 1524 | performLayoutAndPlaceSurfacesLocked(); |
| 1525 | } |
| 1526 | } |
| 1527 | } finally { |
| 1528 | Binder.restoreCallingIdentity(origId); |
| 1529 | } |
| 1530 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1531 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1532 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 1533 | Rect outDisplayFrame) { |
| 1534 | synchronized(mWindowMap) { |
| 1535 | WindowState win = windowForClientLocked(session, client); |
| 1536 | if (win == null) { |
| 1537 | outDisplayFrame.setEmpty(); |
| 1538 | return; |
| 1539 | } |
| 1540 | outDisplayFrame.set(win.mDisplayFrame); |
| 1541 | } |
| 1542 | } |
| 1543 | |
| 1544 | public int relayoutWindow(Session session, IWindow client, |
| 1545 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 1546 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 1547 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
| 1548 | Surface outSurface) { |
| 1549 | boolean displayed = false; |
| 1550 | boolean inTouchMode; |
| 1551 | Configuration newConfig = null; |
| 1552 | long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1553 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1554 | synchronized(mWindowMap) { |
| 1555 | WindowState win = windowForClientLocked(session, client); |
| 1556 | if (win == null) { |
| 1557 | return 0; |
| 1558 | } |
| 1559 | win.mRequestedWidth = requestedWidth; |
| 1560 | win.mRequestedHeight = requestedHeight; |
| 1561 | |
| 1562 | if (attrs != null) { |
| 1563 | mPolicy.adjustWindowParamsLw(attrs); |
| 1564 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1565 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1566 | int attrChanges = 0; |
| 1567 | int flagChanges = 0; |
| 1568 | if (attrs != null) { |
| 1569 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 1570 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 1571 | } |
| 1572 | |
| 1573 | if (localLOGV) Log.v( |
| 1574 | TAG, "Relayout given client " + client.asBinder() |
| 1575 | + " (" + win.mAttrs.getTitle() + ")"); |
| 1576 | |
| 1577 | |
| 1578 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 1579 | win.mAlpha = attrs.alpha; |
| 1580 | } |
| 1581 | |
| 1582 | final boolean scaledWindow = |
| 1583 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 1584 | |
| 1585 | if (scaledWindow) { |
| 1586 | // requested{Width|Height} Surface's physical size |
| 1587 | // attrs.{width|height} Size on screen |
| 1588 | win.mHScale = (attrs.width != requestedWidth) ? |
| 1589 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 1590 | win.mVScale = (attrs.height != requestedHeight) ? |
| 1591 | (attrs.height / (float)requestedHeight) : 1.0f; |
| 1592 | } |
| 1593 | |
| 1594 | boolean imMayMove = (flagChanges&( |
| 1595 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 1596 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1597 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1598 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 1599 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 1600 | || (!win.mRelayoutCalled); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1601 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1602 | win.mRelayoutCalled = true; |
| 1603 | final int oldVisibility = win.mViewVisibility; |
| 1604 | win.mViewVisibility = viewVisibility; |
| 1605 | if (viewVisibility == View.VISIBLE && |
| 1606 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 1607 | displayed = !win.isVisibleLw(); |
| 1608 | if (win.mExiting) { |
| 1609 | win.mExiting = false; |
| 1610 | win.mAnimation = null; |
| 1611 | } |
| 1612 | if (win.mDestroying) { |
| 1613 | win.mDestroying = false; |
| 1614 | mDestroySurface.remove(win); |
| 1615 | } |
| 1616 | if (oldVisibility == View.GONE) { |
| 1617 | win.mEnterAnimationPending = true; |
| 1618 | } |
| 1619 | if (displayed && win.mSurface != null && !win.mDrawPending |
| 1620 | && !win.mCommitDrawPending && !mDisplayFrozen) { |
| 1621 | applyEnterAnimationLocked(win); |
| 1622 | } |
| 1623 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 1624 | // To change the format, we need to re-build the surface. |
| 1625 | win.destroySurfaceLocked(); |
| 1626 | displayed = true; |
| 1627 | } |
| 1628 | try { |
| 1629 | Surface surface = win.createSurfaceLocked(); |
| 1630 | if (surface != null) { |
| 1631 | outSurface.copyFrom(surface); |
| 1632 | } else { |
| 1633 | outSurface.clear(); |
| 1634 | } |
| 1635 | } catch (Exception e) { |
| 1636 | Log.w(TAG, "Exception thrown when creating surface for client " |
| 1637 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 1638 | e); |
| 1639 | Binder.restoreCallingIdentity(origId); |
| 1640 | return 0; |
| 1641 | } |
| 1642 | if (displayed) { |
| 1643 | focusMayChange = true; |
| 1644 | } |
| 1645 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 1646 | && mInputMethodWindow == null) { |
| 1647 | mInputMethodWindow = win; |
| 1648 | imMayMove = true; |
| 1649 | } |
| 1650 | } else { |
| 1651 | win.mEnterAnimationPending = false; |
| 1652 | if (win.mSurface != null) { |
| 1653 | // If we are not currently running the exit animation, we |
| 1654 | // need to see about starting one. |
| 1655 | if (!win.mExiting) { |
| 1656 | // Try starting an animation; if there isn't one, we |
| 1657 | // can destroy the surface right away. |
| 1658 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 1659 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 1660 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 1661 | } |
| 1662 | if (win.isWinVisibleLw() && |
| 1663 | applyAnimationLocked(win, transit, false)) { |
| 1664 | win.mExiting = true; |
| 1665 | mKeyWaiter.finishedKey(session, client, true, |
| 1666 | KeyWaiter.RETURN_NOTHING); |
| 1667 | } else if (win.isAnimating()) { |
| 1668 | // Currently in a hide animation... turn this into |
| 1669 | // an exit. |
| 1670 | win.mExiting = true; |
| 1671 | } else { |
| 1672 | if (mInputMethodWindow == win) { |
| 1673 | mInputMethodWindow = null; |
| 1674 | } |
| 1675 | win.destroySurfaceLocked(); |
| 1676 | } |
| 1677 | } |
| 1678 | } |
| 1679 | outSurface.clear(); |
| 1680 | } |
| 1681 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1682 | if (focusMayChange) { |
| 1683 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 1684 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1685 | imMayMove = false; |
| 1686 | } |
| 1687 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 1688 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1689 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1690 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 1691 | // reassign them at this point if the IM window state gets shuffled |
| 1692 | boolean assignLayers = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1693 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1694 | if (imMayMove) { |
| 1695 | if (moveInputMethodWindowsIfNeededLocked(false)) { |
| 1696 | assignLayers = true; |
| 1697 | } |
| 1698 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1699 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1700 | mLayoutNeeded = true; |
| 1701 | win.mGivenInsetsPending = insetsPending; |
| 1702 | if (assignLayers) { |
| 1703 | assignLayersLocked(); |
| 1704 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1705 | newConfig = updateOrientationFromAppTokensLocked(null, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1706 | performLayoutAndPlaceSurfacesLocked(); |
| 1707 | if (win.mAppToken != null) { |
| 1708 | win.mAppToken.updateReportedVisibilityLocked(); |
| 1709 | } |
| 1710 | outFrame.set(win.mFrame); |
| 1711 | outContentInsets.set(win.mContentInsets); |
| 1712 | outVisibleInsets.set(win.mVisibleInsets); |
| 1713 | if (localLOGV) Log.v( |
| 1714 | TAG, "Relayout given client " + client.asBinder() |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1715 | + ", requestedWidth=" + requestedWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1716 | + ", requestedHeight=" + requestedHeight |
| 1717 | + ", viewVisibility=" + viewVisibility |
| 1718 | + "\nRelayout returning frame=" + outFrame |
| 1719 | + ", surface=" + outSurface); |
| 1720 | |
| 1721 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 1722 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 1723 | |
| 1724 | inTouchMode = mInTouchMode; |
| 1725 | } |
| 1726 | |
| 1727 | if (newConfig != null) { |
| 1728 | sendNewConfiguration(); |
| 1729 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1730 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1731 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1732 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1733 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 1734 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 1735 | } |
| 1736 | |
| 1737 | public void finishDrawingWindow(Session session, IWindow client) { |
| 1738 | final long origId = Binder.clearCallingIdentity(); |
| 1739 | synchronized(mWindowMap) { |
| 1740 | WindowState win = windowForClientLocked(session, client); |
| 1741 | if (win != null && win.finishDrawingLocked()) { |
| 1742 | mLayoutNeeded = true; |
| 1743 | performLayoutAndPlaceSurfacesLocked(); |
| 1744 | } |
| 1745 | } |
| 1746 | Binder.restoreCallingIdentity(origId); |
| 1747 | } |
| 1748 | |
| 1749 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
| 1750 | if (DEBUG_ANIM) Log.v(TAG, "Loading animations: params package=" |
| 1751 | + (lp != null ? lp.packageName : null) |
| 1752 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 1753 | if (lp != null && lp.windowAnimations != 0) { |
| 1754 | // If this is a system resource, don't try to load it from the |
| 1755 | // application resources. It is nice to avoid loading application |
| 1756 | // resources if we can. |
| 1757 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 1758 | int resId = lp.windowAnimations; |
| 1759 | if ((resId&0xFF000000) == 0x01000000) { |
| 1760 | packageName = "android"; |
| 1761 | } |
| 1762 | if (DEBUG_ANIM) Log.v(TAG, "Loading animations: picked package=" |
| 1763 | + packageName); |
| 1764 | return AttributeCache.instance().get(packageName, resId, |
| 1765 | com.android.internal.R.styleable.WindowAnimation); |
| 1766 | } |
| 1767 | return null; |
| 1768 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1769 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1770 | private void applyEnterAnimationLocked(WindowState win) { |
| 1771 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 1772 | if (win.mEnterAnimationPending) { |
| 1773 | win.mEnterAnimationPending = false; |
| 1774 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 1775 | } |
| 1776 | |
| 1777 | applyAnimationLocked(win, transit, true); |
| 1778 | } |
| 1779 | |
| 1780 | private boolean applyAnimationLocked(WindowState win, |
| 1781 | int transit, boolean isEntrance) { |
| 1782 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 1783 | // If we are trying to apply an animation, but already running |
| 1784 | // an animation of the same type, then just leave that one alone. |
| 1785 | return true; |
| 1786 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1787 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1788 | // Only apply an animation if the display isn't frozen. If it is |
| 1789 | // frozen, there is no reason to animate and it can cause strange |
| 1790 | // artifacts when we unfreeze the display if some different animation |
| 1791 | // is running. |
| 1792 | if (!mDisplayFrozen) { |
| 1793 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 1794 | int attr = -1; |
| 1795 | Animation a = null; |
| 1796 | if (anim != 0) { |
| 1797 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 1798 | } else { |
| 1799 | switch (transit) { |
| 1800 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 1801 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 1802 | break; |
| 1803 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 1804 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 1805 | break; |
| 1806 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 1807 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 1808 | break; |
| 1809 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 1810 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 1811 | break; |
| 1812 | } |
| 1813 | if (attr >= 0) { |
| 1814 | a = loadAnimation(win.mAttrs, attr); |
| 1815 | } |
| 1816 | } |
| 1817 | if (DEBUG_ANIM) Log.v(TAG, "applyAnimation: win=" + win |
| 1818 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 1819 | + " mAnimation=" + win.mAnimation |
| 1820 | + " isEntrance=" + isEntrance); |
| 1821 | if (a != null) { |
| 1822 | if (DEBUG_ANIM) { |
| 1823 | RuntimeException e = new RuntimeException(); |
| 1824 | e.fillInStackTrace(); |
| 1825 | Log.v(TAG, "Loaded animation " + a + " for " + win, e); |
| 1826 | } |
| 1827 | win.setAnimation(a); |
| 1828 | win.mAnimationIsEntrance = isEntrance; |
| 1829 | } |
| 1830 | } else { |
| 1831 | win.clearAnimation(); |
| 1832 | } |
| 1833 | |
| 1834 | return win.mAnimation != null; |
| 1835 | } |
| 1836 | |
| 1837 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 1838 | int anim = 0; |
| 1839 | Context context = mContext; |
| 1840 | if (animAttr >= 0) { |
| 1841 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 1842 | if (ent != null) { |
| 1843 | context = ent.context; |
| 1844 | anim = ent.array.getResourceId(animAttr, 0); |
| 1845 | } |
| 1846 | } |
| 1847 | if (anim != 0) { |
| 1848 | return AnimationUtils.loadAnimation(context, anim); |
| 1849 | } |
| 1850 | return null; |
| 1851 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1852 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1853 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 1854 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 1855 | // Only apply an animation if the display isn't frozen. If it is |
| 1856 | // frozen, there is no reason to animate and it can cause strange |
| 1857 | // artifacts when we unfreeze the display if some different animation |
| 1858 | // is running. |
| 1859 | if (!mDisplayFrozen) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 1860 | Animation a; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 1861 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 1862 | a = new FadeInOutAnimation(enter); |
| 1863 | if (DEBUG_ANIM) Log.v(TAG, |
| 1864 | "applying FadeInOutAnimation for a window in compatibility mode"); |
| 1865 | } else { |
| 1866 | int animAttr = 0; |
| 1867 | switch (transit) { |
| 1868 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 1869 | animAttr = enter |
| 1870 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 1871 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 1872 | break; |
| 1873 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 1874 | animAttr = enter |
| 1875 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 1876 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 1877 | break; |
| 1878 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 1879 | animAttr = enter |
| 1880 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 1881 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 1882 | break; |
| 1883 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 1884 | animAttr = enter |
| 1885 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 1886 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 1887 | break; |
| 1888 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 1889 | animAttr = enter |
| 1890 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 1891 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 1892 | break; |
| 1893 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 1894 | animAttr = enter |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 1895 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 1896 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 1897 | break; |
| 1898 | } |
| 1899 | a = loadAnimation(lp, animAttr); |
| 1900 | if (DEBUG_ANIM) Log.v(TAG, "applyAnimation: wtoken=" + wtoken |
| 1901 | + " anim=" + a |
| 1902 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 1903 | + " transit=" + transit); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1904 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1905 | if (a != null) { |
| 1906 | if (DEBUG_ANIM) { |
| 1907 | RuntimeException e = new RuntimeException(); |
| 1908 | e.fillInStackTrace(); |
| 1909 | Log.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
| 1910 | } |
| 1911 | wtoken.setAnimation(a); |
| 1912 | } |
| 1913 | } else { |
| 1914 | wtoken.clearAnimation(); |
| 1915 | } |
| 1916 | |
| 1917 | return wtoken.animation != null; |
| 1918 | } |
| 1919 | |
| 1920 | // ------------------------------------------------------------- |
| 1921 | // Application Window Tokens |
| 1922 | // ------------------------------------------------------------- |
| 1923 | |
| 1924 | public void validateAppTokens(List tokens) { |
| 1925 | int v = tokens.size()-1; |
| 1926 | int m = mAppTokens.size()-1; |
| 1927 | while (v >= 0 && m >= 0) { |
| 1928 | AppWindowToken wtoken = mAppTokens.get(m); |
| 1929 | if (wtoken.removed) { |
| 1930 | m--; |
| 1931 | continue; |
| 1932 | } |
| 1933 | if (tokens.get(v) != wtoken.token) { |
| 1934 | Log.w(TAG, "Tokens out of sync: external is " + tokens.get(v) |
| 1935 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 1936 | } |
| 1937 | v--; |
| 1938 | m--; |
| 1939 | } |
| 1940 | while (v >= 0) { |
| 1941 | Log.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v); |
| 1942 | v--; |
| 1943 | } |
| 1944 | while (m >= 0) { |
| 1945 | AppWindowToken wtoken = mAppTokens.get(m); |
| 1946 | if (!wtoken.removed) { |
| 1947 | Log.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
| 1948 | } |
| 1949 | m--; |
| 1950 | } |
| 1951 | } |
| 1952 | |
| 1953 | boolean checkCallingPermission(String permission, String func) { |
| 1954 | // Quick check: if the calling permission is me, it's all okay. |
| 1955 | if (Binder.getCallingPid() == Process.myPid()) { |
| 1956 | return true; |
| 1957 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1958 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1959 | if (mContext.checkCallingPermission(permission) |
| 1960 | == PackageManager.PERMISSION_GRANTED) { |
| 1961 | return true; |
| 1962 | } |
| 1963 | String msg = "Permission Denial: " + func + " from pid=" |
| 1964 | + Binder.getCallingPid() |
| 1965 | + ", uid=" + Binder.getCallingUid() |
| 1966 | + " requires " + permission; |
| 1967 | Log.w(TAG, msg); |
| 1968 | return false; |
| 1969 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1970 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1971 | AppWindowToken findAppWindowToken(IBinder token) { |
| 1972 | WindowToken wtoken = mTokenMap.get(token); |
| 1973 | if (wtoken == null) { |
| 1974 | return null; |
| 1975 | } |
| 1976 | return wtoken.appWindowToken; |
| 1977 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1978 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1979 | public void addWindowToken(IBinder token, int type) { |
| 1980 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 1981 | "addWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 1982 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1983 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1984 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1985 | synchronized(mWindowMap) { |
| 1986 | WindowToken wtoken = mTokenMap.get(token); |
| 1987 | if (wtoken != null) { |
| 1988 | Log.w(TAG, "Attempted to add existing input method token: " + token); |
| 1989 | return; |
| 1990 | } |
| 1991 | wtoken = new WindowToken(token, type, true); |
| 1992 | mTokenMap.put(token, wtoken); |
| 1993 | mTokenList.add(wtoken); |
| 1994 | } |
| 1995 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1996 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1997 | public void removeWindowToken(IBinder token) { |
| 1998 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 1999 | "removeWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2000 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | final long origId = Binder.clearCallingIdentity(); |
| 2004 | synchronized(mWindowMap) { |
| 2005 | WindowToken wtoken = mTokenMap.remove(token); |
| 2006 | mTokenList.remove(wtoken); |
| 2007 | if (wtoken != null) { |
| 2008 | boolean delayed = false; |
| 2009 | if (!wtoken.hidden) { |
| 2010 | wtoken.hidden = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2011 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2012 | final int N = wtoken.windows.size(); |
| 2013 | boolean changed = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2014 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2015 | for (int i=0; i<N; i++) { |
| 2016 | WindowState win = wtoken.windows.get(i); |
| 2017 | |
| 2018 | if (win.isAnimating()) { |
| 2019 | delayed = true; |
| 2020 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2021 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2022 | if (win.isVisibleNow()) { |
| 2023 | applyAnimationLocked(win, |
| 2024 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 2025 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 2026 | KeyWaiter.RETURN_NOTHING); |
| 2027 | changed = true; |
| 2028 | } |
| 2029 | } |
| 2030 | |
| 2031 | if (changed) { |
| 2032 | mLayoutNeeded = true; |
| 2033 | performLayoutAndPlaceSurfacesLocked(); |
| 2034 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2035 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2036 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2037 | if (delayed) { |
| 2038 | mExitingTokens.add(wtoken); |
| 2039 | } |
| 2040 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2041 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2042 | } else { |
| 2043 | Log.w(TAG, "Attempted to remove non-existing token: " + token); |
| 2044 | } |
| 2045 | } |
| 2046 | Binder.restoreCallingIdentity(origId); |
| 2047 | } |
| 2048 | |
| 2049 | public void addAppToken(int addPos, IApplicationToken token, |
| 2050 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 2051 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2052 | "addAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2053 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2054 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2055 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2056 | synchronized(mWindowMap) { |
| 2057 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 2058 | if (wtoken != null) { |
| 2059 | Log.w(TAG, "Attempted to add existing app token: " + token); |
| 2060 | return; |
| 2061 | } |
| 2062 | wtoken = new AppWindowToken(token); |
| 2063 | wtoken.groupId = groupId; |
| 2064 | wtoken.appFullscreen = fullscreen; |
| 2065 | wtoken.requestedOrientation = requestedOrientation; |
| 2066 | mAppTokens.add(addPos, wtoken); |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 2067 | if (localLOGV) Log.v(TAG, "Adding new app token: " + wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2068 | mTokenMap.put(token.asBinder(), wtoken); |
| 2069 | mTokenList.add(wtoken); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2070 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2071 | // Application tokens start out hidden. |
| 2072 | wtoken.hidden = true; |
| 2073 | wtoken.hiddenRequested = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2074 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2075 | //dump(); |
| 2076 | } |
| 2077 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2078 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2079 | public void setAppGroupId(IBinder token, int groupId) { |
| 2080 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2081 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2082 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2083 | } |
| 2084 | |
| 2085 | synchronized(mWindowMap) { |
| 2086 | AppWindowToken wtoken = findAppWindowToken(token); |
| 2087 | if (wtoken == null) { |
| 2088 | Log.w(TAG, "Attempted to set group id of non-existing app token: " + token); |
| 2089 | return; |
| 2090 | } |
| 2091 | wtoken.groupId = groupId; |
| 2092 | } |
| 2093 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2094 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2095 | public int getOrientationFromWindowsLocked() { |
| 2096 | int pos = mWindows.size() - 1; |
| 2097 | while (pos >= 0) { |
| 2098 | WindowState wtoken = (WindowState) mWindows.get(pos); |
| 2099 | pos--; |
| 2100 | if (wtoken.mAppToken != null) { |
| 2101 | // We hit an application window. so the orientation will be determined by the |
| 2102 | // app window. No point in continuing further. |
| 2103 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2104 | } |
| 2105 | if (!wtoken.isVisibleLw()) { |
| 2106 | continue; |
| 2107 | } |
| 2108 | int req = wtoken.mAttrs.screenOrientation; |
| 2109 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 2110 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 2111 | continue; |
| 2112 | } else { |
| 2113 | return req; |
| 2114 | } |
| 2115 | } |
| 2116 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2117 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2118 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2119 | public int getOrientationFromAppTokensLocked() { |
| 2120 | int pos = mAppTokens.size() - 1; |
| 2121 | int curGroup = 0; |
| 2122 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2123 | boolean findingBehind = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2124 | boolean haveGroup = false; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2125 | boolean lastFullscreen = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2126 | while (pos >= 0) { |
| 2127 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 2128 | pos--; |
Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2129 | // if we're about to tear down this window and not seek for |
| 2130 | // the behind activity, don't use it for orientation |
| 2131 | if (!findingBehind |
| 2132 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2133 | continue; |
| 2134 | } |
| 2135 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2136 | if (!haveGroup) { |
| 2137 | // We ignore any hidden applications on the top. |
| 2138 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
| 2139 | continue; |
| 2140 | } |
| 2141 | haveGroup = true; |
| 2142 | curGroup = wtoken.groupId; |
| 2143 | lastOrientation = wtoken.requestedOrientation; |
| 2144 | } else if (curGroup != wtoken.groupId) { |
| 2145 | // If we have hit a new application group, and the bottom |
| 2146 | // of the previous group didn't explicitly say to use |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2147 | // the orientation behind it, and the last app was |
| 2148 | // full screen, then we'll stick with the |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2149 | // user's orientation. |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2150 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 2151 | && lastFullscreen) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2152 | return lastOrientation; |
| 2153 | } |
| 2154 | } |
| 2155 | int or = wtoken.requestedOrientation; |
Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2156 | // If this application is fullscreen, and didn't explicitly say |
| 2157 | // to use the orientation behind it, then just take whatever |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2158 | // orientation it has and ignores whatever is under it. |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2159 | lastFullscreen = wtoken.appFullscreen; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2160 | if (lastFullscreen |
Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2161 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2162 | return or; |
| 2163 | } |
| 2164 | // If this application has requested an explicit orientation, |
| 2165 | // then use it. |
| 2166 | if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || |
| 2167 | or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || |
| 2168 | or == ActivityInfo.SCREEN_ORIENTATION_SENSOR || |
| 2169 | or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR || |
| 2170 | or == ActivityInfo.SCREEN_ORIENTATION_USER) { |
| 2171 | return or; |
| 2172 | } |
Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2173 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2174 | } |
| 2175 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2176 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2177 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2178 | public Configuration updateOrientationFromAppTokens( |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2179 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2180 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2181 | "updateOrientationFromAppTokens()")) { |
| 2182 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 2183 | } |
| 2184 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2185 | Configuration config; |
| 2186 | long ident = Binder.clearCallingIdentity(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2187 | config = updateOrientationFromAppTokensUnchecked(currentConfig, |
| 2188 | freezeThisOneIfNeeded); |
| 2189 | Binder.restoreCallingIdentity(ident); |
| 2190 | return config; |
| 2191 | } |
| 2192 | |
| 2193 | Configuration updateOrientationFromAppTokensUnchecked( |
| 2194 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| 2195 | Configuration config; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2196 | synchronized(mWindowMap) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2197 | config = updateOrientationFromAppTokensLocked(currentConfig, freezeThisOneIfNeeded); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2198 | } |
| 2199 | if (config != null) { |
| 2200 | mLayoutNeeded = true; |
| 2201 | performLayoutAndPlaceSurfacesLocked(); |
| 2202 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2203 | return config; |
| 2204 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2205 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2206 | /* |
| 2207 | * The orientation is computed from non-application windows first. If none of |
| 2208 | * the non-application windows specify orientation, the orientation is computed from |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2209 | * application tokens. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2210 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 2211 | * android.os.IBinder) |
| 2212 | */ |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2213 | Configuration updateOrientationFromAppTokensLocked( |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2214 | Configuration appConfig, IBinder freezeThisOneIfNeeded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2215 | boolean changed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2216 | long ident = Binder.clearCallingIdentity(); |
| 2217 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2218 | int req = computeForcedAppOrientationLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2219 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2220 | if (req != mForcedAppOrientation) { |
| 2221 | changed = true; |
| 2222 | mForcedAppOrientation = req; |
| 2223 | //send a message to Policy indicating orientation change to take |
| 2224 | //action like disabling/enabling sensors etc., |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2225 | mPolicy.setCurrentOrientationLw(req); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2226 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2227 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2228 | if (changed) { |
| 2229 | changed = setRotationUncheckedLocked( |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 2230 | WindowManagerPolicy.USE_LAST_ROTATION, |
| 2231 | mLastRotationFlags & (~Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2232 | if (changed) { |
| 2233 | if (freezeThisOneIfNeeded != null) { |
| 2234 | AppWindowToken wtoken = findAppWindowToken( |
| 2235 | freezeThisOneIfNeeded); |
| 2236 | if (wtoken != null) { |
| 2237 | startAppFreezingScreenLocked(wtoken, |
| 2238 | ActivityInfo.CONFIG_ORIENTATION); |
| 2239 | } |
| 2240 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 2241 | return computeNewConfigurationLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2242 | } |
| 2243 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2244 | |
| 2245 | // No obvious action we need to take, but if our current |
| 2246 | // state mismatches the activity maanager's, update it |
| 2247 | if (appConfig != null) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 2248 | mTempConfiguration.setToDefaults(); |
| 2249 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 2250 | if (appConfig.diff(mTempConfiguration) != 0) { |
| 2251 | Log.i(TAG, "Config changed: " + mTempConfiguration); |
| 2252 | return new Configuration(mTempConfiguration); |
| 2253 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2254 | } |
| 2255 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2256 | } finally { |
| 2257 | Binder.restoreCallingIdentity(ident); |
| 2258 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2259 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2260 | return null; |
| 2261 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2262 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2263 | int computeForcedAppOrientationLocked() { |
| 2264 | int req = getOrientationFromWindowsLocked(); |
| 2265 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 2266 | req = getOrientationFromAppTokensLocked(); |
| 2267 | } |
| 2268 | return req; |
| 2269 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2270 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2271 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 2272 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2273 | "setAppOrientation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2274 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2275 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2276 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2277 | synchronized(mWindowMap) { |
| 2278 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 2279 | if (wtoken == null) { |
| 2280 | Log.w(TAG, "Attempted to set orientation of non-existing app token: " + token); |
| 2281 | return; |
| 2282 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2283 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2284 | wtoken.requestedOrientation = requestedOrientation; |
| 2285 | } |
| 2286 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2287 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2288 | public int getAppOrientation(IApplicationToken token) { |
| 2289 | synchronized(mWindowMap) { |
| 2290 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 2291 | if (wtoken == null) { |
| 2292 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2293 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2294 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2295 | return wtoken.requestedOrientation; |
| 2296 | } |
| 2297 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2298 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2299 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 2300 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2301 | "setFocusedApp()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2302 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2303 | } |
| 2304 | |
| 2305 | synchronized(mWindowMap) { |
| 2306 | boolean changed = false; |
| 2307 | if (token == null) { |
| 2308 | if (DEBUG_FOCUS) Log.v(TAG, "Clearing focused app, was " + mFocusedApp); |
| 2309 | changed = mFocusedApp != null; |
| 2310 | mFocusedApp = null; |
| 2311 | mKeyWaiter.tickle(); |
| 2312 | } else { |
| 2313 | AppWindowToken newFocus = findAppWindowToken(token); |
| 2314 | if (newFocus == null) { |
| 2315 | Log.w(TAG, "Attempted to set focus to non-existing app token: " + token); |
| 2316 | return; |
| 2317 | } |
| 2318 | changed = mFocusedApp != newFocus; |
| 2319 | mFocusedApp = newFocus; |
| 2320 | if (DEBUG_FOCUS) Log.v(TAG, "Set focused app to: " + mFocusedApp); |
| 2321 | mKeyWaiter.tickle(); |
| 2322 | } |
| 2323 | |
| 2324 | if (moveFocusNow && changed) { |
| 2325 | final long origId = Binder.clearCallingIdentity(); |
| 2326 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2327 | Binder.restoreCallingIdentity(origId); |
| 2328 | } |
| 2329 | } |
| 2330 | } |
| 2331 | |
| 2332 | public void prepareAppTransition(int transit) { |
| 2333 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2334 | "prepareAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2335 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2336 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2337 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2338 | synchronized(mWindowMap) { |
| 2339 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 2340 | TAG, "Prepare app transition: transit=" + transit |
| 2341 | + " mNextAppTransition=" + mNextAppTransition); |
| 2342 | if (!mDisplayFrozen) { |
| 2343 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
| 2344 | mNextAppTransition = transit; |
Dianne Hackborn | d7cd29d | 2009-07-01 11:22:45 -0700 | [diff] [blame] | 2345 | } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 2346 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 2347 | // Opening a new task always supersedes a close for the anim. |
| 2348 | mNextAppTransition = transit; |
| 2349 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 2350 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 2351 | // Opening a new activity always supersedes a close for the anim. |
| 2352 | mNextAppTransition = transit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2353 | } |
| 2354 | mAppTransitionReady = false; |
| 2355 | mAppTransitionTimeout = false; |
| 2356 | mStartingIconInTransition = false; |
| 2357 | mSkipAppTransitionAnimation = false; |
| 2358 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 2359 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 2360 | 5000); |
| 2361 | } |
| 2362 | } |
| 2363 | } |
| 2364 | |
| 2365 | public int getPendingAppTransition() { |
| 2366 | return mNextAppTransition; |
| 2367 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2368 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2369 | public void executeAppTransition() { |
| 2370 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2371 | "executeAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2372 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2373 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2374 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2375 | synchronized(mWindowMap) { |
| 2376 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 2377 | TAG, "Execute app transition: mNextAppTransition=" + mNextAppTransition); |
| 2378 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) { |
| 2379 | mAppTransitionReady = true; |
| 2380 | final long origId = Binder.clearCallingIdentity(); |
| 2381 | performLayoutAndPlaceSurfacesLocked(); |
| 2382 | Binder.restoreCallingIdentity(origId); |
| 2383 | } |
| 2384 | } |
| 2385 | } |
| 2386 | |
| 2387 | public void setAppStartingWindow(IBinder token, String pkg, |
| 2388 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| 2389 | IBinder transferFrom, boolean createIfNeeded) { |
| 2390 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2391 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2392 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2393 | } |
| 2394 | |
| 2395 | synchronized(mWindowMap) { |
| 2396 | if (DEBUG_STARTING_WINDOW) Log.v( |
| 2397 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 2398 | + " transferFrom=" + transferFrom); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2399 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2400 | AppWindowToken wtoken = findAppWindowToken(token); |
| 2401 | if (wtoken == null) { |
| 2402 | Log.w(TAG, "Attempted to set icon of non-existing app token: " + token); |
| 2403 | return; |
| 2404 | } |
| 2405 | |
| 2406 | // If the display is frozen, we won't do anything until the |
| 2407 | // actual window is displayed so there is no reason to put in |
| 2408 | // the starting window. |
| 2409 | if (mDisplayFrozen) { |
| 2410 | return; |
| 2411 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2412 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2413 | if (wtoken.startingData != null) { |
| 2414 | return; |
| 2415 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2416 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2417 | if (transferFrom != null) { |
| 2418 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 2419 | if (ttoken != null) { |
| 2420 | WindowState startingWindow = ttoken.startingWindow; |
| 2421 | if (startingWindow != null) { |
| 2422 | if (mStartingIconInTransition) { |
| 2423 | // In this case, the starting icon has already |
| 2424 | // been displayed, so start letting windows get |
| 2425 | // shown immediately without any more transitions. |
| 2426 | mSkipAppTransitionAnimation = true; |
| 2427 | } |
| 2428 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 2429 | "Moving existing starting from " + ttoken |
| 2430 | + " to " + wtoken); |
| 2431 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2432 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2433 | // Transfer the starting window over to the new |
| 2434 | // token. |
| 2435 | wtoken.startingData = ttoken.startingData; |
| 2436 | wtoken.startingView = ttoken.startingView; |
| 2437 | wtoken.startingWindow = startingWindow; |
| 2438 | ttoken.startingData = null; |
| 2439 | ttoken.startingView = null; |
| 2440 | ttoken.startingWindow = null; |
| 2441 | ttoken.startingMoved = true; |
| 2442 | startingWindow.mToken = wtoken; |
Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 2443 | startingWindow.mRootToken = wtoken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2444 | startingWindow.mAppToken = wtoken; |
| 2445 | mWindows.remove(startingWindow); |
| 2446 | ttoken.windows.remove(startingWindow); |
| 2447 | ttoken.allAppWindows.remove(startingWindow); |
| 2448 | addWindowToListInOrderLocked(startingWindow, true); |
| 2449 | wtoken.allAppWindows.add(startingWindow); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2451 | // Propagate other interesting state between the |
| 2452 | // tokens. If the old token is displayed, we should |
| 2453 | // immediately force the new one to be displayed. If |
| 2454 | // it is animating, we need to move that animation to |
| 2455 | // the new one. |
| 2456 | if (ttoken.allDrawn) { |
| 2457 | wtoken.allDrawn = true; |
| 2458 | } |
| 2459 | if (ttoken.firstWindowDrawn) { |
| 2460 | wtoken.firstWindowDrawn = true; |
| 2461 | } |
| 2462 | if (!ttoken.hidden) { |
| 2463 | wtoken.hidden = false; |
| 2464 | wtoken.hiddenRequested = false; |
| 2465 | wtoken.willBeHidden = false; |
| 2466 | } |
| 2467 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 2468 | wtoken.clientHidden = ttoken.clientHidden; |
| 2469 | wtoken.sendAppVisibilityToClients(); |
| 2470 | } |
| 2471 | if (ttoken.animation != null) { |
| 2472 | wtoken.animation = ttoken.animation; |
| 2473 | wtoken.animating = ttoken.animating; |
| 2474 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 2475 | ttoken.animation = null; |
| 2476 | ttoken.animLayerAdjustment = 0; |
| 2477 | wtoken.updateLayers(); |
| 2478 | ttoken.updateLayers(); |
| 2479 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2480 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2481 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2482 | mLayoutNeeded = true; |
| 2483 | performLayoutAndPlaceSurfacesLocked(); |
| 2484 | Binder.restoreCallingIdentity(origId); |
| 2485 | return; |
| 2486 | } else if (ttoken.startingData != null) { |
| 2487 | // The previous app was getting ready to show a |
| 2488 | // starting window, but hasn't yet done so. Steal it! |
| 2489 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 2490 | "Moving pending starting from " + ttoken |
| 2491 | + " to " + wtoken); |
| 2492 | wtoken.startingData = ttoken.startingData; |
| 2493 | ttoken.startingData = null; |
| 2494 | ttoken.startingMoved = true; |
| 2495 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 2496 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 2497 | // want to process the message ASAP, before any other queued |
| 2498 | // messages. |
| 2499 | mH.sendMessageAtFrontOfQueue(m); |
| 2500 | return; |
| 2501 | } |
| 2502 | } |
| 2503 | } |
| 2504 | |
| 2505 | // There is no existing starting window, and the caller doesn't |
| 2506 | // want us to create one, so that's it! |
| 2507 | if (!createIfNeeded) { |
| 2508 | return; |
| 2509 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2510 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2511 | mStartingIconInTransition = true; |
| 2512 | wtoken.startingData = new StartingData( |
| 2513 | pkg, theme, nonLocalizedLabel, |
| 2514 | labelRes, icon); |
| 2515 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 2516 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 2517 | // want to process the message ASAP, before any other queued |
| 2518 | // messages. |
| 2519 | mH.sendMessageAtFrontOfQueue(m); |
| 2520 | } |
| 2521 | } |
| 2522 | |
| 2523 | public void setAppWillBeHidden(IBinder token) { |
| 2524 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2525 | "setAppWillBeHidden()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2526 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2527 | } |
| 2528 | |
| 2529 | AppWindowToken wtoken; |
| 2530 | |
| 2531 | synchronized(mWindowMap) { |
| 2532 | wtoken = findAppWindowToken(token); |
| 2533 | if (wtoken == null) { |
| 2534 | Log.w(TAG, "Attempted to set will be hidden of non-existing app token: " + token); |
| 2535 | return; |
| 2536 | } |
| 2537 | wtoken.willBeHidden = true; |
| 2538 | } |
| 2539 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2540 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2541 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 2542 | boolean visible, int transit, boolean performLayout) { |
| 2543 | boolean delayed = false; |
| 2544 | |
| 2545 | if (wtoken.clientHidden == visible) { |
| 2546 | wtoken.clientHidden = !visible; |
| 2547 | wtoken.sendAppVisibilityToClients(); |
| 2548 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2549 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2550 | wtoken.willBeHidden = false; |
| 2551 | if (wtoken.hidden == visible) { |
| 2552 | final int N = wtoken.allAppWindows.size(); |
| 2553 | boolean changed = false; |
| 2554 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 2555 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 2556 | + " performLayout=" + performLayout); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2557 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2558 | boolean runningAppAnimation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2559 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2560 | if (transit != WindowManagerPolicy.TRANSIT_NONE) { |
| 2561 | if (wtoken.animation == sDummyAnimation) { |
| 2562 | wtoken.animation = null; |
| 2563 | } |
| 2564 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 2565 | changed = true; |
| 2566 | if (wtoken.animation != null) { |
| 2567 | delayed = runningAppAnimation = true; |
| 2568 | } |
| 2569 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2570 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2571 | for (int i=0; i<N; i++) { |
| 2572 | WindowState win = wtoken.allAppWindows.get(i); |
| 2573 | if (win == wtoken.startingWindow) { |
| 2574 | continue; |
| 2575 | } |
| 2576 | |
| 2577 | if (win.isAnimating()) { |
| 2578 | delayed = true; |
| 2579 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2580 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2581 | //Log.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
| 2582 | //win.dump(" "); |
| 2583 | if (visible) { |
| 2584 | if (!win.isVisibleNow()) { |
| 2585 | if (!runningAppAnimation) { |
| 2586 | applyAnimationLocked(win, |
| 2587 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 2588 | } |
| 2589 | changed = true; |
| 2590 | } |
| 2591 | } else if (win.isVisibleNow()) { |
| 2592 | if (!runningAppAnimation) { |
| 2593 | applyAnimationLocked(win, |
| 2594 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 2595 | } |
| 2596 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 2597 | KeyWaiter.RETURN_NOTHING); |
| 2598 | changed = true; |
| 2599 | } |
| 2600 | } |
| 2601 | |
| 2602 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 2603 | if (!visible) { |
| 2604 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 2605 | } else { |
| 2606 | // If we are being set visible, and the starting window is |
| 2607 | // not yet displayed, then make sure it doesn't get displayed. |
| 2608 | WindowState swin = wtoken.startingWindow; |
| 2609 | if (swin != null && (swin.mDrawPending |
| 2610 | || swin.mCommitDrawPending)) { |
| 2611 | swin.mPolicyVisibility = false; |
| 2612 | swin.mPolicyVisibilityAfterAnim = false; |
| 2613 | } |
| 2614 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2615 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2616 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "setTokenVisibilityLocked: " + wtoken |
| 2617 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 2618 | + wtoken.hiddenRequested); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2619 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2620 | if (changed && performLayout) { |
| 2621 | mLayoutNeeded = true; |
| 2622 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2623 | performLayoutAndPlaceSurfacesLocked(); |
| 2624 | } |
| 2625 | } |
| 2626 | |
| 2627 | if (wtoken.animation != null) { |
| 2628 | delayed = true; |
| 2629 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2630 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2631 | return delayed; |
| 2632 | } |
| 2633 | |
| 2634 | public void setAppVisibility(IBinder token, boolean visible) { |
| 2635 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2636 | "setAppVisibility()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2637 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2638 | } |
| 2639 | |
| 2640 | AppWindowToken wtoken; |
| 2641 | |
| 2642 | synchronized(mWindowMap) { |
| 2643 | wtoken = findAppWindowToken(token); |
| 2644 | if (wtoken == null) { |
| 2645 | Log.w(TAG, "Attempted to set visibility of non-existing app token: " + token); |
| 2646 | return; |
| 2647 | } |
| 2648 | |
| 2649 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
| 2650 | RuntimeException e = new RuntimeException(); |
| 2651 | e.fillInStackTrace(); |
| 2652 | Log.v(TAG, "setAppVisibility(" + token + ", " + visible |
| 2653 | + "): mNextAppTransition=" + mNextAppTransition |
| 2654 | + " hidden=" + wtoken.hidden |
| 2655 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 2656 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2657 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2658 | // If we are preparing an app transition, then delay changing |
| 2659 | // the visibility of this token until we execute that transition. |
| 2660 | if (!mDisplayFrozen && mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) { |
| 2661 | // Already in requested state, don't do anything more. |
| 2662 | if (wtoken.hiddenRequested != visible) { |
| 2663 | return; |
| 2664 | } |
| 2665 | wtoken.hiddenRequested = !visible; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2666 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2667 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 2668 | TAG, "Setting dummy animation on: " + wtoken); |
| 2669 | wtoken.setDummyAnimation(); |
| 2670 | mOpeningApps.remove(wtoken); |
| 2671 | mClosingApps.remove(wtoken); |
| 2672 | wtoken.inPendingTransaction = true; |
| 2673 | if (visible) { |
| 2674 | mOpeningApps.add(wtoken); |
| 2675 | wtoken.allDrawn = false; |
| 2676 | wtoken.startingDisplayed = false; |
| 2677 | wtoken.startingMoved = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2678 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2679 | if (wtoken.clientHidden) { |
| 2680 | // In the case where we are making an app visible |
| 2681 | // but holding off for a transition, we still need |
| 2682 | // to tell the client to make its windows visible so |
| 2683 | // they get drawn. Otherwise, we will wait on |
| 2684 | // performing the transition until all windows have |
| 2685 | // been drawn, they never will be, and we are sad. |
| 2686 | wtoken.clientHidden = false; |
| 2687 | wtoken.sendAppVisibilityToClients(); |
| 2688 | } |
| 2689 | } else { |
| 2690 | mClosingApps.add(wtoken); |
| 2691 | } |
| 2692 | return; |
| 2693 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2694 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2695 | final long origId = Binder.clearCallingIdentity(); |
| 2696 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_NONE, true); |
| 2697 | wtoken.updateReportedVisibilityLocked(); |
| 2698 | Binder.restoreCallingIdentity(origId); |
| 2699 | } |
| 2700 | } |
| 2701 | |
| 2702 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 2703 | boolean unfreezeSurfaceNow, boolean force) { |
| 2704 | if (wtoken.freezingScreen) { |
| 2705 | if (DEBUG_ORIENTATION) Log.v(TAG, "Clear freezing of " + wtoken |
| 2706 | + " force=" + force); |
| 2707 | final int N = wtoken.allAppWindows.size(); |
| 2708 | boolean unfrozeWindows = false; |
| 2709 | for (int i=0; i<N; i++) { |
| 2710 | WindowState w = wtoken.allAppWindows.get(i); |
| 2711 | if (w.mAppFreezing) { |
| 2712 | w.mAppFreezing = false; |
| 2713 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 2714 | w.mOrientationChanging = true; |
| 2715 | } |
| 2716 | unfrozeWindows = true; |
| 2717 | } |
| 2718 | } |
| 2719 | if (force || unfrozeWindows) { |
| 2720 | if (DEBUG_ORIENTATION) Log.v(TAG, "No longer freezing: " + wtoken); |
| 2721 | wtoken.freezingScreen = false; |
| 2722 | mAppsFreezingScreen--; |
| 2723 | } |
| 2724 | if (unfreezeSurfaceNow) { |
| 2725 | if (unfrozeWindows) { |
| 2726 | mLayoutNeeded = true; |
| 2727 | performLayoutAndPlaceSurfacesLocked(); |
| 2728 | } |
| 2729 | if (mAppsFreezingScreen == 0 && !mWindowsFreezingScreen) { |
| 2730 | stopFreezingDisplayLocked(); |
| 2731 | } |
| 2732 | } |
| 2733 | } |
| 2734 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2735 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2736 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 2737 | int configChanges) { |
| 2738 | if (DEBUG_ORIENTATION) { |
| 2739 | RuntimeException e = new RuntimeException(); |
| 2740 | e.fillInStackTrace(); |
| 2741 | Log.i(TAG, "Set freezing of " + wtoken.appToken |
| 2742 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 2743 | + wtoken.freezingScreen, e); |
| 2744 | } |
| 2745 | if (!wtoken.hiddenRequested) { |
| 2746 | if (!wtoken.freezingScreen) { |
| 2747 | wtoken.freezingScreen = true; |
| 2748 | mAppsFreezingScreen++; |
| 2749 | if (mAppsFreezingScreen == 1) { |
| 2750 | startFreezingDisplayLocked(); |
| 2751 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 2752 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 2753 | 5000); |
| 2754 | } |
| 2755 | } |
| 2756 | final int N = wtoken.allAppWindows.size(); |
| 2757 | for (int i=0; i<N; i++) { |
| 2758 | WindowState w = wtoken.allAppWindows.get(i); |
| 2759 | w.mAppFreezing = true; |
| 2760 | } |
| 2761 | } |
| 2762 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2763 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2764 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 2765 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2766 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2767 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2768 | } |
| 2769 | |
| 2770 | synchronized(mWindowMap) { |
| 2771 | if (configChanges == 0 && !mDisplayFrozen) { |
| 2772 | if (DEBUG_ORIENTATION) Log.v(TAG, "Skipping set freeze of " + token); |
| 2773 | return; |
| 2774 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2775 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2776 | AppWindowToken wtoken = findAppWindowToken(token); |
| 2777 | if (wtoken == null || wtoken.appToken == null) { |
| 2778 | Log.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken); |
| 2779 | return; |
| 2780 | } |
| 2781 | final long origId = Binder.clearCallingIdentity(); |
| 2782 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 2783 | Binder.restoreCallingIdentity(origId); |
| 2784 | } |
| 2785 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2786 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2787 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 2788 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2789 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2790 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2791 | } |
| 2792 | |
| 2793 | synchronized(mWindowMap) { |
| 2794 | AppWindowToken wtoken = findAppWindowToken(token); |
| 2795 | if (wtoken == null || wtoken.appToken == null) { |
| 2796 | return; |
| 2797 | } |
| 2798 | final long origId = Binder.clearCallingIdentity(); |
| 2799 | if (DEBUG_ORIENTATION) Log.v(TAG, "Clear freezing of " + token |
| 2800 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 2801 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 2802 | Binder.restoreCallingIdentity(origId); |
| 2803 | } |
| 2804 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2805 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2806 | public void removeAppToken(IBinder token) { |
| 2807 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2808 | "removeAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2809 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2810 | } |
| 2811 | |
| 2812 | AppWindowToken wtoken = null; |
| 2813 | AppWindowToken startingToken = null; |
| 2814 | boolean delayed = false; |
| 2815 | |
| 2816 | final long origId = Binder.clearCallingIdentity(); |
| 2817 | synchronized(mWindowMap) { |
| 2818 | WindowToken basewtoken = mTokenMap.remove(token); |
| 2819 | mTokenList.remove(basewtoken); |
| 2820 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
| 2821 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "Removing app token: " + wtoken); |
| 2822 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_NONE, true); |
| 2823 | wtoken.inPendingTransaction = false; |
| 2824 | mOpeningApps.remove(wtoken); |
| 2825 | if (mClosingApps.contains(wtoken)) { |
| 2826 | delayed = true; |
| 2827 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) { |
| 2828 | mClosingApps.add(wtoken); |
| 2829 | delayed = true; |
| 2830 | } |
| 2831 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 2832 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 2833 | + " animation=" + wtoken.animation |
| 2834 | + " animating=" + wtoken.animating); |
| 2835 | if (delayed) { |
| 2836 | // set the token aside because it has an active animation to be finished |
| 2837 | mExitingAppTokens.add(wtoken); |
| 2838 | } |
| 2839 | mAppTokens.remove(wtoken); |
| 2840 | wtoken.removed = true; |
| 2841 | if (wtoken.startingData != null) { |
| 2842 | startingToken = wtoken; |
| 2843 | } |
| 2844 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 2845 | if (mFocusedApp == wtoken) { |
| 2846 | if (DEBUG_FOCUS) Log.v(TAG, "Removing focused app token:" + wtoken); |
| 2847 | mFocusedApp = null; |
| 2848 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2849 | mKeyWaiter.tickle(); |
| 2850 | } |
| 2851 | } else { |
| 2852 | Log.w(TAG, "Attempted to remove non-existing app token: " + token); |
| 2853 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2854 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2855 | if (!delayed && wtoken != null) { |
| 2856 | wtoken.updateReportedVisibilityLocked(); |
| 2857 | } |
| 2858 | } |
| 2859 | Binder.restoreCallingIdentity(origId); |
| 2860 | |
| 2861 | if (startingToken != null) { |
| 2862 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Schedule remove starting " |
| 2863 | + startingToken + ": app token removed"); |
| 2864 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 2865 | mH.sendMessage(m); |
| 2866 | } |
| 2867 | } |
| 2868 | |
| 2869 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 2870 | final int NW = token.windows.size(); |
| 2871 | for (int i=0; i<NW; i++) { |
| 2872 | WindowState win = token.windows.get(i); |
| 2873 | mWindows.remove(win); |
| 2874 | int j = win.mChildWindows.size(); |
| 2875 | while (j > 0) { |
| 2876 | j--; |
| 2877 | mWindows.remove(win.mChildWindows.get(j)); |
| 2878 | } |
| 2879 | } |
| 2880 | return NW > 0; |
| 2881 | } |
| 2882 | |
| 2883 | void dumpAppTokensLocked() { |
| 2884 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| 2885 | Log.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
| 2886 | } |
| 2887 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2888 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2889 | void dumpWindowsLocked() { |
| 2890 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 2891 | Log.v(TAG, " #" + i + ": " + mWindows.get(i)); |
| 2892 | } |
| 2893 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2894 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2895 | private int findWindowOffsetLocked(int tokenPos) { |
| 2896 | final int NW = mWindows.size(); |
| 2897 | |
| 2898 | if (tokenPos >= mAppTokens.size()) { |
| 2899 | int i = NW; |
| 2900 | while (i > 0) { |
| 2901 | i--; |
| 2902 | WindowState win = (WindowState)mWindows.get(i); |
| 2903 | if (win.getAppToken() != null) { |
| 2904 | return i+1; |
| 2905 | } |
| 2906 | } |
| 2907 | } |
| 2908 | |
| 2909 | while (tokenPos > 0) { |
| 2910 | // Find the first app token below the new position that has |
| 2911 | // a window displayed. |
| 2912 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
| 2913 | if (DEBUG_REORDER) Log.v(TAG, "Looking for lower windows @ " |
| 2914 | + tokenPos + " -- " + wtoken.token); |
| 2915 | int i = wtoken.windows.size(); |
| 2916 | while (i > 0) { |
| 2917 | i--; |
| 2918 | WindowState win = wtoken.windows.get(i); |
| 2919 | int j = win.mChildWindows.size(); |
| 2920 | while (j > 0) { |
| 2921 | j--; |
| 2922 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| 2923 | if (cwin.mSubLayer >= 0 ) { |
| 2924 | for (int pos=NW-1; pos>=0; pos--) { |
| 2925 | if (mWindows.get(pos) == cwin) { |
| 2926 | if (DEBUG_REORDER) Log.v(TAG, |
| 2927 | "Found child win @" + (pos+1)); |
| 2928 | return pos+1; |
| 2929 | } |
| 2930 | } |
| 2931 | } |
| 2932 | } |
| 2933 | for (int pos=NW-1; pos>=0; pos--) { |
| 2934 | if (mWindows.get(pos) == win) { |
| 2935 | if (DEBUG_REORDER) Log.v(TAG, "Found win @" + (pos+1)); |
| 2936 | return pos+1; |
| 2937 | } |
| 2938 | } |
| 2939 | } |
| 2940 | tokenPos--; |
| 2941 | } |
| 2942 | |
| 2943 | return 0; |
| 2944 | } |
| 2945 | |
| 2946 | private final int reAddWindowLocked(int index, WindowState win) { |
| 2947 | final int NCW = win.mChildWindows.size(); |
| 2948 | boolean added = false; |
| 2949 | for (int j=0; j<NCW; j++) { |
| 2950 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| 2951 | if (!added && cwin.mSubLayer >= 0) { |
| 2952 | mWindows.add(index, win); |
| 2953 | index++; |
| 2954 | added = true; |
| 2955 | } |
| 2956 | mWindows.add(index, cwin); |
| 2957 | index++; |
| 2958 | } |
| 2959 | if (!added) { |
| 2960 | mWindows.add(index, win); |
| 2961 | index++; |
| 2962 | } |
| 2963 | return index; |
| 2964 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2965 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2966 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 2967 | final int NW = token.windows.size(); |
| 2968 | for (int i=0; i<NW; i++) { |
| 2969 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 2970 | } |
| 2971 | return index; |
| 2972 | } |
| 2973 | |
| 2974 | public void moveAppToken(int index, IBinder token) { |
| 2975 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2976 | "moveAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2977 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2978 | } |
| 2979 | |
| 2980 | synchronized(mWindowMap) { |
| 2981 | if (DEBUG_REORDER) Log.v(TAG, "Initial app tokens:"); |
| 2982 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 2983 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 2984 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
| 2985 | Log.w(TAG, "Attempting to reorder token that doesn't exist: " |
| 2986 | + token + " (" + wtoken + ")"); |
| 2987 | return; |
| 2988 | } |
| 2989 | mAppTokens.add(index, wtoken); |
| 2990 | if (DEBUG_REORDER) Log.v(TAG, "Moved " + token + " to " + index + ":"); |
| 2991 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2992 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2993 | final long origId = Binder.clearCallingIdentity(); |
| 2994 | if (DEBUG_REORDER) Log.v(TAG, "Removing windows in " + token + ":"); |
| 2995 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 2996 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
| 2997 | if (DEBUG_REORDER) Log.v(TAG, "Adding windows back in:"); |
| 2998 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 2999 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
| 3000 | if (DEBUG_REORDER) Log.v(TAG, "Final window list:"); |
| 3001 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3002 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3003 | mLayoutNeeded = true; |
| 3004 | performLayoutAndPlaceSurfacesLocked(); |
| 3005 | } |
| 3006 | Binder.restoreCallingIdentity(origId); |
| 3007 | } |
| 3008 | } |
| 3009 | |
| 3010 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 3011 | // XXX This should be done more efficiently! |
| 3012 | // (take advantage of the fact that both lists should be |
| 3013 | // ordered in the same way.) |
| 3014 | int N = tokens.size(); |
| 3015 | for (int i=0; i<N; i++) { |
| 3016 | IBinder token = tokens.get(i); |
| 3017 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 3018 | if (!mAppTokens.remove(wtoken)) { |
| 3019 | Log.w(TAG, "Attempting to reorder token that doesn't exist: " |
| 3020 | + token + " (" + wtoken + ")"); |
| 3021 | i--; |
| 3022 | N--; |
| 3023 | } |
| 3024 | } |
| 3025 | } |
| 3026 | |
| 3027 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 3028 | // First remove all of the windows from the list. |
| 3029 | final int N = tokens.size(); |
| 3030 | int i; |
| 3031 | for (i=0; i<N; i++) { |
| 3032 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 3033 | if (token != null) { |
| 3034 | tmpRemoveAppWindowsLocked(token); |
| 3035 | } |
| 3036 | } |
| 3037 | |
| 3038 | // Where to start adding? |
| 3039 | int pos = findWindowOffsetLocked(tokenPos); |
| 3040 | |
| 3041 | // And now add them back at the correct place. |
| 3042 | for (i=0; i<N; i++) { |
| 3043 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 3044 | if (token != null) { |
| 3045 | pos = reAddAppWindowsLocked(pos, token); |
| 3046 | } |
| 3047 | } |
| 3048 | |
| 3049 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3050 | mLayoutNeeded = true; |
| 3051 | performLayoutAndPlaceSurfacesLocked(); |
| 3052 | |
| 3053 | //dump(); |
| 3054 | } |
| 3055 | |
| 3056 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 3057 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3058 | "moveAppTokensToTop()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3059 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3060 | } |
| 3061 | |
| 3062 | final long origId = Binder.clearCallingIdentity(); |
| 3063 | synchronized(mWindowMap) { |
| 3064 | removeAppTokensLocked(tokens); |
| 3065 | final int N = tokens.size(); |
| 3066 | for (int i=0; i<N; i++) { |
| 3067 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 3068 | if (wt != null) { |
| 3069 | mAppTokens.add(wt); |
| 3070 | } |
| 3071 | } |
| 3072 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 3073 | } |
| 3074 | Binder.restoreCallingIdentity(origId); |
| 3075 | } |
| 3076 | |
| 3077 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 3078 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3079 | "moveAppTokensToBottom()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3080 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3081 | } |
| 3082 | |
| 3083 | final long origId = Binder.clearCallingIdentity(); |
| 3084 | synchronized(mWindowMap) { |
| 3085 | removeAppTokensLocked(tokens); |
| 3086 | final int N = tokens.size(); |
| 3087 | int pos = 0; |
| 3088 | for (int i=0; i<N; i++) { |
| 3089 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 3090 | if (wt != null) { |
| 3091 | mAppTokens.add(pos, wt); |
| 3092 | pos++; |
| 3093 | } |
| 3094 | } |
| 3095 | moveAppWindowsLocked(tokens, 0); |
| 3096 | } |
| 3097 | Binder.restoreCallingIdentity(origId); |
| 3098 | } |
| 3099 | |
| 3100 | // ------------------------------------------------------------- |
| 3101 | // Misc IWindowSession methods |
| 3102 | // ------------------------------------------------------------- |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3103 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3104 | public void disableKeyguard(IBinder token, String tag) { |
| 3105 | if (mContext.checkCallingPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| 3106 | != PackageManager.PERMISSION_GRANTED) { |
| 3107 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 3108 | } |
| 3109 | mKeyguardDisabled.acquire(token, tag); |
| 3110 | } |
| 3111 | |
| 3112 | public void reenableKeyguard(IBinder token) { |
| 3113 | if (mContext.checkCallingPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| 3114 | != PackageManager.PERMISSION_GRANTED) { |
| 3115 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 3116 | } |
| 3117 | synchronized (mKeyguardDisabled) { |
| 3118 | mKeyguardDisabled.release(token); |
| 3119 | |
| 3120 | if (!mKeyguardDisabled.isAcquired()) { |
| 3121 | // if we are the last one to reenable the keyguard wait until |
| 3122 | // we have actaully finished reenabling until returning |
| 3123 | mWaitingUntilKeyguardReenabled = true; |
| 3124 | while (mWaitingUntilKeyguardReenabled) { |
| 3125 | try { |
| 3126 | mKeyguardDisabled.wait(); |
| 3127 | } catch (InterruptedException e) { |
| 3128 | Thread.currentThread().interrupt(); |
| 3129 | } |
| 3130 | } |
| 3131 | } |
| 3132 | } |
| 3133 | } |
| 3134 | |
| 3135 | /** |
| 3136 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 3137 | */ |
| 3138 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
| 3139 | if (mContext.checkCallingPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| 3140 | != PackageManager.PERMISSION_GRANTED) { |
| 3141 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 3142 | } |
| 3143 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 3144 | public void onKeyguardExitResult(boolean success) { |
| 3145 | try { |
| 3146 | callback.onKeyguardExitResult(success); |
| 3147 | } catch (RemoteException e) { |
| 3148 | // Client has died, we don't care. |
| 3149 | } |
| 3150 | } |
| 3151 | }); |
| 3152 | } |
| 3153 | |
| 3154 | public boolean inKeyguardRestrictedInputMode() { |
| 3155 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 3156 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3157 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3158 | static float fixScale(float scale) { |
| 3159 | if (scale < 0) scale = 0; |
| 3160 | else if (scale > 20) scale = 20; |
| 3161 | return Math.abs(scale); |
| 3162 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3163 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3164 | public void setAnimationScale(int which, float scale) { |
| 3165 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 3166 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3167 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3168 | } |
| 3169 | |
| 3170 | if (scale < 0) scale = 0; |
| 3171 | else if (scale > 20) scale = 20; |
| 3172 | scale = Math.abs(scale); |
| 3173 | switch (which) { |
| 3174 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 3175 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 3176 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3177 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3178 | // Persist setting |
| 3179 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 3180 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3181 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3182 | public void setAnimationScales(float[] scales) { |
| 3183 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 3184 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3185 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3186 | } |
| 3187 | |
| 3188 | if (scales != null) { |
| 3189 | if (scales.length >= 1) { |
| 3190 | mWindowAnimationScale = fixScale(scales[0]); |
| 3191 | } |
| 3192 | if (scales.length >= 2) { |
| 3193 | mTransitionAnimationScale = fixScale(scales[1]); |
| 3194 | } |
| 3195 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3196 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3197 | // Persist setting |
| 3198 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 3199 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3200 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3201 | public float getAnimationScale(int which) { |
| 3202 | switch (which) { |
| 3203 | case 0: return mWindowAnimationScale; |
| 3204 | case 1: return mTransitionAnimationScale; |
| 3205 | } |
| 3206 | return 0; |
| 3207 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3208 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3209 | public float[] getAnimationScales() { |
| 3210 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 3211 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3212 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3213 | public int getSwitchState(int sw) { |
| 3214 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 3215 | "getSwitchState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3216 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3217 | } |
| 3218 | return KeyInputQueue.getSwitchState(sw); |
| 3219 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3220 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3221 | public int getSwitchStateForDevice(int devid, int sw) { |
| 3222 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 3223 | "getSwitchStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3224 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3225 | } |
| 3226 | return KeyInputQueue.getSwitchState(devid, sw); |
| 3227 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3228 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3229 | public int getScancodeState(int sw) { |
| 3230 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 3231 | "getScancodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3232 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3233 | } |
| 3234 | return KeyInputQueue.getScancodeState(sw); |
| 3235 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3236 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3237 | public int getScancodeStateForDevice(int devid, int sw) { |
| 3238 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 3239 | "getScancodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3240 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3241 | } |
| 3242 | return KeyInputQueue.getScancodeState(devid, sw); |
| 3243 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3244 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3245 | public int getKeycodeState(int sw) { |
| 3246 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 3247 | "getKeycodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3248 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3249 | } |
| 3250 | return KeyInputQueue.getKeycodeState(sw); |
| 3251 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3252 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3253 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 3254 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 3255 | "getKeycodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3256 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3257 | } |
| 3258 | return KeyInputQueue.getKeycodeState(devid, sw); |
| 3259 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3260 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3261 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
| 3262 | return KeyInputQueue.hasKeys(keycodes, keyExists); |
| 3263 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3264 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3265 | public void enableScreenAfterBoot() { |
| 3266 | synchronized(mWindowMap) { |
| 3267 | if (mSystemBooted) { |
| 3268 | return; |
| 3269 | } |
| 3270 | mSystemBooted = true; |
| 3271 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3272 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3273 | performEnableScreen(); |
| 3274 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3275 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3276 | public void enableScreenIfNeededLocked() { |
| 3277 | if (mDisplayEnabled) { |
| 3278 | return; |
| 3279 | } |
| 3280 | if (!mSystemBooted) { |
| 3281 | return; |
| 3282 | } |
| 3283 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 3284 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3285 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3286 | public void performEnableScreen() { |
| 3287 | synchronized(mWindowMap) { |
| 3288 | if (mDisplayEnabled) { |
| 3289 | return; |
| 3290 | } |
| 3291 | if (!mSystemBooted) { |
| 3292 | return; |
| 3293 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3294 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3295 | // Don't enable the screen until all existing windows |
| 3296 | // have been drawn. |
| 3297 | final int N = mWindows.size(); |
| 3298 | for (int i=0; i<N; i++) { |
| 3299 | WindowState w = (WindowState)mWindows.get(i); |
| 3300 | if (w.isVisibleLw() && !w.isDisplayedLw()) { |
| 3301 | return; |
| 3302 | } |
| 3303 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3304 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3305 | mDisplayEnabled = true; |
| 3306 | if (false) { |
| 3307 | Log.i(TAG, "ENABLING SCREEN!"); |
| 3308 | StringWriter sw = new StringWriter(); |
| 3309 | PrintWriter pw = new PrintWriter(sw); |
| 3310 | this.dump(null, pw, null); |
| 3311 | Log.i(TAG, sw.toString()); |
| 3312 | } |
| 3313 | try { |
| 3314 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 3315 | if (surfaceFlinger != null) { |
| 3316 | //Log.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
| 3317 | Parcel data = Parcel.obtain(); |
| 3318 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 3319 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 3320 | data, null, 0); |
| 3321 | data.recycle(); |
| 3322 | } |
| 3323 | } catch (RemoteException ex) { |
| 3324 | Log.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
| 3325 | } |
| 3326 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3327 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3328 | mPolicy.enableScreenAfterBoot(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3329 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3330 | // Make sure the last requested orientation has been applied. |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 3331 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 3332 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3333 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3334 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3335 | public void setInTouchMode(boolean mode) { |
| 3336 | synchronized(mWindowMap) { |
| 3337 | mInTouchMode = mode; |
| 3338 | } |
| 3339 | } |
| 3340 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3341 | public void setRotation(int rotation, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3342 | boolean alwaysSendConfiguration, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3343 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3344 | "setRotation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3345 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3346 | } |
| 3347 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3348 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3349 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3350 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3351 | public void setRotationUnchecked(int rotation, |
| 3352 | boolean alwaysSendConfiguration, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3353 | if(DEBUG_ORIENTATION) Log.v(TAG, |
| 3354 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3355 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3356 | long origId = Binder.clearCallingIdentity(); |
| 3357 | boolean changed; |
| 3358 | synchronized(mWindowMap) { |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3359 | changed = setRotationUncheckedLocked(rotation, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3360 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3361 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3362 | if (changed) { |
| 3363 | sendNewConfiguration(); |
| 3364 | synchronized(mWindowMap) { |
| 3365 | mLayoutNeeded = true; |
| 3366 | performLayoutAndPlaceSurfacesLocked(); |
| 3367 | } |
| 3368 | } else if (alwaysSendConfiguration) { |
| 3369 | //update configuration ignoring orientation change |
| 3370 | sendNewConfiguration(); |
| 3371 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3372 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3373 | Binder.restoreCallingIdentity(origId); |
| 3374 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3375 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3376 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3377 | boolean changed; |
| 3378 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 3379 | rotation = mRequestedRotation; |
| 3380 | } else { |
| 3381 | mRequestedRotation = rotation; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 3382 | mLastRotationFlags = animFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3383 | } |
| 3384 | if (DEBUG_ORIENTATION) Log.v(TAG, "Overwriting rotation value from " + rotation); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3385 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3386 | mRotation, mDisplayEnabled); |
| 3387 | if (DEBUG_ORIENTATION) Log.v(TAG, "new rotation is set to " + rotation); |
| 3388 | changed = mDisplayEnabled && mRotation != rotation; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3389 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3390 | if (changed) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3391 | if (DEBUG_ORIENTATION) Log.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3392 | "Rotation changed to " + rotation |
| 3393 | + " from " + mRotation |
| 3394 | + " (forceApp=" + mForcedAppOrientation |
| 3395 | + ", req=" + mRequestedRotation + ")"); |
| 3396 | mRotation = rotation; |
| 3397 | mWindowsFreezingScreen = true; |
| 3398 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 3399 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 3400 | 2000); |
| 3401 | startFreezingDisplayLocked(); |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3402 | Log.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3403 | mQueue.setOrientation(rotation); |
| 3404 | if (mDisplayEnabled) { |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 3405 | Surface.setOrientation(0, rotation, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3406 | } |
| 3407 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 3408 | WindowState w = (WindowState)mWindows.get(i); |
| 3409 | if (w.mSurface != null) { |
| 3410 | w.mOrientationChanging = true; |
| 3411 | } |
| 3412 | } |
| 3413 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 3414 | try { |
| 3415 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 3416 | } catch (RemoteException e) { |
| 3417 | } |
| 3418 | } |
| 3419 | } //end if changed |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3420 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3421 | return changed; |
| 3422 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3423 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3424 | public int getRotation() { |
| 3425 | return mRotation; |
| 3426 | } |
| 3427 | |
| 3428 | public int watchRotation(IRotationWatcher watcher) { |
| 3429 | final IBinder watcherBinder = watcher.asBinder(); |
| 3430 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 3431 | public void binderDied() { |
| 3432 | synchronized (mWindowMap) { |
| 3433 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 3434 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 3435 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 3436 | if (removed != null) { |
| 3437 | removed.asBinder().unlinkToDeath(this, 0); |
| 3438 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3439 | i--; |
| 3440 | } |
| 3441 | } |
| 3442 | } |
| 3443 | } |
| 3444 | }; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3445 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3446 | synchronized (mWindowMap) { |
| 3447 | try { |
| 3448 | watcher.asBinder().linkToDeath(dr, 0); |
| 3449 | mRotationWatchers.add(watcher); |
| 3450 | } catch (RemoteException e) { |
| 3451 | // Client died, no cleanup needed. |
| 3452 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3453 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3454 | return mRotation; |
| 3455 | } |
| 3456 | } |
| 3457 | |
| 3458 | /** |
| 3459 | * Starts the view server on the specified port. |
| 3460 | * |
| 3461 | * @param port The port to listener to. |
| 3462 | * |
| 3463 | * @return True if the server was successfully started, false otherwise. |
| 3464 | * |
| 3465 | * @see com.android.server.ViewServer |
| 3466 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 3467 | */ |
| 3468 | public boolean startViewServer(int port) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3469 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3470 | return false; |
| 3471 | } |
| 3472 | |
| 3473 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 3474 | return false; |
| 3475 | } |
| 3476 | |
| 3477 | if (port < 1024) { |
| 3478 | return false; |
| 3479 | } |
| 3480 | |
| 3481 | if (mViewServer != null) { |
| 3482 | if (!mViewServer.isRunning()) { |
| 3483 | try { |
| 3484 | return mViewServer.start(); |
| 3485 | } catch (IOException e) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3486 | Log.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3487 | } |
| 3488 | } |
| 3489 | return false; |
| 3490 | } |
| 3491 | |
| 3492 | try { |
| 3493 | mViewServer = new ViewServer(this, port); |
| 3494 | return mViewServer.start(); |
| 3495 | } catch (IOException e) { |
| 3496 | Log.w(TAG, "View server did not start"); |
| 3497 | } |
| 3498 | return false; |
| 3499 | } |
| 3500 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3501 | private boolean isSystemSecure() { |
| 3502 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 3503 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 3504 | } |
| 3505 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3506 | /** |
| 3507 | * Stops the view server if it exists. |
| 3508 | * |
| 3509 | * @return True if the server stopped, false if it wasn't started or |
| 3510 | * couldn't be stopped. |
| 3511 | * |
| 3512 | * @see com.android.server.ViewServer |
| 3513 | */ |
| 3514 | public boolean stopViewServer() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3515 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3516 | return false; |
| 3517 | } |
| 3518 | |
| 3519 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 3520 | return false; |
| 3521 | } |
| 3522 | |
| 3523 | if (mViewServer != null) { |
| 3524 | return mViewServer.stop(); |
| 3525 | } |
| 3526 | return false; |
| 3527 | } |
| 3528 | |
| 3529 | /** |
| 3530 | * Indicates whether the view server is running. |
| 3531 | * |
| 3532 | * @return True if the server is running, false otherwise. |
| 3533 | * |
| 3534 | * @see com.android.server.ViewServer |
| 3535 | */ |
| 3536 | public boolean isViewServerRunning() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3537 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3538 | return false; |
| 3539 | } |
| 3540 | |
| 3541 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 3542 | return false; |
| 3543 | } |
| 3544 | |
| 3545 | return mViewServer != null && mViewServer.isRunning(); |
| 3546 | } |
| 3547 | |
| 3548 | /** |
| 3549 | * Lists all availble windows in the system. The listing is written in the |
| 3550 | * specified Socket's output stream with the following syntax: |
| 3551 | * windowHashCodeInHexadecimal windowName |
| 3552 | * Each line of the ouput represents a different window. |
| 3553 | * |
| 3554 | * @param client The remote client to send the listing to. |
| 3555 | * @return False if an error occured, true otherwise. |
| 3556 | */ |
| 3557 | boolean viewServerListWindows(Socket client) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3558 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3559 | return false; |
| 3560 | } |
| 3561 | |
| 3562 | boolean result = true; |
| 3563 | |
| 3564 | Object[] windows; |
| 3565 | synchronized (mWindowMap) { |
| 3566 | windows = new Object[mWindows.size()]; |
| 3567 | //noinspection unchecked |
| 3568 | windows = mWindows.toArray(windows); |
| 3569 | } |
| 3570 | |
| 3571 | BufferedWriter out = null; |
| 3572 | |
| 3573 | // Any uncaught exception will crash the system process |
| 3574 | try { |
| 3575 | OutputStream clientStream = client.getOutputStream(); |
| 3576 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 3577 | |
| 3578 | final int count = windows.length; |
| 3579 | for (int i = 0; i < count; i++) { |
| 3580 | final WindowState w = (WindowState) windows[i]; |
| 3581 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 3582 | out.write(' '); |
| 3583 | out.append(w.mAttrs.getTitle()); |
| 3584 | out.write('\n'); |
| 3585 | } |
| 3586 | |
| 3587 | out.write("DONE.\n"); |
| 3588 | out.flush(); |
| 3589 | } catch (Exception e) { |
| 3590 | result = false; |
| 3591 | } finally { |
| 3592 | if (out != null) { |
| 3593 | try { |
| 3594 | out.close(); |
| 3595 | } catch (IOException e) { |
| 3596 | result = false; |
| 3597 | } |
| 3598 | } |
| 3599 | } |
| 3600 | |
| 3601 | return result; |
| 3602 | } |
| 3603 | |
| 3604 | /** |
| 3605 | * Sends a command to a target window. The result of the command, if any, will be |
| 3606 | * written in the output stream of the specified socket. |
| 3607 | * |
| 3608 | * The parameters must follow this syntax: |
| 3609 | * windowHashcode extra |
| 3610 | * |
| 3611 | * Where XX is the length in characeters of the windowTitle. |
| 3612 | * |
| 3613 | * The first parameter is the target window. The window with the specified hashcode |
| 3614 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 3615 | * will be delivered to the target window and as parameters to the command itself. |
| 3616 | * |
| 3617 | * @param client The remote client to sent the result, if any, to. |
| 3618 | * @param command The command to execute. |
| 3619 | * @param parameters The command parameters. |
| 3620 | * |
| 3621 | * @return True if the command was successfully delivered, false otherwise. This does |
| 3622 | * not indicate whether the command itself was successful. |
| 3623 | */ |
| 3624 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3625 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3626 | return false; |
| 3627 | } |
| 3628 | |
| 3629 | boolean success = true; |
| 3630 | Parcel data = null; |
| 3631 | Parcel reply = null; |
| 3632 | |
| 3633 | // Any uncaught exception will crash the system process |
| 3634 | try { |
| 3635 | // Find the hashcode of the window |
| 3636 | int index = parameters.indexOf(' '); |
| 3637 | if (index == -1) { |
| 3638 | index = parameters.length(); |
| 3639 | } |
| 3640 | final String code = parameters.substring(0, index); |
| 3641 | int hashCode = "ffffffff".equals(code) ? -1 : Integer.parseInt(code, 16); |
| 3642 | |
| 3643 | // Extract the command's parameter after the window description |
| 3644 | if (index < parameters.length()) { |
| 3645 | parameters = parameters.substring(index + 1); |
| 3646 | } else { |
| 3647 | parameters = ""; |
| 3648 | } |
| 3649 | |
| 3650 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 3651 | if (window == null) { |
| 3652 | return false; |
| 3653 | } |
| 3654 | |
| 3655 | data = Parcel.obtain(); |
| 3656 | data.writeInterfaceToken("android.view.IWindow"); |
| 3657 | data.writeString(command); |
| 3658 | data.writeString(parameters); |
| 3659 | data.writeInt(1); |
| 3660 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 3661 | |
| 3662 | reply = Parcel.obtain(); |
| 3663 | |
| 3664 | final IBinder binder = window.mClient.asBinder(); |
| 3665 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 3666 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 3667 | |
| 3668 | reply.readException(); |
| 3669 | |
| 3670 | } catch (Exception e) { |
| 3671 | Log.w(TAG, "Could not send command " + command + " with parameters " + parameters, e); |
| 3672 | success = false; |
| 3673 | } finally { |
| 3674 | if (data != null) { |
| 3675 | data.recycle(); |
| 3676 | } |
| 3677 | if (reply != null) { |
| 3678 | reply.recycle(); |
| 3679 | } |
| 3680 | } |
| 3681 | |
| 3682 | return success; |
| 3683 | } |
| 3684 | |
| 3685 | private WindowState findWindow(int hashCode) { |
| 3686 | if (hashCode == -1) { |
| 3687 | return getFocusedWindow(); |
| 3688 | } |
| 3689 | |
| 3690 | synchronized (mWindowMap) { |
| 3691 | final ArrayList windows = mWindows; |
| 3692 | final int count = windows.size(); |
| 3693 | |
| 3694 | for (int i = 0; i < count; i++) { |
| 3695 | WindowState w = (WindowState) windows.get(i); |
| 3696 | if (System.identityHashCode(w) == hashCode) { |
| 3697 | return w; |
| 3698 | } |
| 3699 | } |
| 3700 | } |
| 3701 | |
| 3702 | return null; |
| 3703 | } |
| 3704 | |
| 3705 | /* |
| 3706 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 3707 | * that to config-changed listeners if appropriate. |
| 3708 | */ |
| 3709 | void sendNewConfiguration() { |
| 3710 | try { |
| 3711 | mActivityManager.updateConfiguration(null); |
| 3712 | } catch (RemoteException e) { |
| 3713 | } |
| 3714 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3715 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3716 | public Configuration computeNewConfiguration() { |
| 3717 | synchronized (mWindowMap) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 3718 | return computeNewConfigurationLocked(); |
| 3719 | } |
| 3720 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3721 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 3722 | Configuration computeNewConfigurationLocked() { |
| 3723 | Configuration config = new Configuration(); |
| 3724 | if (!computeNewConfigurationLocked(config)) { |
| 3725 | return null; |
| 3726 | } |
| 3727 | Log.i(TAG, "Config changed: " + config); |
| 3728 | long now = SystemClock.uptimeMillis(); |
| 3729 | //Log.i(TAG, "Config changing, gc pending: " + mFreezeGcPending + ", now " + now); |
| 3730 | if (mFreezeGcPending != 0) { |
| 3731 | if (now > (mFreezeGcPending+1000)) { |
| 3732 | //Log.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| 3733 | mH.removeMessages(H.FORCE_GC); |
| 3734 | Runtime.getRuntime().gc(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3735 | mFreezeGcPending = now; |
| 3736 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 3737 | } else { |
| 3738 | mFreezeGcPending = now; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3739 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 3740 | return config; |
| 3741 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3742 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 3743 | boolean computeNewConfigurationLocked(Configuration config) { |
| 3744 | if (mDisplay == null) { |
| 3745 | return false; |
| 3746 | } |
| 3747 | mQueue.getInputConfiguration(config); |
| 3748 | final int dw = mDisplay.getWidth(); |
| 3749 | final int dh = mDisplay.getHeight(); |
| 3750 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 3751 | if (dw < dh) { |
| 3752 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 3753 | } else if (dw > dh) { |
| 3754 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 3755 | } |
| 3756 | config.orientation = orientation; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 3757 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 3758 | DisplayMetrics dm = new DisplayMetrics(); |
| 3759 | mDisplay.getMetrics(dm); |
| 3760 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 3761 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 3762 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 3763 | // Note we only do this once because at this point we don't |
| 3764 | // expect the screen to change in this way at runtime, and want |
| 3765 | // to avoid all of this computation for every config change. |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 3766 | int longSize = dw; |
| 3767 | int shortSize = dh; |
| 3768 | if (longSize < shortSize) { |
| 3769 | int tmp = longSize; |
| 3770 | longSize = shortSize; |
| 3771 | shortSize = tmp; |
| 3772 | } |
| 3773 | longSize = (int)(longSize/dm.density); |
| 3774 | shortSize = (int)(shortSize/dm.density); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 3775 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 3776 | // These semi-magic numbers define our compatibility modes for |
| 3777 | // applications with different screens. Don't change unless you |
| 3778 | // make sure to test lots and lots of apps! |
| 3779 | if (longSize < 470) { |
| 3780 | // This is shorter than an HVGA normal density screen (which |
| 3781 | // is 480 pixels on its long side). |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 3782 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 3783 | | Configuration.SCREENLAYOUT_LONG_NO; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 3784 | } else { |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 3785 | // Is this a large screen? |
| 3786 | if (longSize > 640 && shortSize >= 480) { |
| 3787 | // VGA or larger screens at medium density are the point |
| 3788 | // at which we consider it to be a large screen. |
| 3789 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 3790 | } else { |
| 3791 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
| 3792 | |
| 3793 | // If this screen is wider than normal HVGA, or taller |
| 3794 | // than FWVGA, then for old apps we want to run in size |
| 3795 | // compatibility mode. |
| 3796 | if (shortSize > 321 || longSize > 570) { |
| 3797 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 3798 | } |
| 3799 | } |
| 3800 | |
| 3801 | // Is this a long screen? |
| 3802 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 3803 | // Anything wider than WVGA (5:3) is considering to be long. |
| 3804 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 3805 | } else { |
| 3806 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 3807 | } |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 3808 | } |
| 3809 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 3810 | config.screenLayout = mScreenLayout; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 3811 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 3812 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 3813 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 3814 | mPolicy.adjustConfigurationLw(config); |
| 3815 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3816 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3817 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3818 | // ------------------------------------------------------------- |
| 3819 | // Input Events and Focus Management |
| 3820 | // ------------------------------------------------------------- |
| 3821 | |
| 3822 | private final void wakeupIfNeeded(WindowState targetWin, int eventType) { |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 3823 | long curTime = SystemClock.uptimeMillis(); |
| 3824 | |
| 3825 | if (eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) { |
| 3826 | if (mLastTouchEventType == eventType && |
| 3827 | (curTime - mLastUserActivityCallTime) < MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 3828 | return; |
| 3829 | } |
| 3830 | mLastUserActivityCallTime = curTime; |
| 3831 | mLastTouchEventType = eventType; |
| 3832 | } |
| 3833 | |
| 3834 | if (targetWin == null |
| 3835 | || targetWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) { |
| 3836 | mPowerManager.userActivity(curTime, false, eventType, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3837 | } |
| 3838 | } |
| 3839 | |
| 3840 | // tells if it's a cheek event or not -- this function is stateful |
| 3841 | private static final int EVENT_NONE = 0; |
| 3842 | private static final int EVENT_UNKNOWN = 0; |
| 3843 | private static final int EVENT_CHEEK = 0; |
| 3844 | private static final int EVENT_IGNORE_DURATION = 300; // ms |
| 3845 | private static final float CHEEK_THRESHOLD = 0.6f; |
| 3846 | private int mEventState = EVENT_NONE; |
| 3847 | private float mEventSize; |
Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 3848 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3849 | private int eventType(MotionEvent ev) { |
| 3850 | float size = ev.getSize(); |
| 3851 | switch (ev.getAction()) { |
| 3852 | case MotionEvent.ACTION_DOWN: |
| 3853 | mEventSize = size; |
| 3854 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_EVENT; |
| 3855 | case MotionEvent.ACTION_UP: |
| 3856 | if (size > mEventSize) mEventSize = size; |
Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 3857 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_UP_EVENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3858 | case MotionEvent.ACTION_MOVE: |
| 3859 | final int N = ev.getHistorySize(); |
| 3860 | if (size > mEventSize) mEventSize = size; |
| 3861 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 3862 | for (int i=0; i<N; i++) { |
| 3863 | size = ev.getHistoricalSize(i); |
| 3864 | if (size > mEventSize) mEventSize = size; |
| 3865 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 3866 | } |
| 3867 | if (ev.getEventTime() < ev.getDownTime() + EVENT_IGNORE_DURATION) { |
| 3868 | return TOUCH_EVENT; |
| 3869 | } else { |
Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 3870 | return LONG_TOUCH_EVENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3871 | } |
| 3872 | default: |
| 3873 | // not good |
| 3874 | return OTHER_EVENT; |
| 3875 | } |
| 3876 | } |
| 3877 | |
| 3878 | /** |
| 3879 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 3880 | */ |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3881 | private int dispatchPointer(QueuedEvent qev, MotionEvent ev, int pid, int uid) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3882 | if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Log.v(TAG, |
| 3883 | "dispatchPointer " + ev); |
| 3884 | |
| 3885 | Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 3886 | ev, true, false, pid, uid); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3887 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3888 | int action = ev.getAction(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3889 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3890 | if (action == MotionEvent.ACTION_UP) { |
| 3891 | // let go of our target |
| 3892 | mKeyWaiter.mMotionTarget = null; |
| 3893 | mPowerManager.logPointerUpEvent(); |
| 3894 | } else if (action == MotionEvent.ACTION_DOWN) { |
| 3895 | mPowerManager.logPointerDownEvent(); |
| 3896 | } |
| 3897 | |
| 3898 | if (targetObj == null) { |
| 3899 | // In this case we are either dropping the event, or have received |
| 3900 | // a move or up without a down. It is common to receive move |
| 3901 | // events in such a way, since this means the user is moving the |
| 3902 | // pointer without actually pressing down. All other cases should |
| 3903 | // be atypical, so let's log them. |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 3904 | if (action != MotionEvent.ACTION_MOVE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3905 | Log.w(TAG, "No window to dispatch pointer action " + ev.getAction()); |
| 3906 | } |
| 3907 | if (qev != null) { |
| 3908 | mQueue.recycleEvent(qev); |
| 3909 | } |
| 3910 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3911 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3912 | } |
| 3913 | if (targetObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| 3914 | if (qev != null) { |
| 3915 | mQueue.recycleEvent(qev); |
| 3916 | } |
| 3917 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3918 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3919 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3920 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3921 | WindowState target = (WindowState)targetObj; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3922 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3923 | final long eventTime = ev.getEventTime(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3924 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3925 | //Log.i(TAG, "Sending " + ev + " to " + target); |
| 3926 | |
| 3927 | if (uid != 0 && uid != target.mSession.mUid) { |
| 3928 | if (mContext.checkPermission( |
| 3929 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 3930 | != PackageManager.PERMISSION_GRANTED) { |
| 3931 | Log.w(TAG, "Permission denied: injecting pointer event from pid " |
| 3932 | + pid + " uid " + uid + " to window " + target |
| 3933 | + " owned by uid " + target.mSession.mUid); |
| 3934 | if (qev != null) { |
| 3935 | mQueue.recycleEvent(qev); |
| 3936 | } |
| 3937 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3938 | return INJECT_NO_PERMISSION; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3939 | } |
| 3940 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3941 | |
| 3942 | if ((target.mAttrs.flags & |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3943 | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES) != 0) { |
| 3944 | //target wants to ignore fat touch events |
| 3945 | boolean cheekPress = mPolicy.isCheekPressedAgainstScreen(ev); |
| 3946 | //explicit flag to return without processing event further |
| 3947 | boolean returnFlag = false; |
| 3948 | if((action == MotionEvent.ACTION_DOWN)) { |
| 3949 | mFatTouch = false; |
| 3950 | if(cheekPress) { |
| 3951 | mFatTouch = true; |
| 3952 | returnFlag = true; |
| 3953 | } |
| 3954 | } else { |
| 3955 | if(action == MotionEvent.ACTION_UP) { |
| 3956 | if(mFatTouch) { |
| 3957 | //earlier even was invalid doesnt matter if current up is cheekpress or not |
| 3958 | mFatTouch = false; |
| 3959 | returnFlag = true; |
| 3960 | } else if(cheekPress) { |
| 3961 | //cancel the earlier event |
| 3962 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 3963 | action = MotionEvent.ACTION_CANCEL; |
| 3964 | } |
| 3965 | } else if(action == MotionEvent.ACTION_MOVE) { |
| 3966 | if(mFatTouch) { |
| 3967 | //two cases here |
| 3968 | //an invalid down followed by 0 or moves(valid or invalid) |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3969 | //a valid down, invalid move, more moves. want to ignore till up |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3970 | returnFlag = true; |
| 3971 | } else if(cheekPress) { |
| 3972 | //valid down followed by invalid moves |
| 3973 | //an invalid move have to cancel earlier action |
| 3974 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 3975 | action = MotionEvent.ACTION_CANCEL; |
| 3976 | if (DEBUG_INPUT) Log.v(TAG, "Sending cancel for invalid ACTION_MOVE"); |
| 3977 | //note that the subsequent invalid moves will not get here |
| 3978 | mFatTouch = true; |
| 3979 | } |
| 3980 | } |
| 3981 | } //else if action |
| 3982 | if(returnFlag) { |
| 3983 | //recycle que, ev |
| 3984 | if (qev != null) { |
| 3985 | mQueue.recycleEvent(qev); |
| 3986 | } |
| 3987 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3988 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3989 | } |
| 3990 | } //end if target |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 3991 | |
| 3992 | // TODO remove once we settle on a value or make it app specific |
| 3993 | if (action == MotionEvent.ACTION_DOWN) { |
| 3994 | int max_events_per_sec = 35; |
| 3995 | try { |
| 3996 | max_events_per_sec = Integer.parseInt(SystemProperties |
| 3997 | .get("windowsmgr.max_events_per_sec")); |
| 3998 | if (max_events_per_sec < 1) { |
| 3999 | max_events_per_sec = 35; |
| 4000 | } |
| 4001 | } catch (NumberFormatException e) { |
| 4002 | } |
| 4003 | mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec; |
| 4004 | } |
| 4005 | |
| 4006 | /* |
| 4007 | * Throttle events to minimize CPU usage when there's a flood of events |
| 4008 | * e.g. constant contact with the screen |
| 4009 | */ |
| 4010 | if (action == MotionEvent.ACTION_MOVE) { |
| 4011 | long nextEventTime = mLastTouchEventTime + mMinWaitTimeBetweenTouchEvents; |
| 4012 | long now = SystemClock.uptimeMillis(); |
| 4013 | if (now < nextEventTime) { |
| 4014 | try { |
| 4015 | Thread.sleep(nextEventTime - now); |
| 4016 | } catch (InterruptedException e) { |
| 4017 | } |
| 4018 | mLastTouchEventTime = nextEventTime; |
| 4019 | } else { |
| 4020 | mLastTouchEventTime = now; |
| 4021 | } |
| 4022 | } |
| 4023 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4024 | synchronized(mWindowMap) { |
| 4025 | if (qev != null && action == MotionEvent.ACTION_MOVE) { |
| 4026 | mKeyWaiter.bindTargetWindowLocked(target, |
| 4027 | KeyWaiter.RETURN_PENDING_POINTER, qev); |
| 4028 | ev = null; |
| 4029 | } else { |
| 4030 | if (action == MotionEvent.ACTION_DOWN) { |
| 4031 | WindowState out = mKeyWaiter.mOutsideTouchTargets; |
| 4032 | if (out != null) { |
| 4033 | MotionEvent oev = MotionEvent.obtain(ev); |
| 4034 | oev.setAction(MotionEvent.ACTION_OUTSIDE); |
| 4035 | do { |
| 4036 | final Rect frame = out.mFrame; |
| 4037 | oev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 4038 | try { |
| 4039 | out.mClient.dispatchPointer(oev, eventTime); |
| 4040 | } catch (android.os.RemoteException e) { |
| 4041 | Log.i(TAG, "WINDOW DIED during outside motion dispatch: " + out); |
| 4042 | } |
| 4043 | oev.offsetLocation((float)frame.left, (float)frame.top); |
| 4044 | out = out.mNextOutsideTouch; |
| 4045 | } while (out != null); |
| 4046 | mKeyWaiter.mOutsideTouchTargets = null; |
| 4047 | } |
| 4048 | } |
| 4049 | final Rect frame = target.mFrame; |
| 4050 | ev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 4051 | mKeyWaiter.bindTargetWindowLocked(target); |
| 4052 | } |
| 4053 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4054 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4055 | // finally offset the event to the target's coordinate system and |
| 4056 | // dispatch the event. |
| 4057 | try { |
| 4058 | if (DEBUG_INPUT || DEBUG_FOCUS || WindowManagerPolicy.WATCH_POINTER) { |
| 4059 | Log.v(TAG, "Delivering pointer " + qev + " to " + target); |
| 4060 | } |
| 4061 | target.mClient.dispatchPointer(ev, eventTime); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4062 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4063 | } catch (android.os.RemoteException e) { |
| 4064 | Log.i(TAG, "WINDOW DIED during motion dispatch: " + target); |
| 4065 | mKeyWaiter.mMotionTarget = null; |
| 4066 | try { |
| 4067 | removeWindow(target.mSession, target.mClient); |
| 4068 | } catch (java.util.NoSuchElementException ex) { |
| 4069 | // This will happen if the window has already been |
| 4070 | // removed. |
| 4071 | } |
| 4072 | } |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4073 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4074 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4075 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4076 | /** |
| 4077 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4078 | */ |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4079 | private int dispatchTrackball(QueuedEvent qev, MotionEvent ev, int pid, int uid) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4080 | if (DEBUG_INPUT) Log.v( |
| 4081 | TAG, "dispatchTrackball [" + ev.getAction() +"] <" + ev.getX() + ", " + ev.getY() + ">"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4082 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4083 | Object focusObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4084 | ev, false, false, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4085 | if (focusObj == null) { |
| 4086 | Log.w(TAG, "No focus window, dropping trackball: " + ev); |
| 4087 | if (qev != null) { |
| 4088 | mQueue.recycleEvent(qev); |
| 4089 | } |
| 4090 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4091 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4092 | } |
| 4093 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| 4094 | if (qev != null) { |
| 4095 | mQueue.recycleEvent(qev); |
| 4096 | } |
| 4097 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4098 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4099 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4100 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4101 | WindowState focus = (WindowState)focusObj; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4102 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4103 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 4104 | if (mContext.checkPermission( |
| 4105 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 4106 | != PackageManager.PERMISSION_GRANTED) { |
| 4107 | Log.w(TAG, "Permission denied: injecting key event from pid " |
| 4108 | + pid + " uid " + uid + " to window " + focus |
| 4109 | + " owned by uid " + focus.mSession.mUid); |
| 4110 | if (qev != null) { |
| 4111 | mQueue.recycleEvent(qev); |
| 4112 | } |
| 4113 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4114 | return INJECT_NO_PERMISSION; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4115 | } |
| 4116 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4117 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4118 | final long eventTime = ev.getEventTime(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4119 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4120 | synchronized(mWindowMap) { |
| 4121 | if (qev != null && ev.getAction() == MotionEvent.ACTION_MOVE) { |
| 4122 | mKeyWaiter.bindTargetWindowLocked(focus, |
| 4123 | KeyWaiter.RETURN_PENDING_TRACKBALL, qev); |
| 4124 | // We don't deliver movement events to the client, we hold |
| 4125 | // them and wait for them to call back. |
| 4126 | ev = null; |
| 4127 | } else { |
| 4128 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 4129 | } |
| 4130 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4131 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4132 | try { |
| 4133 | focus.mClient.dispatchTrackball(ev, eventTime); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4134 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4135 | } catch (android.os.RemoteException e) { |
| 4136 | Log.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| 4137 | try { |
| 4138 | removeWindow(focus.mSession, focus.mClient); |
| 4139 | } catch (java.util.NoSuchElementException ex) { |
| 4140 | // This will happen if the window has already been |
| 4141 | // removed. |
| 4142 | } |
| 4143 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4144 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4145 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4146 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4147 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4148 | /** |
| 4149 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4150 | */ |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4151 | private int dispatchKey(KeyEvent event, int pid, int uid) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4152 | if (DEBUG_INPUT) Log.v(TAG, "Dispatch key: " + event); |
| 4153 | |
| 4154 | Object focusObj = mKeyWaiter.waitForNextEventTarget(event, null, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4155 | null, false, false, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4156 | if (focusObj == null) { |
| 4157 | Log.w(TAG, "No focus window, dropping: " + event); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4158 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4159 | } |
| 4160 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4161 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4162 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4163 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4164 | WindowState focus = (WindowState)focusObj; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4165 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4166 | if (DEBUG_INPUT) Log.v( |
| 4167 | TAG, "Dispatching to " + focus + ": " + event); |
| 4168 | |
| 4169 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 4170 | if (mContext.checkPermission( |
| 4171 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 4172 | != PackageManager.PERMISSION_GRANTED) { |
| 4173 | Log.w(TAG, "Permission denied: injecting key event from pid " |
| 4174 | + pid + " uid " + uid + " to window " + focus |
| 4175 | + " owned by uid " + focus.mSession.mUid); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4176 | return INJECT_NO_PERMISSION; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4177 | } |
| 4178 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4179 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4180 | synchronized(mWindowMap) { |
| 4181 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 4182 | } |
| 4183 | |
| 4184 | // NOSHIP extra state logging |
| 4185 | mKeyWaiter.recordDispatchState(event, focus); |
| 4186 | // END NOSHIP |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4187 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4188 | try { |
| 4189 | if (DEBUG_INPUT || DEBUG_FOCUS) { |
| 4190 | Log.v(TAG, "Delivering key " + event.getKeyCode() |
| 4191 | + " to " + focus); |
| 4192 | } |
| 4193 | focus.mClient.dispatchKey(event); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4194 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4195 | } catch (android.os.RemoteException e) { |
| 4196 | Log.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| 4197 | try { |
| 4198 | removeWindow(focus.mSession, focus.mClient); |
| 4199 | } catch (java.util.NoSuchElementException ex) { |
| 4200 | // This will happen if the window has already been |
| 4201 | // removed. |
| 4202 | } |
| 4203 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4204 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4205 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4206 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4207 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4208 | public void pauseKeyDispatching(IBinder _token) { |
| 4209 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4210 | "pauseKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4211 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4212 | } |
| 4213 | |
| 4214 | synchronized (mWindowMap) { |
| 4215 | WindowToken token = mTokenMap.get(_token); |
| 4216 | if (token != null) { |
| 4217 | mKeyWaiter.pauseDispatchingLocked(token); |
| 4218 | } |
| 4219 | } |
| 4220 | } |
| 4221 | |
| 4222 | public void resumeKeyDispatching(IBinder _token) { |
| 4223 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4224 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4225 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4226 | } |
| 4227 | |
| 4228 | synchronized (mWindowMap) { |
| 4229 | WindowToken token = mTokenMap.get(_token); |
| 4230 | if (token != null) { |
| 4231 | mKeyWaiter.resumeDispatchingLocked(token); |
| 4232 | } |
| 4233 | } |
| 4234 | } |
| 4235 | |
| 4236 | public void setEventDispatching(boolean enabled) { |
| 4237 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4238 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4239 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4240 | } |
| 4241 | |
| 4242 | synchronized (mWindowMap) { |
| 4243 | mKeyWaiter.setEventDispatchingLocked(enabled); |
| 4244 | } |
| 4245 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4246 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4247 | /** |
| 4248 | * Injects a keystroke event into the UI. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4249 | * |
| 4250 | * @param ev A motion event describing the keystroke action. (Be sure to use |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4251 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 4252 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 4253 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4254 | */ |
| 4255 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 4256 | long downTime = ev.getDownTime(); |
| 4257 | long eventTime = ev.getEventTime(); |
| 4258 | |
| 4259 | int action = ev.getAction(); |
| 4260 | int code = ev.getKeyCode(); |
| 4261 | int repeatCount = ev.getRepeatCount(); |
| 4262 | int metaState = ev.getMetaState(); |
| 4263 | int deviceId = ev.getDeviceId(); |
| 4264 | int scancode = ev.getScanCode(); |
| 4265 | |
| 4266 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 4267 | if (downTime == 0) downTime = eventTime; |
| 4268 | |
| 4269 | KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4270 | deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4271 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4272 | final int pid = Binder.getCallingPid(); |
| 4273 | final int uid = Binder.getCallingUid(); |
| 4274 | final long ident = Binder.clearCallingIdentity(); |
| 4275 | final int result = dispatchKey(newEvent, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4276 | if (sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4277 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4278 | } |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4279 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4280 | switch (result) { |
| 4281 | case INJECT_NO_PERMISSION: |
| 4282 | throw new SecurityException( |
| 4283 | "Injecting to another application requires INJECT_EVENT permission"); |
| 4284 | case INJECT_SUCCEEDED: |
| 4285 | return true; |
| 4286 | } |
| 4287 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4288 | } |
| 4289 | |
| 4290 | /** |
| 4291 | * Inject a pointer (touch) event into the UI. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4292 | * |
| 4293 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 4294 | * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4295 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 4296 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 4297 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4298 | */ |
| 4299 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4300 | final int pid = Binder.getCallingPid(); |
| 4301 | final int uid = Binder.getCallingUid(); |
| 4302 | final long ident = Binder.clearCallingIdentity(); |
| 4303 | final int result = dispatchPointer(null, ev, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4304 | if (sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4305 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4306 | } |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4307 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4308 | switch (result) { |
| 4309 | case INJECT_NO_PERMISSION: |
| 4310 | throw new SecurityException( |
| 4311 | "Injecting to another application requires INJECT_EVENT permission"); |
| 4312 | case INJECT_SUCCEEDED: |
| 4313 | return true; |
| 4314 | } |
| 4315 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4316 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4317 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4318 | /** |
| 4319 | * Inject a trackball (navigation device) event into the UI. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4320 | * |
| 4321 | * @param ev A motion event describing the trackball action. (As noted in |
| 4322 | * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4323 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 4324 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 4325 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4326 | */ |
| 4327 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4328 | final int pid = Binder.getCallingPid(); |
| 4329 | final int uid = Binder.getCallingUid(); |
| 4330 | final long ident = Binder.clearCallingIdentity(); |
| 4331 | final int result = dispatchTrackball(null, ev, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4332 | if (sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4333 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4334 | } |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4335 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4336 | switch (result) { |
| 4337 | case INJECT_NO_PERMISSION: |
| 4338 | throw new SecurityException( |
| 4339 | "Injecting to another application requires INJECT_EVENT permission"); |
| 4340 | case INJECT_SUCCEEDED: |
| 4341 | return true; |
| 4342 | } |
| 4343 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4344 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4345 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4346 | private WindowState getFocusedWindow() { |
| 4347 | synchronized (mWindowMap) { |
| 4348 | return getFocusedWindowLocked(); |
| 4349 | } |
| 4350 | } |
| 4351 | |
| 4352 | private WindowState getFocusedWindowLocked() { |
| 4353 | return mCurrentFocus; |
| 4354 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4355 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4356 | /** |
| 4357 | * This class holds the state for dispatching key events. This state |
| 4358 | * is protected by the KeyWaiter instance, NOT by the window lock. You |
| 4359 | * can be holding the main window lock while acquire the KeyWaiter lock, |
| 4360 | * but not the other way around. |
| 4361 | */ |
| 4362 | final class KeyWaiter { |
| 4363 | // NOSHIP debugging |
| 4364 | public class DispatchState { |
| 4365 | private KeyEvent event; |
| 4366 | private WindowState focus; |
| 4367 | private long time; |
| 4368 | private WindowState lastWin; |
| 4369 | private IBinder lastBinder; |
| 4370 | private boolean finished; |
| 4371 | private boolean gotFirstWindow; |
| 4372 | private boolean eventDispatching; |
| 4373 | private long timeToSwitch; |
| 4374 | private boolean wasFrozen; |
| 4375 | private boolean focusPaused; |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 4376 | private WindowState curFocus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4377 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4378 | DispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 4379 | focus = theFocus; |
| 4380 | event = theEvent; |
| 4381 | time = System.currentTimeMillis(); |
| 4382 | // snapshot KeyWaiter state |
| 4383 | lastWin = mLastWin; |
| 4384 | lastBinder = mLastBinder; |
| 4385 | finished = mFinished; |
| 4386 | gotFirstWindow = mGotFirstWindow; |
| 4387 | eventDispatching = mEventDispatching; |
| 4388 | timeToSwitch = mTimeToSwitch; |
| 4389 | wasFrozen = mWasFrozen; |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 4390 | curFocus = mCurrentFocus; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4391 | // cache the paused state at ctor time as well |
| 4392 | if (theFocus == null || theFocus.mToken == null) { |
| 4393 | Log.i(TAG, "focus " + theFocus + " mToken is null at event dispatch!"); |
| 4394 | focusPaused = false; |
| 4395 | } else { |
| 4396 | focusPaused = theFocus.mToken.paused; |
| 4397 | } |
| 4398 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4399 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4400 | public String toString() { |
| 4401 | return "{{" + event + " to " + focus + " @ " + time |
| 4402 | + " lw=" + lastWin + " lb=" + lastBinder |
| 4403 | + " fin=" + finished + " gfw=" + gotFirstWindow |
| 4404 | + " ed=" + eventDispatching + " tts=" + timeToSwitch |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 4405 | + " wf=" + wasFrozen + " fp=" + focusPaused |
| 4406 | + " mcf=" + mCurrentFocus + "}}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4407 | } |
| 4408 | }; |
| 4409 | private DispatchState mDispatchState = null; |
| 4410 | public void recordDispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 4411 | mDispatchState = new DispatchState(theEvent, theFocus); |
| 4412 | } |
| 4413 | // END NOSHIP |
| 4414 | |
| 4415 | public static final int RETURN_NOTHING = 0; |
| 4416 | public static final int RETURN_PENDING_POINTER = 1; |
| 4417 | public static final int RETURN_PENDING_TRACKBALL = 2; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4418 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4419 | final Object SKIP_TARGET_TOKEN = new Object(); |
| 4420 | final Object CONSUMED_EVENT_TOKEN = new Object(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4421 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4422 | private WindowState mLastWin = null; |
| 4423 | private IBinder mLastBinder = null; |
| 4424 | private boolean mFinished = true; |
| 4425 | private boolean mGotFirstWindow = false; |
| 4426 | private boolean mEventDispatching = true; |
| 4427 | private long mTimeToSwitch = 0; |
| 4428 | /* package */ boolean mWasFrozen = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4429 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4430 | // Target of Motion events |
| 4431 | WindowState mMotionTarget; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4432 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4433 | // Windows above the target who would like to receive an "outside" |
| 4434 | // touch event for any down events outside of them. |
| 4435 | WindowState mOutsideTouchTargets; |
| 4436 | |
| 4437 | /** |
| 4438 | * Wait for the last event dispatch to complete, then find the next |
| 4439 | * target that should receive the given event and wait for that one |
| 4440 | * to be ready to receive it. |
| 4441 | */ |
| 4442 | Object waitForNextEventTarget(KeyEvent nextKey, QueuedEvent qev, |
| 4443 | MotionEvent nextMotion, boolean isPointerEvent, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4444 | boolean failIfTimeout, int callingPid, int callingUid) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4445 | long startTime = SystemClock.uptimeMillis(); |
| 4446 | long keyDispatchingTimeout = 5 * 1000; |
| 4447 | long waitedFor = 0; |
| 4448 | |
| 4449 | while (true) { |
| 4450 | // Figure out which window we care about. It is either the |
| 4451 | // last window we are waiting to have process the event or, |
| 4452 | // if none, then the next window we think the event should go |
| 4453 | // to. Note: we retrieve mLastWin outside of the lock, so |
| 4454 | // it may change before we lock. Thus we must check it again. |
| 4455 | WindowState targetWin = mLastWin; |
| 4456 | boolean targetIsNew = targetWin == null; |
| 4457 | if (DEBUG_INPUT) Log.v( |
| 4458 | TAG, "waitForLastKey: mFinished=" + mFinished + |
| 4459 | ", mLastWin=" + mLastWin); |
| 4460 | if (targetIsNew) { |
| 4461 | Object target = findTargetWindow(nextKey, qev, nextMotion, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4462 | isPointerEvent, callingPid, callingUid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4463 | if (target == SKIP_TARGET_TOKEN) { |
| 4464 | // The user has pressed a special key, and we are |
| 4465 | // dropping all pending events before it. |
| 4466 | if (DEBUG_INPUT) Log.v(TAG, "Skipping: " + nextKey |
| 4467 | + " " + nextMotion); |
| 4468 | return null; |
| 4469 | } |
| 4470 | if (target == CONSUMED_EVENT_TOKEN) { |
| 4471 | if (DEBUG_INPUT) Log.v(TAG, "Consumed: " + nextKey |
| 4472 | + " " + nextMotion); |
| 4473 | return target; |
| 4474 | } |
| 4475 | targetWin = (WindowState)target; |
| 4476 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4477 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4478 | AppWindowToken targetApp = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4479 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4480 | // Now: is it okay to send the next event to this window? |
| 4481 | synchronized (this) { |
| 4482 | // First: did we come here based on the last window not |
| 4483 | // being null, but it changed by the time we got here? |
| 4484 | // If so, try again. |
| 4485 | if (!targetIsNew && mLastWin == null) { |
| 4486 | continue; |
| 4487 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4488 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4489 | // We never dispatch events if not finished with the |
| 4490 | // last one, or the display is frozen. |
| 4491 | if (mFinished && !mDisplayFrozen) { |
| 4492 | // If event dispatching is disabled, then we |
| 4493 | // just consume the events. |
| 4494 | if (!mEventDispatching) { |
| 4495 | if (DEBUG_INPUT) Log.v(TAG, |
| 4496 | "Skipping event; dispatching disabled: " |
| 4497 | + nextKey + " " + nextMotion); |
| 4498 | return null; |
| 4499 | } |
| 4500 | if (targetWin != null) { |
| 4501 | // If this is a new target, and that target is not |
| 4502 | // paused or unresponsive, then all looks good to |
| 4503 | // handle the event. |
| 4504 | if (targetIsNew && !targetWin.mToken.paused) { |
| 4505 | return targetWin; |
| 4506 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4507 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4508 | // If we didn't find a target window, and there is no |
| 4509 | // focused app window, then just eat the events. |
| 4510 | } else if (mFocusedApp == null) { |
| 4511 | if (DEBUG_INPUT) Log.v(TAG, |
| 4512 | "Skipping event; no focused app: " |
| 4513 | + nextKey + " " + nextMotion); |
| 4514 | return null; |
| 4515 | } |
| 4516 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4517 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4518 | if (DEBUG_INPUT) Log.v( |
| 4519 | TAG, "Waiting for last key in " + mLastBinder |
| 4520 | + " target=" + targetWin |
| 4521 | + " mFinished=" + mFinished |
| 4522 | + " mDisplayFrozen=" + mDisplayFrozen |
| 4523 | + " targetIsNew=" + targetIsNew |
| 4524 | + " paused=" |
| 4525 | + (targetWin != null ? targetWin.mToken.paused : false) |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 4526 | + " mFocusedApp=" + mFocusedApp |
| 4527 | + " mCurrentFocus=" + mCurrentFocus); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4528 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4529 | targetApp = targetWin != null |
| 4530 | ? targetWin.mAppToken : mFocusedApp; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4531 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4532 | long curTimeout = keyDispatchingTimeout; |
| 4533 | if (mTimeToSwitch != 0) { |
| 4534 | long now = SystemClock.uptimeMillis(); |
| 4535 | if (mTimeToSwitch <= now) { |
| 4536 | // If an app switch key has been pressed, and we have |
| 4537 | // waited too long for the current app to finish |
| 4538 | // processing keys, then wait no more! |
| 4539 | doFinishedKeyLocked(true); |
| 4540 | continue; |
| 4541 | } |
| 4542 | long switchTimeout = mTimeToSwitch - now; |
| 4543 | if (curTimeout > switchTimeout) { |
| 4544 | curTimeout = switchTimeout; |
| 4545 | } |
| 4546 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4547 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4548 | try { |
| 4549 | // after that continue |
| 4550 | // processing keys, so we don't get stuck. |
| 4551 | if (DEBUG_INPUT) Log.v( |
| 4552 | TAG, "Waiting for key dispatch: " + curTimeout); |
| 4553 | wait(curTimeout); |
| 4554 | if (DEBUG_INPUT) Log.v(TAG, "Finished waiting @" |
| 4555 | + SystemClock.uptimeMillis() + " startTime=" |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 4556 | + startTime + " switchTime=" + mTimeToSwitch |
| 4557 | + " target=" + targetWin + " mLW=" + mLastWin |
| 4558 | + " mLB=" + mLastBinder + " fin=" + mFinished |
| 4559 | + " mCurrentFocus=" + mCurrentFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4560 | } catch (InterruptedException e) { |
| 4561 | } |
| 4562 | } |
| 4563 | |
| 4564 | // If we were frozen during configuration change, restart the |
| 4565 | // timeout checks from now; otherwise look at whether we timed |
| 4566 | // out before awakening. |
| 4567 | if (mWasFrozen) { |
| 4568 | waitedFor = 0; |
| 4569 | mWasFrozen = false; |
| 4570 | } else { |
| 4571 | waitedFor = SystemClock.uptimeMillis() - startTime; |
| 4572 | } |
| 4573 | |
| 4574 | if (waitedFor >= keyDispatchingTimeout && mTimeToSwitch == 0) { |
| 4575 | IApplicationToken at = null; |
| 4576 | synchronized (this) { |
| 4577 | Log.w(TAG, "Key dispatching timed out sending to " + |
| 4578 | (targetWin != null ? targetWin.mAttrs.getTitle() |
| 4579 | : "<null>")); |
| 4580 | // NOSHIP debugging |
| 4581 | Log.w(TAG, "Dispatch state: " + mDispatchState); |
| 4582 | Log.w(TAG, "Current state: " + new DispatchState(nextKey, targetWin)); |
| 4583 | // END NOSHIP |
| 4584 | //dump(); |
| 4585 | if (targetWin != null) { |
| 4586 | at = targetWin.getAppToken(); |
| 4587 | } else if (targetApp != null) { |
| 4588 | at = targetApp.appToken; |
| 4589 | } |
| 4590 | } |
| 4591 | |
| 4592 | boolean abort = true; |
| 4593 | if (at != null) { |
| 4594 | try { |
| 4595 | long timeout = at.getKeyDispatchingTimeout(); |
| 4596 | if (timeout > waitedFor) { |
| 4597 | // we did not wait the proper amount of time for this application. |
| 4598 | // set the timeout to be the real timeout and wait again. |
| 4599 | keyDispatchingTimeout = timeout - waitedFor; |
| 4600 | continue; |
| 4601 | } else { |
| 4602 | abort = at.keyDispatchingTimedOut(); |
| 4603 | } |
| 4604 | } catch (RemoteException ex) { |
| 4605 | } |
| 4606 | } |
| 4607 | |
| 4608 | synchronized (this) { |
| 4609 | if (abort && (mLastWin == targetWin || targetWin == null)) { |
| 4610 | mFinished = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4611 | if (mLastWin != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4612 | if (DEBUG_INPUT) Log.v(TAG, |
| 4613 | "Window " + mLastWin + |
| 4614 | " timed out on key input"); |
| 4615 | if (mLastWin.mToken.paused) { |
| 4616 | Log.w(TAG, "Un-pausing dispatching to this window"); |
| 4617 | mLastWin.mToken.paused = false; |
| 4618 | } |
| 4619 | } |
| 4620 | if (mMotionTarget == targetWin) { |
| 4621 | mMotionTarget = null; |
| 4622 | } |
| 4623 | mLastWin = null; |
| 4624 | mLastBinder = null; |
| 4625 | if (failIfTimeout || targetWin == null) { |
| 4626 | return null; |
| 4627 | } |
| 4628 | } else { |
| 4629 | Log.w(TAG, "Continuing to wait for key to be dispatched"); |
| 4630 | startTime = SystemClock.uptimeMillis(); |
| 4631 | } |
| 4632 | } |
| 4633 | } |
| 4634 | } |
| 4635 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4636 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4637 | Object findTargetWindow(KeyEvent nextKey, QueuedEvent qev, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4638 | MotionEvent nextMotion, boolean isPointerEvent, |
| 4639 | int callingPid, int callingUid) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4640 | mOutsideTouchTargets = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4641 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4642 | if (nextKey != null) { |
| 4643 | // Find the target window for a normal key event. |
| 4644 | final int keycode = nextKey.getKeyCode(); |
| 4645 | final int repeatCount = nextKey.getRepeatCount(); |
| 4646 | final boolean down = nextKey.getAction() != KeyEvent.ACTION_UP; |
| 4647 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(keycode); |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4648 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4649 | if (!dispatch) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4650 | if (callingUid == 0 || |
| 4651 | mContext.checkPermission( |
| 4652 | android.Manifest.permission.INJECT_EVENTS, |
| 4653 | callingPid, callingUid) |
| 4654 | == PackageManager.PERMISSION_GRANTED) { |
| 4655 | mPolicy.interceptKeyTi(null, keycode, |
| 4656 | nextKey.getMetaState(), down, repeatCount); |
| 4657 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4658 | Log.w(TAG, "Event timeout during app switch: dropping " |
| 4659 | + nextKey); |
| 4660 | return SKIP_TARGET_TOKEN; |
| 4661 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4662 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4663 | // System.out.println("##### [" + SystemClock.uptimeMillis() + "] WindowManagerService.dispatchKey(" + keycode + ", " + down + ", " + repeatCount + ")"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4664 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4665 | WindowState focus = null; |
| 4666 | synchronized(mWindowMap) { |
| 4667 | focus = getFocusedWindowLocked(); |
| 4668 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4669 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4670 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4671 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4672 | if (callingUid == 0 || |
| 4673 | (focus != null && callingUid == focus.mSession.mUid) || |
| 4674 | mContext.checkPermission( |
| 4675 | android.Manifest.permission.INJECT_EVENTS, |
| 4676 | callingPid, callingUid) |
| 4677 | == PackageManager.PERMISSION_GRANTED) { |
| 4678 | if (mPolicy.interceptKeyTi(focus, |
| 4679 | keycode, nextKey.getMetaState(), down, repeatCount)) { |
| 4680 | return CONSUMED_EVENT_TOKEN; |
| 4681 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4682 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4683 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4684 | return focus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4685 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4686 | } else if (!isPointerEvent) { |
| 4687 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(-1); |
| 4688 | if (!dispatch) { |
| 4689 | Log.w(TAG, "Event timeout during app switch: dropping trackball " |
| 4690 | + nextMotion); |
| 4691 | return SKIP_TARGET_TOKEN; |
| 4692 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4693 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4694 | WindowState focus = null; |
| 4695 | synchronized(mWindowMap) { |
| 4696 | focus = getFocusedWindowLocked(); |
| 4697 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4698 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4699 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
| 4700 | return focus; |
| 4701 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4702 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4703 | if (nextMotion == null) { |
| 4704 | return SKIP_TARGET_TOKEN; |
| 4705 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4706 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4707 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey( |
| 4708 | KeyEvent.KEYCODE_UNKNOWN); |
| 4709 | if (!dispatch) { |
| 4710 | Log.w(TAG, "Event timeout during app switch: dropping pointer " |
| 4711 | + nextMotion); |
| 4712 | return SKIP_TARGET_TOKEN; |
| 4713 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4714 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4715 | // Find the target window for a pointer event. |
| 4716 | int action = nextMotion.getAction(); |
| 4717 | final float xf = nextMotion.getX(); |
| 4718 | final float yf = nextMotion.getY(); |
| 4719 | final long eventTime = nextMotion.getEventTime(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4720 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4721 | final boolean screenWasOff = qev != null |
| 4722 | && (qev.flags&WindowManagerPolicy.FLAG_BRIGHT_HERE) != 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4723 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4724 | WindowState target = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4725 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4726 | synchronized(mWindowMap) { |
| 4727 | synchronized (this) { |
| 4728 | if (action == MotionEvent.ACTION_DOWN) { |
| 4729 | if (mMotionTarget != null) { |
| 4730 | // this is weird, we got a pen down, but we thought it was |
| 4731 | // already down! |
| 4732 | // XXX: We should probably send an ACTION_UP to the current |
| 4733 | // target. |
| 4734 | Log.w(TAG, "Pointer down received while already down in: " |
| 4735 | + mMotionTarget); |
| 4736 | mMotionTarget = null; |
| 4737 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4738 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4739 | // ACTION_DOWN is special, because we need to lock next events to |
| 4740 | // the window we'll land onto. |
| 4741 | final int x = (int)xf; |
| 4742 | final int y = (int)yf; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4743 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4744 | final ArrayList windows = mWindows; |
| 4745 | final int N = windows.size(); |
| 4746 | WindowState topErrWindow = null; |
| 4747 | final Rect tmpRect = mTempRect; |
| 4748 | for (int i=N-1; i>=0; i--) { |
| 4749 | WindowState child = (WindowState)windows.get(i); |
| 4750 | //Log.i(TAG, "Checking dispatch to: " + child); |
| 4751 | final int flags = child.mAttrs.flags; |
| 4752 | if ((flags & WindowManager.LayoutParams.FLAG_SYSTEM_ERROR) != 0) { |
| 4753 | if (topErrWindow == null) { |
| 4754 | topErrWindow = child; |
| 4755 | } |
| 4756 | } |
| 4757 | if (!child.isVisibleLw()) { |
| 4758 | //Log.i(TAG, "Not visible!"); |
| 4759 | continue; |
| 4760 | } |
| 4761 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 4762 | //Log.i(TAG, "Not touchable!"); |
| 4763 | if ((flags & WindowManager.LayoutParams |
| 4764 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 4765 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 4766 | mOutsideTouchTargets = child; |
| 4767 | } |
| 4768 | continue; |
| 4769 | } |
| 4770 | tmpRect.set(child.mFrame); |
| 4771 | if (child.mTouchableInsets == ViewTreeObserver |
| 4772 | .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) { |
| 4773 | // The touch is inside of the window if it is |
| 4774 | // inside the frame, AND the content part of that |
| 4775 | // frame that was given by the application. |
| 4776 | tmpRect.left += child.mGivenContentInsets.left; |
| 4777 | tmpRect.top += child.mGivenContentInsets.top; |
| 4778 | tmpRect.right -= child.mGivenContentInsets.right; |
| 4779 | tmpRect.bottom -= child.mGivenContentInsets.bottom; |
| 4780 | } else if (child.mTouchableInsets == ViewTreeObserver |
| 4781 | .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) { |
| 4782 | // The touch is inside of the window if it is |
| 4783 | // inside the frame, AND the visible part of that |
| 4784 | // frame that was given by the application. |
| 4785 | tmpRect.left += child.mGivenVisibleInsets.left; |
| 4786 | tmpRect.top += child.mGivenVisibleInsets.top; |
| 4787 | tmpRect.right -= child.mGivenVisibleInsets.right; |
| 4788 | tmpRect.bottom -= child.mGivenVisibleInsets.bottom; |
| 4789 | } |
| 4790 | final int touchFlags = flags & |
| 4791 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 4792 | |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 4793 | if (tmpRect.contains(x, y) || touchFlags == 0) { |
| 4794 | //Log.i(TAG, "Using this target!"); |
| 4795 | if (!screenWasOff || (flags & |
| 4796 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING) != 0) { |
| 4797 | mMotionTarget = child; |
| 4798 | } else { |
| 4799 | //Log.i(TAG, "Waking, skip!"); |
| 4800 | mMotionTarget = null; |
| 4801 | } |
| 4802 | break; |
| 4803 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4804 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4805 | if ((flags & WindowManager.LayoutParams |
| 4806 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 4807 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 4808 | mOutsideTouchTargets = child; |
| 4809 | //Log.i(TAG, "Adding to outside target list: " + child); |
| 4810 | } |
| 4811 | } |
| 4812 | |
| 4813 | // if there's an error window but it's not accepting |
| 4814 | // focus (typically because it is not yet visible) just |
| 4815 | // wait for it -- any other focused window may in fact |
| 4816 | // be in ANR state. |
| 4817 | if (topErrWindow != null && mMotionTarget != topErrWindow) { |
| 4818 | mMotionTarget = null; |
| 4819 | } |
| 4820 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4821 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4822 | target = mMotionTarget; |
| 4823 | } |
| 4824 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4825 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4826 | wakeupIfNeeded(target, eventType(nextMotion)); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4827 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4828 | // Pointer events are a little different -- if there isn't a |
| 4829 | // target found for any event, then just drop it. |
| 4830 | return target != null ? target : SKIP_TARGET_TOKEN; |
| 4831 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4832 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4833 | boolean checkShouldDispatchKey(int keycode) { |
| 4834 | synchronized (this) { |
| 4835 | if (mPolicy.isAppSwitchKeyTqTiLwLi(keycode)) { |
| 4836 | mTimeToSwitch = 0; |
| 4837 | return true; |
| 4838 | } |
| 4839 | if (mTimeToSwitch != 0 |
| 4840 | && mTimeToSwitch < SystemClock.uptimeMillis()) { |
| 4841 | return false; |
| 4842 | } |
| 4843 | return true; |
| 4844 | } |
| 4845 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4846 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4847 | void bindTargetWindowLocked(WindowState win, |
| 4848 | int pendingWhat, QueuedEvent pendingMotion) { |
| 4849 | synchronized (this) { |
| 4850 | bindTargetWindowLockedLocked(win, pendingWhat, pendingMotion); |
| 4851 | } |
| 4852 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4853 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4854 | void bindTargetWindowLocked(WindowState win) { |
| 4855 | synchronized (this) { |
| 4856 | bindTargetWindowLockedLocked(win, RETURN_NOTHING, null); |
| 4857 | } |
| 4858 | } |
| 4859 | |
| 4860 | void bindTargetWindowLockedLocked(WindowState win, |
| 4861 | int pendingWhat, QueuedEvent pendingMotion) { |
| 4862 | mLastWin = win; |
| 4863 | mLastBinder = win.mClient.asBinder(); |
| 4864 | mFinished = false; |
| 4865 | if (pendingMotion != null) { |
| 4866 | final Session s = win.mSession; |
| 4867 | if (pendingWhat == RETURN_PENDING_POINTER) { |
| 4868 | releasePendingPointerLocked(s); |
| 4869 | s.mPendingPointerMove = pendingMotion; |
| 4870 | s.mPendingPointerWindow = win; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4871 | if (DEBUG_INPUT) Log.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4872 | "bindTargetToWindow " + s.mPendingPointerMove); |
| 4873 | } else if (pendingWhat == RETURN_PENDING_TRACKBALL) { |
| 4874 | releasePendingTrackballLocked(s); |
| 4875 | s.mPendingTrackballMove = pendingMotion; |
| 4876 | s.mPendingTrackballWindow = win; |
| 4877 | } |
| 4878 | } |
| 4879 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4880 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4881 | void releasePendingPointerLocked(Session s) { |
| 4882 | if (DEBUG_INPUT) Log.v(TAG, |
| 4883 | "releasePendingPointer " + s.mPendingPointerMove); |
| 4884 | if (s.mPendingPointerMove != null) { |
| 4885 | mQueue.recycleEvent(s.mPendingPointerMove); |
| 4886 | s.mPendingPointerMove = null; |
| 4887 | } |
| 4888 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4889 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4890 | void releasePendingTrackballLocked(Session s) { |
| 4891 | if (s.mPendingTrackballMove != null) { |
| 4892 | mQueue.recycleEvent(s.mPendingTrackballMove); |
| 4893 | s.mPendingTrackballMove = null; |
| 4894 | } |
| 4895 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4896 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4897 | MotionEvent finishedKey(Session session, IWindow client, boolean force, |
| 4898 | int returnWhat) { |
| 4899 | if (DEBUG_INPUT) Log.v( |
| 4900 | TAG, "finishedKey: client=" + client + ", force=" + force); |
| 4901 | |
| 4902 | if (client == null) { |
| 4903 | return null; |
| 4904 | } |
| 4905 | |
| 4906 | synchronized (this) { |
| 4907 | if (DEBUG_INPUT) Log.v( |
| 4908 | TAG, "finishedKey: client=" + client.asBinder() |
| 4909 | + ", force=" + force + ", last=" + mLastBinder |
| 4910 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) + ")"); |
| 4911 | |
| 4912 | QueuedEvent qev = null; |
| 4913 | WindowState win = null; |
| 4914 | if (returnWhat == RETURN_PENDING_POINTER) { |
| 4915 | qev = session.mPendingPointerMove; |
| 4916 | win = session.mPendingPointerWindow; |
| 4917 | session.mPendingPointerMove = null; |
| 4918 | session.mPendingPointerWindow = null; |
| 4919 | } else if (returnWhat == RETURN_PENDING_TRACKBALL) { |
| 4920 | qev = session.mPendingTrackballMove; |
| 4921 | win = session.mPendingTrackballWindow; |
| 4922 | session.mPendingTrackballMove = null; |
| 4923 | session.mPendingTrackballWindow = null; |
| 4924 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4925 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4926 | if (mLastBinder == client.asBinder()) { |
| 4927 | if (DEBUG_INPUT) Log.v( |
| 4928 | TAG, "finishedKey: last paused=" |
| 4929 | + ((mLastWin != null) ? mLastWin.mToken.paused : "null")); |
| 4930 | if (mLastWin != null && (!mLastWin.mToken.paused || force |
| 4931 | || !mEventDispatching)) { |
| 4932 | doFinishedKeyLocked(false); |
| 4933 | } else { |
| 4934 | // Make sure to wake up anyone currently waiting to |
| 4935 | // dispatch a key, so they can re-evaluate their |
| 4936 | // current situation. |
| 4937 | mFinished = true; |
| 4938 | notifyAll(); |
| 4939 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4940 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4941 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4942 | if (qev != null) { |
| 4943 | MotionEvent res = (MotionEvent)qev.event; |
| 4944 | if (DEBUG_INPUT) Log.v(TAG, |
| 4945 | "Returning pending motion: " + res); |
| 4946 | mQueue.recycleEvent(qev); |
| 4947 | if (win != null && returnWhat == RETURN_PENDING_POINTER) { |
| 4948 | res.offsetLocation(-win.mFrame.left, -win.mFrame.top); |
| 4949 | } |
| 4950 | return res; |
| 4951 | } |
| 4952 | return null; |
| 4953 | } |
| 4954 | } |
| 4955 | |
| 4956 | void tickle() { |
| 4957 | synchronized (this) { |
| 4958 | notifyAll(); |
| 4959 | } |
| 4960 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4961 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4962 | void handleNewWindowLocked(WindowState newWindow) { |
| 4963 | if (!newWindow.canReceiveKeys()) { |
| 4964 | return; |
| 4965 | } |
| 4966 | synchronized (this) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 4967 | if (DEBUG_INPUT) Log.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4968 | TAG, "New key dispatch window: win=" |
| 4969 | + newWindow.mClient.asBinder() |
| 4970 | + ", last=" + mLastBinder |
| 4971 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 4972 | + "), finished=" + mFinished + ", paused=" |
| 4973 | + newWindow.mToken.paused); |
| 4974 | |
| 4975 | // Displaying a window implicitly causes dispatching to |
| 4976 | // be unpaused. (This is to protect against bugs if someone |
| 4977 | // pauses dispatching but forgets to resume.) |
| 4978 | newWindow.mToken.paused = false; |
| 4979 | |
| 4980 | mGotFirstWindow = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4981 | |
| 4982 | if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) { |
| 4983 | if (DEBUG_INPUT) Log.v(TAG, |
| 4984 | "New SYSTEM_ERROR window; resetting state"); |
| 4985 | mLastWin = null; |
| 4986 | mLastBinder = null; |
| 4987 | mMotionTarget = null; |
| 4988 | mFinished = true; |
| 4989 | } else if (mLastWin != null) { |
| 4990 | // If the new window is above the window we are |
| 4991 | // waiting on, then stop waiting and let key dispatching |
| 4992 | // start on the new guy. |
| 4993 | if (DEBUG_INPUT) Log.v( |
| 4994 | TAG, "Last win layer=" + mLastWin.mLayer |
| 4995 | + ", new win layer=" + newWindow.mLayer); |
| 4996 | if (newWindow.mLayer >= mLastWin.mLayer) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 4997 | // The new window is above the old; finish pending input to the last |
| 4998 | // window and start directing it to the new one. |
| 4999 | mLastWin.mToken.paused = false; |
| 5000 | doFinishedKeyLocked(true); // does a notifyAll() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5001 | } |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5002 | // Either the new window is lower, so there is no need to wake key waiters, |
| 5003 | // or we just finished key input to the previous window, which implicitly |
| 5004 | // notified the key waiters. In both cases, we don't need to issue the |
| 5005 | // notification here. |
| 5006 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5007 | } |
| 5008 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5009 | // Now that we've put a new window state in place, make the event waiter |
| 5010 | // take notice and retarget its attentions. |
| 5011 | notifyAll(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5012 | } |
| 5013 | } |
| 5014 | |
| 5015 | void pauseDispatchingLocked(WindowToken token) { |
| 5016 | synchronized (this) |
| 5017 | { |
| 5018 | if (DEBUG_INPUT) Log.v(TAG, "Pausing WindowToken " + token); |
| 5019 | token.paused = true; |
| 5020 | |
| 5021 | /* |
| 5022 | if (mLastWin != null && !mFinished && mLastWin.mBaseLayer <= layer) { |
| 5023 | mPaused = true; |
| 5024 | } else { |
| 5025 | if (mLastWin == null) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 5026 | Log.i(TAG, "Key dispatching not paused: no last window."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5027 | } else if (mFinished) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 5028 | Log.i(TAG, "Key dispatching not paused: finished last key."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5029 | } else { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 5030 | Log.i(TAG, "Key dispatching not paused: window in higher layer."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5031 | } |
| 5032 | } |
| 5033 | */ |
| 5034 | } |
| 5035 | } |
| 5036 | |
| 5037 | void resumeDispatchingLocked(WindowToken token) { |
| 5038 | synchronized (this) { |
| 5039 | if (token.paused) { |
| 5040 | if (DEBUG_INPUT) Log.v( |
| 5041 | TAG, "Resuming WindowToken " + token |
| 5042 | + ", last=" + mLastBinder |
| 5043 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 5044 | + "), finished=" + mFinished + ", paused=" |
| 5045 | + token.paused); |
| 5046 | token.paused = false; |
| 5047 | if (mLastWin != null && mLastWin.mToken == token && mFinished) { |
| 5048 | doFinishedKeyLocked(true); |
| 5049 | } else { |
| 5050 | notifyAll(); |
| 5051 | } |
| 5052 | } |
| 5053 | } |
| 5054 | } |
| 5055 | |
| 5056 | void setEventDispatchingLocked(boolean enabled) { |
| 5057 | synchronized (this) { |
| 5058 | mEventDispatching = enabled; |
| 5059 | notifyAll(); |
| 5060 | } |
| 5061 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5062 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5063 | void appSwitchComing() { |
| 5064 | synchronized (this) { |
| 5065 | // Don't wait for more than .5 seconds for app to finish |
| 5066 | // processing the pending events. |
| 5067 | long now = SystemClock.uptimeMillis() + 500; |
| 5068 | if (DEBUG_INPUT) Log.v(TAG, "appSwitchComing: " + now); |
| 5069 | if (mTimeToSwitch == 0 || now < mTimeToSwitch) { |
| 5070 | mTimeToSwitch = now; |
| 5071 | } |
| 5072 | notifyAll(); |
| 5073 | } |
| 5074 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5075 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5076 | private final void doFinishedKeyLocked(boolean doRecycle) { |
| 5077 | if (mLastWin != null) { |
| 5078 | releasePendingPointerLocked(mLastWin.mSession); |
| 5079 | releasePendingTrackballLocked(mLastWin.mSession); |
| 5080 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5081 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5082 | if (mLastWin == null || !mLastWin.mToken.paused |
| 5083 | || !mLastWin.isVisibleLw()) { |
| 5084 | // If the current window has been paused, we aren't -really- |
| 5085 | // finished... so let the waiters still wait. |
| 5086 | mLastWin = null; |
| 5087 | mLastBinder = null; |
| 5088 | } |
| 5089 | mFinished = true; |
| 5090 | notifyAll(); |
| 5091 | } |
| 5092 | } |
| 5093 | |
| 5094 | private class KeyQ extends KeyInputQueue |
| 5095 | implements KeyInputQueue.FilterCallback { |
| 5096 | PowerManager.WakeLock mHoldingScreen; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5097 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5098 | KeyQ() { |
| 5099 | super(mContext); |
| 5100 | PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE); |
| 5101 | mHoldingScreen = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 5102 | "KEEP_SCREEN_ON_FLAG"); |
| 5103 | mHoldingScreen.setReferenceCounted(false); |
| 5104 | } |
| 5105 | |
| 5106 | @Override |
| 5107 | boolean preprocessEvent(InputDevice device, RawInputEvent event) { |
| 5108 | if (mPolicy.preprocessInputEventTq(event)) { |
| 5109 | return true; |
| 5110 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5111 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5112 | switch (event.type) { |
| 5113 | case RawInputEvent.EV_KEY: { |
| 5114 | // XXX begin hack |
| 5115 | if (DEBUG) { |
| 5116 | if (event.keycode == KeyEvent.KEYCODE_G) { |
| 5117 | if (event.value != 0) { |
| 5118 | // G down |
| 5119 | mPolicy.screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 5120 | } |
| 5121 | return false; |
| 5122 | } |
| 5123 | if (event.keycode == KeyEvent.KEYCODE_D) { |
| 5124 | if (event.value != 0) { |
| 5125 | //dump(); |
| 5126 | } |
| 5127 | return false; |
| 5128 | } |
| 5129 | } |
| 5130 | // XXX end hack |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5131 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5132 | boolean screenIsOff = !mPowerManager.screenIsOn(); |
| 5133 | boolean screenIsDim = !mPowerManager.screenIsBright(); |
| 5134 | int actions = mPolicy.interceptKeyTq(event, !screenIsOff); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5135 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5136 | if ((actions & WindowManagerPolicy.ACTION_GO_TO_SLEEP) != 0) { |
| 5137 | mPowerManager.goToSleep(event.when); |
| 5138 | } |
| 5139 | |
| 5140 | if (screenIsOff) { |
| 5141 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 5142 | } |
| 5143 | if (screenIsDim) { |
| 5144 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 5145 | } |
| 5146 | if ((actions & WindowManagerPolicy.ACTION_POKE_USER_ACTIVITY) != 0) { |
| 5147 | mPowerManager.userActivity(event.when, false, |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5148 | LocalPowerManager.BUTTON_EVENT, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5149 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5150 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5151 | if ((actions & WindowManagerPolicy.ACTION_PASS_TO_USER) != 0) { |
| 5152 | if (event.value != 0 && mPolicy.isAppSwitchKeyTqTiLwLi(event.keycode)) { |
| 5153 | filterQueue(this); |
| 5154 | mKeyWaiter.appSwitchComing(); |
| 5155 | } |
| 5156 | return true; |
| 5157 | } else { |
| 5158 | return false; |
| 5159 | } |
| 5160 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5161 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5162 | case RawInputEvent.EV_REL: { |
| 5163 | boolean screenIsOff = !mPowerManager.screenIsOn(); |
| 5164 | boolean screenIsDim = !mPowerManager.screenIsBright(); |
| 5165 | if (screenIsOff) { |
| 5166 | if (!mPolicy.isWakeRelMovementTq(event.deviceId, |
| 5167 | device.classes, event)) { |
| 5168 | //Log.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| 5169 | return false; |
| 5170 | } |
| 5171 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 5172 | } |
| 5173 | if (screenIsDim) { |
| 5174 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 5175 | } |
| 5176 | return true; |
| 5177 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5178 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5179 | case RawInputEvent.EV_ABS: { |
| 5180 | boolean screenIsOff = !mPowerManager.screenIsOn(); |
| 5181 | boolean screenIsDim = !mPowerManager.screenIsBright(); |
| 5182 | if (screenIsOff) { |
| 5183 | if (!mPolicy.isWakeAbsMovementTq(event.deviceId, |
| 5184 | device.classes, event)) { |
| 5185 | //Log.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| 5186 | return false; |
| 5187 | } |
| 5188 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 5189 | } |
| 5190 | if (screenIsDim) { |
| 5191 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 5192 | } |
| 5193 | return true; |
| 5194 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5195 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5196 | default: |
| 5197 | return true; |
| 5198 | } |
| 5199 | } |
| 5200 | |
| 5201 | public int filterEvent(QueuedEvent ev) { |
| 5202 | switch (ev.classType) { |
| 5203 | case RawInputEvent.CLASS_KEYBOARD: |
| 5204 | KeyEvent ke = (KeyEvent)ev.event; |
| 5205 | if (mPolicy.isMovementKeyTi(ke.getKeyCode())) { |
| 5206 | Log.w(TAG, "Dropping movement key during app switch: " |
| 5207 | + ke.getKeyCode() + ", action=" + ke.getAction()); |
| 5208 | return FILTER_REMOVE; |
| 5209 | } |
| 5210 | return FILTER_ABORT; |
| 5211 | default: |
| 5212 | return FILTER_KEEP; |
| 5213 | } |
| 5214 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5215 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5216 | /** |
| 5217 | * Must be called with the main window manager lock held. |
| 5218 | */ |
| 5219 | void setHoldScreenLocked(boolean holding) { |
| 5220 | boolean state = mHoldingScreen.isHeld(); |
| 5221 | if (holding != state) { |
| 5222 | if (holding) { |
| 5223 | mHoldingScreen.acquire(); |
| 5224 | } else { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 5225 | mPolicy.screenOnStoppedLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5226 | mHoldingScreen.release(); |
| 5227 | } |
| 5228 | } |
| 5229 | } |
| 5230 | }; |
| 5231 | |
| 5232 | public boolean detectSafeMode() { |
| 5233 | mSafeMode = mPolicy.detectSafeMode(); |
| 5234 | return mSafeMode; |
| 5235 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5236 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5237 | public void systemReady() { |
| 5238 | mPolicy.systemReady(); |
| 5239 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5240 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5241 | private final class InputDispatcherThread extends Thread { |
| 5242 | // Time to wait when there is nothing to do: 9999 seconds. |
| 5243 | static final int LONG_WAIT=9999*1000; |
| 5244 | |
| 5245 | public InputDispatcherThread() { |
| 5246 | super("InputDispatcher"); |
| 5247 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5248 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5249 | @Override |
| 5250 | public void run() { |
| 5251 | while (true) { |
| 5252 | try { |
| 5253 | process(); |
| 5254 | } catch (Exception e) { |
| 5255 | Log.e(TAG, "Exception in input dispatcher", e); |
| 5256 | } |
| 5257 | } |
| 5258 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5259 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5260 | private void process() { |
| 5261 | android.os.Process.setThreadPriority( |
| 5262 | android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5263 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5264 | // The last key event we saw |
| 5265 | KeyEvent lastKey = null; |
| 5266 | |
| 5267 | // Last keydown time for auto-repeating keys |
| 5268 | long lastKeyTime = SystemClock.uptimeMillis(); |
| 5269 | long nextKeyTime = lastKeyTime+LONG_WAIT; |
| 5270 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5271 | // How many successive repeats we generated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5272 | int keyRepeatCount = 0; |
| 5273 | |
| 5274 | // Need to report that configuration has changed? |
| 5275 | boolean configChanged = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5276 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5277 | while (true) { |
| 5278 | long curTime = SystemClock.uptimeMillis(); |
| 5279 | |
| 5280 | if (DEBUG_INPUT) Log.v( |
| 5281 | TAG, "Waiting for next key: now=" + curTime |
| 5282 | + ", repeat @ " + nextKeyTime); |
| 5283 | |
| 5284 | // Retrieve next event, waiting only as long as the next |
| 5285 | // repeat timeout. If the configuration has changed, then |
| 5286 | // don't wait at all -- we'll report the change as soon as |
| 5287 | // we have processed all events. |
| 5288 | QueuedEvent ev = mQueue.getEvent( |
| 5289 | (int)((!configChanged && curTime < nextKeyTime) |
| 5290 | ? (nextKeyTime-curTime) : 0)); |
| 5291 | |
| 5292 | if (DEBUG_INPUT && ev != null) Log.v( |
| 5293 | TAG, "Event: type=" + ev.classType + " data=" + ev.event); |
| 5294 | |
| 5295 | try { |
| 5296 | if (ev != null) { |
| 5297 | curTime = ev.when; |
| 5298 | int eventType; |
| 5299 | if (ev.classType == RawInputEvent.CLASS_TOUCHSCREEN) { |
| 5300 | eventType = eventType((MotionEvent)ev.event); |
| 5301 | } else if (ev.classType == RawInputEvent.CLASS_KEYBOARD || |
| 5302 | ev.classType == RawInputEvent.CLASS_TRACKBALL) { |
| 5303 | eventType = LocalPowerManager.BUTTON_EVENT; |
| 5304 | } else { |
| 5305 | eventType = LocalPowerManager.OTHER_EVENT; |
| 5306 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5307 | try { |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5308 | long now = SystemClock.uptimeMillis(); |
| 5309 | |
| 5310 | if ((now - mLastBatteryStatsCallTime) |
| 5311 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 5312 | mLastBatteryStatsCallTime = now; |
| 5313 | mBatteryStats.noteInputEvent(); |
| 5314 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5315 | } catch (RemoteException e) { |
| 5316 | // Ignore |
| 5317 | } |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5318 | mPowerManager.userActivity(curTime, false, eventType, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5319 | switch (ev.classType) { |
| 5320 | case RawInputEvent.CLASS_KEYBOARD: |
| 5321 | KeyEvent ke = (KeyEvent)ev.event; |
| 5322 | if (ke.isDown()) { |
| 5323 | lastKey = ke; |
| 5324 | keyRepeatCount = 0; |
| 5325 | lastKeyTime = curTime; |
| 5326 | nextKeyTime = lastKeyTime |
| 5327 | + KEY_REPEAT_FIRST_DELAY; |
| 5328 | if (DEBUG_INPUT) Log.v( |
| 5329 | TAG, "Received key down: first repeat @ " |
| 5330 | + nextKeyTime); |
| 5331 | } else { |
| 5332 | lastKey = null; |
| 5333 | // Arbitrary long timeout. |
| 5334 | lastKeyTime = curTime; |
| 5335 | nextKeyTime = curTime + LONG_WAIT; |
| 5336 | if (DEBUG_INPUT) Log.v( |
| 5337 | TAG, "Received key up: ignore repeat @ " |
| 5338 | + nextKeyTime); |
| 5339 | } |
| 5340 | dispatchKey((KeyEvent)ev.event, 0, 0); |
| 5341 | mQueue.recycleEvent(ev); |
| 5342 | break; |
| 5343 | case RawInputEvent.CLASS_TOUCHSCREEN: |
| 5344 | //Log.i(TAG, "Read next event " + ev); |
| 5345 | dispatchPointer(ev, (MotionEvent)ev.event, 0, 0); |
| 5346 | break; |
| 5347 | case RawInputEvent.CLASS_TRACKBALL: |
| 5348 | dispatchTrackball(ev, (MotionEvent)ev.event, 0, 0); |
| 5349 | break; |
| 5350 | case RawInputEvent.CLASS_CONFIGURATION_CHANGED: |
| 5351 | configChanged = true; |
| 5352 | break; |
| 5353 | default: |
| 5354 | mQueue.recycleEvent(ev); |
| 5355 | break; |
| 5356 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5357 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5358 | } else if (configChanged) { |
| 5359 | configChanged = false; |
| 5360 | sendNewConfiguration(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5361 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5362 | } else if (lastKey != null) { |
| 5363 | curTime = SystemClock.uptimeMillis(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5364 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5365 | // Timeout occurred while key was down. If it is at or |
| 5366 | // past the key repeat time, dispatch the repeat. |
| 5367 | if (DEBUG_INPUT) Log.v( |
| 5368 | TAG, "Key timeout: repeat=" + nextKeyTime |
| 5369 | + ", now=" + curTime); |
| 5370 | if (curTime < nextKeyTime) { |
| 5371 | continue; |
| 5372 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5374 | lastKeyTime = nextKeyTime; |
| 5375 | nextKeyTime = nextKeyTime + KEY_REPEAT_DELAY; |
| 5376 | keyRepeatCount++; |
| 5377 | if (DEBUG_INPUT) Log.v( |
| 5378 | TAG, "Key repeat: count=" + keyRepeatCount |
| 5379 | + ", next @ " + nextKeyTime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5380 | dispatchKey(KeyEvent.changeTimeRepeat(lastKey, curTime, keyRepeatCount), 0, 0); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5381 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5382 | } else { |
| 5383 | curTime = SystemClock.uptimeMillis(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5384 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5385 | lastKeyTime = curTime; |
| 5386 | nextKeyTime = curTime + LONG_WAIT; |
| 5387 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5388 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5389 | } catch (Exception e) { |
| 5390 | Log.e(TAG, |
| 5391 | "Input thread received uncaught exception: " + e, e); |
| 5392 | } |
| 5393 | } |
| 5394 | } |
| 5395 | } |
| 5396 | |
| 5397 | // ------------------------------------------------------------- |
| 5398 | // Client Session State |
| 5399 | // ------------------------------------------------------------- |
| 5400 | |
| 5401 | private final class Session extends IWindowSession.Stub |
| 5402 | implements IBinder.DeathRecipient { |
| 5403 | final IInputMethodClient mClient; |
| 5404 | final IInputContext mInputContext; |
| 5405 | final int mUid; |
| 5406 | final int mPid; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5407 | final String mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5408 | SurfaceSession mSurfaceSession; |
| 5409 | int mNumWindow = 0; |
| 5410 | boolean mClientDead = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5411 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5412 | /** |
| 5413 | * Current pointer move event being dispatched to client window... must |
| 5414 | * hold key lock to access. |
| 5415 | */ |
| 5416 | QueuedEvent mPendingPointerMove; |
| 5417 | WindowState mPendingPointerWindow; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5418 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5419 | /** |
| 5420 | * Current trackball move event being dispatched to client window... must |
| 5421 | * hold key lock to access. |
| 5422 | */ |
| 5423 | QueuedEvent mPendingTrackballMove; |
| 5424 | WindowState mPendingTrackballWindow; |
| 5425 | |
| 5426 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 5427 | mClient = client; |
| 5428 | mInputContext = inputContext; |
| 5429 | mUid = Binder.getCallingUid(); |
| 5430 | mPid = Binder.getCallingPid(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5431 | StringBuilder sb = new StringBuilder(); |
| 5432 | sb.append("Session{"); |
| 5433 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 5434 | sb.append(" uid "); |
| 5435 | sb.append(mUid); |
| 5436 | sb.append("}"); |
| 5437 | mStringName = sb.toString(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5438 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5439 | synchronized (mWindowMap) { |
| 5440 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 5441 | IBinder b = ServiceManager.getService( |
| 5442 | Context.INPUT_METHOD_SERVICE); |
| 5443 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 5444 | } |
| 5445 | } |
| 5446 | long ident = Binder.clearCallingIdentity(); |
| 5447 | try { |
| 5448 | // Note: it is safe to call in to the input method manager |
| 5449 | // here because we are not holding our lock. |
| 5450 | if (mInputMethodManager != null) { |
| 5451 | mInputMethodManager.addClient(client, inputContext, |
| 5452 | mUid, mPid); |
| 5453 | } else { |
| 5454 | client.setUsingInputMethod(false); |
| 5455 | } |
| 5456 | client.asBinder().linkToDeath(this, 0); |
| 5457 | } catch (RemoteException e) { |
| 5458 | // The caller has died, so we can just forget about this. |
| 5459 | try { |
| 5460 | if (mInputMethodManager != null) { |
| 5461 | mInputMethodManager.removeClient(client); |
| 5462 | } |
| 5463 | } catch (RemoteException ee) { |
| 5464 | } |
| 5465 | } finally { |
| 5466 | Binder.restoreCallingIdentity(ident); |
| 5467 | } |
| 5468 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5469 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5470 | @Override |
| 5471 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 5472 | throws RemoteException { |
| 5473 | try { |
| 5474 | return super.onTransact(code, data, reply, flags); |
| 5475 | } catch (RuntimeException e) { |
| 5476 | // Log all 'real' exceptions thrown to the caller |
| 5477 | if (!(e instanceof SecurityException)) { |
| 5478 | Log.e(TAG, "Window Session Crash", e); |
| 5479 | } |
| 5480 | throw e; |
| 5481 | } |
| 5482 | } |
| 5483 | |
| 5484 | public void binderDied() { |
| 5485 | // Note: it is safe to call in to the input method manager |
| 5486 | // here because we are not holding our lock. |
| 5487 | try { |
| 5488 | if (mInputMethodManager != null) { |
| 5489 | mInputMethodManager.removeClient(mClient); |
| 5490 | } |
| 5491 | } catch (RemoteException e) { |
| 5492 | } |
| 5493 | synchronized(mWindowMap) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 5494 | mClient.asBinder().unlinkToDeath(this, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5495 | mClientDead = true; |
| 5496 | killSessionLocked(); |
| 5497 | } |
| 5498 | } |
| 5499 | |
| 5500 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
| 5501 | int viewVisibility, Rect outContentInsets) { |
| 5502 | return addWindow(this, window, attrs, viewVisibility, outContentInsets); |
| 5503 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5504 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5505 | public void remove(IWindow window) { |
| 5506 | removeWindow(this, window); |
| 5507 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5508 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5509 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 5510 | int requestedWidth, int requestedHeight, int viewFlags, |
| 5511 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
| 5512 | Rect outVisibleInsets, Surface outSurface) { |
| 5513 | return relayoutWindow(this, window, attrs, |
| 5514 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
| 5515 | outFrame, outContentInsets, outVisibleInsets, outSurface); |
| 5516 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5517 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5518 | public void setTransparentRegion(IWindow window, Region region) { |
| 5519 | setTransparentRegionWindow(this, window, region); |
| 5520 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5521 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5522 | public void setInsets(IWindow window, int touchableInsets, |
| 5523 | Rect contentInsets, Rect visibleInsets) { |
| 5524 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 5525 | visibleInsets); |
| 5526 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5527 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5528 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 5529 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 5530 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5531 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5532 | public void finishDrawing(IWindow window) { |
| 5533 | if (localLOGV) Log.v( |
| 5534 | TAG, "IWindow finishDrawing called for " + window); |
| 5535 | finishDrawingWindow(this, window); |
| 5536 | } |
| 5537 | |
| 5538 | public void finishKey(IWindow window) { |
| 5539 | if (localLOGV) Log.v( |
| 5540 | TAG, "IWindow finishKey called for " + window); |
| 5541 | mKeyWaiter.finishedKey(this, window, false, |
| 5542 | KeyWaiter.RETURN_NOTHING); |
| 5543 | } |
| 5544 | |
| 5545 | public MotionEvent getPendingPointerMove(IWindow window) { |
| 5546 | if (localLOGV) Log.v( |
| 5547 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 5548 | return mKeyWaiter.finishedKey(this, window, false, |
| 5549 | KeyWaiter.RETURN_PENDING_POINTER); |
| 5550 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5551 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5552 | public MotionEvent getPendingTrackballMove(IWindow window) { |
| 5553 | if (localLOGV) Log.v( |
| 5554 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 5555 | return mKeyWaiter.finishedKey(this, window, false, |
| 5556 | KeyWaiter.RETURN_PENDING_TRACKBALL); |
| 5557 | } |
| 5558 | |
| 5559 | public void setInTouchMode(boolean mode) { |
| 5560 | synchronized(mWindowMap) { |
| 5561 | mInTouchMode = mode; |
| 5562 | } |
| 5563 | } |
| 5564 | |
| 5565 | public boolean getInTouchMode() { |
| 5566 | synchronized(mWindowMap) { |
| 5567 | return mInTouchMode; |
| 5568 | } |
| 5569 | } |
| 5570 | |
| 5571 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 5572 | boolean always) { |
| 5573 | synchronized(mWindowMap) { |
| 5574 | long ident = Binder.clearCallingIdentity(); |
| 5575 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 5576 | return mPolicy.performHapticFeedbackLw( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5577 | windowForClientLocked(this, window), effectId, always); |
| 5578 | } finally { |
| 5579 | Binder.restoreCallingIdentity(ident); |
| 5580 | } |
| 5581 | } |
| 5582 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5583 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5584 | void windowAddedLocked() { |
| 5585 | if (mSurfaceSession == null) { |
| 5586 | if (localLOGV) Log.v( |
| 5587 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 5588 | mSurfaceSession = new SurfaceSession(); |
| 5589 | mSessions.add(this); |
| 5590 | } |
| 5591 | mNumWindow++; |
| 5592 | } |
| 5593 | |
| 5594 | void windowRemovedLocked() { |
| 5595 | mNumWindow--; |
| 5596 | killSessionLocked(); |
| 5597 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5598 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5599 | void killSessionLocked() { |
| 5600 | if (mNumWindow <= 0 && mClientDead) { |
| 5601 | mSessions.remove(this); |
| 5602 | if (mSurfaceSession != null) { |
| 5603 | if (localLOGV) Log.v( |
| 5604 | TAG, "Last window removed from " + this |
| 5605 | + ", destroying " + mSurfaceSession); |
| 5606 | try { |
| 5607 | mSurfaceSession.kill(); |
| 5608 | } catch (Exception e) { |
| 5609 | Log.w(TAG, "Exception thrown when killing surface session " |
| 5610 | + mSurfaceSession + " in session " + this |
| 5611 | + ": " + e.toString()); |
| 5612 | } |
| 5613 | mSurfaceSession = null; |
| 5614 | } |
| 5615 | } |
| 5616 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5617 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5618 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5619 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 5620 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 5621 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
| 5622 | if (mPendingPointerWindow != null || mPendingPointerMove != null) { |
| 5623 | pw.print(prefix); |
| 5624 | pw.print("mPendingPointerWindow="); pw.print(mPendingPointerWindow); |
| 5625 | pw.print(" mPendingPointerMove="); pw.println(mPendingPointerMove); |
| 5626 | } |
| 5627 | if (mPendingTrackballWindow != null || mPendingTrackballMove != null) { |
| 5628 | pw.print(prefix); |
| 5629 | pw.print("mPendingTrackballWindow="); pw.print(mPendingTrackballWindow); |
| 5630 | pw.print(" mPendingTrackballMove="); pw.println(mPendingTrackballMove); |
| 5631 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5632 | } |
| 5633 | |
| 5634 | @Override |
| 5635 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5636 | return mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5637 | } |
| 5638 | } |
| 5639 | |
| 5640 | // ------------------------------------------------------------- |
| 5641 | // Client Window State |
| 5642 | // ------------------------------------------------------------- |
| 5643 | |
| 5644 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 5645 | final Session mSession; |
| 5646 | final IWindow mClient; |
| 5647 | WindowToken mToken; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5648 | WindowToken mRootToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5649 | AppWindowToken mAppToken; |
| 5650 | AppWindowToken mTargetAppToken; |
| 5651 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 5652 | final DeathRecipient mDeathRecipient; |
| 5653 | final WindowState mAttachedWindow; |
| 5654 | final ArrayList mChildWindows = new ArrayList(); |
| 5655 | final int mBaseLayer; |
| 5656 | final int mSubLayer; |
| 5657 | final boolean mLayoutAttached; |
| 5658 | final boolean mIsImWindow; |
| 5659 | int mViewVisibility; |
| 5660 | boolean mPolicyVisibility = true; |
| 5661 | boolean mPolicyVisibilityAfterAnim = true; |
| 5662 | boolean mAppFreezing; |
| 5663 | Surface mSurface; |
| 5664 | boolean mAttachedHidden; // is our parent window hidden? |
| 5665 | boolean mLastHidden; // was this window last hidden? |
| 5666 | int mRequestedWidth; |
| 5667 | int mRequestedHeight; |
| 5668 | int mLastRequestedWidth; |
| 5669 | int mLastRequestedHeight; |
| 5670 | int mReqXPos; |
| 5671 | int mReqYPos; |
| 5672 | int mLayer; |
| 5673 | int mAnimLayer; |
| 5674 | int mLastLayer; |
| 5675 | boolean mHaveFrame; |
| 5676 | |
| 5677 | WindowState mNextOutsideTouch; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5678 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5679 | // Actual frame shown on-screen (may be modified by animation) |
| 5680 | final Rect mShownFrame = new Rect(); |
| 5681 | final Rect mLastShownFrame = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5682 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5683 | /** |
| 5684 | * Insets that determine the actually visible area |
| 5685 | */ |
| 5686 | final Rect mVisibleInsets = new Rect(); |
| 5687 | final Rect mLastVisibleInsets = new Rect(); |
| 5688 | boolean mVisibleInsetsChanged; |
| 5689 | |
| 5690 | /** |
| 5691 | * Insets that are covered by system windows |
| 5692 | */ |
| 5693 | final Rect mContentInsets = new Rect(); |
| 5694 | final Rect mLastContentInsets = new Rect(); |
| 5695 | boolean mContentInsetsChanged; |
| 5696 | |
| 5697 | /** |
| 5698 | * Set to true if we are waiting for this window to receive its |
| 5699 | * given internal insets before laying out other windows based on it. |
| 5700 | */ |
| 5701 | boolean mGivenInsetsPending; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5702 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5703 | /** |
| 5704 | * These are the content insets that were given during layout for |
| 5705 | * this window, to be applied to windows behind it. |
| 5706 | */ |
| 5707 | final Rect mGivenContentInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5708 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5709 | /** |
| 5710 | * These are the visible insets that were given during layout for |
| 5711 | * this window, to be applied to windows behind it. |
| 5712 | */ |
| 5713 | final Rect mGivenVisibleInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5714 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5715 | /** |
| 5716 | * Flag indicating whether the touchable region should be adjusted by |
| 5717 | * the visible insets; if false the area outside the visible insets is |
| 5718 | * NOT touchable, so we must use those to adjust the frame during hit |
| 5719 | * tests. |
| 5720 | */ |
| 5721 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5722 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5723 | // Current transformation being applied. |
| 5724 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 5725 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 5726 | float mHScale=1, mVScale=1; |
| 5727 | float mLastHScale=1, mLastVScale=1; |
| 5728 | final Matrix mTmpMatrix = new Matrix(); |
| 5729 | |
| 5730 | // "Real" frame that the application sees. |
| 5731 | final Rect mFrame = new Rect(); |
| 5732 | final Rect mLastFrame = new Rect(); |
| 5733 | |
| 5734 | final Rect mContainingFrame = new Rect(); |
| 5735 | final Rect mDisplayFrame = new Rect(); |
| 5736 | final Rect mContentFrame = new Rect(); |
| 5737 | final Rect mVisibleFrame = new Rect(); |
| 5738 | |
| 5739 | float mShownAlpha = 1; |
| 5740 | float mAlpha = 1; |
| 5741 | float mLastAlpha = 1; |
| 5742 | |
| 5743 | // Set to true if, when the window gets displayed, it should perform |
| 5744 | // an enter animation. |
| 5745 | boolean mEnterAnimationPending; |
| 5746 | |
| 5747 | // Currently running animation. |
| 5748 | boolean mAnimating; |
| 5749 | boolean mLocalAnimating; |
| 5750 | Animation mAnimation; |
| 5751 | boolean mAnimationIsEntrance; |
| 5752 | boolean mHasTransformation; |
| 5753 | boolean mHasLocalTransformation; |
| 5754 | final Transformation mTransformation = new Transformation(); |
| 5755 | |
| 5756 | // This is set after IWindowSession.relayout() has been called at |
| 5757 | // least once for the window. It allows us to detect the situation |
| 5758 | // where we don't yet have a surface, but should have one soon, so |
| 5759 | // we can give the window focus before waiting for the relayout. |
| 5760 | boolean mRelayoutCalled; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5761 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5762 | // This is set after the Surface has been created but before the |
| 5763 | // window has been drawn. During this time the surface is hidden. |
| 5764 | boolean mDrawPending; |
| 5765 | |
| 5766 | // This is set after the window has finished drawing for the first |
| 5767 | // time but before its surface is shown. The surface will be |
| 5768 | // displayed when the next layout is run. |
| 5769 | boolean mCommitDrawPending; |
| 5770 | |
| 5771 | // This is set during the time after the window's drawing has been |
| 5772 | // committed, and before its surface is actually shown. It is used |
| 5773 | // to delay showing the surface until all windows in a token are ready |
| 5774 | // to be shown. |
| 5775 | boolean mReadyToShow; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5776 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5777 | // Set when the window has been shown in the screen the first time. |
| 5778 | boolean mHasDrawn; |
| 5779 | |
| 5780 | // Currently running an exit animation? |
| 5781 | boolean mExiting; |
| 5782 | |
| 5783 | // Currently on the mDestroySurface list? |
| 5784 | boolean mDestroying; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5785 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5786 | // Completely remove from window manager after exit animation? |
| 5787 | boolean mRemoveOnExit; |
| 5788 | |
| 5789 | // Set when the orientation is changing and this window has not yet |
| 5790 | // been updated for the new orientation. |
| 5791 | boolean mOrientationChanging; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5792 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5793 | // Is this window now (or just being) removed? |
| 5794 | boolean mRemoved; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5795 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5796 | WindowState(Session s, IWindow c, WindowToken token, |
| 5797 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 5798 | int viewVisibility) { |
| 5799 | mSession = s; |
| 5800 | mClient = c; |
| 5801 | mToken = token; |
| 5802 | mAttrs.copyFrom(a); |
| 5803 | mViewVisibility = viewVisibility; |
| 5804 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 5805 | mAlpha = a.alpha; |
| 5806 | if (localLOGV) Log.v( |
| 5807 | TAG, "Window " + this + " client=" + c.asBinder() |
| 5808 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 5809 | try { |
| 5810 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 5811 | } catch (RemoteException e) { |
| 5812 | mDeathRecipient = null; |
| 5813 | mAttachedWindow = null; |
| 5814 | mLayoutAttached = false; |
| 5815 | mIsImWindow = false; |
| 5816 | mBaseLayer = 0; |
| 5817 | mSubLayer = 0; |
| 5818 | return; |
| 5819 | } |
| 5820 | mDeathRecipient = deathRecipient; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5821 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5822 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 5823 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 5824 | // The multiplier here is to reserve space for multiple |
| 5825 | // windows in the same type layer. |
| 5826 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 5827 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 5828 | + TYPE_LAYER_OFFSET; |
| 5829 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 5830 | mAttachedWindow = attachedWindow; |
| 5831 | mAttachedWindow.mChildWindows.add(this); |
| 5832 | mLayoutAttached = mAttrs.type != |
| 5833 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 5834 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 5835 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| 5836 | } else { |
| 5837 | // The multiplier here is to reserve space for multiple |
| 5838 | // windows in the same type layer. |
| 5839 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 5840 | * TYPE_LAYER_MULTIPLIER |
| 5841 | + TYPE_LAYER_OFFSET; |
| 5842 | mSubLayer = 0; |
| 5843 | mAttachedWindow = null; |
| 5844 | mLayoutAttached = false; |
| 5845 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 5846 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| 5847 | } |
| 5848 | |
| 5849 | WindowState appWin = this; |
| 5850 | while (appWin.mAttachedWindow != null) { |
| 5851 | appWin = mAttachedWindow; |
| 5852 | } |
| 5853 | WindowToken appToken = appWin.mToken; |
| 5854 | while (appToken.appWindowToken == null) { |
| 5855 | WindowToken parent = mTokenMap.get(appToken.token); |
| 5856 | if (parent == null || appToken == parent) { |
| 5857 | break; |
| 5858 | } |
| 5859 | appToken = parent; |
| 5860 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5861 | mRootToken = appToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5862 | mAppToken = appToken.appWindowToken; |
| 5863 | |
| 5864 | mSurface = null; |
| 5865 | mRequestedWidth = 0; |
| 5866 | mRequestedHeight = 0; |
| 5867 | mLastRequestedWidth = 0; |
| 5868 | mLastRequestedHeight = 0; |
| 5869 | mReqXPos = 0; |
| 5870 | mReqYPos = 0; |
| 5871 | mLayer = 0; |
| 5872 | mAnimLayer = 0; |
| 5873 | mLastLayer = 0; |
| 5874 | } |
| 5875 | |
| 5876 | void attach() { |
| 5877 | if (localLOGV) Log.v( |
| 5878 | TAG, "Attaching " + this + " token=" + mToken |
| 5879 | + ", list=" + mToken.windows); |
| 5880 | mSession.windowAddedLocked(); |
| 5881 | } |
| 5882 | |
| 5883 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 5884 | mHaveFrame = true; |
| 5885 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5886 | final Rect container = mContainingFrame; |
| 5887 | container.set(pf); |
| 5888 | |
| 5889 | final Rect display = mDisplayFrame; |
| 5890 | display.set(df); |
| 5891 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 5892 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5893 | container.intersect(mCompatibleScreenFrame); |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 5894 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 5895 | display.intersect(mCompatibleScreenFrame); |
| 5896 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5897 | } |
| 5898 | |
| 5899 | final int pw = container.right - container.left; |
| 5900 | final int ph = container.bottom - container.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5901 | |
| 5902 | int w,h; |
| 5903 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 5904 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 5905 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 5906 | } else { |
| 5907 | w = mAttrs.width == mAttrs.FILL_PARENT ? pw : mRequestedWidth; |
| 5908 | h = mAttrs.height== mAttrs.FILL_PARENT ? ph : mRequestedHeight; |
| 5909 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5910 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5911 | final Rect content = mContentFrame; |
| 5912 | content.set(cf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5913 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5914 | final Rect visible = mVisibleFrame; |
| 5915 | visible.set(vf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5916 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5917 | final Rect frame = mFrame; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5918 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5919 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 5920 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 5921 | |
| 5922 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 5923 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 5924 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 5925 | |
| 5926 | //System.out.println("Out: " + mFrame); |
| 5927 | |
| 5928 | // Now make sure the window fits in the overall display. |
| 5929 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5930 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5931 | // Make sure the content and visible frames are inside of the |
| 5932 | // final window frame. |
| 5933 | if (content.left < frame.left) content.left = frame.left; |
| 5934 | if (content.top < frame.top) content.top = frame.top; |
| 5935 | if (content.right > frame.right) content.right = frame.right; |
| 5936 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 5937 | if (visible.left < frame.left) visible.left = frame.left; |
| 5938 | if (visible.top < frame.top) visible.top = frame.top; |
| 5939 | if (visible.right > frame.right) visible.right = frame.right; |
| 5940 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5941 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5942 | final Rect contentInsets = mContentInsets; |
| 5943 | contentInsets.left = content.left-frame.left; |
| 5944 | contentInsets.top = content.top-frame.top; |
| 5945 | contentInsets.right = frame.right-content.right; |
| 5946 | contentInsets.bottom = frame.bottom-content.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5947 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5948 | final Rect visibleInsets = mVisibleInsets; |
| 5949 | visibleInsets.left = visible.left-frame.left; |
| 5950 | visibleInsets.top = visible.top-frame.top; |
| 5951 | visibleInsets.right = frame.right-visible.right; |
| 5952 | visibleInsets.bottom = frame.bottom-visible.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5953 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5954 | if (localLOGV) { |
| 5955 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 5956 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
| 5957 | Log.v(TAG, "Resolving (mRequestedWidth=" |
| 5958 | + mRequestedWidth + ", mRequestedheight=" |
| 5959 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 5960 | + "): frame=" + mFrame.toShortString() |
| 5961 | + " ci=" + contentInsets.toShortString() |
| 5962 | + " vi=" + visibleInsets.toShortString()); |
| 5963 | //} |
| 5964 | } |
| 5965 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5966 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5967 | public Rect getFrameLw() { |
| 5968 | return mFrame; |
| 5969 | } |
| 5970 | |
| 5971 | public Rect getShownFrameLw() { |
| 5972 | return mShownFrame; |
| 5973 | } |
| 5974 | |
| 5975 | public Rect getDisplayFrameLw() { |
| 5976 | return mDisplayFrame; |
| 5977 | } |
| 5978 | |
| 5979 | public Rect getContentFrameLw() { |
| 5980 | return mContentFrame; |
| 5981 | } |
| 5982 | |
| 5983 | public Rect getVisibleFrameLw() { |
| 5984 | return mVisibleFrame; |
| 5985 | } |
| 5986 | |
| 5987 | public boolean getGivenInsetsPendingLw() { |
| 5988 | return mGivenInsetsPending; |
| 5989 | } |
| 5990 | |
| 5991 | public Rect getGivenContentInsetsLw() { |
| 5992 | return mGivenContentInsets; |
| 5993 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5994 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5995 | public Rect getGivenVisibleInsetsLw() { |
| 5996 | return mGivenVisibleInsets; |
| 5997 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5998 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5999 | public WindowManager.LayoutParams getAttrs() { |
| 6000 | return mAttrs; |
| 6001 | } |
| 6002 | |
| 6003 | public int getSurfaceLayer() { |
| 6004 | return mLayer; |
| 6005 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6006 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6007 | public IApplicationToken getAppToken() { |
| 6008 | return mAppToken != null ? mAppToken.appToken : null; |
| 6009 | } |
| 6010 | |
| 6011 | public boolean hasAppShownWindows() { |
| 6012 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 6013 | } |
| 6014 | |
| 6015 | public boolean hasAppStartingIcon() { |
| 6016 | return mAppToken != null ? (mAppToken.startingData != null) : false; |
| 6017 | } |
| 6018 | |
| 6019 | public WindowManagerPolicy.WindowState getAppStartingWindow() { |
| 6020 | return mAppToken != null ? mAppToken.startingWindow : null; |
| 6021 | } |
| 6022 | |
| 6023 | public void setAnimation(Animation anim) { |
| 6024 | if (localLOGV) Log.v( |
| 6025 | TAG, "Setting animation in " + this + ": " + anim); |
| 6026 | mAnimating = false; |
| 6027 | mLocalAnimating = false; |
| 6028 | mAnimation = anim; |
| 6029 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 6030 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 6031 | } |
| 6032 | |
| 6033 | public void clearAnimation() { |
| 6034 | if (mAnimation != null) { |
| 6035 | mAnimating = true; |
| 6036 | mLocalAnimating = false; |
| 6037 | mAnimation = null; |
| 6038 | } |
| 6039 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6040 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6041 | Surface createSurfaceLocked() { |
| 6042 | if (mSurface == null) { |
| 6043 | mDrawPending = true; |
| 6044 | mCommitDrawPending = false; |
| 6045 | mReadyToShow = false; |
| 6046 | if (mAppToken != null) { |
| 6047 | mAppToken.allDrawn = false; |
| 6048 | } |
| 6049 | |
| 6050 | int flags = 0; |
| 6051 | if (mAttrs.memoryType == MEMORY_TYPE_HARDWARE) { |
| 6052 | flags |= Surface.HARDWARE; |
| 6053 | } else if (mAttrs.memoryType == MEMORY_TYPE_GPU) { |
| 6054 | flags |= Surface.GPU; |
| 6055 | } else if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
| 6056 | flags |= Surface.PUSH_BUFFERS; |
| 6057 | } |
| 6058 | |
| 6059 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 6060 | flags |= Surface.SECURE; |
| 6061 | } |
| 6062 | if (DEBUG_VISIBILITY) Log.v( |
| 6063 | TAG, "Creating surface in session " |
| 6064 | + mSession.mSurfaceSession + " window " + this |
| 6065 | + " w=" + mFrame.width() |
| 6066 | + " h=" + mFrame.height() + " format=" |
| 6067 | + mAttrs.format + " flags=" + flags); |
| 6068 | |
| 6069 | int w = mFrame.width(); |
| 6070 | int h = mFrame.height(); |
| 6071 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 6072 | // for a scaled surface, we always want the requested |
| 6073 | // size. |
| 6074 | w = mRequestedWidth; |
| 6075 | h = mRequestedHeight; |
| 6076 | } |
| 6077 | |
| 6078 | try { |
| 6079 | mSurface = new Surface( |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6080 | mSession.mSurfaceSession, mSession.mPid, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6081 | 0, w, h, mAttrs.format, flags); |
| 6082 | } catch (Surface.OutOfResourcesException e) { |
| 6083 | Log.w(TAG, "OutOfResourcesException creating surface"); |
| 6084 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 6085 | return null; |
| 6086 | } catch (Exception e) { |
| 6087 | Log.e(TAG, "Exception creating surface", e); |
| 6088 | return null; |
| 6089 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6090 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6091 | if (localLOGV) Log.v( |
| 6092 | TAG, "Got surface: " + mSurface |
| 6093 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 6094 | + ", animLayer=" + mAnimLayer); |
| 6095 | if (SHOW_TRANSACTIONS) { |
| 6096 | Log.i(TAG, ">>> OPEN TRANSACTION"); |
| 6097 | Log.i(TAG, " SURFACE " + mSurface + ": CREATE (" |
| 6098 | + mAttrs.getTitle() + ") pos=(" + |
| 6099 | mFrame.left + "," + mFrame.top + ") (" + |
| 6100 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 6101 | mAnimLayer + " HIDE"); |
| 6102 | } |
| 6103 | Surface.openTransaction(); |
| 6104 | try { |
| 6105 | try { |
| 6106 | mSurface.setPosition(mFrame.left, mFrame.top); |
| 6107 | mSurface.setLayer(mAnimLayer); |
| 6108 | mSurface.hide(); |
| 6109 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
| 6110 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 6111 | Surface.SURFACE_DITHER); |
| 6112 | } |
| 6113 | } catch (RuntimeException e) { |
| 6114 | Log.w(TAG, "Error creating surface in " + w, e); |
| 6115 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 6116 | } |
| 6117 | mLastHidden = true; |
| 6118 | } finally { |
| 6119 | if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION"); |
| 6120 | Surface.closeTransaction(); |
| 6121 | } |
| 6122 | if (localLOGV) Log.v( |
| 6123 | TAG, "Created surface " + this); |
| 6124 | } |
| 6125 | return mSurface; |
| 6126 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6127 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6128 | void destroySurfaceLocked() { |
| 6129 | // Window is no longer on-screen, so can no longer receive |
| 6130 | // key events... if we were waiting for it to finish |
| 6131 | // handling a key event, the wait is over! |
| 6132 | mKeyWaiter.finishedKey(mSession, mClient, true, |
| 6133 | KeyWaiter.RETURN_NOTHING); |
| 6134 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 6135 | mKeyWaiter.releasePendingTrackballLocked(mSession); |
| 6136 | |
| 6137 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 6138 | mAppToken.startingDisplayed = false; |
| 6139 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6141 | if (localLOGV) Log.v( |
| 6142 | TAG, "Window " + this |
| 6143 | + " destroying surface " + mSurface + ", session " + mSession); |
| 6144 | if (mSurface != null) { |
| 6145 | try { |
| 6146 | if (SHOW_TRANSACTIONS) { |
| 6147 | RuntimeException ex = new RuntimeException(); |
| 6148 | ex.fillInStackTrace(); |
| 6149 | Log.i(TAG, " SURFACE " + mSurface + ": DESTROY (" |
| 6150 | + mAttrs.getTitle() + ")", ex); |
| 6151 | } |
| 6152 | mSurface.clear(); |
| 6153 | } catch (RuntimeException e) { |
| 6154 | Log.w(TAG, "Exception thrown when destroying Window " + this |
| 6155 | + " surface " + mSurface + " session " + mSession |
| 6156 | + ": " + e.toString()); |
| 6157 | } |
| 6158 | mSurface = null; |
| 6159 | mDrawPending = false; |
| 6160 | mCommitDrawPending = false; |
| 6161 | mReadyToShow = false; |
| 6162 | |
| 6163 | int i = mChildWindows.size(); |
| 6164 | while (i > 0) { |
| 6165 | i--; |
| 6166 | WindowState c = (WindowState)mChildWindows.get(i); |
| 6167 | c.mAttachedHidden = true; |
| 6168 | } |
| 6169 | } |
| 6170 | } |
| 6171 | |
| 6172 | boolean finishDrawingLocked() { |
| 6173 | if (mDrawPending) { |
| 6174 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Log.v( |
| 6175 | TAG, "finishDrawingLocked: " + mSurface); |
| 6176 | mCommitDrawPending = true; |
| 6177 | mDrawPending = false; |
| 6178 | return true; |
| 6179 | } |
| 6180 | return false; |
| 6181 | } |
| 6182 | |
| 6183 | // This must be called while inside a transaction. |
| 6184 | void commitFinishDrawingLocked(long currentTime) { |
| 6185 | //Log.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
| 6186 | if (!mCommitDrawPending) { |
| 6187 | return; |
| 6188 | } |
| 6189 | mCommitDrawPending = false; |
| 6190 | mReadyToShow = true; |
| 6191 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 6192 | final AppWindowToken atoken = mAppToken; |
| 6193 | if (atoken == null || atoken.allDrawn || starting) { |
| 6194 | performShowLocked(); |
| 6195 | } |
| 6196 | } |
| 6197 | |
| 6198 | // This must be called while inside a transaction. |
| 6199 | boolean performShowLocked() { |
| 6200 | if (DEBUG_VISIBILITY) { |
| 6201 | RuntimeException e = new RuntimeException(); |
| 6202 | e.fillInStackTrace(); |
| 6203 | Log.v(TAG, "performShow on " + this |
| 6204 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 6205 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 6206 | } |
| 6207 | if (mReadyToShow && isReadyForDisplay()) { |
| 6208 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Log.i( |
| 6209 | TAG, " SURFACE " + mSurface + ": SHOW (performShowLocked)"); |
| 6210 | if (DEBUG_VISIBILITY) Log.v(TAG, "Showing " + this |
| 6211 | + " during animation: policyVis=" + mPolicyVisibility |
| 6212 | + " attHidden=" + mAttachedHidden |
| 6213 | + " tok.hiddenRequested=" |
| 6214 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
| 6215 | + " tok.idden=" |
| 6216 | + (mAppToken != null ? mAppToken.hidden : false) |
| 6217 | + " animating=" + mAnimating |
| 6218 | + " tok animating=" |
| 6219 | + (mAppToken != null ? mAppToken.animating : false)); |
| 6220 | if (!showSurfaceRobustlyLocked(this)) { |
| 6221 | return false; |
| 6222 | } |
| 6223 | mLastAlpha = -1; |
| 6224 | mHasDrawn = true; |
| 6225 | mLastHidden = false; |
| 6226 | mReadyToShow = false; |
| 6227 | enableScreenIfNeededLocked(); |
| 6228 | |
| 6229 | applyEnterAnimationLocked(this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6230 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6231 | int i = mChildWindows.size(); |
| 6232 | while (i > 0) { |
| 6233 | i--; |
| 6234 | WindowState c = (WindowState)mChildWindows.get(i); |
| 6235 | if (c.mSurface != null && c.mAttachedHidden) { |
| 6236 | c.mAttachedHidden = false; |
| 6237 | c.performShowLocked(); |
| 6238 | } |
| 6239 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6240 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6241 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 6242 | && mAppToken != null) { |
| 6243 | mAppToken.firstWindowDrawn = true; |
| 6244 | if (mAnimation == null && mAppToken.startingData != null) { |
| 6245 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Finish starting " |
| 6246 | + mToken |
| 6247 | + ": first real window is shown, no animation"); |
| 6248 | mFinishedStarting.add(mAppToken); |
| 6249 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 6250 | } |
| 6251 | mAppToken.updateReportedVisibilityLocked(); |
| 6252 | } |
| 6253 | } |
| 6254 | return true; |
| 6255 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6256 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6257 | // This must be called while inside a transaction. Returns true if |
| 6258 | // there is more animation to run. |
| 6259 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| 6260 | if (!mDisplayFrozen) { |
| 6261 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6262 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6263 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 6264 | mHasTransformation = true; |
| 6265 | mHasLocalTransformation = true; |
| 6266 | if (!mLocalAnimating) { |
| 6267 | if (DEBUG_ANIM) Log.v( |
| 6268 | TAG, "Starting animation in " + this + |
| 6269 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 6270 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 6271 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 6272 | mAnimation.setStartTime(currentTime); |
| 6273 | mLocalAnimating = true; |
| 6274 | mAnimating = true; |
| 6275 | } |
| 6276 | mTransformation.clear(); |
| 6277 | final boolean more = mAnimation.getTransformation( |
| 6278 | currentTime, mTransformation); |
| 6279 | if (DEBUG_ANIM) Log.v( |
| 6280 | TAG, "Stepped animation in " + this + |
| 6281 | ": more=" + more + ", xform=" + mTransformation); |
| 6282 | if (more) { |
| 6283 | // we're not done! |
| 6284 | return true; |
| 6285 | } |
| 6286 | if (DEBUG_ANIM) Log.v( |
| 6287 | TAG, "Finished animation in " + this + |
| 6288 | " @ " + currentTime); |
| 6289 | mAnimation = null; |
| 6290 | //WindowManagerService.this.dump(); |
| 6291 | } |
| 6292 | mHasLocalTransformation = false; |
| 6293 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
| 6294 | && mAppToken.hasTransformation) { |
| 6295 | // When our app token is animating, we kind-of pretend like |
| 6296 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 6297 | // part of this check means that we will only do this if |
| 6298 | // our window is not currently exiting, or it is not |
| 6299 | // locally animating itself. The idea being that one that |
| 6300 | // is exiting and doing a local animation should be removed |
| 6301 | // once that animation is done. |
| 6302 | mAnimating = true; |
| 6303 | mHasTransformation = true; |
| 6304 | mTransformation.clear(); |
| 6305 | return false; |
| 6306 | } else if (mHasTransformation) { |
| 6307 | // Little trick to get through the path below to act like |
| 6308 | // we have finished an animation. |
| 6309 | mAnimating = true; |
| 6310 | } else if (isAnimating()) { |
| 6311 | mAnimating = true; |
| 6312 | } |
| 6313 | } else if (mAnimation != null) { |
| 6314 | // If the display is frozen, and there is a pending animation, |
| 6315 | // clear it and make sure we run the cleanup code. |
| 6316 | mAnimating = true; |
| 6317 | mLocalAnimating = true; |
| 6318 | mAnimation = null; |
| 6319 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6320 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6321 | if (!mAnimating && !mLocalAnimating) { |
| 6322 | return false; |
| 6323 | } |
| 6324 | |
| 6325 | if (DEBUG_ANIM) Log.v( |
| 6326 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 6327 | + ", reportedVisible=" |
| 6328 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6329 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6330 | mAnimating = false; |
| 6331 | mLocalAnimating = false; |
| 6332 | mAnimation = null; |
| 6333 | mAnimLayer = mLayer; |
| 6334 | if (mIsImWindow) { |
| 6335 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
| 6336 | } |
| 6337 | if (DEBUG_LAYERS) Log.v(TAG, "Stepping win " + this |
| 6338 | + " anim layer: " + mAnimLayer); |
| 6339 | mHasTransformation = false; |
| 6340 | mHasLocalTransformation = false; |
| 6341 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 6342 | mTransformation.clear(); |
| 6343 | if (mHasDrawn |
| 6344 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 6345 | && mAppToken != null |
| 6346 | && mAppToken.firstWindowDrawn |
| 6347 | && mAppToken.startingData != null) { |
| 6348 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Finish starting " |
| 6349 | + mToken + ": first real window done animating"); |
| 6350 | mFinishedStarting.add(mAppToken); |
| 6351 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 6352 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6353 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6354 | finishExit(); |
| 6355 | |
| 6356 | if (mAppToken != null) { |
| 6357 | mAppToken.updateReportedVisibilityLocked(); |
| 6358 | } |
| 6359 | |
| 6360 | return false; |
| 6361 | } |
| 6362 | |
| 6363 | void finishExit() { |
| 6364 | if (DEBUG_ANIM) Log.v( |
| 6365 | TAG, "finishExit in " + this |
| 6366 | + ": exiting=" + mExiting |
| 6367 | + " remove=" + mRemoveOnExit |
| 6368 | + " windowAnimating=" + isWindowAnimating()); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6369 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6370 | final int N = mChildWindows.size(); |
| 6371 | for (int i=0; i<N; i++) { |
| 6372 | ((WindowState)mChildWindows.get(i)).finishExit(); |
| 6373 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6374 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6375 | if (!mExiting) { |
| 6376 | return; |
| 6377 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6378 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6379 | if (isWindowAnimating()) { |
| 6380 | return; |
| 6381 | } |
| 6382 | |
| 6383 | if (localLOGV) Log.v( |
| 6384 | TAG, "Exit animation finished in " + this |
| 6385 | + ": remove=" + mRemoveOnExit); |
| 6386 | if (mSurface != null) { |
| 6387 | mDestroySurface.add(this); |
| 6388 | mDestroying = true; |
| 6389 | if (SHOW_TRANSACTIONS) Log.i( |
| 6390 | TAG, " SURFACE " + mSurface + ": HIDE (finishExit)"); |
| 6391 | try { |
| 6392 | mSurface.hide(); |
| 6393 | } catch (RuntimeException e) { |
| 6394 | Log.w(TAG, "Error hiding surface in " + this, e); |
| 6395 | } |
| 6396 | mLastHidden = true; |
| 6397 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 6398 | } |
| 6399 | mExiting = false; |
| 6400 | if (mRemoveOnExit) { |
| 6401 | mPendingRemove.add(this); |
| 6402 | mRemoveOnExit = false; |
| 6403 | } |
| 6404 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6405 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6406 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 6407 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 6408 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 6409 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 6410 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 6411 | return true; |
| 6412 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6414 | void computeShownFrameLocked() { |
| 6415 | final boolean selfTransformation = mHasLocalTransformation; |
| 6416 | Transformation attachedTransformation = |
| 6417 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 6418 | ? mAttachedWindow.mTransformation : null; |
| 6419 | Transformation appTransformation = |
| 6420 | (mAppToken != null && mAppToken.hasTransformation) |
| 6421 | ? mAppToken.transformation : null; |
| 6422 | if (selfTransformation || attachedTransformation != null |
| 6423 | || appTransformation != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6424 | // cache often used attributes locally |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6425 | final Rect frame = mFrame; |
| 6426 | final float tmpFloats[] = mTmpFloats; |
| 6427 | final Matrix tmpMatrix = mTmpMatrix; |
| 6428 | |
| 6429 | // Compute the desired transformation. |
| 6430 | tmpMatrix.setTranslate(frame.left, frame.top); |
| 6431 | if (selfTransformation) { |
| 6432 | tmpMatrix.preConcat(mTransformation.getMatrix()); |
| 6433 | } |
| 6434 | if (attachedTransformation != null) { |
| 6435 | tmpMatrix.preConcat(attachedTransformation.getMatrix()); |
| 6436 | } |
| 6437 | if (appTransformation != null) { |
| 6438 | tmpMatrix.preConcat(appTransformation.getMatrix()); |
| 6439 | } |
| 6440 | |
| 6441 | // "convert" it into SurfaceFlinger's format |
| 6442 | // (a 2x2 matrix + an offset) |
| 6443 | // Here we must not transform the position of the surface |
| 6444 | // since it is already included in the transformation. |
| 6445 | //Log.i(TAG, "Transform: " + matrix); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6446 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6447 | tmpMatrix.getValues(tmpFloats); |
| 6448 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 6449 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 6450 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 6451 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
| 6452 | int x = (int)tmpFloats[Matrix.MTRANS_X]; |
| 6453 | int y = (int)tmpFloats[Matrix.MTRANS_Y]; |
| 6454 | int w = frame.width(); |
| 6455 | int h = frame.height(); |
| 6456 | mShownFrame.set(x, y, x+w, y+h); |
| 6457 | |
| 6458 | // Now set the alpha... but because our current hardware |
| 6459 | // can't do alpha transformation on a non-opaque surface, |
| 6460 | // turn it off if we are running an animation that is also |
| 6461 | // transforming since it is more important to have that |
| 6462 | // animation be smooth. |
| 6463 | mShownAlpha = mAlpha; |
| 6464 | if (!mLimitedAlphaCompositing |
| 6465 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 6466 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 6467 | && x == frame.left && y == frame.top))) { |
| 6468 | //Log.i(TAG, "Applying alpha transform"); |
| 6469 | if (selfTransformation) { |
| 6470 | mShownAlpha *= mTransformation.getAlpha(); |
| 6471 | } |
| 6472 | if (attachedTransformation != null) { |
| 6473 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 6474 | } |
| 6475 | if (appTransformation != null) { |
| 6476 | mShownAlpha *= appTransformation.getAlpha(); |
| 6477 | } |
| 6478 | } else { |
| 6479 | //Log.i(TAG, "Not applying alpha transform"); |
| 6480 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6481 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6482 | if (localLOGV) Log.v( |
| 6483 | TAG, "Continuing animation in " + this + |
| 6484 | ": " + mShownFrame + |
| 6485 | ", alpha=" + mTransformation.getAlpha()); |
| 6486 | return; |
| 6487 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6488 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6489 | mShownFrame.set(mFrame); |
| 6490 | mShownAlpha = mAlpha; |
| 6491 | mDsDx = 1; |
| 6492 | mDtDx = 0; |
| 6493 | mDsDy = 0; |
| 6494 | mDtDy = 1; |
| 6495 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6496 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6497 | /** |
| 6498 | * Is this window visible? It is not visible if there is no |
| 6499 | * surface, or we are in the process of running an exit animation |
| 6500 | * that will remove the surface, or its app token has been hidden. |
| 6501 | */ |
| 6502 | public boolean isVisibleLw() { |
| 6503 | final AppWindowToken atoken = mAppToken; |
| 6504 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 6505 | && (atoken == null || !atoken.hiddenRequested) |
| 6506 | && !mExiting && !mDestroying; |
| 6507 | } |
| 6508 | |
| 6509 | /** |
| 6510 | * Is this window visible, ignoring its app token? It is not visible |
| 6511 | * if there is no surface, or we are in the process of running an exit animation |
| 6512 | * that will remove the surface. |
| 6513 | */ |
| 6514 | public boolean isWinVisibleLw() { |
| 6515 | final AppWindowToken atoken = mAppToken; |
| 6516 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 6517 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 6518 | && !mExiting && !mDestroying; |
| 6519 | } |
| 6520 | |
| 6521 | /** |
| 6522 | * The same as isVisible(), but follows the current hidden state of |
| 6523 | * the associated app token, not the pending requested hidden state. |
| 6524 | */ |
| 6525 | boolean isVisibleNow() { |
| 6526 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6527 | && !mRootToken.hidden && !mExiting && !mDestroying; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6528 | } |
| 6529 | |
| 6530 | /** |
| 6531 | * Same as isVisible(), but we also count it as visible between the |
| 6532 | * call to IWindowSession.add() and the first relayout(). |
| 6533 | */ |
| 6534 | boolean isVisibleOrAdding() { |
| 6535 | final AppWindowToken atoken = mAppToken; |
| 6536 | return (mSurface != null |
| 6537 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 6538 | && mPolicyVisibility && !mAttachedHidden |
| 6539 | && (atoken == null || !atoken.hiddenRequested) |
| 6540 | && !mExiting && !mDestroying; |
| 6541 | } |
| 6542 | |
| 6543 | /** |
| 6544 | * Is this window currently on-screen? It is on-screen either if it |
| 6545 | * is visible or it is currently running an animation before no longer |
| 6546 | * being visible. |
| 6547 | */ |
| 6548 | boolean isOnScreen() { |
| 6549 | final AppWindowToken atoken = mAppToken; |
| 6550 | if (atoken != null) { |
| 6551 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 6552 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
| 6553 | || mAnimating || atoken.animating); |
| 6554 | } else { |
| 6555 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 6556 | && (!mAttachedHidden || mAnimating); |
| 6557 | } |
| 6558 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6559 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6560 | /** |
| 6561 | * Like isOnScreen(), but we don't return true if the window is part |
| 6562 | * of a transition that has not yet been started. |
| 6563 | */ |
| 6564 | boolean isReadyForDisplay() { |
| 6565 | final AppWindowToken atoken = mAppToken; |
| 6566 | final boolean animating = atoken != null ? atoken.animating : false; |
| 6567 | return mSurface != null && mPolicyVisibility && !mDestroying |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6568 | && ((!mAttachedHidden && !mRootToken.hidden) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6569 | || mAnimating || animating); |
| 6570 | } |
| 6571 | |
| 6572 | /** Is the window or its container currently animating? */ |
| 6573 | boolean isAnimating() { |
| 6574 | final WindowState attached = mAttachedWindow; |
| 6575 | final AppWindowToken atoken = mAppToken; |
| 6576 | return mAnimation != null |
| 6577 | || (attached != null && attached.mAnimation != null) |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6578 | || (atoken != null && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6579 | (atoken.animation != null |
| 6580 | || atoken.inPendingTransaction)); |
| 6581 | } |
| 6582 | |
| 6583 | /** Is this window currently animating? */ |
| 6584 | boolean isWindowAnimating() { |
| 6585 | return mAnimation != null; |
| 6586 | } |
| 6587 | |
| 6588 | /** |
| 6589 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 6590 | * been drawn. |
| 6591 | */ |
| 6592 | public boolean isDisplayedLw() { |
| 6593 | final AppWindowToken atoken = mAppToken; |
| 6594 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 6595 | && !mDrawPending && !mCommitDrawPending |
| 6596 | && ((!mAttachedHidden && |
| 6597 | (atoken == null || !atoken.hiddenRequested)) |
| 6598 | || mAnimating); |
| 6599 | } |
| 6600 | |
| 6601 | public boolean fillsScreenLw(int screenWidth, int screenHeight, |
| 6602 | boolean shownFrame, boolean onlyOpaque) { |
| 6603 | if (mSurface == null) { |
| 6604 | return false; |
| 6605 | } |
| 6606 | if (mAppToken != null && !mAppToken.appFullscreen) { |
| 6607 | return false; |
| 6608 | } |
| 6609 | if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) { |
| 6610 | return false; |
| 6611 | } |
| 6612 | final Rect frame = shownFrame ? mShownFrame : mFrame; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6613 | |
| 6614 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| 6615 | return frame.left <= mCompatibleScreenFrame.left && |
| 6616 | frame.top <= mCompatibleScreenFrame.top && |
| 6617 | frame.right >= mCompatibleScreenFrame.right && |
| 6618 | frame.bottom >= mCompatibleScreenFrame.bottom; |
| 6619 | } else { |
| 6620 | return frame.left <= 0 && frame.top <= 0 |
| 6621 | && frame.right >= screenWidth |
| 6622 | && frame.bottom >= screenHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6623 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6624 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6625 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6626 | /** |
| 6627 | * Return true if the window is opaque and fully drawn. |
| 6628 | */ |
| 6629 | boolean isOpaqueDrawn() { |
| 6630 | return mAttrs.format == PixelFormat.OPAQUE && mSurface != null |
| 6631 | && mAnimation == null && !mDrawPending && !mCommitDrawPending; |
| 6632 | } |
| 6633 | |
| 6634 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 6635 | return |
| 6636 | // only if the application is requesting compatible window |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6637 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 6638 | // only if it's visible |
| 6639 | mHasDrawn && mViewVisibility == View.VISIBLE && |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6640 | // and only if the application fills the compatible screen |
| 6641 | mFrame.left <= mCompatibleScreenFrame.left && |
| 6642 | mFrame.top <= mCompatibleScreenFrame.top && |
| 6643 | mFrame.right >= mCompatibleScreenFrame.right && |
| 6644 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6645 | // and starting window do not need background filler |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6646 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6647 | } |
| 6648 | |
| 6649 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 6650 | return mFrame.left <= 0 && mFrame.top <= 0 && |
| 6651 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6652 | } |
| 6653 | |
| 6654 | void removeLocked() { |
| 6655 | if (mAttachedWindow != null) { |
| 6656 | mAttachedWindow.mChildWindows.remove(this); |
| 6657 | } |
| 6658 | destroySurfaceLocked(); |
| 6659 | mSession.windowRemovedLocked(); |
| 6660 | try { |
| 6661 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 6662 | } catch (RuntimeException e) { |
| 6663 | // Ignore if it has already been removed (usually because |
| 6664 | // we are doing this as part of processing a death note.) |
| 6665 | } |
| 6666 | } |
| 6667 | |
| 6668 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 6669 | public void binderDied() { |
| 6670 | try { |
| 6671 | synchronized(mWindowMap) { |
| 6672 | WindowState win = windowForClientLocked(mSession, mClient); |
| 6673 | Log.i(TAG, "WIN DEATH: " + win); |
| 6674 | if (win != null) { |
| 6675 | removeWindowLocked(mSession, win); |
| 6676 | } |
| 6677 | } |
| 6678 | } catch (IllegalArgumentException ex) { |
| 6679 | // This will happen if the window has already been |
| 6680 | // removed. |
| 6681 | } |
| 6682 | } |
| 6683 | } |
| 6684 | |
| 6685 | /** Returns true if this window desires key events. */ |
| 6686 | public final boolean canReceiveKeys() { |
| 6687 | return isVisibleOrAdding() |
| 6688 | && (mViewVisibility == View.VISIBLE) |
| 6689 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 6690 | } |
| 6691 | |
| 6692 | public boolean hasDrawnLw() { |
| 6693 | return mHasDrawn; |
| 6694 | } |
| 6695 | |
| 6696 | public boolean showLw(boolean doAnimation) { |
| 6697 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim) { |
| 6698 | mPolicyVisibility = true; |
| 6699 | mPolicyVisibilityAfterAnim = true; |
| 6700 | if (doAnimation) { |
| 6701 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 6702 | } |
| 6703 | requestAnimationLocked(0); |
| 6704 | return true; |
| 6705 | } |
| 6706 | return false; |
| 6707 | } |
| 6708 | |
| 6709 | public boolean hideLw(boolean doAnimation) { |
| 6710 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 6711 | : mPolicyVisibility; |
| 6712 | if (current) { |
| 6713 | if (doAnimation) { |
| 6714 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 6715 | if (mAnimation == null) { |
| 6716 | doAnimation = false; |
| 6717 | } |
| 6718 | } |
| 6719 | if (doAnimation) { |
| 6720 | mPolicyVisibilityAfterAnim = false; |
| 6721 | } else { |
| 6722 | mPolicyVisibilityAfterAnim = false; |
| 6723 | mPolicyVisibility = false; |
| 6724 | } |
| 6725 | requestAnimationLocked(0); |
| 6726 | return true; |
| 6727 | } |
| 6728 | return false; |
| 6729 | } |
| 6730 | |
| 6731 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6732 | StringBuilder sb = new StringBuilder(64); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6733 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6734 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 6735 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 6736 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 6737 | if (mAttachedWindow != null || mLayoutAttached) { |
| 6738 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 6739 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 6740 | } |
| 6741 | if (mIsImWindow) { |
| 6742 | pw.print(prefix); pw.print("mIsImWindow="); pw.println(mIsImWindow); |
| 6743 | } |
| 6744 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 6745 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 6746 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 6747 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 6748 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 6749 | pw.print("="); pw.print(mAnimLayer); |
| 6750 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 6751 | if (mSurface != null) { |
| 6752 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
| 6753 | } |
| 6754 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 6755 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 6756 | if (mAppToken != null) { |
| 6757 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 6758 | } |
| 6759 | if (mTargetAppToken != null) { |
| 6760 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 6761 | } |
| 6762 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 6763 | pw.print(Integer.toHexString(mViewVisibility)); |
| 6764 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
| 6765 | pw.print(" mHaveFrame="); pw.println(mHaveFrame); |
| 6766 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 6767 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 6768 | pw.print(mPolicyVisibility); |
| 6769 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 6770 | pw.print(mPolicyVisibilityAfterAnim); |
| 6771 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 6772 | } |
| 6773 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
| 6774 | pw.print(" h="); pw.print(mRequestedHeight); |
| 6775 | pw.print(" x="); pw.print(mReqXPos); |
| 6776 | pw.print(" y="); pw.println(mReqYPos); |
| 6777 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 6778 | mGivenContentInsets.printShortString(pw); |
| 6779 | pw.print(" mGivenVisibleInsets="); |
| 6780 | mGivenVisibleInsets.printShortString(pw); |
| 6781 | pw.println(); |
| 6782 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 6783 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 6784 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 6785 | } |
| 6786 | pw.print(prefix); pw.print("mShownFrame="); |
| 6787 | mShownFrame.printShortString(pw); |
| 6788 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 6789 | pw.println(); |
| 6790 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 6791 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 6792 | pw.println(); |
| 6793 | pw.print(prefix); pw.print("mContainingFrame="); |
| 6794 | mContainingFrame.printShortString(pw); |
| 6795 | pw.print(" mDisplayFrame="); |
| 6796 | mDisplayFrame.printShortString(pw); |
| 6797 | pw.println(); |
| 6798 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 6799 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 6800 | pw.println(); |
| 6801 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 6802 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 6803 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 6804 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 6805 | pw.println(); |
| 6806 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 6807 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 6808 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 6809 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 6810 | } |
| 6811 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 6812 | || mAnimation != null) { |
| 6813 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 6814 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 6815 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 6816 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 6817 | } |
| 6818 | if (mHasTransformation || mHasLocalTransformation) { |
| 6819 | pw.print(prefix); pw.print("XForm: has="); |
| 6820 | pw.print(mHasTransformation); |
| 6821 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 6822 | pw.print(" "); mTransformation.printShortString(pw); |
| 6823 | pw.println(); |
| 6824 | } |
| 6825 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 6826 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 6827 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 6828 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 6829 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 6830 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 6831 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 6832 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 6833 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 6834 | } |
| 6835 | if (mOrientationChanging || mAppFreezing) { |
| 6836 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 6837 | pw.print(mOrientationChanging); |
| 6838 | pw.print(" mAppFreezing="); pw.println(mAppFreezing); |
| 6839 | } |
Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 6840 | if (mHScale != 1 || mVScale != 1) { |
| 6841 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 6842 | pw.print(" mVScale="); pw.println(mVScale); |
| 6843 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6844 | } |
| 6845 | |
| 6846 | @Override |
| 6847 | public String toString() { |
| 6848 | return "Window{" |
| 6849 | + Integer.toHexString(System.identityHashCode(this)) |
| 6850 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 6851 | } |
| 6852 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6853 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6854 | // ------------------------------------------------------------- |
| 6855 | // Window Token State |
| 6856 | // ------------------------------------------------------------- |
| 6857 | |
| 6858 | class WindowToken { |
| 6859 | // The actual token. |
| 6860 | final IBinder token; |
| 6861 | |
| 6862 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 6863 | final int windowType; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6864 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6865 | // Set if this token was explicitly added by a client, so should |
| 6866 | // not be removed when all windows are removed. |
| 6867 | final boolean explicit; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6868 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6869 | // For printing. |
| 6870 | String stringName; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6871 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6872 | // If this is an AppWindowToken, this is non-null. |
| 6873 | AppWindowToken appWindowToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6874 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6875 | // All of the windows associated with this token. |
| 6876 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 6877 | |
| 6878 | // Is key dispatching paused for this token? |
| 6879 | boolean paused = false; |
| 6880 | |
| 6881 | // Should this token's windows be hidden? |
| 6882 | boolean hidden; |
| 6883 | |
| 6884 | // Temporary for finding which tokens no longer have visible windows. |
| 6885 | boolean hasVisible; |
| 6886 | |
| 6887 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 6888 | token = _token; |
| 6889 | windowType = type; |
| 6890 | explicit = _explicit; |
| 6891 | } |
| 6892 | |
| 6893 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6894 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 6895 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 6896 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 6897 | pw.print(" hidden="); pw.print(hidden); |
| 6898 | pw.print(" hasVisible="); pw.println(hasVisible); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6899 | } |
| 6900 | |
| 6901 | @Override |
| 6902 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6903 | if (stringName == null) { |
| 6904 | StringBuilder sb = new StringBuilder(); |
| 6905 | sb.append("WindowToken{"); |
| 6906 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 6907 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 6908 | stringName = sb.toString(); |
| 6909 | } |
| 6910 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6911 | } |
| 6912 | }; |
| 6913 | |
| 6914 | class AppWindowToken extends WindowToken { |
| 6915 | // Non-null only for application tokens. |
| 6916 | final IApplicationToken appToken; |
| 6917 | |
| 6918 | // All of the windows and child windows that are included in this |
| 6919 | // application token. Note this list is NOT sorted! |
| 6920 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 6921 | |
| 6922 | int groupId = -1; |
| 6923 | boolean appFullscreen; |
| 6924 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6925 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6926 | // These are used for determining when all windows associated with |
| 6927 | // an activity have been drawn, so they can be made visible together |
| 6928 | // at the same time. |
| 6929 | int lastTransactionSequence = mTransactionSequence-1; |
| 6930 | int numInterestingWindows; |
| 6931 | int numDrawnWindows; |
| 6932 | boolean inPendingTransaction; |
| 6933 | boolean allDrawn; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6934 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6935 | // Is this token going to be hidden in a little while? If so, it |
| 6936 | // won't be taken into account for setting the screen orientation. |
| 6937 | boolean willBeHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6938 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6939 | // Is this window's surface needed? This is almost like hidden, except |
| 6940 | // it will sometimes be true a little earlier: when the token has |
| 6941 | // been shown, but is still waiting for its app transition to execute |
| 6942 | // before making its windows shown. |
| 6943 | boolean hiddenRequested; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6944 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6945 | // Have we told the window clients to hide themselves? |
| 6946 | boolean clientHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6947 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6948 | // Last visibility state we reported to the app token. |
| 6949 | boolean reportedVisible; |
| 6950 | |
| 6951 | // Set to true when the token has been removed from the window mgr. |
| 6952 | boolean removed; |
| 6953 | |
| 6954 | // Have we been asked to have this token keep the screen frozen? |
| 6955 | boolean freezingScreen; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6956 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6957 | boolean animating; |
| 6958 | Animation animation; |
| 6959 | boolean hasTransformation; |
| 6960 | final Transformation transformation = new Transformation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6961 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6962 | // Offset to the window of all layers in the token, for use by |
| 6963 | // AppWindowToken animations. |
| 6964 | int animLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6965 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6966 | // Information about an application starting window if displayed. |
| 6967 | StartingData startingData; |
| 6968 | WindowState startingWindow; |
| 6969 | View startingView; |
| 6970 | boolean startingDisplayed; |
| 6971 | boolean startingMoved; |
| 6972 | boolean firstWindowDrawn; |
| 6973 | |
| 6974 | AppWindowToken(IApplicationToken _token) { |
| 6975 | super(_token.asBinder(), |
| 6976 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 6977 | appWindowToken = this; |
| 6978 | appToken = _token; |
| 6979 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6980 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6981 | public void setAnimation(Animation anim) { |
| 6982 | if (localLOGV) Log.v( |
| 6983 | TAG, "Setting animation in " + this + ": " + anim); |
| 6984 | animation = anim; |
| 6985 | animating = false; |
| 6986 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 6987 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 6988 | int zorder = anim.getZAdjustment(); |
| 6989 | int adj = 0; |
| 6990 | if (zorder == Animation.ZORDER_TOP) { |
| 6991 | adj = TYPE_LAYER_OFFSET; |
| 6992 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 6993 | adj = -TYPE_LAYER_OFFSET; |
| 6994 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6995 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6996 | if (animLayerAdjustment != adj) { |
| 6997 | animLayerAdjustment = adj; |
| 6998 | updateLayers(); |
| 6999 | } |
| 7000 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7001 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7002 | public void setDummyAnimation() { |
| 7003 | if (animation == null) { |
| 7004 | if (localLOGV) Log.v( |
| 7005 | TAG, "Setting dummy animation in " + this); |
| 7006 | animation = sDummyAnimation; |
| 7007 | } |
| 7008 | } |
| 7009 | |
| 7010 | public void clearAnimation() { |
| 7011 | if (animation != null) { |
| 7012 | animation = null; |
| 7013 | animating = true; |
| 7014 | } |
| 7015 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7016 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7017 | void updateLayers() { |
| 7018 | final int N = allAppWindows.size(); |
| 7019 | final int adj = animLayerAdjustment; |
| 7020 | for (int i=0; i<N; i++) { |
| 7021 | WindowState w = allAppWindows.get(i); |
| 7022 | w.mAnimLayer = w.mLayer + adj; |
| 7023 | if (DEBUG_LAYERS) Log.v(TAG, "Updating layer " + w + ": " |
| 7024 | + w.mAnimLayer); |
| 7025 | if (w == mInputMethodTarget) { |
| 7026 | setInputMethodAnimLayerAdjustment(adj); |
| 7027 | } |
| 7028 | } |
| 7029 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7030 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7031 | void sendAppVisibilityToClients() { |
| 7032 | final int N = allAppWindows.size(); |
| 7033 | for (int i=0; i<N; i++) { |
| 7034 | WindowState win = allAppWindows.get(i); |
| 7035 | if (win == startingWindow && clientHidden) { |
| 7036 | // Don't hide the starting window. |
| 7037 | continue; |
| 7038 | } |
| 7039 | try { |
| 7040 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 7041 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 7042 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 7043 | } catch (RemoteException e) { |
| 7044 | } |
| 7045 | } |
| 7046 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7047 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7048 | void showAllWindowsLocked() { |
| 7049 | final int NW = allAppWindows.size(); |
| 7050 | for (int i=0; i<NW; i++) { |
| 7051 | WindowState w = allAppWindows.get(i); |
| 7052 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 7053 | "performing show on: " + w); |
| 7054 | w.performShowLocked(); |
| 7055 | } |
| 7056 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7057 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7058 | // This must be called while inside a transaction. |
| 7059 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| 7060 | if (!mDisplayFrozen) { |
| 7061 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7062 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7063 | if (animation == sDummyAnimation) { |
| 7064 | // This guy is going to animate, but not yet. For now count |
| 7065 | // it is not animating for purposes of scheduling transactions; |
| 7066 | // when it is really time to animate, this will be set to |
| 7067 | // a real animation and the next call will execute normally. |
| 7068 | return false; |
| 7069 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7070 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7071 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 7072 | if (!animating) { |
| 7073 | if (DEBUG_ANIM) Log.v( |
| 7074 | TAG, "Starting animation in " + this + |
| 7075 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 7076 | + " scale=" + mTransitionAnimationScale |
| 7077 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 7078 | animation.initialize(dw, dh, dw, dh); |
| 7079 | animation.setStartTime(currentTime); |
| 7080 | animating = true; |
| 7081 | } |
| 7082 | transformation.clear(); |
| 7083 | final boolean more = animation.getTransformation( |
| 7084 | currentTime, transformation); |
| 7085 | if (DEBUG_ANIM) Log.v( |
| 7086 | TAG, "Stepped animation in " + this + |
| 7087 | ": more=" + more + ", xform=" + transformation); |
| 7088 | if (more) { |
| 7089 | // we're done! |
| 7090 | hasTransformation = true; |
| 7091 | return true; |
| 7092 | } |
| 7093 | if (DEBUG_ANIM) Log.v( |
| 7094 | TAG, "Finished animation in " + this + |
| 7095 | " @ " + currentTime); |
| 7096 | animation = null; |
| 7097 | } |
| 7098 | } else if (animation != null) { |
| 7099 | // If the display is frozen, and there is a pending animation, |
| 7100 | // clear it and make sure we run the cleanup code. |
| 7101 | animating = true; |
| 7102 | animation = null; |
| 7103 | } |
| 7104 | |
| 7105 | hasTransformation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7106 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7107 | if (!animating) { |
| 7108 | return false; |
| 7109 | } |
| 7110 | |
| 7111 | clearAnimation(); |
| 7112 | animating = false; |
| 7113 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 7114 | moveInputMethodWindowsIfNeededLocked(true); |
| 7115 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7116 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7117 | if (DEBUG_ANIM) Log.v( |
| 7118 | TAG, "Animation done in " + this |
| 7119 | + ": reportedVisible=" + reportedVisible); |
| 7120 | |
| 7121 | transformation.clear(); |
| 7122 | if (animLayerAdjustment != 0) { |
| 7123 | animLayerAdjustment = 0; |
| 7124 | updateLayers(); |
| 7125 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7126 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7127 | final int N = windows.size(); |
| 7128 | for (int i=0; i<N; i++) { |
| 7129 | ((WindowState)windows.get(i)).finishExit(); |
| 7130 | } |
| 7131 | updateReportedVisibilityLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7132 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7133 | return false; |
| 7134 | } |
| 7135 | |
| 7136 | void updateReportedVisibilityLocked() { |
| 7137 | if (appToken == null) { |
| 7138 | return; |
| 7139 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7141 | int numInteresting = 0; |
| 7142 | int numVisible = 0; |
| 7143 | boolean nowGone = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7144 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7145 | if (DEBUG_VISIBILITY) Log.v(TAG, "Update reported visibility: " + this); |
| 7146 | final int N = allAppWindows.size(); |
| 7147 | for (int i=0; i<N; i++) { |
| 7148 | WindowState win = allAppWindows.get(i); |
| 7149 | if (win == startingWindow || win.mAppFreezing) { |
| 7150 | continue; |
| 7151 | } |
| 7152 | if (DEBUG_VISIBILITY) { |
| 7153 | Log.v(TAG, "Win " + win + ": isDisplayed=" |
| 7154 | + win.isDisplayedLw() |
| 7155 | + ", isAnimating=" + win.isAnimating()); |
| 7156 | if (!win.isDisplayedLw()) { |
| 7157 | Log.v(TAG, "Not displayed: s=" + win.mSurface |
| 7158 | + " pv=" + win.mPolicyVisibility |
| 7159 | + " dp=" + win.mDrawPending |
| 7160 | + " cdp=" + win.mCommitDrawPending |
| 7161 | + " ah=" + win.mAttachedHidden |
| 7162 | + " th=" |
| 7163 | + (win.mAppToken != null |
| 7164 | ? win.mAppToken.hiddenRequested : false) |
| 7165 | + " a=" + win.mAnimating); |
| 7166 | } |
| 7167 | } |
| 7168 | numInteresting++; |
| 7169 | if (win.isDisplayedLw()) { |
| 7170 | if (!win.isAnimating()) { |
| 7171 | numVisible++; |
| 7172 | } |
| 7173 | nowGone = false; |
| 7174 | } else if (win.isAnimating()) { |
| 7175 | nowGone = false; |
| 7176 | } |
| 7177 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7178 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7179 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
| 7180 | if (DEBUG_VISIBILITY) Log.v(TAG, "VIS " + this + ": interesting=" |
| 7181 | + numInteresting + " visible=" + numVisible); |
| 7182 | if (nowVisible != reportedVisible) { |
| 7183 | if (DEBUG_VISIBILITY) Log.v( |
| 7184 | TAG, "Visibility changed in " + this |
| 7185 | + ": vis=" + nowVisible); |
| 7186 | reportedVisible = nowVisible; |
| 7187 | Message m = mH.obtainMessage( |
| 7188 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 7189 | nowVisible ? 1 : 0, |
| 7190 | nowGone ? 1 : 0, |
| 7191 | this); |
| 7192 | mH.sendMessage(m); |
| 7193 | } |
| 7194 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7195 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7196 | void dump(PrintWriter pw, String prefix) { |
| 7197 | super.dump(pw, prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7198 | if (appToken != null) { |
| 7199 | pw.print(prefix); pw.println("app=true"); |
| 7200 | } |
| 7201 | if (allAppWindows.size() > 0) { |
| 7202 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 7203 | } |
| 7204 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
| 7205 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 7206 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 7207 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 7208 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 7209 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 7210 | if (paused || freezingScreen) { |
| 7211 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 7212 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 7213 | } |
| 7214 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 7215 | || inPendingTransaction || allDrawn) { |
| 7216 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 7217 | pw.print(numInterestingWindows); |
| 7218 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 7219 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 7220 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 7221 | } |
| 7222 | if (animating || animation != null) { |
| 7223 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 7224 | pw.print(" animation="); pw.println(animation); |
| 7225 | } |
| 7226 | if (animLayerAdjustment != 0) { |
| 7227 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 7228 | } |
| 7229 | if (hasTransformation) { |
| 7230 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 7231 | pw.print(" transformation="); transformation.printShortString(pw); |
| 7232 | pw.println(); |
| 7233 | } |
| 7234 | if (startingData != null || removed || firstWindowDrawn) { |
| 7235 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 7236 | pw.print(" removed="); pw.print(removed); |
| 7237 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 7238 | } |
| 7239 | if (startingWindow != null || startingView != null |
| 7240 | || startingDisplayed || startingMoved) { |
| 7241 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 7242 | pw.print(" startingView="); pw.print(startingView); |
| 7243 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 7244 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 7245 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7246 | } |
| 7247 | |
| 7248 | @Override |
| 7249 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7250 | if (stringName == null) { |
| 7251 | StringBuilder sb = new StringBuilder(); |
| 7252 | sb.append("AppWindowToken{"); |
| 7253 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7254 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 7255 | stringName = sb.toString(); |
| 7256 | } |
| 7257 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7258 | } |
| 7259 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7260 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7261 | public static WindowManager.LayoutParams findAnimations( |
| 7262 | ArrayList<AppWindowToken> order, |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 7263 | ArrayList<AppWindowToken> openingTokenList1, |
| 7264 | ArrayList<AppWindowToken> closingTokenList2) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7265 | // We need to figure out which animation to use... |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 7266 | |
| 7267 | // First, check if there is a compatible window in opening/closing |
| 7268 | // apps, and use it if exists. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7269 | WindowManager.LayoutParams animParams = null; |
| 7270 | int animSrc = 0; |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 7271 | animParams = findCompatibleWindowParams(openingTokenList1); |
| 7272 | if (animParams == null) { |
| 7273 | animParams = findCompatibleWindowParams(closingTokenList2); |
| 7274 | } |
| 7275 | if (animParams != null) { |
| 7276 | return animParams; |
| 7277 | } |
| 7278 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7279 | //Log.i(TAG, "Looking for animations..."); |
| 7280 | for (int i=order.size()-1; i>=0; i--) { |
| 7281 | AppWindowToken wtoken = order.get(i); |
| 7282 | //Log.i(TAG, "Token " + wtoken + " with " + wtoken.windows.size() + " windows"); |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 7283 | if (openingTokenList1.contains(wtoken) || closingTokenList2.contains(wtoken)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7284 | int j = wtoken.windows.size(); |
| 7285 | while (j > 0) { |
| 7286 | j--; |
| 7287 | WindowState win = wtoken.windows.get(j); |
| 7288 | //Log.i(TAG, "Window " + win + ": type=" + win.mAttrs.type); |
| 7289 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 7290 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 7291 | //Log.i(TAG, "Found base or application window, done!"); |
| 7292 | if (wtoken.appFullscreen) { |
| 7293 | return win.mAttrs; |
| 7294 | } |
| 7295 | if (animSrc < 2) { |
| 7296 | animParams = win.mAttrs; |
| 7297 | animSrc = 2; |
| 7298 | } |
| 7299 | } else if (animSrc < 1 && win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION) { |
| 7300 | //Log.i(TAG, "Found normal window, we may use this..."); |
| 7301 | animParams = win.mAttrs; |
| 7302 | animSrc = 1; |
| 7303 | } |
| 7304 | } |
| 7305 | } |
| 7306 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7307 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7308 | return animParams; |
| 7309 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7310 | |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 7311 | private static LayoutParams findCompatibleWindowParams(ArrayList<AppWindowToken> tokenList) { |
| 7312 | for (int appCount = tokenList.size() - 1; appCount >= 0; appCount--) { |
| 7313 | AppWindowToken wtoken = tokenList.get(appCount); |
| 7314 | // Just checking one window is sufficient as all windows have the compatible flag |
| 7315 | // if the application is in compatibility mode. |
| 7316 | if (wtoken.windows.size() > 0) { |
| 7317 | WindowManager.LayoutParams params = wtoken.windows.get(0).mAttrs; |
| 7318 | if ((params.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| 7319 | return params; |
| 7320 | } |
| 7321 | } |
| 7322 | } |
| 7323 | return null; |
| 7324 | } |
| 7325 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7326 | // ------------------------------------------------------------- |
| 7327 | // DummyAnimation |
| 7328 | // ------------------------------------------------------------- |
| 7329 | |
| 7330 | // This is an animation that does nothing: it just immediately finishes |
| 7331 | // itself every time it is called. It is used as a stub animation in cases |
| 7332 | // where we want to synchronize multiple things that may be animating. |
| 7333 | static final class DummyAnimation extends Animation { |
| 7334 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 7335 | return false; |
| 7336 | } |
| 7337 | } |
| 7338 | static final Animation sDummyAnimation = new DummyAnimation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7339 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7340 | // ------------------------------------------------------------- |
| 7341 | // Async Handler |
| 7342 | // ------------------------------------------------------------- |
| 7343 | |
| 7344 | static final class StartingData { |
| 7345 | final String pkg; |
| 7346 | final int theme; |
| 7347 | final CharSequence nonLocalizedLabel; |
| 7348 | final int labelRes; |
| 7349 | final int icon; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7350 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7351 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 7352 | int _labelRes, int _icon) { |
| 7353 | pkg = _pkg; |
| 7354 | theme = _theme; |
| 7355 | nonLocalizedLabel = _nonLocalizedLabel; |
| 7356 | labelRes = _labelRes; |
| 7357 | icon = _icon; |
| 7358 | } |
| 7359 | } |
| 7360 | |
| 7361 | private final class H extends Handler { |
| 7362 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 7363 | public static final int REPORT_LOSING_FOCUS = 3; |
| 7364 | public static final int ANIMATE = 4; |
| 7365 | public static final int ADD_STARTING = 5; |
| 7366 | public static final int REMOVE_STARTING = 6; |
| 7367 | public static final int FINISHED_STARTING = 7; |
| 7368 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7369 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 7370 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 7371 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 7372 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 7373 | public static final int FORCE_GC = 15; |
| 7374 | public static final int ENABLE_SCREEN = 16; |
| 7375 | public static final int APP_FREEZE_TIMEOUT = 17; |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 7376 | public static final int COMPUTE_AND_SEND_NEW_CONFIGURATION = 18; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7377 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7378 | private Session mLastReportedHold; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7379 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7380 | public H() { |
| 7381 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7382 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7383 | @Override |
| 7384 | public void handleMessage(Message msg) { |
| 7385 | switch (msg.what) { |
| 7386 | case REPORT_FOCUS_CHANGE: { |
| 7387 | WindowState lastFocus; |
| 7388 | WindowState newFocus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7389 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7390 | synchronized(mWindowMap) { |
| 7391 | lastFocus = mLastFocus; |
| 7392 | newFocus = mCurrentFocus; |
| 7393 | if (lastFocus == newFocus) { |
| 7394 | // Focus is not changing, so nothing to do. |
| 7395 | return; |
| 7396 | } |
| 7397 | mLastFocus = newFocus; |
| 7398 | //Log.i(TAG, "Focus moving from " + lastFocus |
| 7399 | // + " to " + newFocus); |
| 7400 | if (newFocus != null && lastFocus != null |
| 7401 | && !newFocus.isDisplayedLw()) { |
| 7402 | //Log.i(TAG, "Delaying loss of focus..."); |
| 7403 | mLosingFocus.add(lastFocus); |
| 7404 | lastFocus = null; |
| 7405 | } |
| 7406 | } |
| 7407 | |
| 7408 | if (lastFocus != newFocus) { |
| 7409 | //System.out.println("Changing focus from " + lastFocus |
| 7410 | // + " to " + newFocus); |
| 7411 | if (newFocus != null) { |
| 7412 | try { |
| 7413 | //Log.i(TAG, "Gaining focus: " + newFocus); |
| 7414 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 7415 | } catch (RemoteException e) { |
| 7416 | // Ignore if process has died. |
| 7417 | } |
| 7418 | } |
| 7419 | |
| 7420 | if (lastFocus != null) { |
| 7421 | try { |
| 7422 | //Log.i(TAG, "Losing focus: " + lastFocus); |
| 7423 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 7424 | } catch (RemoteException e) { |
| 7425 | // Ignore if process has died. |
| 7426 | } |
| 7427 | } |
| 7428 | } |
| 7429 | } break; |
| 7430 | |
| 7431 | case REPORT_LOSING_FOCUS: { |
| 7432 | ArrayList<WindowState> losers; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7433 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7434 | synchronized(mWindowMap) { |
| 7435 | losers = mLosingFocus; |
| 7436 | mLosingFocus = new ArrayList<WindowState>(); |
| 7437 | } |
| 7438 | |
| 7439 | final int N = losers.size(); |
| 7440 | for (int i=0; i<N; i++) { |
| 7441 | try { |
| 7442 | //Log.i(TAG, "Losing delayed focus: " + losers.get(i)); |
| 7443 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 7444 | } catch (RemoteException e) { |
| 7445 | // Ignore if process has died. |
| 7446 | } |
| 7447 | } |
| 7448 | } break; |
| 7449 | |
| 7450 | case ANIMATE: { |
| 7451 | synchronized(mWindowMap) { |
| 7452 | mAnimationPending = false; |
| 7453 | performLayoutAndPlaceSurfacesLocked(); |
| 7454 | } |
| 7455 | } break; |
| 7456 | |
| 7457 | case ADD_STARTING: { |
| 7458 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7459 | final StartingData sd = wtoken.startingData; |
| 7460 | |
| 7461 | if (sd == null) { |
| 7462 | // Animation has been canceled... do nothing. |
| 7463 | return; |
| 7464 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7465 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7466 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Add starting " |
| 7467 | + wtoken + ": pkg=" + sd.pkg); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7468 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7469 | View view = null; |
| 7470 | try { |
| 7471 | view = mPolicy.addStartingWindow( |
| 7472 | wtoken.token, sd.pkg, |
| 7473 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 7474 | sd.icon); |
| 7475 | } catch (Exception e) { |
| 7476 | Log.w(TAG, "Exception when adding starting window", e); |
| 7477 | } |
| 7478 | |
| 7479 | if (view != null) { |
| 7480 | boolean abort = false; |
| 7481 | |
| 7482 | synchronized(mWindowMap) { |
| 7483 | if (wtoken.removed || wtoken.startingData == null) { |
| 7484 | // If the window was successfully added, then |
| 7485 | // we need to remove it. |
| 7486 | if (wtoken.startingWindow != null) { |
| 7487 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 7488 | "Aborted starting " + wtoken |
| 7489 | + ": removed=" + wtoken.removed |
| 7490 | + " startingData=" + wtoken.startingData); |
| 7491 | wtoken.startingWindow = null; |
| 7492 | wtoken.startingData = null; |
| 7493 | abort = true; |
| 7494 | } |
| 7495 | } else { |
| 7496 | wtoken.startingView = view; |
| 7497 | } |
| 7498 | if (DEBUG_STARTING_WINDOW && !abort) Log.v(TAG, |
| 7499 | "Added starting " + wtoken |
| 7500 | + ": startingWindow=" |
| 7501 | + wtoken.startingWindow + " startingView=" |
| 7502 | + wtoken.startingView); |
| 7503 | } |
| 7504 | |
| 7505 | if (abort) { |
| 7506 | try { |
| 7507 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 7508 | } catch (Exception e) { |
| 7509 | Log.w(TAG, "Exception when removing starting window", e); |
| 7510 | } |
| 7511 | } |
| 7512 | } |
| 7513 | } break; |
| 7514 | |
| 7515 | case REMOVE_STARTING: { |
| 7516 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7517 | IBinder token = null; |
| 7518 | View view = null; |
| 7519 | synchronized (mWindowMap) { |
| 7520 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Remove starting " |
| 7521 | + wtoken + ": startingWindow=" |
| 7522 | + wtoken.startingWindow + " startingView=" |
| 7523 | + wtoken.startingView); |
| 7524 | if (wtoken.startingWindow != null) { |
| 7525 | view = wtoken.startingView; |
| 7526 | token = wtoken.token; |
| 7527 | wtoken.startingData = null; |
| 7528 | wtoken.startingView = null; |
| 7529 | wtoken.startingWindow = null; |
| 7530 | } |
| 7531 | } |
| 7532 | if (view != null) { |
| 7533 | try { |
| 7534 | mPolicy.removeStartingWindow(token, view); |
| 7535 | } catch (Exception e) { |
| 7536 | Log.w(TAG, "Exception when removing starting window", e); |
| 7537 | } |
| 7538 | } |
| 7539 | } break; |
| 7540 | |
| 7541 | case FINISHED_STARTING: { |
| 7542 | IBinder token = null; |
| 7543 | View view = null; |
| 7544 | while (true) { |
| 7545 | synchronized (mWindowMap) { |
| 7546 | final int N = mFinishedStarting.size(); |
| 7547 | if (N <= 0) { |
| 7548 | break; |
| 7549 | } |
| 7550 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 7551 | |
| 7552 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 7553 | "Finished starting " + wtoken |
| 7554 | + ": startingWindow=" + wtoken.startingWindow |
| 7555 | + " startingView=" + wtoken.startingView); |
| 7556 | |
| 7557 | if (wtoken.startingWindow == null) { |
| 7558 | continue; |
| 7559 | } |
| 7560 | |
| 7561 | view = wtoken.startingView; |
| 7562 | token = wtoken.token; |
| 7563 | wtoken.startingData = null; |
| 7564 | wtoken.startingView = null; |
| 7565 | wtoken.startingWindow = null; |
| 7566 | } |
| 7567 | |
| 7568 | try { |
| 7569 | mPolicy.removeStartingWindow(token, view); |
| 7570 | } catch (Exception e) { |
| 7571 | Log.w(TAG, "Exception when removing starting window", e); |
| 7572 | } |
| 7573 | } |
| 7574 | } break; |
| 7575 | |
| 7576 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 7577 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7578 | |
| 7579 | boolean nowVisible = msg.arg1 != 0; |
| 7580 | boolean nowGone = msg.arg2 != 0; |
| 7581 | |
| 7582 | try { |
| 7583 | if (DEBUG_VISIBILITY) Log.v( |
| 7584 | TAG, "Reporting visible in " + wtoken |
| 7585 | + " visible=" + nowVisible |
| 7586 | + " gone=" + nowGone); |
| 7587 | if (nowVisible) { |
| 7588 | wtoken.appToken.windowsVisible(); |
| 7589 | } else { |
| 7590 | wtoken.appToken.windowsGone(); |
| 7591 | } |
| 7592 | } catch (RemoteException ex) { |
| 7593 | } |
| 7594 | } break; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7595 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7596 | case WINDOW_FREEZE_TIMEOUT: { |
| 7597 | synchronized (mWindowMap) { |
| 7598 | Log.w(TAG, "Window freeze timeout expired."); |
| 7599 | int i = mWindows.size(); |
| 7600 | while (i > 0) { |
| 7601 | i--; |
| 7602 | WindowState w = (WindowState)mWindows.get(i); |
| 7603 | if (w.mOrientationChanging) { |
| 7604 | w.mOrientationChanging = false; |
| 7605 | Log.w(TAG, "Force clearing orientation change: " + w); |
| 7606 | } |
| 7607 | } |
| 7608 | performLayoutAndPlaceSurfacesLocked(); |
| 7609 | } |
| 7610 | break; |
| 7611 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7612 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7613 | case HOLD_SCREEN_CHANGED: { |
| 7614 | Session oldHold; |
| 7615 | Session newHold; |
| 7616 | synchronized (mWindowMap) { |
| 7617 | oldHold = mLastReportedHold; |
| 7618 | newHold = (Session)msg.obj; |
| 7619 | mLastReportedHold = newHold; |
| 7620 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7621 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7622 | if (oldHold != newHold) { |
| 7623 | try { |
| 7624 | if (oldHold != null) { |
| 7625 | mBatteryStats.noteStopWakelock(oldHold.mUid, |
| 7626 | "window", |
| 7627 | BatteryStats.WAKE_TYPE_WINDOW); |
| 7628 | } |
| 7629 | if (newHold != null) { |
| 7630 | mBatteryStats.noteStartWakelock(newHold.mUid, |
| 7631 | "window", |
| 7632 | BatteryStats.WAKE_TYPE_WINDOW); |
| 7633 | } |
| 7634 | } catch (RemoteException e) { |
| 7635 | } |
| 7636 | } |
| 7637 | break; |
| 7638 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7639 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7640 | case APP_TRANSITION_TIMEOUT: { |
| 7641 | synchronized (mWindowMap) { |
| 7642 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) { |
| 7643 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 7644 | "*** APP TRANSITION TIMEOUT"); |
| 7645 | mAppTransitionReady = true; |
| 7646 | mAppTransitionTimeout = true; |
| 7647 | performLayoutAndPlaceSurfacesLocked(); |
| 7648 | } |
| 7649 | } |
| 7650 | break; |
| 7651 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7652 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7653 | case PERSIST_ANIMATION_SCALE: { |
| 7654 | Settings.System.putFloat(mContext.getContentResolver(), |
| 7655 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 7656 | Settings.System.putFloat(mContext.getContentResolver(), |
| 7657 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 7658 | break; |
| 7659 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7660 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7661 | case FORCE_GC: { |
| 7662 | synchronized(mWindowMap) { |
| 7663 | if (mAnimationPending) { |
| 7664 | // If we are animating, don't do the gc now but |
| 7665 | // delay a bit so we don't interrupt the animation. |
| 7666 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 7667 | 2000); |
| 7668 | return; |
| 7669 | } |
| 7670 | // If we are currently rotating the display, it will |
| 7671 | // schedule a new message when done. |
| 7672 | if (mDisplayFrozen) { |
| 7673 | return; |
| 7674 | } |
| 7675 | mFreezeGcPending = 0; |
| 7676 | } |
| 7677 | Runtime.getRuntime().gc(); |
| 7678 | break; |
| 7679 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7680 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7681 | case ENABLE_SCREEN: { |
| 7682 | performEnableScreen(); |
| 7683 | break; |
| 7684 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7685 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7686 | case APP_FREEZE_TIMEOUT: { |
| 7687 | synchronized (mWindowMap) { |
| 7688 | Log.w(TAG, "App freeze timeout expired."); |
| 7689 | int i = mAppTokens.size(); |
| 7690 | while (i > 0) { |
| 7691 | i--; |
| 7692 | AppWindowToken tok = mAppTokens.get(i); |
| 7693 | if (tok.freezingScreen) { |
| 7694 | Log.w(TAG, "Force clearing freeze: " + tok); |
| 7695 | unsetAppFreezingScreenLocked(tok, true, true); |
| 7696 | } |
| 7697 | } |
| 7698 | } |
| 7699 | break; |
| 7700 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7701 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 7702 | case COMPUTE_AND_SEND_NEW_CONFIGURATION: { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 7703 | if (updateOrientationFromAppTokensUnchecked(null, null) != null) { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 7704 | sendNewConfiguration(); |
| 7705 | } |
| 7706 | break; |
| 7707 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7708 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7709 | } |
| 7710 | } |
| 7711 | } |
| 7712 | |
| 7713 | // ------------------------------------------------------------- |
| 7714 | // IWindowManager API |
| 7715 | // ------------------------------------------------------------- |
| 7716 | |
| 7717 | public IWindowSession openSession(IInputMethodClient client, |
| 7718 | IInputContext inputContext) { |
| 7719 | if (client == null) throw new IllegalArgumentException("null client"); |
| 7720 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
| 7721 | return new Session(client, inputContext); |
| 7722 | } |
| 7723 | |
| 7724 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 7725 | synchronized (mWindowMap) { |
| 7726 | // The focus for the client is the window immediately below |
| 7727 | // where we would place the input method window. |
| 7728 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 7729 | WindowState imFocus; |
| 7730 | if (idx > 0) { |
| 7731 | imFocus = (WindowState)mWindows.get(idx-1); |
| 7732 | if (imFocus != null) { |
| 7733 | if (imFocus.mSession.mClient != null && |
| 7734 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 7735 | return true; |
| 7736 | } |
| 7737 | } |
| 7738 | } |
| 7739 | } |
| 7740 | return false; |
| 7741 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7742 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7743 | // ------------------------------------------------------------- |
| 7744 | // Internals |
| 7745 | // ------------------------------------------------------------- |
| 7746 | |
| 7747 | final WindowState windowForClientLocked(Session session, IWindow client) { |
| 7748 | return windowForClientLocked(session, client.asBinder()); |
| 7749 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7750 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7751 | final WindowState windowForClientLocked(Session session, IBinder client) { |
| 7752 | WindowState win = mWindowMap.get(client); |
| 7753 | if (localLOGV) Log.v( |
| 7754 | TAG, "Looking up client " + client + ": " + win); |
| 7755 | if (win == null) { |
| 7756 | RuntimeException ex = new RuntimeException(); |
| 7757 | Log.w(TAG, "Requested window " + client + " does not exist", ex); |
| 7758 | return null; |
| 7759 | } |
| 7760 | if (session != null && win.mSession != session) { |
| 7761 | RuntimeException ex = new RuntimeException(); |
| 7762 | Log.w(TAG, "Requested window " + client + " is in session " + |
| 7763 | win.mSession + ", not " + session, ex); |
| 7764 | return null; |
| 7765 | } |
| 7766 | |
| 7767 | return win; |
| 7768 | } |
| 7769 | |
| 7770 | private final void assignLayersLocked() { |
| 7771 | int N = mWindows.size(); |
| 7772 | int curBaseLayer = 0; |
| 7773 | int curLayer = 0; |
| 7774 | int i; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7775 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7776 | for (i=0; i<N; i++) { |
| 7777 | WindowState w = (WindowState)mWindows.get(i); |
| 7778 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow) { |
| 7779 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 7780 | w.mLayer = curLayer; |
| 7781 | } else { |
| 7782 | curBaseLayer = curLayer = w.mBaseLayer; |
| 7783 | w.mLayer = curLayer; |
| 7784 | } |
| 7785 | if (w.mTargetAppToken != null) { |
| 7786 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 7787 | } else if (w.mAppToken != null) { |
| 7788 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 7789 | } else { |
| 7790 | w.mAnimLayer = w.mLayer; |
| 7791 | } |
| 7792 | if (w.mIsImWindow) { |
| 7793 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
| 7794 | } |
| 7795 | if (DEBUG_LAYERS) Log.v(TAG, "Assign layer " + w + ": " |
| 7796 | + w.mAnimLayer); |
| 7797 | //System.out.println( |
| 7798 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 7799 | } |
| 7800 | } |
| 7801 | |
| 7802 | private boolean mInLayout = false; |
| 7803 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 7804 | if (mInLayout) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 7805 | if (DEBUG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7806 | throw new RuntimeException("Recursive call!"); |
| 7807 | } |
| 7808 | Log.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
| 7809 | return; |
| 7810 | } |
| 7811 | |
| 7812 | boolean recoveringMemory = false; |
| 7813 | if (mForceRemoves != null) { |
| 7814 | recoveringMemory = true; |
| 7815 | // Wait a little it for things to settle down, and off we go. |
| 7816 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 7817 | WindowState ws = mForceRemoves.get(i); |
| 7818 | Log.i(TAG, "Force removing: " + ws); |
| 7819 | removeWindowInnerLocked(ws.mSession, ws); |
| 7820 | } |
| 7821 | mForceRemoves = null; |
| 7822 | Log.w(TAG, "Due to memory failure, waiting a bit for next layout"); |
| 7823 | Object tmp = new Object(); |
| 7824 | synchronized (tmp) { |
| 7825 | try { |
| 7826 | tmp.wait(250); |
| 7827 | } catch (InterruptedException e) { |
| 7828 | } |
| 7829 | } |
| 7830 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7831 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7832 | mInLayout = true; |
| 7833 | try { |
| 7834 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7835 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7836 | int i = mPendingRemove.size()-1; |
| 7837 | if (i >= 0) { |
| 7838 | while (i >= 0) { |
| 7839 | WindowState w = mPendingRemove.get(i); |
| 7840 | removeWindowInnerLocked(w.mSession, w); |
| 7841 | i--; |
| 7842 | } |
| 7843 | mPendingRemove.clear(); |
| 7844 | |
| 7845 | mInLayout = false; |
| 7846 | assignLayersLocked(); |
| 7847 | mLayoutNeeded = true; |
| 7848 | performLayoutAndPlaceSurfacesLocked(); |
| 7849 | |
| 7850 | } else { |
| 7851 | mInLayout = false; |
| 7852 | if (mLayoutNeeded) { |
| 7853 | requestAnimationLocked(0); |
| 7854 | } |
| 7855 | } |
| 7856 | } catch (RuntimeException e) { |
| 7857 | mInLayout = false; |
| 7858 | Log.e(TAG, "Unhandled exception while layout out windows", e); |
| 7859 | } |
| 7860 | } |
| 7861 | |
| 7862 | private final void performLayoutLockedInner() { |
| 7863 | final int dw = mDisplay.getWidth(); |
| 7864 | final int dh = mDisplay.getHeight(); |
| 7865 | |
| 7866 | final int N = mWindows.size(); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 7867 | int repeats = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7868 | int i; |
| 7869 | |
| 7870 | // FIRST LOOP: Perform a layout, if needed. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7871 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 7872 | while (mLayoutNeeded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7873 | mPolicy.beginLayoutLw(dw, dh); |
| 7874 | |
| 7875 | // First perform layout of any root windows (not attached |
| 7876 | // to another window). |
| 7877 | int topAttached = -1; |
| 7878 | for (i = N-1; i >= 0; i--) { |
| 7879 | WindowState win = (WindowState) mWindows.get(i); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 7880 | |
| 7881 | // Don't do layout of a window if it is not visible, or |
| 7882 | // soon won't be visible, to avoid wasting time and funky |
| 7883 | // changes while a window is animating away. |
| 7884 | final AppWindowToken atoken = win.mAppToken; |
| 7885 | final boolean gone = win.mViewVisibility == View.GONE |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7886 | || !win.mRelayoutCalled |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 7887 | || win.mRootToken.hidden |
| 7888 | || (atoken != null && atoken.hiddenRequested) |
| 7889 | || !win.mPolicyVisibility |
| 7890 | || win.mAttachedHidden |
| 7891 | || win.mExiting || win.mDestroying; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7892 | |
| 7893 | // If this view is GONE, then skip it -- keep the current |
| 7894 | // frame, and let the caller know so they can ignore it |
| 7895 | // if they want. (We do the normal layout for INVISIBLE |
| 7896 | // windows, since that means "perform layout as normal, |
| 7897 | // just don't display"). |
| 7898 | if (!gone || !win.mHaveFrame) { |
| 7899 | if (!win.mLayoutAttached) { |
| 7900 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 7901 | } else { |
| 7902 | if (topAttached < 0) topAttached = i; |
| 7903 | } |
| 7904 | } |
| 7905 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7906 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7907 | // Now perform layout of attached windows, which usually |
| 7908 | // depend on the position of the window they are attached to. |
| 7909 | // XXX does not deal with windows that are attached to windows |
| 7910 | // that are themselves attached. |
| 7911 | for (i = topAttached; i >= 0; i--) { |
| 7912 | WindowState win = (WindowState) mWindows.get(i); |
| 7913 | |
| 7914 | // If this view is GONE, then skip it -- keep the current |
| 7915 | // frame, and let the caller know so they can ignore it |
| 7916 | // if they want. (We do the normal layout for INVISIBLE |
| 7917 | // windows, since that means "perform layout as normal, |
| 7918 | // just don't display"). |
| 7919 | if (win.mLayoutAttached) { |
| 7920 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 7921 | || !win.mHaveFrame) { |
| 7922 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 7923 | } |
| 7924 | } |
| 7925 | } |
| 7926 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 7927 | if (!mPolicy.finishLayoutLw()) { |
| 7928 | mLayoutNeeded = false; |
| 7929 | } else if (repeats > 2) { |
| 7930 | Log.w(TAG, "Layout repeat aborted after too many iterations"); |
| 7931 | mLayoutNeeded = false; |
| 7932 | } else { |
| 7933 | repeats++; |
| 7934 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7935 | } |
| 7936 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7937 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7938 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 7939 | boolean recoveringMemory) { |
| 7940 | final long currentTime = SystemClock.uptimeMillis(); |
| 7941 | final int dw = mDisplay.getWidth(); |
| 7942 | final int dh = mDisplay.getHeight(); |
| 7943 | |
| 7944 | final int N = mWindows.size(); |
| 7945 | int i; |
| 7946 | |
| 7947 | // FIRST LOOP: Perform a layout, if needed. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7948 | performLayoutLockedInner(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7949 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7950 | if (mFxSession == null) { |
| 7951 | mFxSession = new SurfaceSession(); |
| 7952 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7953 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7954 | if (SHOW_TRANSACTIONS) Log.i(TAG, ">>> OPEN TRANSACTION"); |
| 7955 | |
| 7956 | // Initialize state of exiting tokens. |
| 7957 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 7958 | mExitingTokens.get(i).hasVisible = false; |
| 7959 | } |
| 7960 | |
| 7961 | // Initialize state of exiting applications. |
| 7962 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 7963 | mExitingAppTokens.get(i).hasVisible = false; |
| 7964 | } |
| 7965 | |
| 7966 | // SECOND LOOP: Execute animations and update visibility of windows. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7967 | boolean orientationChangeComplete = true; |
| 7968 | Session holdScreen = null; |
| 7969 | float screenBrightness = -1; |
| 7970 | boolean focusDisplayed = false; |
| 7971 | boolean animating = false; |
| 7972 | |
| 7973 | Surface.openTransaction(); |
| 7974 | try { |
| 7975 | boolean restart; |
| 7976 | |
| 7977 | do { |
| 7978 | final int transactionSequence = ++mTransactionSequence; |
| 7979 | |
| 7980 | // Update animations of all applications, including those |
| 7981 | // associated with exiting/removed apps |
| 7982 | boolean tokensAnimating = false; |
| 7983 | final int NAT = mAppTokens.size(); |
| 7984 | for (i=0; i<NAT; i++) { |
| 7985 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 7986 | tokensAnimating = true; |
| 7987 | } |
| 7988 | } |
| 7989 | final int NEAT = mExitingAppTokens.size(); |
| 7990 | for (i=0; i<NEAT; i++) { |
| 7991 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 7992 | tokensAnimating = true; |
| 7993 | } |
| 7994 | } |
| 7995 | |
| 7996 | animating = tokensAnimating; |
| 7997 | restart = false; |
| 7998 | |
| 7999 | boolean tokenMayBeDrawn = false; |
| 8000 | |
| 8001 | mPolicy.beginAnimationLw(dw, dh); |
| 8002 | |
| 8003 | for (i=N-1; i>=0; i--) { |
| 8004 | WindowState w = (WindowState)mWindows.get(i); |
| 8005 | |
| 8006 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 8007 | |
| 8008 | if (w.mSurface != null) { |
| 8009 | // Execute animation. |
| 8010 | w.commitFinishDrawingLocked(currentTime); |
| 8011 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 8012 | animating = true; |
| 8013 | //w.dump(" "); |
| 8014 | } |
| 8015 | |
| 8016 | mPolicy.animatingWindowLw(w, attrs); |
| 8017 | } |
| 8018 | |
| 8019 | final AppWindowToken atoken = w.mAppToken; |
| 8020 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 8021 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 8022 | atoken.lastTransactionSequence = transactionSequence; |
| 8023 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 8024 | atoken.startingDisplayed = false; |
| 8025 | } |
| 8026 | if ((w.isOnScreen() || w.mAttrs.type |
| 8027 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 8028 | && !w.mExiting && !w.mDestroying) { |
| 8029 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
| 8030 | Log.v(TAG, "Eval win " + w + ": isDisplayed=" |
| 8031 | + w.isDisplayedLw() |
| 8032 | + ", isAnimating=" + w.isAnimating()); |
| 8033 | if (!w.isDisplayedLw()) { |
| 8034 | Log.v(TAG, "Not displayed: s=" + w.mSurface |
| 8035 | + " pv=" + w.mPolicyVisibility |
| 8036 | + " dp=" + w.mDrawPending |
| 8037 | + " cdp=" + w.mCommitDrawPending |
| 8038 | + " ah=" + w.mAttachedHidden |
| 8039 | + " th=" + atoken.hiddenRequested |
| 8040 | + " a=" + w.mAnimating); |
| 8041 | } |
| 8042 | } |
| 8043 | if (w != atoken.startingWindow) { |
| 8044 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 8045 | atoken.numInterestingWindows++; |
| 8046 | if (w.isDisplayedLw()) { |
| 8047 | atoken.numDrawnWindows++; |
| 8048 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Log.v(TAG, |
| 8049 | "tokenMayBeDrawn: " + atoken |
| 8050 | + " freezingScreen=" + atoken.freezingScreen |
| 8051 | + " mAppFreezing=" + w.mAppFreezing); |
| 8052 | tokenMayBeDrawn = true; |
| 8053 | } |
| 8054 | } |
| 8055 | } else if (w.isDisplayedLw()) { |
| 8056 | atoken.startingDisplayed = true; |
| 8057 | } |
| 8058 | } |
| 8059 | } else if (w.mReadyToShow) { |
| 8060 | w.performShowLocked(); |
| 8061 | } |
| 8062 | } |
| 8063 | |
| 8064 | if (mPolicy.finishAnimationLw()) { |
| 8065 | restart = true; |
| 8066 | } |
| 8067 | |
| 8068 | if (tokenMayBeDrawn) { |
| 8069 | // See if any windows have been drawn, so they (and others |
| 8070 | // associated with them) can now be shown. |
| 8071 | final int NT = mTokenList.size(); |
| 8072 | for (i=0; i<NT; i++) { |
| 8073 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 8074 | if (wtoken == null) { |
| 8075 | continue; |
| 8076 | } |
| 8077 | if (wtoken.freezingScreen) { |
| 8078 | int numInteresting = wtoken.numInterestingWindows; |
| 8079 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| 8080 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 8081 | "allDrawn: " + wtoken |
| 8082 | + " interesting=" + numInteresting |
| 8083 | + " drawn=" + wtoken.numDrawnWindows); |
| 8084 | wtoken.showAllWindowsLocked(); |
| 8085 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 8086 | orientationChangeComplete = true; |
| 8087 | } |
| 8088 | } else if (!wtoken.allDrawn) { |
| 8089 | int numInteresting = wtoken.numInterestingWindows; |
| 8090 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| 8091 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 8092 | "allDrawn: " + wtoken |
| 8093 | + " interesting=" + numInteresting |
| 8094 | + " drawn=" + wtoken.numDrawnWindows); |
| 8095 | wtoken.allDrawn = true; |
| 8096 | restart = true; |
| 8097 | |
| 8098 | // We can now show all of the drawn windows! |
| 8099 | if (!mOpeningApps.contains(wtoken)) { |
| 8100 | wtoken.showAllWindowsLocked(); |
| 8101 | } |
| 8102 | } |
| 8103 | } |
| 8104 | } |
| 8105 | } |
| 8106 | |
| 8107 | // If we are ready to perform an app transition, check through |
| 8108 | // all of the app tokens to be shown and see if they are ready |
| 8109 | // to go. |
| 8110 | if (mAppTransitionReady) { |
| 8111 | int NN = mOpeningApps.size(); |
| 8112 | boolean goodToGo = true; |
| 8113 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 8114 | "Checking " + NN + " opening apps (frozen=" |
| 8115 | + mDisplayFrozen + " timeout=" |
| 8116 | + mAppTransitionTimeout + ")..."); |
| 8117 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 8118 | // If the display isn't frozen, wait to do anything until |
| 8119 | // all of the apps are ready. Otherwise just go because |
| 8120 | // we'll unfreeze the display when everyone is ready. |
| 8121 | for (i=0; i<NN && goodToGo; i++) { |
| 8122 | AppWindowToken wtoken = mOpeningApps.get(i); |
| 8123 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 8124 | "Check opening app" + wtoken + ": allDrawn=" |
| 8125 | + wtoken.allDrawn + " startingDisplayed=" |
| 8126 | + wtoken.startingDisplayed); |
| 8127 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 8128 | && !wtoken.startingMoved) { |
| 8129 | goodToGo = false; |
| 8130 | } |
| 8131 | } |
| 8132 | } |
| 8133 | if (goodToGo) { |
| 8134 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "**** GOOD TO GO"); |
| 8135 | int transit = mNextAppTransition; |
| 8136 | if (mSkipAppTransitionAnimation) { |
| 8137 | transit = WindowManagerPolicy.TRANSIT_NONE; |
| 8138 | } |
| 8139 | mNextAppTransition = WindowManagerPolicy.TRANSIT_NONE; |
| 8140 | mAppTransitionReady = false; |
| 8141 | mAppTransitionTimeout = false; |
| 8142 | mStartingIconInTransition = false; |
| 8143 | mSkipAppTransitionAnimation = false; |
| 8144 | |
| 8145 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 8146 | |
| 8147 | // We need to figure out which animation to use... |
| 8148 | WindowManager.LayoutParams lp = findAnimations(mAppTokens, |
| 8149 | mOpeningApps, mClosingApps); |
| 8150 | |
| 8151 | NN = mOpeningApps.size(); |
| 8152 | for (i=0; i<NN; i++) { |
| 8153 | AppWindowToken wtoken = mOpeningApps.get(i); |
| 8154 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 8155 | "Now opening app" + wtoken); |
| 8156 | wtoken.reportedVisible = false; |
| 8157 | wtoken.inPendingTransaction = false; |
| 8158 | setTokenVisibilityLocked(wtoken, lp, true, transit, false); |
| 8159 | wtoken.updateReportedVisibilityLocked(); |
| 8160 | wtoken.showAllWindowsLocked(); |
| 8161 | } |
| 8162 | NN = mClosingApps.size(); |
| 8163 | for (i=0; i<NN; i++) { |
| 8164 | AppWindowToken wtoken = mClosingApps.get(i); |
| 8165 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 8166 | "Now closing app" + wtoken); |
| 8167 | wtoken.inPendingTransaction = false; |
| 8168 | setTokenVisibilityLocked(wtoken, lp, false, transit, false); |
| 8169 | wtoken.updateReportedVisibilityLocked(); |
| 8170 | // Force the allDrawn flag, because we want to start |
| 8171 | // this guy's animations regardless of whether it's |
| 8172 | // gotten drawn. |
| 8173 | wtoken.allDrawn = true; |
| 8174 | } |
| 8175 | |
| 8176 | mOpeningApps.clear(); |
| 8177 | mClosingApps.clear(); |
| 8178 | |
| 8179 | // This has changed the visibility of windows, so perform |
| 8180 | // a new layout to get them all up-to-date. |
| 8181 | mLayoutNeeded = true; |
Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame^] | 8182 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 8183 | assignLayersLocked(); |
| 8184 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8185 | performLayoutLockedInner(); |
| 8186 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
| 8187 | |
| 8188 | restart = true; |
| 8189 | } |
| 8190 | } |
| 8191 | } while (restart); |
| 8192 | |
| 8193 | // THIRD LOOP: Update the surfaces of all windows. |
| 8194 | |
| 8195 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 8196 | |
| 8197 | boolean obscured = false; |
| 8198 | boolean blurring = false; |
| 8199 | boolean dimming = false; |
| 8200 | boolean covered = false; |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 8201 | boolean syswin = false; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8202 | boolean backgroundFillerShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8203 | |
| 8204 | for (i=N-1; i>=0; i--) { |
| 8205 | WindowState w = (WindowState)mWindows.get(i); |
| 8206 | |
| 8207 | boolean displayed = false; |
| 8208 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 8209 | final int attrFlags = attrs.flags; |
| 8210 | |
| 8211 | if (w.mSurface != null) { |
| 8212 | w.computeShownFrameLocked(); |
| 8213 | if (localLOGV) Log.v( |
| 8214 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 8215 | + ": new=" + w.mShownFrame + ", old=" |
| 8216 | + w.mLastShownFrame); |
| 8217 | |
| 8218 | boolean resize; |
| 8219 | int width, height; |
| 8220 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 8221 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 8222 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 8223 | // for a scaled surface, we just want to use |
| 8224 | // the requested size. |
| 8225 | width = w.mRequestedWidth; |
| 8226 | height = w.mRequestedHeight; |
| 8227 | w.mLastRequestedWidth = width; |
| 8228 | w.mLastRequestedHeight = height; |
| 8229 | w.mLastShownFrame.set(w.mShownFrame); |
| 8230 | try { |
| 8231 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 8232 | } catch (RuntimeException e) { |
| 8233 | Log.w(TAG, "Error positioning surface in " + w, e); |
| 8234 | if (!recoveringMemory) { |
| 8235 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 8236 | } |
| 8237 | } |
| 8238 | } else { |
| 8239 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 8240 | width = w.mShownFrame.width(); |
| 8241 | height = w.mShownFrame.height(); |
| 8242 | w.mLastShownFrame.set(w.mShownFrame); |
| 8243 | if (resize) { |
| 8244 | if (SHOW_TRANSACTIONS) Log.i( |
| 8245 | TAG, " SURFACE " + w.mSurface + ": (" |
| 8246 | + w.mShownFrame.left + "," |
| 8247 | + w.mShownFrame.top + ") (" |
| 8248 | + w.mShownFrame.width() + "x" |
| 8249 | + w.mShownFrame.height() + ")"); |
| 8250 | } |
| 8251 | } |
| 8252 | |
| 8253 | if (resize) { |
| 8254 | if (width < 1) width = 1; |
| 8255 | if (height < 1) height = 1; |
| 8256 | if (w.mSurface != null) { |
| 8257 | try { |
| 8258 | w.mSurface.setSize(width, height); |
| 8259 | w.mSurface.setPosition(w.mShownFrame.left, |
| 8260 | w.mShownFrame.top); |
| 8261 | } catch (RuntimeException e) { |
| 8262 | // If something goes wrong with the surface (such |
| 8263 | // as running out of memory), don't take down the |
| 8264 | // entire system. |
| 8265 | Log.e(TAG, "Failure updating surface of " + w |
| 8266 | + "size=(" + width + "x" + height |
| 8267 | + "), pos=(" + w.mShownFrame.left |
| 8268 | + "," + w.mShownFrame.top + ")", e); |
| 8269 | if (!recoveringMemory) { |
| 8270 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 8271 | } |
| 8272 | } |
| 8273 | } |
| 8274 | } |
| 8275 | if (!w.mAppFreezing) { |
| 8276 | w.mContentInsetsChanged = |
| 8277 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 8278 | w.mVisibleInsetsChanged = |
| 8279 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8280 | if (!w.mLastFrame.equals(w.mFrame) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8281 | || w.mContentInsetsChanged |
| 8282 | || w.mVisibleInsetsChanged) { |
| 8283 | w.mLastFrame.set(w.mFrame); |
| 8284 | w.mLastContentInsets.set(w.mContentInsets); |
| 8285 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
| 8286 | // If the orientation is changing, then we need to |
| 8287 | // hold off on unfreezing the display until this |
| 8288 | // window has been redrawn; to do that, we need |
| 8289 | // to go through the process of getting informed |
| 8290 | // by the application when it has finished drawing. |
| 8291 | if (w.mOrientationChanging) { |
| 8292 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 8293 | "Orientation start waiting for draw in " |
| 8294 | + w + ", surface " + w.mSurface); |
| 8295 | w.mDrawPending = true; |
| 8296 | w.mCommitDrawPending = false; |
| 8297 | w.mReadyToShow = false; |
| 8298 | if (w.mAppToken != null) { |
| 8299 | w.mAppToken.allDrawn = false; |
| 8300 | } |
| 8301 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8302 | if (DEBUG_ORIENTATION) Log.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8303 | "Resizing window " + w + " to " + w.mFrame); |
| 8304 | mResizingWindows.add(w); |
| 8305 | } else if (w.mOrientationChanging) { |
| 8306 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
| 8307 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 8308 | "Orientation not waiting for draw in " |
| 8309 | + w + ", surface " + w.mSurface); |
| 8310 | w.mOrientationChanging = false; |
| 8311 | } |
| 8312 | } |
| 8313 | } |
| 8314 | |
| 8315 | if (w.mAttachedHidden) { |
| 8316 | if (!w.mLastHidden) { |
| 8317 | //dump(); |
| 8318 | w.mLastHidden = true; |
| 8319 | if (SHOW_TRANSACTIONS) Log.i( |
| 8320 | TAG, " SURFACE " + w.mSurface + ": HIDE (performLayout-attached)"); |
| 8321 | if (w.mSurface != null) { |
| 8322 | try { |
| 8323 | w.mSurface.hide(); |
| 8324 | } catch (RuntimeException e) { |
| 8325 | Log.w(TAG, "Exception hiding surface in " + w); |
| 8326 | } |
| 8327 | } |
| 8328 | mKeyWaiter.releasePendingPointerLocked(w.mSession); |
| 8329 | } |
| 8330 | // If we are waiting for this window to handle an |
| 8331 | // orientation change, well, it is hidden, so |
| 8332 | // doesn't really matter. Note that this does |
| 8333 | // introduce a potential glitch if the window |
| 8334 | // becomes unhidden before it has drawn for the |
| 8335 | // new orientation. |
| 8336 | if (w.mOrientationChanging) { |
| 8337 | w.mOrientationChanging = false; |
| 8338 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 8339 | "Orientation change skips hidden " + w); |
| 8340 | } |
| 8341 | } else if (!w.isReadyForDisplay()) { |
| 8342 | if (!w.mLastHidden) { |
| 8343 | //dump(); |
| 8344 | w.mLastHidden = true; |
| 8345 | if (SHOW_TRANSACTIONS) Log.i( |
| 8346 | TAG, " SURFACE " + w.mSurface + ": HIDE (performLayout-ready)"); |
| 8347 | if (w.mSurface != null) { |
| 8348 | try { |
| 8349 | w.mSurface.hide(); |
| 8350 | } catch (RuntimeException e) { |
| 8351 | Log.w(TAG, "Exception exception hiding surface in " + w); |
| 8352 | } |
| 8353 | } |
| 8354 | mKeyWaiter.releasePendingPointerLocked(w.mSession); |
| 8355 | } |
| 8356 | // If we are waiting for this window to handle an |
| 8357 | // orientation change, well, it is hidden, so |
| 8358 | // doesn't really matter. Note that this does |
| 8359 | // introduce a potential glitch if the window |
| 8360 | // becomes unhidden before it has drawn for the |
| 8361 | // new orientation. |
| 8362 | if (w.mOrientationChanging) { |
| 8363 | w.mOrientationChanging = false; |
| 8364 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 8365 | "Orientation change skips hidden " + w); |
| 8366 | } |
| 8367 | } else if (w.mLastLayer != w.mAnimLayer |
| 8368 | || w.mLastAlpha != w.mShownAlpha |
| 8369 | || w.mLastDsDx != w.mDsDx |
| 8370 | || w.mLastDtDx != w.mDtDx |
| 8371 | || w.mLastDsDy != w.mDsDy |
| 8372 | || w.mLastDtDy != w.mDtDy |
| 8373 | || w.mLastHScale != w.mHScale |
| 8374 | || w.mLastVScale != w.mVScale |
| 8375 | || w.mLastHidden) { |
| 8376 | displayed = true; |
| 8377 | w.mLastAlpha = w.mShownAlpha; |
| 8378 | w.mLastLayer = w.mAnimLayer; |
| 8379 | w.mLastDsDx = w.mDsDx; |
| 8380 | w.mLastDtDx = w.mDtDx; |
| 8381 | w.mLastDsDy = w.mDsDy; |
| 8382 | w.mLastDtDy = w.mDtDy; |
| 8383 | w.mLastHScale = w.mHScale; |
| 8384 | w.mLastVScale = w.mVScale; |
| 8385 | if (SHOW_TRANSACTIONS) Log.i( |
| 8386 | TAG, " SURFACE " + w.mSurface + ": alpha=" |
| 8387 | + w.mShownAlpha + " layer=" + w.mAnimLayer); |
| 8388 | if (w.mSurface != null) { |
| 8389 | try { |
| 8390 | w.mSurface.setAlpha(w.mShownAlpha); |
| 8391 | w.mSurface.setLayer(w.mAnimLayer); |
| 8392 | w.mSurface.setMatrix( |
| 8393 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 8394 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 8395 | } catch (RuntimeException e) { |
| 8396 | Log.w(TAG, "Error updating surface in " + w, e); |
| 8397 | if (!recoveringMemory) { |
| 8398 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 8399 | } |
| 8400 | } |
| 8401 | } |
| 8402 | |
| 8403 | if (w.mLastHidden && !w.mDrawPending |
| 8404 | && !w.mCommitDrawPending |
| 8405 | && !w.mReadyToShow) { |
| 8406 | if (SHOW_TRANSACTIONS) Log.i( |
| 8407 | TAG, " SURFACE " + w.mSurface + ": SHOW (performLayout)"); |
| 8408 | if (DEBUG_VISIBILITY) Log.v(TAG, "Showing " + w |
| 8409 | + " during relayout"); |
| 8410 | if (showSurfaceRobustlyLocked(w)) { |
| 8411 | w.mHasDrawn = true; |
| 8412 | w.mLastHidden = false; |
| 8413 | } else { |
| 8414 | w.mOrientationChanging = false; |
| 8415 | } |
| 8416 | } |
| 8417 | if (w.mSurface != null) { |
| 8418 | w.mToken.hasVisible = true; |
| 8419 | } |
| 8420 | } else { |
| 8421 | displayed = true; |
| 8422 | } |
| 8423 | |
| 8424 | if (displayed) { |
| 8425 | if (!covered) { |
| 8426 | if (attrs.width == LayoutParams.FILL_PARENT |
| 8427 | && attrs.height == LayoutParams.FILL_PARENT) { |
| 8428 | covered = true; |
| 8429 | } |
| 8430 | } |
| 8431 | if (w.mOrientationChanging) { |
| 8432 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 8433 | orientationChangeComplete = false; |
| 8434 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 8435 | "Orientation continue waiting for draw in " + w); |
| 8436 | } else { |
| 8437 | w.mOrientationChanging = false; |
| 8438 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 8439 | "Orientation change complete in " + w); |
| 8440 | } |
| 8441 | } |
| 8442 | w.mToken.hasVisible = true; |
| 8443 | } |
| 8444 | } else if (w.mOrientationChanging) { |
| 8445 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 8446 | "Orientation change skips hidden " + w); |
| 8447 | w.mOrientationChanging = false; |
| 8448 | } |
| 8449 | |
| 8450 | final boolean canBeSeen = w.isDisplayedLw(); |
| 8451 | |
| 8452 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 8453 | focusDisplayed = true; |
| 8454 | } |
| 8455 | |
| 8456 | // Update effect. |
| 8457 | if (!obscured) { |
| 8458 | if (w.mSurface != null) { |
| 8459 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 8460 | holdScreen = w.mSession; |
| 8461 | } |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 8462 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 8463 | && screenBrightness < 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8464 | screenBrightness = w.mAttrs.screenBrightness; |
| 8465 | } |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 8466 | if (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 8467 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 8468 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR) { |
| 8469 | syswin = true; |
| 8470 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8471 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8472 | |
| 8473 | boolean opaqueDrawn = w.isOpaqueDrawn(); |
| 8474 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8475 | // This window completely covers everything behind it, |
| 8476 | // so we want to leave all of them as unblurred (for |
| 8477 | // performance reasons). |
| 8478 | obscured = true; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8479 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
| 8480 | if (SHOW_TRANSACTIONS) Log.d(TAG, "showing background filler"); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8481 | // This window is in compatibility mode, and needs background filler. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8482 | obscured = true; |
| 8483 | if (mBackgroundFillerSurface == null) { |
| 8484 | try { |
| 8485 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
| 8486 | 0, dw, dh, |
| 8487 | PixelFormat.OPAQUE, |
| 8488 | Surface.FX_SURFACE_NORMAL); |
| 8489 | } catch (Exception e) { |
| 8490 | Log.e(TAG, "Exception creating filler surface", e); |
| 8491 | } |
| 8492 | } |
| 8493 | try { |
| 8494 | mBackgroundFillerSurface.setPosition(0, 0); |
| 8495 | mBackgroundFillerSurface.setSize(dw, dh); |
| 8496 | // Using the same layer as Dim because they will never be shown at the |
| 8497 | // same time. |
| 8498 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 8499 | mBackgroundFillerSurface.show(); |
| 8500 | } catch (RuntimeException e) { |
| 8501 | Log.e(TAG, "Exception showing filler surface"); |
| 8502 | } |
| 8503 | backgroundFillerShown = true; |
| 8504 | mBackgroundFillerShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8505 | } else if (canBeSeen && !obscured && |
| 8506 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
| 8507 | if (localLOGV) Log.v(TAG, "Win " + w |
| 8508 | + ": blurring=" + blurring |
| 8509 | + " obscured=" + obscured |
| 8510 | + " displayed=" + displayed); |
| 8511 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 8512 | if (!dimming) { |
| 8513 | //Log.i(TAG, "DIM BEHIND: " + w); |
| 8514 | dimming = true; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8515 | if (mDimAnimator == null) { |
| 8516 | mDimAnimator = new DimAnimator(mFxSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8517 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8518 | mDimAnimator.show(dw, dh); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8519 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8520 | mDimAnimator.updateParameters(w, currentTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8521 | } |
| 8522 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 8523 | if (!blurring) { |
| 8524 | //Log.i(TAG, "BLUR BEHIND: " + w); |
| 8525 | blurring = true; |
| 8526 | mBlurShown = true; |
| 8527 | if (mBlurSurface == null) { |
| 8528 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " |
| 8529 | + mBlurSurface + ": CREATE"); |
| 8530 | try { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8531 | mBlurSurface = new Surface(mFxSession, 0, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8532 | -1, 16, 16, |
| 8533 | PixelFormat.OPAQUE, |
| 8534 | Surface.FX_SURFACE_BLUR); |
| 8535 | } catch (Exception e) { |
| 8536 | Log.e(TAG, "Exception creating Blur surface", e); |
| 8537 | } |
| 8538 | } |
| 8539 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " |
| 8540 | + mBlurSurface + ": SHOW pos=(0,0) (" + |
| 8541 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
| 8542 | if (mBlurSurface != null) { |
| 8543 | mBlurSurface.setPosition(0, 0); |
| 8544 | mBlurSurface.setSize(dw, dh); |
| 8545 | try { |
| 8546 | mBlurSurface.show(); |
| 8547 | } catch (RuntimeException e) { |
| 8548 | Log.w(TAG, "Failure showing blur surface", e); |
| 8549 | } |
| 8550 | } |
| 8551 | } |
| 8552 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 8553 | } |
| 8554 | } |
| 8555 | } |
| 8556 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8557 | |
| 8558 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 8559 | mBackgroundFillerShown = false; |
| 8560 | if (SHOW_TRANSACTIONS) Log.d(TAG, "hiding background filler"); |
| 8561 | try { |
| 8562 | mBackgroundFillerSurface.hide(); |
| 8563 | } catch (RuntimeException e) { |
| 8564 | Log.e(TAG, "Exception hiding filler surface", e); |
| 8565 | } |
| 8566 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8567 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8568 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
| 8569 | animating |= mDimAnimator.updateSurface(dimming, currentTime, mDisplayFrozen); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8570 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8571 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8572 | if (!blurring && mBlurShown) { |
| 8573 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " + mBlurSurface |
| 8574 | + ": HIDE"); |
| 8575 | try { |
| 8576 | mBlurSurface.hide(); |
| 8577 | } catch (IllegalArgumentException e) { |
| 8578 | Log.w(TAG, "Illegal argument exception hiding blur surface"); |
| 8579 | } |
| 8580 | mBlurShown = false; |
| 8581 | } |
| 8582 | |
| 8583 | if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION"); |
| 8584 | } catch (RuntimeException e) { |
| 8585 | Log.e(TAG, "Unhandled exception in Window Manager", e); |
| 8586 | } |
| 8587 | |
| 8588 | Surface.closeTransaction(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8589 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8590 | if (DEBUG_ORIENTATION && mDisplayFrozen) Log.v(TAG, |
| 8591 | "With display frozen, orientationChangeComplete=" |
| 8592 | + orientationChangeComplete); |
| 8593 | if (orientationChangeComplete) { |
| 8594 | if (mWindowsFreezingScreen) { |
| 8595 | mWindowsFreezingScreen = false; |
| 8596 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 8597 | } |
| 8598 | if (mAppsFreezingScreen == 0) { |
| 8599 | stopFreezingDisplayLocked(); |
| 8600 | } |
| 8601 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8602 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8603 | i = mResizingWindows.size(); |
| 8604 | if (i > 0) { |
| 8605 | do { |
| 8606 | i--; |
| 8607 | WindowState win = mResizingWindows.get(i); |
| 8608 | try { |
| 8609 | win.mClient.resized(win.mFrame.width(), |
| 8610 | win.mFrame.height(), win.mLastContentInsets, |
| 8611 | win.mLastVisibleInsets, win.mDrawPending); |
| 8612 | win.mContentInsetsChanged = false; |
| 8613 | win.mVisibleInsetsChanged = false; |
| 8614 | } catch (RemoteException e) { |
| 8615 | win.mOrientationChanging = false; |
| 8616 | } |
| 8617 | } while (i > 0); |
| 8618 | mResizingWindows.clear(); |
| 8619 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8620 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8621 | // Destroy the surface of any windows that are no longer visible. |
| 8622 | i = mDestroySurface.size(); |
| 8623 | if (i > 0) { |
| 8624 | do { |
| 8625 | i--; |
| 8626 | WindowState win = mDestroySurface.get(i); |
| 8627 | win.mDestroying = false; |
| 8628 | if (mInputMethodWindow == win) { |
| 8629 | mInputMethodWindow = null; |
| 8630 | } |
| 8631 | win.destroySurfaceLocked(); |
| 8632 | } while (i > 0); |
| 8633 | mDestroySurface.clear(); |
| 8634 | } |
| 8635 | |
| 8636 | // Time to remove any exiting tokens? |
| 8637 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 8638 | WindowToken token = mExitingTokens.get(i); |
| 8639 | if (!token.hasVisible) { |
| 8640 | mExitingTokens.remove(i); |
| 8641 | } |
| 8642 | } |
| 8643 | |
| 8644 | // Time to remove any exiting applications? |
| 8645 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 8646 | AppWindowToken token = mExitingAppTokens.get(i); |
| 8647 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
| 8648 | mAppTokens.remove(token); |
| 8649 | mExitingAppTokens.remove(i); |
| 8650 | } |
| 8651 | } |
| 8652 | |
| 8653 | if (focusDisplayed) { |
| 8654 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 8655 | } |
| 8656 | if (animating) { |
| 8657 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 8658 | } |
| 8659 | mQueue.setHoldScreenLocked(holdScreen != null); |
| 8660 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 8661 | mPowerManager.setScreenBrightnessOverride(-1); |
| 8662 | } else { |
| 8663 | mPowerManager.setScreenBrightnessOverride((int) |
| 8664 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 8665 | } |
| 8666 | if (holdScreen != mHoldingScreenOn) { |
| 8667 | mHoldingScreenOn = holdScreen; |
| 8668 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 8669 | mH.sendMessage(m); |
| 8670 | } |
| 8671 | } |
| 8672 | |
| 8673 | void requestAnimationLocked(long delay) { |
| 8674 | if (!mAnimationPending) { |
| 8675 | mAnimationPending = true; |
| 8676 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 8677 | } |
| 8678 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8679 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8680 | /** |
| 8681 | * Have the surface flinger show a surface, robustly dealing with |
| 8682 | * error conditions. In particular, if there is not enough memory |
| 8683 | * to show the surface, then we will try to get rid of other surfaces |
| 8684 | * in order to succeed. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8685 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8686 | * @return Returns true if the surface was successfully shown. |
| 8687 | */ |
| 8688 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 8689 | try { |
| 8690 | if (win.mSurface != null) { |
| 8691 | win.mSurface.show(); |
| 8692 | } |
| 8693 | return true; |
| 8694 | } catch (RuntimeException e) { |
| 8695 | Log.w(TAG, "Failure showing surface " + win.mSurface + " in " + win); |
| 8696 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8697 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8698 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8699 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8700 | return false; |
| 8701 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8702 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8703 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 8704 | final Surface surface = win.mSurface; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8705 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8706 | EventLog.writeEvent(LOG_WM_NO_SURFACE_MEMORY, win.toString(), |
| 8707 | win.mSession.mPid, operation); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8708 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8709 | if (mForceRemoves == null) { |
| 8710 | mForceRemoves = new ArrayList<WindowState>(); |
| 8711 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8712 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8713 | long callingIdentity = Binder.clearCallingIdentity(); |
| 8714 | try { |
| 8715 | // There was some problem... first, do a sanity check of the |
| 8716 | // window list to make sure we haven't left any dangling surfaces |
| 8717 | // around. |
| 8718 | int N = mWindows.size(); |
| 8719 | boolean leakedSurface = false; |
| 8720 | Log.i(TAG, "Out of memory for surface! Looking for leaks..."); |
| 8721 | for (int i=0; i<N; i++) { |
| 8722 | WindowState ws = (WindowState)mWindows.get(i); |
| 8723 | if (ws.mSurface != null) { |
| 8724 | if (!mSessions.contains(ws.mSession)) { |
| 8725 | Log.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
| 8726 | + ws + " surface=" + ws.mSurface |
| 8727 | + " token=" + win.mToken |
| 8728 | + " pid=" + ws.mSession.mPid |
| 8729 | + " uid=" + ws.mSession.mUid); |
| 8730 | ws.mSurface.clear(); |
| 8731 | ws.mSurface = null; |
| 8732 | mForceRemoves.add(ws); |
| 8733 | i--; |
| 8734 | N--; |
| 8735 | leakedSurface = true; |
| 8736 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
| 8737 | Log.w(TAG, "LEAKED SURFACE (app token hidden): " |
| 8738 | + ws + " surface=" + ws.mSurface |
| 8739 | + " token=" + win.mAppToken); |
| 8740 | ws.mSurface.clear(); |
| 8741 | ws.mSurface = null; |
| 8742 | leakedSurface = true; |
| 8743 | } |
| 8744 | } |
| 8745 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8746 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8747 | boolean killedApps = false; |
| 8748 | if (!leakedSurface) { |
| 8749 | Log.w(TAG, "No leaked surfaces; killing applicatons!"); |
| 8750 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 8751 | for (int i=0; i<N; i++) { |
| 8752 | WindowState ws = (WindowState)mWindows.get(i); |
| 8753 | if (ws.mSurface != null) { |
| 8754 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 8755 | } |
| 8756 | } |
| 8757 | if (pidCandidates.size() > 0) { |
| 8758 | int[] pids = new int[pidCandidates.size()]; |
| 8759 | for (int i=0; i<pids.length; i++) { |
| 8760 | pids[i] = pidCandidates.keyAt(i); |
| 8761 | } |
| 8762 | try { |
| 8763 | if (mActivityManager.killPidsForMemory(pids)) { |
| 8764 | killedApps = true; |
| 8765 | } |
| 8766 | } catch (RemoteException e) { |
| 8767 | } |
| 8768 | } |
| 8769 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8770 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8771 | if (leakedSurface || killedApps) { |
| 8772 | // We managed to reclaim some memory, so get rid of the trouble |
| 8773 | // surface and ask the app to request another one. |
| 8774 | Log.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry."); |
| 8775 | if (surface != null) { |
| 8776 | surface.clear(); |
| 8777 | win.mSurface = null; |
| 8778 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8779 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8780 | try { |
| 8781 | win.mClient.dispatchGetNewSurface(); |
| 8782 | } catch (RemoteException e) { |
| 8783 | } |
| 8784 | } |
| 8785 | } finally { |
| 8786 | Binder.restoreCallingIdentity(callingIdentity); |
| 8787 | } |
| 8788 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8789 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8790 | private boolean updateFocusedWindowLocked(int mode) { |
| 8791 | WindowState newFocus = computeFocusedWindowLocked(); |
| 8792 | if (mCurrentFocus != newFocus) { |
| 8793 | // This check makes sure that we don't already have the focus |
| 8794 | // change message pending. |
| 8795 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 8796 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
| 8797 | if (localLOGV) Log.v( |
| 8798 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 8799 | final WindowState oldFocus = mCurrentFocus; |
| 8800 | mCurrentFocus = newFocus; |
| 8801 | mLosingFocus.remove(newFocus); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8802 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8803 | final WindowState imWindow = mInputMethodWindow; |
| 8804 | if (newFocus != imWindow && oldFocus != imWindow) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 8805 | if (moveInputMethodWindowsIfNeededLocked( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8806 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 8807 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 8808 | mLayoutNeeded = true; |
| 8809 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8810 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 8811 | performLayoutLockedInner(); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 8812 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 8813 | // Client will do the layout, but we need to assign layers |
| 8814 | // for handleNewWindowLocked() below. |
| 8815 | assignLayersLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8816 | } |
| 8817 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8818 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 8819 | if (newFocus != null && mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 8820 | mKeyWaiter.handleNewWindowLocked(newFocus); |
| 8821 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8822 | return true; |
| 8823 | } |
| 8824 | return false; |
| 8825 | } |
| 8826 | |
| 8827 | private WindowState computeFocusedWindowLocked() { |
| 8828 | WindowState result = null; |
| 8829 | WindowState win; |
| 8830 | |
| 8831 | int i = mWindows.size() - 1; |
| 8832 | int nextAppIndex = mAppTokens.size()-1; |
| 8833 | WindowToken nextApp = nextAppIndex >= 0 |
| 8834 | ? mAppTokens.get(nextAppIndex) : null; |
| 8835 | |
| 8836 | while (i >= 0) { |
| 8837 | win = (WindowState)mWindows.get(i); |
| 8838 | |
| 8839 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 8840 | TAG, "Looking for focus: " + i |
| 8841 | + " = " + win |
| 8842 | + ", flags=" + win.mAttrs.flags |
| 8843 | + ", canReceive=" + win.canReceiveKeys()); |
| 8844 | |
| 8845 | AppWindowToken thisApp = win.mAppToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8846 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8847 | // If this window's application has been removed, just skip it. |
| 8848 | if (thisApp != null && thisApp.removed) { |
| 8849 | i--; |
| 8850 | continue; |
| 8851 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8852 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8853 | // If there is a focused app, don't allow focus to go to any |
| 8854 | // windows below it. If this is an application window, step |
| 8855 | // through the app tokens until we find its app. |
| 8856 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 8857 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 8858 | int origAppIndex = nextAppIndex; |
| 8859 | while (nextAppIndex > 0) { |
| 8860 | if (nextApp == mFocusedApp) { |
| 8861 | // Whoops, we are below the focused app... no focus |
| 8862 | // for you! |
| 8863 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 8864 | TAG, "Reached focused app: " + mFocusedApp); |
| 8865 | return null; |
| 8866 | } |
| 8867 | nextAppIndex--; |
| 8868 | nextApp = mAppTokens.get(nextAppIndex); |
| 8869 | if (nextApp == thisApp) { |
| 8870 | break; |
| 8871 | } |
| 8872 | } |
| 8873 | if (thisApp != nextApp) { |
| 8874 | // Uh oh, the app token doesn't exist! This shouldn't |
| 8875 | // happen, but if it does we can get totally hosed... |
| 8876 | // so restart at the original app. |
| 8877 | nextAppIndex = origAppIndex; |
| 8878 | nextApp = mAppTokens.get(nextAppIndex); |
| 8879 | } |
| 8880 | } |
| 8881 | |
| 8882 | // Dispatch to this window if it is wants key events. |
| 8883 | if (win.canReceiveKeys()) { |
| 8884 | if (DEBUG_FOCUS) Log.v( |
| 8885 | TAG, "Found focus @ " + i + " = " + win); |
| 8886 | result = win; |
| 8887 | break; |
| 8888 | } |
| 8889 | |
| 8890 | i--; |
| 8891 | } |
| 8892 | |
| 8893 | return result; |
| 8894 | } |
| 8895 | |
| 8896 | private void startFreezingDisplayLocked() { |
| 8897 | if (mDisplayFrozen) { |
Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 8898 | // Freezing the display also suspends key event delivery, to |
| 8899 | // keep events from going astray while the display is reconfigured. |
| 8900 | // If someone has changed orientation again while the screen is |
| 8901 | // still frozen, the events will continue to be blocked while the |
| 8902 | // successive orientation change is processed. To prevent spurious |
| 8903 | // ANRs, we reset the event dispatch timeout in this case. |
| 8904 | synchronized (mKeyWaiter) { |
| 8905 | mKeyWaiter.mWasFrozen = true; |
| 8906 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8907 | return; |
| 8908 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8909 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8910 | mScreenFrozenLock.acquire(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8911 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8912 | long now = SystemClock.uptimeMillis(); |
| 8913 | //Log.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
| 8914 | if (mFreezeGcPending != 0) { |
| 8915 | if (now > (mFreezeGcPending+1000)) { |
| 8916 | //Log.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| 8917 | mH.removeMessages(H.FORCE_GC); |
| 8918 | Runtime.getRuntime().gc(); |
| 8919 | mFreezeGcPending = now; |
| 8920 | } |
| 8921 | } else { |
| 8922 | mFreezeGcPending = now; |
| 8923 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8924 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8925 | mDisplayFrozen = true; |
| 8926 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) { |
| 8927 | mNextAppTransition = WindowManagerPolicy.TRANSIT_NONE; |
| 8928 | mAppTransitionReady = true; |
| 8929 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8930 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8931 | if (PROFILE_ORIENTATION) { |
| 8932 | File file = new File("/data/system/frozen"); |
| 8933 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 8934 | } |
| 8935 | Surface.freezeDisplay(0); |
| 8936 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8937 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8938 | private void stopFreezingDisplayLocked() { |
| 8939 | if (!mDisplayFrozen) { |
| 8940 | return; |
| 8941 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8942 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8943 | mDisplayFrozen = false; |
| 8944 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 8945 | if (PROFILE_ORIENTATION) { |
| 8946 | Debug.stopMethodTracing(); |
| 8947 | } |
| 8948 | Surface.unfreezeDisplay(0); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8949 | |
Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 8950 | // Reset the key delivery timeout on unfreeze, too. We force a wakeup here |
| 8951 | // too because regular key delivery processing should resume immediately. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8952 | synchronized (mKeyWaiter) { |
| 8953 | mKeyWaiter.mWasFrozen = true; |
| 8954 | mKeyWaiter.notifyAll(); |
| 8955 | } |
| 8956 | |
| 8957 | // A little kludge: a lot could have happened while the |
| 8958 | // display was frozen, so now that we are coming back we |
| 8959 | // do a gc so that any remote references the system |
| 8960 | // processes holds on others can be released if they are |
| 8961 | // no longer needed. |
| 8962 | mH.removeMessages(H.FORCE_GC); |
| 8963 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 8964 | 2000); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8965 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8966 | mScreenFrozenLock.release(); |
| 8967 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8968 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8969 | @Override |
| 8970 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 8971 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 8972 | != PackageManager.PERMISSION_GRANTED) { |
| 8973 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 8974 | + Binder.getCallingPid() |
| 8975 | + ", uid=" + Binder.getCallingUid()); |
| 8976 | return; |
| 8977 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8978 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8979 | synchronized(mWindowMap) { |
| 8980 | pw.println("Current Window Manager state:"); |
| 8981 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 8982 | WindowState w = (WindowState)mWindows.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8983 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 8984 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8985 | w.dump(pw, " "); |
| 8986 | } |
| 8987 | if (mInputMethodDialogs.size() > 0) { |
| 8988 | pw.println(" "); |
| 8989 | pw.println(" Input method dialogs:"); |
| 8990 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 8991 | WindowState w = mInputMethodDialogs.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8992 | pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8993 | } |
| 8994 | } |
| 8995 | if (mPendingRemove.size() > 0) { |
| 8996 | pw.println(" "); |
| 8997 | pw.println(" Remove pending for:"); |
| 8998 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 8999 | WindowState w = mPendingRemove.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9000 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 9001 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9002 | w.dump(pw, " "); |
| 9003 | } |
| 9004 | } |
| 9005 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 9006 | pw.println(" "); |
| 9007 | pw.println(" Windows force removing:"); |
| 9008 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 9009 | WindowState w = mForceRemoves.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9010 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 9011 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9012 | w.dump(pw, " "); |
| 9013 | } |
| 9014 | } |
| 9015 | if (mDestroySurface.size() > 0) { |
| 9016 | pw.println(" "); |
| 9017 | pw.println(" Windows waiting to destroy their surface:"); |
| 9018 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 9019 | WindowState w = mDestroySurface.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9020 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 9021 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9022 | w.dump(pw, " "); |
| 9023 | } |
| 9024 | } |
| 9025 | if (mLosingFocus.size() > 0) { |
| 9026 | pw.println(" "); |
| 9027 | pw.println(" Windows losing focus:"); |
| 9028 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 9029 | WindowState w = mLosingFocus.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9030 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 9031 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9032 | w.dump(pw, " "); |
| 9033 | } |
| 9034 | } |
| 9035 | if (mSessions.size() > 0) { |
| 9036 | pw.println(" "); |
| 9037 | pw.println(" All active sessions:"); |
| 9038 | Iterator<Session> it = mSessions.iterator(); |
| 9039 | while (it.hasNext()) { |
| 9040 | Session s = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9041 | pw.print(" Session "); pw.print(s); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9042 | s.dump(pw, " "); |
| 9043 | } |
| 9044 | } |
| 9045 | if (mTokenMap.size() > 0) { |
| 9046 | pw.println(" "); |
| 9047 | pw.println(" All tokens:"); |
| 9048 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 9049 | while (it.hasNext()) { |
| 9050 | WindowToken token = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9051 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9052 | token.dump(pw, " "); |
| 9053 | } |
| 9054 | } |
| 9055 | if (mTokenList.size() > 0) { |
| 9056 | pw.println(" "); |
| 9057 | pw.println(" Window token list:"); |
| 9058 | for (int i=0; i<mTokenList.size(); i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9059 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 9060 | pw.println(mTokenList.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9061 | } |
| 9062 | } |
| 9063 | if (mAppTokens.size() > 0) { |
| 9064 | pw.println(" "); |
| 9065 | pw.println(" Application tokens in Z order:"); |
| 9066 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9067 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 9068 | pw.println(mAppTokens.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9069 | } |
| 9070 | } |
| 9071 | if (mFinishedStarting.size() > 0) { |
| 9072 | pw.println(" "); |
| 9073 | pw.println(" Finishing start of application tokens:"); |
| 9074 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 9075 | WindowToken token = mFinishedStarting.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9076 | pw.print(" Finished Starting #"); pw.print(i); |
| 9077 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9078 | token.dump(pw, " "); |
| 9079 | } |
| 9080 | } |
| 9081 | if (mExitingTokens.size() > 0) { |
| 9082 | pw.println(" "); |
| 9083 | pw.println(" Exiting tokens:"); |
| 9084 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 9085 | WindowToken token = mExitingTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9086 | pw.print(" Exiting #"); pw.print(i); |
| 9087 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9088 | token.dump(pw, " "); |
| 9089 | } |
| 9090 | } |
| 9091 | if (mExitingAppTokens.size() > 0) { |
| 9092 | pw.println(" "); |
| 9093 | pw.println(" Exiting application tokens:"); |
| 9094 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9095 | WindowToken token = mExitingAppTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9096 | pw.print(" Exiting App #"); pw.print(i); |
| 9097 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9098 | token.dump(pw, " "); |
| 9099 | } |
| 9100 | } |
| 9101 | pw.println(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9102 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 9103 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 9104 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 9105 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 9106 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
| 9107 | pw.print(" mInTouchMode="); pw.println(mInTouchMode); |
| 9108 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 9109 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 9110 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 9111 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9112 | if (mDimAnimator != null) { |
| 9113 | mDimAnimator.printTo(pw); |
| 9114 | } else { |
| 9115 | pw.print( " no DimAnimator "); |
| 9116 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9117 | pw.print(" mInputMethodAnimLayerAdjustment="); |
| 9118 | pw.println(mInputMethodAnimLayerAdjustment); |
| 9119 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 9120 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
| 9121 | pw.print(" mAppsFreezingScreen="); pw.println(mAppsFreezingScreen); |
| 9122 | pw.print(" mRotation="); pw.print(mRotation); |
| 9123 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 9124 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 9125 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 9126 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 9127 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 9128 | pw.print(" mNextAppTransition=0x"); |
| 9129 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 9130 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
| 9131 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
| 9132 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 9133 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| 9134 | if (mOpeningApps.size() > 0) { |
| 9135 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 9136 | } |
| 9137 | if (mClosingApps.size() > 0) { |
| 9138 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 9139 | } |
| 9140 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 9141 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9142 | pw.println(" KeyWaiter state:"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9143 | pw.print(" mLastWin="); pw.print(mKeyWaiter.mLastWin); |
| 9144 | pw.print(" mLastBinder="); pw.println(mKeyWaiter.mLastBinder); |
| 9145 | pw.print(" mFinished="); pw.print(mKeyWaiter.mFinished); |
| 9146 | pw.print(" mGotFirstWindow="); pw.print(mKeyWaiter.mGotFirstWindow); |
| 9147 | pw.print(" mEventDispatching="); pw.print(mKeyWaiter.mEventDispatching); |
| 9148 | pw.print(" mTimeToSwitch="); pw.println(mKeyWaiter.mTimeToSwitch); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9149 | } |
| 9150 | } |
| 9151 | |
| 9152 | public void monitor() { |
| 9153 | synchronized (mWindowMap) { } |
| 9154 | synchronized (mKeyguardDisabled) { } |
| 9155 | synchronized (mKeyWaiter) { } |
| 9156 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9157 | |
| 9158 | /** |
| 9159 | * DimAnimator class that controls the dim animation. This holds the surface and |
| 9160 | * all state used for dim animation. |
| 9161 | */ |
| 9162 | private static class DimAnimator { |
| 9163 | Surface mDimSurface; |
| 9164 | boolean mDimShown = false; |
| 9165 | float mDimCurrentAlpha; |
| 9166 | float mDimTargetAlpha; |
| 9167 | float mDimDeltaPerMs; |
| 9168 | long mLastDimAnimTime; |
| 9169 | |
| 9170 | DimAnimator (SurfaceSession session) { |
| 9171 | if (mDimSurface == null) { |
| 9172 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 9173 | + mDimSurface + ": CREATE"); |
| 9174 | try { |
| 9175 | mDimSurface = new Surface(session, 0, -1, 16, 16, PixelFormat.OPAQUE, |
| 9176 | Surface.FX_SURFACE_DIM); |
| 9177 | } catch (Exception e) { |
| 9178 | Log.e(TAG, "Exception creating Dim surface", e); |
| 9179 | } |
| 9180 | } |
| 9181 | } |
| 9182 | |
| 9183 | /** |
| 9184 | * Show the dim surface. |
| 9185 | */ |
| 9186 | void show(int dw, int dh) { |
| 9187 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 9188 | dw + "x" + dh + ")"); |
| 9189 | mDimShown = true; |
| 9190 | try { |
| 9191 | mDimSurface.setPosition(0, 0); |
| 9192 | mDimSurface.setSize(dw, dh); |
| 9193 | mDimSurface.show(); |
| 9194 | } catch (RuntimeException e) { |
| 9195 | Log.w(TAG, "Failure showing dim surface", e); |
| 9196 | } |
| 9197 | } |
| 9198 | |
| 9199 | /** |
| 9200 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 9201 | * {@link updateSurface} after all windows are examined. |
| 9202 | */ |
| 9203 | void updateParameters(WindowState w, long currentTime) { |
| 9204 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 9205 | |
| 9206 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
| 9207 | if (SHOW_TRANSACTIONS) Log.i(TAG, "layer=" + (w.mAnimLayer-1) + ", target=" + target); |
| 9208 | if (mDimTargetAlpha != target) { |
| 9209 | // If the desired dim level has changed, then |
| 9210 | // start an animation to it. |
| 9211 | mLastDimAnimTime = currentTime; |
| 9212 | long duration = (w.mAnimating && w.mAnimation != null) |
| 9213 | ? w.mAnimation.computeDurationHint() |
| 9214 | : DEFAULT_DIM_DURATION; |
| 9215 | if (target > mDimTargetAlpha) { |
| 9216 | // This is happening behind the activity UI, |
| 9217 | // so we can make it run a little longer to |
| 9218 | // give a stronger impression without disrupting |
| 9219 | // the user. |
| 9220 | duration *= DIM_DURATION_MULTIPLIER; |
| 9221 | } |
| 9222 | if (duration < 1) { |
| 9223 | // Don't divide by zero |
| 9224 | duration = 1; |
| 9225 | } |
| 9226 | mDimTargetAlpha = target; |
| 9227 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 9228 | } |
| 9229 | } |
| 9230 | |
| 9231 | /** |
| 9232 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 9233 | * false when the animation is finished and the dim surface is hidden. |
| 9234 | */ |
| 9235 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 9236 | if (!dimming) { |
| 9237 | if (mDimTargetAlpha != 0) { |
| 9238 | mLastDimAnimTime = currentTime; |
| 9239 | mDimTargetAlpha = 0; |
| 9240 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 9241 | } |
| 9242 | } |
| 9243 | |
| 9244 | boolean animating = false; |
| 9245 | if (mLastDimAnimTime != 0) { |
| 9246 | mDimCurrentAlpha += mDimDeltaPerMs |
| 9247 | * (currentTime-mLastDimAnimTime); |
| 9248 | boolean more = true; |
| 9249 | if (displayFrozen) { |
| 9250 | // If the display is frozen, there is no reason to animate. |
| 9251 | more = false; |
| 9252 | } else if (mDimDeltaPerMs > 0) { |
| 9253 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 9254 | more = false; |
| 9255 | } |
| 9256 | } else if (mDimDeltaPerMs < 0) { |
| 9257 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 9258 | more = false; |
| 9259 | } |
| 9260 | } else { |
| 9261 | more = false; |
| 9262 | } |
| 9263 | |
| 9264 | // Do we need to continue animating? |
| 9265 | if (more) { |
| 9266 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 9267 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 9268 | mLastDimAnimTime = currentTime; |
| 9269 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 9270 | animating = true; |
| 9271 | } else { |
| 9272 | mDimCurrentAlpha = mDimTargetAlpha; |
| 9273 | mLastDimAnimTime = 0; |
| 9274 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 9275 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 9276 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 9277 | if (!dimming) { |
| 9278 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface |
| 9279 | + ": HIDE"); |
| 9280 | try { |
| 9281 | mDimSurface.hide(); |
| 9282 | } catch (RuntimeException e) { |
| 9283 | Log.w(TAG, "Illegal argument exception hiding dim surface"); |
| 9284 | } |
| 9285 | mDimShown = false; |
| 9286 | } |
| 9287 | } |
| 9288 | } |
| 9289 | return animating; |
| 9290 | } |
| 9291 | |
| 9292 | public void printTo(PrintWriter pw) { |
| 9293 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 9294 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 9295 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 9296 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 9297 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 9298 | } |
| 9299 | } |
| 9300 | |
| 9301 | /** |
| 9302 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 9303 | * This is used for opening/closing transition for apps in compatible mode. |
| 9304 | */ |
| 9305 | private static class FadeInOutAnimation extends Animation { |
| 9306 | int mWidth; |
| 9307 | boolean mFadeIn; |
| 9308 | |
| 9309 | public FadeInOutAnimation(boolean fadeIn) { |
| 9310 | setInterpolator(new AccelerateInterpolator()); |
| 9311 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 9312 | mFadeIn = fadeIn; |
| 9313 | } |
| 9314 | |
| 9315 | @Override |
| 9316 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 9317 | float x = interpolatedTime; |
| 9318 | if (!mFadeIn) { |
| 9319 | x = 1.0f - x; // reverse the interpolation for fade out |
| 9320 | } |
| 9321 | if (x < 0.5) { |
| 9322 | // move the window out of the screen. |
| 9323 | t.getMatrix().setTranslate(mWidth, 0); |
| 9324 | } else { |
| 9325 | t.getMatrix().setTranslate(0, 0);// show |
| 9326 | t.setAlpha((x - 0.5f) * 2); |
| 9327 | } |
| 9328 | } |
| 9329 | |
| 9330 | @Override |
| 9331 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 9332 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 9333 | mWidth = width; |
| 9334 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9335 | |
| 9336 | @Override |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 9337 | public int getZAdjustment() { |
| 9338 | return Animation.ZORDER_TOP; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9339 | } |
| 9340 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9341 | } |