| 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; |
| 27 | import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND; |
| 28 | import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; |
| 29 | import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR; |
| 30 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 31 | import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
| 32 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 33 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
| 34 | import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_GPU; |
| 35 | import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_HARDWARE; |
| 36 | import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS; |
| 37 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 38 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 39 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 40 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
| 41 | |
| 42 | import com.android.internal.app.IBatteryStats; |
| 43 | import com.android.internal.policy.PolicyManager; |
| 44 | import com.android.internal.view.IInputContext; |
| 45 | import com.android.internal.view.IInputMethodClient; |
| 46 | import com.android.internal.view.IInputMethodManager; |
| 47 | import com.android.server.KeyInputQueue.QueuedEvent; |
| 48 | import com.android.server.am.BatteryStatsService; |
| 49 | |
| 50 | import android.Manifest; |
| 51 | import android.app.ActivityManagerNative; |
| 52 | import android.app.IActivityManager; |
| 53 | import android.content.Context; |
| 54 | import android.content.pm.ActivityInfo; |
| 55 | import android.content.pm.PackageManager; |
| 56 | import android.content.res.Configuration; |
| 57 | import android.graphics.Matrix; |
| 58 | import android.graphics.PixelFormat; |
| 59 | import android.graphics.Rect; |
| 60 | import android.graphics.Region; |
| 61 | import android.os.BatteryStats; |
| 62 | import android.os.Binder; |
| 63 | import android.os.Debug; |
| 64 | import android.os.Handler; |
| 65 | import android.os.IBinder; |
| 66 | import android.os.LocalPowerManager; |
| 67 | import android.os.Looper; |
| 68 | import android.os.Message; |
| 69 | import android.os.Parcel; |
| 70 | import android.os.ParcelFileDescriptor; |
| 71 | import android.os.Power; |
| 72 | import android.os.PowerManager; |
| 73 | import android.os.Process; |
| 74 | import android.os.RemoteException; |
| 75 | import android.os.ServiceManager; |
| 76 | import android.os.SystemClock; |
| 77 | import android.os.SystemProperties; |
| 78 | import android.os.TokenWatcher; |
| 79 | import android.provider.Settings; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 80 | import android.util.DisplayMetrics; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | import android.util.EventLog; |
| 82 | import android.util.Log; |
| 83 | import android.util.SparseIntArray; |
| 84 | import android.view.Display; |
| 85 | import android.view.Gravity; |
| 86 | import android.view.IApplicationToken; |
| 87 | import android.view.IOnKeyguardExitResult; |
| 88 | import android.view.IRotationWatcher; |
| 89 | import android.view.IWindow; |
| 90 | import android.view.IWindowManager; |
| 91 | import android.view.IWindowSession; |
| 92 | import android.view.KeyEvent; |
| 93 | import android.view.MotionEvent; |
| 94 | import android.view.RawInputEvent; |
| 95 | import android.view.Surface; |
| 96 | import android.view.SurfaceSession; |
| 97 | import android.view.View; |
| 98 | import android.view.ViewTreeObserver; |
| 99 | import android.view.WindowManager; |
| 100 | import android.view.WindowManagerImpl; |
| 101 | import android.view.WindowManagerPolicy; |
| 102 | import android.view.WindowManager.LayoutParams; |
| 103 | import android.view.animation.Animation; |
| 104 | import android.view.animation.AnimationUtils; |
| 105 | import android.view.animation.Transformation; |
| 106 | |
| 107 | import java.io.BufferedWriter; |
| 108 | import java.io.File; |
| 109 | import java.io.FileDescriptor; |
| 110 | import java.io.IOException; |
| 111 | import java.io.OutputStream; |
| 112 | import java.io.OutputStreamWriter; |
| 113 | import java.io.PrintWriter; |
| 114 | import java.io.StringWriter; |
| 115 | import java.net.Socket; |
| 116 | import java.util.ArrayList; |
| 117 | import java.util.HashMap; |
| 118 | import java.util.HashSet; |
| 119 | import java.util.Iterator; |
| 120 | import java.util.List; |
| 121 | |
| 122 | /** {@hide} */ |
| 123 | public class WindowManagerService extends IWindowManager.Stub implements Watchdog.Monitor { |
| 124 | static final String TAG = "WindowManager"; |
| 125 | static final boolean DEBUG = false; |
| 126 | static final boolean DEBUG_FOCUS = false; |
| 127 | static final boolean DEBUG_ANIM = false; |
| 128 | static final boolean DEBUG_LAYERS = false; |
| 129 | static final boolean DEBUG_INPUT = false; |
| 130 | static final boolean DEBUG_INPUT_METHOD = false; |
| 131 | static final boolean DEBUG_VISIBILITY = false; |
| 132 | static final boolean DEBUG_ORIENTATION = false; |
| 133 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 134 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 135 | static final boolean DEBUG_REORDER = false; |
| 136 | static final boolean SHOW_TRANSACTIONS = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 137 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | static final boolean PROFILE_ORIENTATION = false; |
| 139 | static final boolean BLUR = true; |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 140 | static final boolean localLOGV = DEBUG; |
| 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 int LOG_WM_NO_SURFACE_MEMORY = 31000; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 143 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | /** How long to wait for first key repeat, in milliseconds */ |
| 145 | static final int KEY_REPEAT_FIRST_DELAY = 750; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 146 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | /** How long to wait for subsequent key repeats, in milliseconds */ |
| 148 | static final int KEY_REPEAT_DELAY = 50; |
| 149 | |
| 150 | /** How much to multiply the policy's type layer, to reserve room |
| 151 | * for multiple windows of the same type and Z-ordering adjustment |
| 152 | * with TYPE_LAYER_OFFSET. */ |
| 153 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 154 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 156 | * or below others in the same layer. */ |
| 157 | static final int TYPE_LAYER_OFFSET = 1000; |
| 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 | /** How much to increment the layer for each window, to reserve room |
| 160 | * for effect surfaces between them. |
| 161 | */ |
| 162 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 163 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | /** The maximum length we will accept for a loaded animation duration: |
| 165 | * this is 10 seconds. |
| 166 | */ |
| 167 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 168 | |
| 169 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 170 | * value to another, when no window animation is driving it. |
| 171 | */ |
| 172 | static final int DEFAULT_DIM_DURATION = 200; |
| 173 | |
| 174 | /** Adjustment to time to perform a dim, to make it more dramatic. |
| 175 | */ |
| 176 | static final int DIM_DURATION_MULTIPLIER = 6; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 177 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 178 | static final int INJECT_FAILED = 0; |
| 179 | static final int INJECT_SUCCEEDED = 1; |
| 180 | static final int INJECT_NO_PERMISSION = -1; |
| 181 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 183 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 184 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 185 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 186 | |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 187 | /** The minimum time between dispatching touch events. */ |
| 188 | int mMinWaitTimeBetweenTouchEvents = 1000 / 35; |
| 189 | |
| 190 | // Last touch event time |
| 191 | long mLastTouchEventTime = 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 192 | |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 193 | // Last touch event type |
| 194 | int mLastTouchEventType = OTHER_EVENT; |
| 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 | // Time to wait before calling useractivity again. This saves CPU usage |
| 197 | // when we get a flood of touch events. |
| 198 | static final int MIN_TIME_BETWEEN_USERACTIVITIES = 1000; |
| 199 | |
| 200 | // Last time we call user activity |
| 201 | long mLastUserActivityCallTime = 0; |
| 202 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 203 | // Last time we updated battery stats |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 204 | long mLastBatteryStatsCallTime = 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 205 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | private static final String SYSTEM_SECURE = "ro.secure"; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 207 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | |
| 209 | /** |
| 210 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 211 | * the window policy has finished. |
| 212 | */ |
| 213 | private boolean mWaitingUntilKeyguardReenabled = false; |
| 214 | |
| 215 | |
| 216 | final TokenWatcher mKeyguardDisabled = new TokenWatcher( |
| 217 | new Handler(), "WindowManagerService.mKeyguardDisabled") { |
| 218 | public void acquired() { |
| 219 | mPolicy.enableKeyguard(false); |
| 220 | } |
| 221 | public void released() { |
| 222 | synchronized (mKeyguardDisabled) { |
| 223 | mPolicy.enableKeyguard(true); |
| 224 | mWaitingUntilKeyguardReenabled = false; |
| 225 | mKeyguardDisabled.notifyAll(); |
| 226 | } |
| 227 | } |
| 228 | }; |
| 229 | |
| 230 | final Context mContext; |
| 231 | |
| 232 | final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 233 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | final boolean mLimitedAlphaCompositing; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 235 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 237 | |
| 238 | final IActivityManager mActivityManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 239 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | final IBatteryStats mBatteryStats; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 241 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 242 | /** |
| 243 | * All currently active sessions with clients. |
| 244 | */ |
| 245 | final HashSet<Session> mSessions = new HashSet<Session>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 246 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | /** |
| 248 | * Mapping from an IWindow IBinder to the server's Window object. |
| 249 | * This is also used as the lock for all of our state. |
| 250 | */ |
| 251 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 252 | |
| 253 | /** |
| 254 | * Mapping from a token IBinder to a WindowToken object. |
| 255 | */ |
| 256 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 257 | new HashMap<IBinder, WindowToken>(); |
| 258 | |
| 259 | /** |
| 260 | * The same tokens as mTokenMap, stored in a list for efficient iteration |
| 261 | * over them. |
| 262 | */ |
| 263 | final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 264 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 265 | /** |
| 266 | * Window tokens that are in the process of exiting, but still |
| 267 | * on screen for animations. |
| 268 | */ |
| 269 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 270 | |
| 271 | /** |
| 272 | * Z-ordered (bottom-most first) list of all application tokens, for |
| 273 | * controlling the ordering of windows in different applications. This |
| 274 | * contains WindowToken objects. |
| 275 | */ |
| 276 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 277 | |
| 278 | /** |
| 279 | * Application tokens that are in the process of exiting, but still |
| 280 | * on screen for animations. |
| 281 | */ |
| 282 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 283 | |
| 284 | /** |
| 285 | * List of window tokens that have finished starting their application, |
| 286 | * and now need to have the policy remove their windows. |
| 287 | */ |
| 288 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 289 | |
| 290 | /** |
| 291 | * Z-ordered (bottom-most first) list of all Window objects. |
| 292 | */ |
| 293 | final ArrayList mWindows = new ArrayList(); |
| 294 | |
| 295 | /** |
| 296 | * Windows that are being resized. Used so we can tell the client about |
| 297 | * the resize after closing the transaction in which we resized the |
| 298 | * underlying surface. |
| 299 | */ |
| 300 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 301 | |
| 302 | /** |
| 303 | * Windows whose animations have ended and now must be removed. |
| 304 | */ |
| 305 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 306 | |
| 307 | /** |
| 308 | * Windows whose surface should be destroyed. |
| 309 | */ |
| 310 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 311 | |
| 312 | /** |
| 313 | * Windows that have lost input focus and are waiting for the new |
| 314 | * focus window to be displayed before they are told about this. |
| 315 | */ |
| 316 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 317 | |
| 318 | /** |
| 319 | * This is set when we have run out of memory, and will either be an empty |
| 320 | * list or contain windows that need to be force removed. |
| 321 | */ |
| 322 | ArrayList<WindowState> mForceRemoves; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 323 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 324 | IInputMethodManager mInputMethodManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 325 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 326 | SurfaceSession mFxSession; |
| 327 | Surface mDimSurface; |
| 328 | boolean mDimShown; |
| 329 | float mDimCurrentAlpha; |
| 330 | float mDimTargetAlpha; |
| 331 | float mDimDeltaPerMs; |
| 332 | long mLastDimAnimTime; |
| 333 | Surface mBlurSurface; |
| 334 | boolean mBlurShown; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 335 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 336 | int mTransactionSequence = 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 337 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 338 | final float[] mTmpFloats = new float[9]; |
| 339 | |
| 340 | boolean mSafeMode; |
| 341 | boolean mDisplayEnabled = false; |
| 342 | boolean mSystemBooted = false; |
| 343 | int mRotation = 0; |
| 344 | int mRequestedRotation = 0; |
| 345 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 346 | int mLastRotationFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | ArrayList<IRotationWatcher> mRotationWatchers |
| 348 | = new ArrayList<IRotationWatcher>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 349 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | boolean mLayoutNeeded = true; |
| 351 | boolean mAnimationPending = false; |
| 352 | boolean mDisplayFrozen = false; |
| 353 | boolean mWindowsFreezingScreen = false; |
| 354 | long mFreezeGcPending = 0; |
| 355 | int mAppsFreezingScreen = 0; |
| 356 | |
| 357 | // This is held as long as we have the screen frozen, to give us time to |
| 358 | // perform a rotation animation when turning off shows the lock screen which |
| 359 | // changes the orientation. |
| 360 | PowerManager.WakeLock mScreenFrozenLock; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 361 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | // State management of app transitions. When we are preparing for a |
| 363 | // transition, mNextAppTransition will be the kind of transition to |
| 364 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 365 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 366 | // made visible or hidden at the next transition. |
| 367 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_NONE; |
| 368 | boolean mAppTransitionReady = false; |
| 369 | boolean mAppTransitionTimeout = false; |
| 370 | boolean mStartingIconInTransition = false; |
| 371 | boolean mSkipAppTransitionAnimation = false; |
| 372 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 373 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 374 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 375 | //flag to detect fat touch events |
| 376 | boolean mFatTouch = false; |
| 377 | Display mDisplay; |
| 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 | H mH = new H(); |
| 380 | |
| 381 | WindowState mCurrentFocus = null; |
| 382 | WindowState mLastFocus = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 383 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 384 | // This just indicates the window the input method is on top of, not |
| 385 | // necessarily the window its input is going to. |
| 386 | WindowState mInputMethodTarget = null; |
| 387 | WindowState mUpcomingInputMethodTarget = null; |
| 388 | boolean mInputMethodTargetWaitingAnim; |
| 389 | int mInputMethodAnimLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 390 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 391 | WindowState mInputMethodWindow = null; |
| 392 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 393 | |
| 394 | AppWindowToken mFocusedApp = null; |
| 395 | |
| 396 | PowerManagerService mPowerManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 397 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | float mWindowAnimationScale = 1.0f; |
| 399 | float mTransitionAnimationScale = 1.0f; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 400 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 401 | final KeyWaiter mKeyWaiter = new KeyWaiter(); |
| 402 | final KeyQ mQueue; |
| 403 | final InputDispatcherThread mInputThread; |
| 404 | |
| 405 | // Who is holding the screen on. |
| 406 | Session mHoldingScreenOn; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 407 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | /** |
| 409 | * Whether the UI is currently running in touch mode (not showing |
| 410 | * navigational focus because the user is directly pressing the screen). |
| 411 | */ |
| 412 | boolean mInTouchMode = false; |
| 413 | |
| 414 | private ViewServer mViewServer; |
| 415 | |
| 416 | final Rect mTempRect = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 417 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 418 | final Configuration mTempConfiguration = new Configuration(); |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 419 | int screenLayout = Configuration.SCREENLAYOUT_UNDEFINED; |
| 420 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 421 | public static WindowManagerService main(Context context, |
| 422 | PowerManagerService pm, boolean haveInputMethods) { |
| 423 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 424 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 425 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 426 | synchronized (thr) { |
| 427 | while (thr.mService == null) { |
| 428 | try { |
| 429 | thr.wait(); |
| 430 | } catch (InterruptedException e) { |
| 431 | } |
| 432 | } |
| 433 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 434 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | return thr.mService; |
| 436 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 437 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 438 | static class WMThread extends Thread { |
| 439 | WindowManagerService mService; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 440 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 441 | private final Context mContext; |
| 442 | private final PowerManagerService mPM; |
| 443 | private final boolean mHaveInputMethods; |
| 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 | public WMThread(Context context, PowerManagerService pm, |
| 446 | boolean haveInputMethods) { |
| 447 | super("WindowManager"); |
| 448 | mContext = context; |
| 449 | mPM = pm; |
| 450 | mHaveInputMethods = haveInputMethods; |
| 451 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 452 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 453 | public void run() { |
| 454 | Looper.prepare(); |
| 455 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 456 | mHaveInputMethods); |
| 457 | android.os.Process.setThreadPriority( |
| 458 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 459 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | synchronized (this) { |
| 461 | mService = s; |
| 462 | notifyAll(); |
| 463 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 464 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 465 | Looper.loop(); |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | static class PolicyThread extends Thread { |
| 470 | private final WindowManagerPolicy mPolicy; |
| 471 | private final WindowManagerService mService; |
| 472 | private final Context mContext; |
| 473 | private final PowerManagerService mPM; |
| 474 | boolean mRunning = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 475 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | public PolicyThread(WindowManagerPolicy policy, |
| 477 | WindowManagerService service, Context context, |
| 478 | PowerManagerService pm) { |
| 479 | super("WindowManagerPolicy"); |
| 480 | mPolicy = policy; |
| 481 | mService = service; |
| 482 | mContext = context; |
| 483 | mPM = pm; |
| 484 | } |
| 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 void run() { |
| 487 | Looper.prepare(); |
| 488 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
| 489 | // Log.VERBOSE, "WindowManagerPolicy")); |
| 490 | android.os.Process.setThreadPriority( |
| 491 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
| 492 | mPolicy.init(mContext, mService, mPM); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 493 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 494 | synchronized (this) { |
| 495 | mRunning = true; |
| 496 | notifyAll(); |
| 497 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 498 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 499 | Looper.loop(); |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | private WindowManagerService(Context context, PowerManagerService pm, |
| 504 | boolean haveInputMethods) { |
| 505 | mContext = context; |
| 506 | mHaveInputMethods = haveInputMethods; |
| 507 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 508 | com.android.internal.R.bool.config_sf_limitedAlpha); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 509 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 510 | mPowerManager = pm; |
| 511 | mPowerManager.setPolicy(mPolicy); |
| 512 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 513 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 514 | "SCREEN_FROZEN"); |
| 515 | mScreenFrozenLock.setReferenceCounted(false); |
| 516 | |
| 517 | mActivityManager = ActivityManagerNative.getDefault(); |
| 518 | mBatteryStats = BatteryStatsService.getService(); |
| 519 | |
| 520 | // Get persisted window scale setting |
| 521 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 522 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 523 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 524 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 525 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 526 | mQueue = new KeyQ(); |
| 527 | |
| 528 | mInputThread = new InputDispatcherThread(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 529 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 530 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 531 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 532 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 533 | synchronized (thr) { |
| 534 | while (!thr.mRunning) { |
| 535 | try { |
| 536 | thr.wait(); |
| 537 | } catch (InterruptedException e) { |
| 538 | } |
| 539 | } |
| 540 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 541 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 542 | mInputThread.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 543 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 544 | // Add ourself to the Watchdog monitors. |
| 545 | Watchdog.getInstance().addMonitor(this); |
| 546 | } |
| 547 | |
| 548 | @Override |
| 549 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 550 | throws RemoteException { |
| 551 | try { |
| 552 | return super.onTransact(code, data, reply, flags); |
| 553 | } catch (RuntimeException e) { |
| 554 | // The window manager only throws security exceptions, so let's |
| 555 | // log all others. |
| 556 | if (!(e instanceof SecurityException)) { |
| 557 | Log.e(TAG, "Window Manager Crash", e); |
| 558 | } |
| 559 | throw e; |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | private void placeWindowAfter(Object pos, WindowState window) { |
| 564 | final int i = mWindows.indexOf(pos); |
| 565 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 566 | TAG, "Adding window " + window + " at " |
| 567 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 568 | mWindows.add(i+1, window); |
| 569 | } |
| 570 | |
| 571 | private void placeWindowBefore(Object pos, WindowState window) { |
| 572 | final int i = mWindows.indexOf(pos); |
| 573 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 574 | TAG, "Adding window " + window + " at " |
| 575 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 576 | mWindows.add(i, window); |
| 577 | } |
| 578 | |
| 579 | //This method finds out the index of a window that has the same app token as |
| 580 | //win. used for z ordering the windows in mWindows |
| 581 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 582 | //use a local variable to cache mWindows |
| 583 | ArrayList localmWindows = mWindows; |
| 584 | int jmax = localmWindows.size(); |
| 585 | if(jmax == 0) { |
| 586 | return -1; |
| 587 | } |
| 588 | for(int j = (jmax-1); j >= 0; j--) { |
| 589 | WindowState wentry = (WindowState)localmWindows.get(j); |
| 590 | if(wentry.mAppToken == win.mAppToken) { |
| 591 | return j; |
| 592 | } |
| 593 | } |
| 594 | return -1; |
| 595 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 596 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 597 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 598 | final IWindow client = win.mClient; |
| 599 | final WindowToken token = win.mToken; |
| 600 | final ArrayList localmWindows = mWindows; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 601 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 602 | final int N = localmWindows.size(); |
| 603 | final WindowState attached = win.mAttachedWindow; |
| 604 | int i; |
| 605 | if (attached == null) { |
| 606 | int tokenWindowsPos = token.windows.size(); |
| 607 | if (token.appWindowToken != null) { |
| 608 | int index = tokenWindowsPos-1; |
| 609 | if (index >= 0) { |
| 610 | // If this application has existing windows, we |
| 611 | // simply place the new window on top of them... but |
| 612 | // keep the starting window on top. |
| 613 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 614 | // Base windows go behind everything else. |
| 615 | placeWindowBefore(token.windows.get(0), win); |
| 616 | tokenWindowsPos = 0; |
| 617 | } else { |
| 618 | AppWindowToken atoken = win.mAppToken; |
| 619 | if (atoken != null && |
| 620 | token.windows.get(index) == atoken.startingWindow) { |
| 621 | placeWindowBefore(token.windows.get(index), win); |
| 622 | tokenWindowsPos--; |
| 623 | } else { |
| 624 | int newIdx = findIdxBasedOnAppTokens(win); |
| 625 | if(newIdx != -1) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 626 | //there is a window above this one associated with the same |
| 627 | //apptoken note that the window could be a floating window |
| 628 | //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] | 629 | //windows associated with this token. |
| 630 | localmWindows.add(newIdx+1, win); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 631 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 632 | } |
| 633 | } |
| 634 | } else { |
| 635 | if (localLOGV) Log.v( |
| 636 | TAG, "Figuring out where to add app window " |
| 637 | + client.asBinder() + " (token=" + token + ")"); |
| 638 | // Figure out where the window should go, based on the |
| 639 | // order of applications. |
| 640 | final int NA = mAppTokens.size(); |
| 641 | Object pos = null; |
| 642 | for (i=NA-1; i>=0; i--) { |
| 643 | AppWindowToken t = mAppTokens.get(i); |
| 644 | if (t == token) { |
| 645 | i--; |
| 646 | break; |
| 647 | } |
| 648 | if (t.windows.size() > 0) { |
| 649 | pos = t.windows.get(0); |
| 650 | } |
| 651 | } |
| 652 | // We now know the index into the apps. If we found |
| 653 | // an app window above, that gives us the position; else |
| 654 | // we need to look some more. |
| 655 | if (pos != null) { |
| 656 | // Move behind any windows attached to this one. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 657 | WindowToken atoken = |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 658 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 659 | if (atoken != null) { |
| 660 | final int NC = atoken.windows.size(); |
| 661 | if (NC > 0) { |
| 662 | WindowState bottom = atoken.windows.get(0); |
| 663 | if (bottom.mSubLayer < 0) { |
| 664 | pos = bottom; |
| 665 | } |
| 666 | } |
| 667 | } |
| 668 | placeWindowBefore(pos, win); |
| 669 | } else { |
| 670 | while (i >= 0) { |
| 671 | AppWindowToken t = mAppTokens.get(i); |
| 672 | final int NW = t.windows.size(); |
| 673 | if (NW > 0) { |
| 674 | pos = t.windows.get(NW-1); |
| 675 | break; |
| 676 | } |
| 677 | i--; |
| 678 | } |
| 679 | if (pos != null) { |
| 680 | // Move in front of any windows attached to this |
| 681 | // one. |
| 682 | WindowToken atoken = |
| 683 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 684 | if (atoken != null) { |
| 685 | final int NC = atoken.windows.size(); |
| 686 | if (NC > 0) { |
| 687 | WindowState top = atoken.windows.get(NC-1); |
| 688 | if (top.mSubLayer >= 0) { |
| 689 | pos = top; |
| 690 | } |
| 691 | } |
| 692 | } |
| 693 | placeWindowAfter(pos, win); |
| 694 | } else { |
| 695 | // Just search for the start of this layer. |
| 696 | final int myLayer = win.mBaseLayer; |
| 697 | for (i=0; i<N; i++) { |
| 698 | WindowState w = (WindowState)localmWindows.get(i); |
| 699 | if (w.mBaseLayer > myLayer) { |
| 700 | break; |
| 701 | } |
| 702 | } |
| 703 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 704 | TAG, "Adding window " + win + " at " |
| 705 | + i + " of " + N); |
| 706 | localmWindows.add(i, win); |
| 707 | } |
| 708 | } |
| 709 | } |
| 710 | } else { |
| 711 | // Figure out where window should go, based on layer. |
| 712 | final int myLayer = win.mBaseLayer; |
| 713 | for (i=N-1; i>=0; i--) { |
| 714 | if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) { |
| 715 | i++; |
| 716 | break; |
| 717 | } |
| 718 | } |
| 719 | if (i < 0) i = 0; |
| 720 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 721 | TAG, "Adding window " + win + " at " |
| 722 | + i + " of " + N); |
| 723 | localmWindows.add(i, win); |
| 724 | } |
| 725 | if (addToToken) { |
| 726 | token.windows.add(tokenWindowsPos, win); |
| 727 | } |
| 728 | |
| 729 | } else { |
| 730 | // Figure out this window's ordering relative to the window |
| 731 | // it is attached to. |
| 732 | final int NA = token.windows.size(); |
| 733 | final int sublayer = win.mSubLayer; |
| 734 | int largestSublayer = Integer.MIN_VALUE; |
| 735 | WindowState windowWithLargestSublayer = null; |
| 736 | for (i=0; i<NA; i++) { |
| 737 | WindowState w = token.windows.get(i); |
| 738 | final int wSublayer = w.mSubLayer; |
| 739 | if (wSublayer >= largestSublayer) { |
| 740 | largestSublayer = wSublayer; |
| 741 | windowWithLargestSublayer = w; |
| 742 | } |
| 743 | if (sublayer < 0) { |
| 744 | // For negative sublayers, we go below all windows |
| 745 | // in the same sublayer. |
| 746 | if (wSublayer >= sublayer) { |
| 747 | if (addToToken) { |
| 748 | token.windows.add(i, win); |
| 749 | } |
| 750 | placeWindowBefore( |
| 751 | wSublayer >= 0 ? attached : w, win); |
| 752 | break; |
| 753 | } |
| 754 | } else { |
| 755 | // For positive sublayers, we go above all windows |
| 756 | // in the same sublayer. |
| 757 | if (wSublayer > sublayer) { |
| 758 | if (addToToken) { |
| 759 | token.windows.add(i, win); |
| 760 | } |
| 761 | placeWindowBefore(w, win); |
| 762 | break; |
| 763 | } |
| 764 | } |
| 765 | } |
| 766 | if (i >= NA) { |
| 767 | if (addToToken) { |
| 768 | token.windows.add(win); |
| 769 | } |
| 770 | if (sublayer < 0) { |
| 771 | placeWindowBefore(attached, win); |
| 772 | } else { |
| 773 | placeWindowAfter(largestSublayer >= 0 |
| 774 | ? windowWithLargestSublayer |
| 775 | : attached, |
| 776 | win); |
| 777 | } |
| 778 | } |
| 779 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 780 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 781 | if (win.mAppToken != null && addToToken) { |
| 782 | win.mAppToken.allAppWindows.add(win); |
| 783 | } |
| 784 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 785 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 786 | static boolean canBeImeTarget(WindowState w) { |
| 787 | final int fl = w.mAttrs.flags |
| 788 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 789 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 790 | return w.isVisibleOrAdding(); |
| 791 | } |
| 792 | return false; |
| 793 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 794 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 795 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
| 796 | final ArrayList localmWindows = mWindows; |
| 797 | final int N = localmWindows.size(); |
| 798 | WindowState w = null; |
| 799 | int i = N; |
| 800 | while (i > 0) { |
| 801 | i--; |
| 802 | w = (WindowState)localmWindows.get(i); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 803 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 804 | //Log.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
| 805 | // + Integer.toHexString(w.mAttrs.flags)); |
| 806 | if (canBeImeTarget(w)) { |
| 807 | //Log.i(TAG, "Putting input method here!"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 808 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 809 | // Yet more tricksyness! If this window is a "starting" |
| 810 | // window, we do actually want to be on top of it, but |
| 811 | // it is not -really- where input will go. So if the caller |
| 812 | // is not actually looking to move the IME, look down below |
| 813 | // for a real window to target... |
| 814 | if (!willMove |
| 815 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 816 | && i > 0) { |
| 817 | WindowState wb = (WindowState)localmWindows.get(i-1); |
| 818 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 819 | i--; |
| 820 | w = wb; |
| 821 | } |
| 822 | } |
| 823 | break; |
| 824 | } |
| 825 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 826 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 827 | mUpcomingInputMethodTarget = w; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 828 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 829 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Desired input method target=" |
| 830 | + w + " willMove=" + willMove); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 831 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 832 | if (willMove && w != null) { |
| 833 | final WindowState curTarget = mInputMethodTarget; |
| 834 | if (curTarget != null && curTarget.mAppToken != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 835 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 836 | // Now some fun for dealing with window animations that |
| 837 | // modify the Z order. We need to look at all windows below |
| 838 | // the current target that are in this app, finding the highest |
| 839 | // visible one in layering. |
| 840 | AppWindowToken token = curTarget.mAppToken; |
| 841 | WindowState highestTarget = null; |
| 842 | int highestPos = 0; |
| 843 | if (token.animating || token.animation != null) { |
| 844 | int pos = 0; |
| 845 | pos = localmWindows.indexOf(curTarget); |
| 846 | while (pos >= 0) { |
| 847 | WindowState win = (WindowState)localmWindows.get(pos); |
| 848 | if (win.mAppToken != token) { |
| 849 | break; |
| 850 | } |
| 851 | if (!win.mRemoved) { |
| 852 | if (highestTarget == null || win.mAnimLayer > |
| 853 | highestTarget.mAnimLayer) { |
| 854 | highestTarget = win; |
| 855 | highestPos = pos; |
| 856 | } |
| 857 | } |
| 858 | pos--; |
| 859 | } |
| 860 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 861 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 862 | if (highestTarget != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 863 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "mNextAppTransition=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 864 | + mNextAppTransition + " " + highestTarget |
| 865 | + " animating=" + highestTarget.isAnimating() |
| 866 | + " layer=" + highestTarget.mAnimLayer |
| 867 | + " new layer=" + w.mAnimLayer); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 868 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 869 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) { |
| 870 | // If we are currently setting up for an animation, |
| 871 | // hold everything until we can find out what will happen. |
| 872 | mInputMethodTargetWaitingAnim = true; |
| 873 | mInputMethodTarget = highestTarget; |
| 874 | return highestPos + 1; |
| 875 | } else if (highestTarget.isAnimating() && |
| 876 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 877 | // If the window we are currently targeting is involved |
| 878 | // with an animation, and it is on top of the next target |
| 879 | // we will be over, then hold off on moving until |
| 880 | // that is done. |
| 881 | mInputMethodTarget = highestTarget; |
| 882 | return highestPos + 1; |
| 883 | } |
| 884 | } |
| 885 | } |
| 886 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 887 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 888 | //Log.i(TAG, "Placing input method @" + (i+1)); |
| 889 | if (w != null) { |
| 890 | if (willMove) { |
| 891 | RuntimeException e = new RuntimeException(); |
| 892 | e.fillInStackTrace(); |
| 893 | if (DEBUG_INPUT_METHOD) Log.w(TAG, "Moving IM target from " |
| 894 | + mInputMethodTarget + " to " + w, e); |
| 895 | mInputMethodTarget = w; |
| 896 | if (w.mAppToken != null) { |
| 897 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 898 | } else { |
| 899 | setInputMethodAnimLayerAdjustment(0); |
| 900 | } |
| 901 | } |
| 902 | return i+1; |
| 903 | } |
| 904 | if (willMove) { |
| 905 | RuntimeException e = new RuntimeException(); |
| 906 | e.fillInStackTrace(); |
| 907 | if (DEBUG_INPUT_METHOD) Log.w(TAG, "Moving IM target from " |
| 908 | + mInputMethodTarget + " to null", e); |
| 909 | mInputMethodTarget = null; |
| 910 | setInputMethodAnimLayerAdjustment(0); |
| 911 | } |
| 912 | return -1; |
| 913 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 914 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 915 | void addInputMethodWindowToListLocked(WindowState win) { |
| 916 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 917 | if (pos >= 0) { |
| 918 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 919 | mWindows.add(pos, win); |
| 920 | moveInputMethodDialogsLocked(pos+1); |
| 921 | return; |
| 922 | } |
| 923 | win.mTargetAppToken = null; |
| 924 | addWindowToListInOrderLocked(win, true); |
| 925 | moveInputMethodDialogsLocked(pos); |
| 926 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 927 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 928 | void setInputMethodAnimLayerAdjustment(int adj) { |
| 929 | if (DEBUG_LAYERS) Log.v(TAG, "Setting im layer adj to " + adj); |
| 930 | mInputMethodAnimLayerAdjustment = adj; |
| 931 | WindowState imw = mInputMethodWindow; |
| 932 | if (imw != null) { |
| 933 | imw.mAnimLayer = imw.mLayer + adj; |
| 934 | if (DEBUG_LAYERS) Log.v(TAG, "IM win " + imw |
| 935 | + " anim layer: " + imw.mAnimLayer); |
| 936 | int wi = imw.mChildWindows.size(); |
| 937 | while (wi > 0) { |
| 938 | wi--; |
| 939 | WindowState cw = (WindowState)imw.mChildWindows.get(wi); |
| 940 | cw.mAnimLayer = cw.mLayer + adj; |
| 941 | if (DEBUG_LAYERS) Log.v(TAG, "IM win " + cw |
| 942 | + " anim layer: " + cw.mAnimLayer); |
| 943 | } |
| 944 | } |
| 945 | int di = mInputMethodDialogs.size(); |
| 946 | while (di > 0) { |
| 947 | di --; |
| 948 | imw = mInputMethodDialogs.get(di); |
| 949 | imw.mAnimLayer = imw.mLayer + adj; |
| 950 | if (DEBUG_LAYERS) Log.v(TAG, "IM win " + imw |
| 951 | + " anim layer: " + imw.mAnimLayer); |
| 952 | } |
| 953 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 954 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 955 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 956 | int wpos = mWindows.indexOf(win); |
| 957 | if (wpos >= 0) { |
| 958 | if (wpos < interestingPos) interestingPos--; |
| 959 | mWindows.remove(wpos); |
| 960 | int NC = win.mChildWindows.size(); |
| 961 | while (NC > 0) { |
| 962 | NC--; |
| 963 | WindowState cw = (WindowState)win.mChildWindows.get(NC); |
| 964 | int cpos = mWindows.indexOf(cw); |
| 965 | if (cpos >= 0) { |
| 966 | if (cpos < interestingPos) interestingPos--; |
| 967 | mWindows.remove(cpos); |
| 968 | } |
| 969 | } |
| 970 | } |
| 971 | return interestingPos; |
| 972 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 973 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 974 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 975 | addWindowToListInOrderLocked(win, false); |
| 976 | // This is a hack to get all of the child windows added as well |
| 977 | // at the right position. Child windows should be rare and |
| 978 | // this case should be rare, so it shouldn't be that big a deal. |
| 979 | int wpos = mWindows.indexOf(win); |
| 980 | if (wpos >= 0) { |
| 981 | mWindows.remove(wpos); |
| 982 | reAddWindowLocked(wpos, win); |
| 983 | } |
| 984 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 985 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 986 | void logWindowList(String prefix) { |
| 987 | int N = mWindows.size(); |
| 988 | while (N > 0) { |
| 989 | N--; |
| 990 | Log.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
| 991 | } |
| 992 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 993 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 994 | void moveInputMethodDialogsLocked(int pos) { |
| 995 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 996 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 997 | final int N = dialogs.size(); |
| 998 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Removing " + N + " dialogs w/pos=" + pos); |
| 999 | for (int i=0; i<N; i++) { |
| 1000 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1001 | } |
| 1002 | if (DEBUG_INPUT_METHOD) { |
| 1003 | Log.v(TAG, "Window list w/pos=" + pos); |
| 1004 | logWindowList(" "); |
| 1005 | } |
| 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 | if (pos >= 0) { |
| 1008 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1009 | if (pos < mWindows.size()) { |
| 1010 | WindowState wp = (WindowState)mWindows.get(pos); |
| 1011 | if (wp == mInputMethodWindow) { |
| 1012 | pos++; |
| 1013 | } |
| 1014 | } |
| 1015 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Adding " + N + " dialogs at pos=" + pos); |
| 1016 | for (int i=0; i<N; i++) { |
| 1017 | WindowState win = dialogs.get(i); |
| 1018 | win.mTargetAppToken = targetAppToken; |
| 1019 | pos = reAddWindowLocked(pos, win); |
| 1020 | } |
| 1021 | if (DEBUG_INPUT_METHOD) { |
| 1022 | Log.v(TAG, "Final window list:"); |
| 1023 | logWindowList(" "); |
| 1024 | } |
| 1025 | return; |
| 1026 | } |
| 1027 | for (int i=0; i<N; i++) { |
| 1028 | WindowState win = dialogs.get(i); |
| 1029 | win.mTargetAppToken = null; |
| 1030 | reAddWindowToListInOrderLocked(win); |
| 1031 | if (DEBUG_INPUT_METHOD) { |
| 1032 | Log.v(TAG, "No IM target, final list:"); |
| 1033 | logWindowList(" "); |
| 1034 | } |
| 1035 | } |
| 1036 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1037 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1038 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1039 | final WindowState imWin = mInputMethodWindow; |
| 1040 | final int DN = mInputMethodDialogs.size(); |
| 1041 | if (imWin == null && DN == 0) { |
| 1042 | return false; |
| 1043 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1044 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1045 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1046 | if (imPos >= 0) { |
| 1047 | // In this case, the input method windows are to be placed |
| 1048 | // immediately above the window they are targeting. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1049 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1050 | // First check to see if the input method windows are already |
| 1051 | // located here, and contiguous. |
| 1052 | final int N = mWindows.size(); |
| 1053 | WindowState firstImWin = imPos < N |
| 1054 | ? (WindowState)mWindows.get(imPos) : null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1055 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1056 | // Figure out the actual input method window that should be |
| 1057 | // at the bottom of their stack. |
| 1058 | WindowState baseImWin = imWin != null |
| 1059 | ? imWin : mInputMethodDialogs.get(0); |
| 1060 | if (baseImWin.mChildWindows.size() > 0) { |
| 1061 | WindowState cw = (WindowState)baseImWin.mChildWindows.get(0); |
| 1062 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1063 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1064 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1065 | if (firstImWin == baseImWin) { |
| 1066 | // The windows haven't moved... but are they still contiguous? |
| 1067 | // First find the top IM window. |
| 1068 | int pos = imPos+1; |
| 1069 | while (pos < N) { |
| 1070 | if (!((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1071 | break; |
| 1072 | } |
| 1073 | pos++; |
| 1074 | } |
| 1075 | pos++; |
| 1076 | // Now there should be no more input method windows above. |
| 1077 | while (pos < N) { |
| 1078 | if (((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1079 | break; |
| 1080 | } |
| 1081 | pos++; |
| 1082 | } |
| 1083 | if (pos >= N) { |
| 1084 | // All is good! |
| 1085 | return false; |
| 1086 | } |
| 1087 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1088 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1089 | if (imWin != null) { |
| 1090 | if (DEBUG_INPUT_METHOD) { |
| 1091 | Log.v(TAG, "Moving IM from " + imPos); |
| 1092 | logWindowList(" "); |
| 1093 | } |
| 1094 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1095 | if (DEBUG_INPUT_METHOD) { |
| 1096 | Log.v(TAG, "List after moving with new pos " + imPos + ":"); |
| 1097 | logWindowList(" "); |
| 1098 | } |
| 1099 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1100 | reAddWindowLocked(imPos, imWin); |
| 1101 | if (DEBUG_INPUT_METHOD) { |
| 1102 | Log.v(TAG, "List after moving IM to " + imPos + ":"); |
| 1103 | logWindowList(" "); |
| 1104 | } |
| 1105 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1106 | } else { |
| 1107 | moveInputMethodDialogsLocked(imPos); |
| 1108 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1109 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1110 | } else { |
| 1111 | // In this case, the input method windows go in a fixed layer, |
| 1112 | // because they aren't currently associated with a focus window. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1113 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1114 | if (imWin != null) { |
| 1115 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Moving IM from " + imPos); |
| 1116 | tmpRemoveWindowLocked(0, imWin); |
| 1117 | imWin.mTargetAppToken = null; |
| 1118 | reAddWindowToListInOrderLocked(imWin); |
| 1119 | if (DEBUG_INPUT_METHOD) { |
| 1120 | Log.v(TAG, "List with no IM target:"); |
| 1121 | logWindowList(" "); |
| 1122 | } |
| 1123 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1124 | } else { |
| 1125 | moveInputMethodDialogsLocked(-1);; |
| 1126 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1127 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1128 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1129 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1130 | if (needAssignLayers) { |
| 1131 | assignLayersLocked(); |
| 1132 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1133 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1134 | return true; |
| 1135 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1136 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1137 | void adjustInputMethodDialogsLocked() { |
| 1138 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1139 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1140 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1141 | public int addWindow(Session session, IWindow client, |
| 1142 | WindowManager.LayoutParams attrs, int viewVisibility, |
| 1143 | Rect outContentInsets) { |
| 1144 | int res = mPolicy.checkAddPermission(attrs); |
| 1145 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1146 | return res; |
| 1147 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1148 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1149 | boolean reportNewConfig = false; |
| 1150 | WindowState attachedWindow = null; |
| 1151 | WindowState win = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1152 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1153 | synchronized(mWindowMap) { |
| 1154 | // Instantiating a Display requires talking with the simulator, |
| 1155 | // so don't do it until we know the system is mostly up and |
| 1156 | // running. |
| 1157 | if (mDisplay == null) { |
| 1158 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 1159 | mDisplay = wm.getDefaultDisplay(); |
| 1160 | mQueue.setDisplay(mDisplay); |
| 1161 | reportNewConfig = true; |
| 1162 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1163 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1164 | if (mWindowMap.containsKey(client.asBinder())) { |
| 1165 | Log.w(TAG, "Window " + client + " is already added"); |
| 1166 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 1167 | } |
| 1168 | |
| 1169 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1170 | attachedWindow = windowForClientLocked(null, attrs.token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1171 | if (attachedWindow == null) { |
| 1172 | Log.w(TAG, "Attempted to add window with token that is not a window: " |
| 1173 | + attrs.token + ". Aborting."); |
| 1174 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1175 | } |
| 1176 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 1177 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
| 1178 | Log.w(TAG, "Attempted to add window with token that is a sub-window: " |
| 1179 | + attrs.token + ". Aborting."); |
| 1180 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1181 | } |
| 1182 | } |
| 1183 | |
| 1184 | boolean addToken = false; |
| 1185 | WindowToken token = mTokenMap.get(attrs.token); |
| 1186 | if (token == null) { |
| 1187 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1188 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1189 | Log.w(TAG, "Attempted to add application window with unknown token " |
| 1190 | + attrs.token + ". Aborting."); |
| 1191 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1192 | } |
| 1193 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 1194 | Log.w(TAG, "Attempted to add input method window with unknown token " |
| 1195 | + attrs.token + ". Aborting."); |
| 1196 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1197 | } |
| 1198 | token = new WindowToken(attrs.token, -1, false); |
| 1199 | addToken = true; |
| 1200 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1201 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1202 | AppWindowToken atoken = token.appWindowToken; |
| 1203 | if (atoken == null) { |
| 1204 | Log.w(TAG, "Attempted to add window with non-application token " |
| 1205 | + token + ". Aborting."); |
| 1206 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 1207 | } else if (atoken.removed) { |
| 1208 | Log.w(TAG, "Attempted to add window with exiting application token " |
| 1209 | + token + ". Aborting."); |
| 1210 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1211 | } |
| 1212 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 1213 | // No need for this guy! |
| 1214 | if (localLOGV) Log.v( |
| 1215 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 1216 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 1217 | } |
| 1218 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 1219 | if (token.windowType != TYPE_INPUT_METHOD) { |
| 1220 | Log.w(TAG, "Attempted to add input method window with bad token " |
| 1221 | + attrs.token + ". Aborting."); |
| 1222 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1223 | } |
| 1224 | } |
| 1225 | |
| 1226 | win = new WindowState(session, client, token, |
| 1227 | attachedWindow, attrs, viewVisibility); |
| 1228 | if (win.mDeathRecipient == null) { |
| 1229 | // Client has apparently died, so there is no reason to |
| 1230 | // continue. |
| 1231 | Log.w(TAG, "Adding window client " + client.asBinder() |
| 1232 | + " that is dead, aborting."); |
| 1233 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1234 | } |
| 1235 | |
| 1236 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1237 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1238 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 1239 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1240 | return res; |
| 1241 | } |
| 1242 | |
| 1243 | // From now on, no exceptions or errors allowed! |
| 1244 | |
| 1245 | res = WindowManagerImpl.ADD_OKAY; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1246 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1247 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1248 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1249 | if (addToken) { |
| 1250 | mTokenMap.put(attrs.token, token); |
| 1251 | mTokenList.add(token); |
| 1252 | } |
| 1253 | win.attach(); |
| 1254 | mWindowMap.put(client.asBinder(), win); |
| 1255 | |
| 1256 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 1257 | token.appWindowToken != null) { |
| 1258 | token.appWindowToken.startingWindow = win; |
| 1259 | } |
| 1260 | |
| 1261 | boolean imMayMove = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1262 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1263 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 1264 | mInputMethodWindow = win; |
| 1265 | addInputMethodWindowToListLocked(win); |
| 1266 | imMayMove = false; |
| 1267 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 1268 | mInputMethodDialogs.add(win); |
| 1269 | addWindowToListInOrderLocked(win, true); |
| 1270 | adjustInputMethodDialogsLocked(); |
| 1271 | imMayMove = false; |
| 1272 | } else { |
| 1273 | addWindowToListInOrderLocked(win, true); |
| 1274 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1275 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1276 | win.mEnterAnimationPending = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1277 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1278 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1279 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1280 | if (mInTouchMode) { |
| 1281 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 1282 | } |
| 1283 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 1284 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 1285 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1286 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1287 | boolean focusChanged = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1288 | if (win.canReceiveKeys()) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1289 | if ((focusChanged=updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS)) |
| 1290 | == true) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1291 | imMayMove = false; |
| 1292 | } |
| 1293 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1294 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1295 | if (imMayMove) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1296 | moveInputMethodWindowsIfNeededLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1297 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1298 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1299 | assignLayersLocked(); |
| 1300 | // Don't do layout here, the window must call |
| 1301 | // relayout to be displayed, so we'll do it there. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1302 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1303 | //dump(); |
| 1304 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1305 | if (focusChanged) { |
| 1306 | if (mCurrentFocus != null) { |
| 1307 | mKeyWaiter.handleNewWindowLocked(mCurrentFocus); |
| 1308 | } |
| 1309 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1310 | if (localLOGV) Log.v( |
| 1311 | TAG, "New client " + client.asBinder() |
| 1312 | + ": window=" + win); |
| 1313 | } |
| 1314 | |
| 1315 | // sendNewConfiguration() checks caller permissions so we must call it with |
| 1316 | // privilege. updateOrientationFromAppTokens() clears and resets the caller |
| 1317 | // identity anyway, so it's safe to just clear & restore around this whole |
| 1318 | // block. |
| 1319 | final long origId = Binder.clearCallingIdentity(); |
| 1320 | if (reportNewConfig) { |
| 1321 | sendNewConfiguration(); |
| 1322 | } else { |
| 1323 | // Update Orientation after adding a window, only if the window needs to be |
| 1324 | // displayed right away |
| 1325 | if (win.isVisibleOrAdding()) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 1326 | if (updateOrientationFromAppTokensUnchecked(null, null) != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1327 | sendNewConfiguration(); |
| 1328 | } |
| 1329 | } |
| 1330 | } |
| 1331 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1332 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1333 | return res; |
| 1334 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1335 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1336 | public void removeWindow(Session session, IWindow client) { |
| 1337 | synchronized(mWindowMap) { |
| 1338 | WindowState win = windowForClientLocked(session, client); |
| 1339 | if (win == null) { |
| 1340 | return; |
| 1341 | } |
| 1342 | removeWindowLocked(session, win); |
| 1343 | } |
| 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 removeWindowLocked(Session session, WindowState win) { |
| 1347 | |
| 1348 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 1349 | TAG, "Remove " + win + " client=" |
| 1350 | + Integer.toHexString(System.identityHashCode( |
| 1351 | win.mClient.asBinder())) |
| 1352 | + ", surface=" + win.mSurface); |
| 1353 | |
| 1354 | final long origId = Binder.clearCallingIdentity(); |
| 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 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 1357 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 1358 | + " mExiting=" + win.mExiting |
| 1359 | + " isAnimating=" + win.isAnimating() |
| 1360 | + " app-animation=" |
| 1361 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 1362 | + " inPendingTransaction=" |
| 1363 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 1364 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 1365 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 1366 | boolean wasVisible = false; |
| 1367 | // First, see if we need to run an animation. If we do, we have |
| 1368 | // to hold off on removing the window until the animation is done. |
| 1369 | // If the display is frozen, just remove immediately, since the |
| 1370 | // animation wouldn't be seen. |
| 1371 | if (win.mSurface != null && !mDisplayFrozen) { |
| 1372 | // If we are not currently running the exit animation, we |
| 1373 | // need to see about starting one. |
| 1374 | if (wasVisible=win.isWinVisibleLw()) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1375 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1376 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 1377 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 1378 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 1379 | } |
| 1380 | // Try starting an animation. |
| 1381 | if (applyAnimationLocked(win, transit, false)) { |
| 1382 | win.mExiting = true; |
| 1383 | } |
| 1384 | } |
| 1385 | if (win.mExiting || win.isAnimating()) { |
| 1386 | // The exit animation is running... wait for it! |
| 1387 | //Log.i(TAG, "*** Running exit animation..."); |
| 1388 | win.mExiting = true; |
| 1389 | win.mRemoveOnExit = true; |
| 1390 | mLayoutNeeded = true; |
| 1391 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 1392 | performLayoutAndPlaceSurfacesLocked(); |
| 1393 | if (win.mAppToken != null) { |
| 1394 | win.mAppToken.updateReportedVisibilityLocked(); |
| 1395 | } |
| 1396 | //dump(); |
| 1397 | Binder.restoreCallingIdentity(origId); |
| 1398 | return; |
| 1399 | } |
| 1400 | } |
| 1401 | |
| 1402 | removeWindowInnerLocked(session, win); |
| 1403 | // Removing a visible window will effect the computed orientation |
| 1404 | // So just update orientation if needed. |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1405 | if (wasVisible && computeForcedAppOrientationLocked() |
| 1406 | != mForcedAppOrientation) { |
| 1407 | 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] | 1408 | } |
| 1409 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 1410 | Binder.restoreCallingIdentity(origId); |
| 1411 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1412 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1413 | private void removeWindowInnerLocked(Session session, WindowState win) { |
| 1414 | mKeyWaiter.releasePendingPointerLocked(win.mSession); |
| 1415 | mKeyWaiter.releasePendingTrackballLocked(win.mSession); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1416 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1417 | win.mRemoved = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1418 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1419 | if (mInputMethodTarget == win) { |
| 1420 | moveInputMethodWindowsIfNeededLocked(false); |
| 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 | mPolicy.removeWindowLw(win); |
| 1424 | win.removeLocked(); |
| 1425 | |
| 1426 | mWindowMap.remove(win.mClient.asBinder()); |
| 1427 | mWindows.remove(win); |
| 1428 | |
| 1429 | if (mInputMethodWindow == win) { |
| 1430 | mInputMethodWindow = null; |
| 1431 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 1432 | mInputMethodDialogs.remove(win); |
| 1433 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1434 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1435 | final WindowToken token = win.mToken; |
| 1436 | final AppWindowToken atoken = win.mAppToken; |
| 1437 | token.windows.remove(win); |
| 1438 | if (atoken != null) { |
| 1439 | atoken.allAppWindows.remove(win); |
| 1440 | } |
| 1441 | if (localLOGV) Log.v( |
| 1442 | TAG, "**** Removing window " + win + ": count=" |
| 1443 | + token.windows.size()); |
| 1444 | if (token.windows.size() == 0) { |
| 1445 | if (!token.explicit) { |
| 1446 | mTokenMap.remove(token.token); |
| 1447 | mTokenList.remove(token); |
| 1448 | } else if (atoken != null) { |
| 1449 | atoken.firstWindowDrawn = false; |
| 1450 | } |
| 1451 | } |
| 1452 | |
| 1453 | if (atoken != null) { |
| 1454 | if (atoken.startingWindow == win) { |
| 1455 | atoken.startingWindow = null; |
| 1456 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 1457 | // If this is the last window and we had requested a starting |
| 1458 | // transition window, well there is no point now. |
| 1459 | atoken.startingData = null; |
| 1460 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 1461 | // If this is the last window except for a starting transition |
| 1462 | // window, we need to get rid of the starting transition. |
| 1463 | if (DEBUG_STARTING_WINDOW) { |
| 1464 | Log.v(TAG, "Schedule remove starting " + token |
| 1465 | + ": no more real windows"); |
| 1466 | } |
| 1467 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 1468 | mH.sendMessage(m); |
| 1469 | } |
| 1470 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1471 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1472 | if (!mInLayout) { |
| 1473 | assignLayersLocked(); |
| 1474 | mLayoutNeeded = true; |
| 1475 | performLayoutAndPlaceSurfacesLocked(); |
| 1476 | if (win.mAppToken != null) { |
| 1477 | win.mAppToken.updateReportedVisibilityLocked(); |
| 1478 | } |
| 1479 | } |
| 1480 | } |
| 1481 | |
| 1482 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 1483 | long origId = Binder.clearCallingIdentity(); |
| 1484 | try { |
| 1485 | synchronized (mWindowMap) { |
| 1486 | WindowState w = windowForClientLocked(session, client); |
| 1487 | if ((w != null) && (w.mSurface != null)) { |
| 1488 | Surface.openTransaction(); |
| 1489 | try { |
| 1490 | w.mSurface.setTransparentRegionHint(region); |
| 1491 | } finally { |
| 1492 | Surface.closeTransaction(); |
| 1493 | } |
| 1494 | } |
| 1495 | } |
| 1496 | } finally { |
| 1497 | Binder.restoreCallingIdentity(origId); |
| 1498 | } |
| 1499 | } |
| 1500 | |
| 1501 | void setInsetsWindow(Session session, IWindow client, |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1502 | int touchableInsets, Rect contentInsets, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1503 | Rect visibleInsets) { |
| 1504 | long origId = Binder.clearCallingIdentity(); |
| 1505 | try { |
| 1506 | synchronized (mWindowMap) { |
| 1507 | WindowState w = windowForClientLocked(session, client); |
| 1508 | if (w != null) { |
| 1509 | w.mGivenInsetsPending = false; |
| 1510 | w.mGivenContentInsets.set(contentInsets); |
| 1511 | w.mGivenVisibleInsets.set(visibleInsets); |
| 1512 | w.mTouchableInsets = touchableInsets; |
| 1513 | mLayoutNeeded = true; |
| 1514 | performLayoutAndPlaceSurfacesLocked(); |
| 1515 | } |
| 1516 | } |
| 1517 | } finally { |
| 1518 | Binder.restoreCallingIdentity(origId); |
| 1519 | } |
| 1520 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1521 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1522 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 1523 | Rect outDisplayFrame) { |
| 1524 | synchronized(mWindowMap) { |
| 1525 | WindowState win = windowForClientLocked(session, client); |
| 1526 | if (win == null) { |
| 1527 | outDisplayFrame.setEmpty(); |
| 1528 | return; |
| 1529 | } |
| 1530 | outDisplayFrame.set(win.mDisplayFrame); |
| 1531 | } |
| 1532 | } |
| 1533 | |
| 1534 | public int relayoutWindow(Session session, IWindow client, |
| 1535 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 1536 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 1537 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
| 1538 | Surface outSurface) { |
| 1539 | boolean displayed = false; |
| 1540 | boolean inTouchMode; |
| 1541 | Configuration newConfig = null; |
| 1542 | long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1543 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1544 | synchronized(mWindowMap) { |
| 1545 | WindowState win = windowForClientLocked(session, client); |
| 1546 | if (win == null) { |
| 1547 | return 0; |
| 1548 | } |
| 1549 | win.mRequestedWidth = requestedWidth; |
| 1550 | win.mRequestedHeight = requestedHeight; |
| 1551 | |
| 1552 | if (attrs != null) { |
| 1553 | mPolicy.adjustWindowParamsLw(attrs); |
| 1554 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1555 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1556 | int attrChanges = 0; |
| 1557 | int flagChanges = 0; |
| 1558 | if (attrs != null) { |
| 1559 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 1560 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 1561 | } |
| 1562 | |
| 1563 | if (localLOGV) Log.v( |
| 1564 | TAG, "Relayout given client " + client.asBinder() |
| 1565 | + " (" + win.mAttrs.getTitle() + ")"); |
| 1566 | |
| 1567 | |
| 1568 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 1569 | win.mAlpha = attrs.alpha; |
| 1570 | } |
| 1571 | |
| 1572 | final boolean scaledWindow = |
| 1573 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 1574 | |
| 1575 | if (scaledWindow) { |
| 1576 | // requested{Width|Height} Surface's physical size |
| 1577 | // attrs.{width|height} Size on screen |
| 1578 | win.mHScale = (attrs.width != requestedWidth) ? |
| 1579 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 1580 | win.mVScale = (attrs.height != requestedHeight) ? |
| 1581 | (attrs.height / (float)requestedHeight) : 1.0f; |
| 1582 | } |
| 1583 | |
| 1584 | boolean imMayMove = (flagChanges&( |
| 1585 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 1586 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1587 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1588 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 1589 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 1590 | || (!win.mRelayoutCalled); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1591 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1592 | win.mRelayoutCalled = true; |
| 1593 | final int oldVisibility = win.mViewVisibility; |
| 1594 | win.mViewVisibility = viewVisibility; |
| 1595 | if (viewVisibility == View.VISIBLE && |
| 1596 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 1597 | displayed = !win.isVisibleLw(); |
| 1598 | if (win.mExiting) { |
| 1599 | win.mExiting = false; |
| 1600 | win.mAnimation = null; |
| 1601 | } |
| 1602 | if (win.mDestroying) { |
| 1603 | win.mDestroying = false; |
| 1604 | mDestroySurface.remove(win); |
| 1605 | } |
| 1606 | if (oldVisibility == View.GONE) { |
| 1607 | win.mEnterAnimationPending = true; |
| 1608 | } |
| 1609 | if (displayed && win.mSurface != null && !win.mDrawPending |
| 1610 | && !win.mCommitDrawPending && !mDisplayFrozen) { |
| 1611 | applyEnterAnimationLocked(win); |
| 1612 | } |
| 1613 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 1614 | // To change the format, we need to re-build the surface. |
| 1615 | win.destroySurfaceLocked(); |
| 1616 | displayed = true; |
| 1617 | } |
| 1618 | try { |
| 1619 | Surface surface = win.createSurfaceLocked(); |
| 1620 | if (surface != null) { |
| 1621 | outSurface.copyFrom(surface); |
| 1622 | } else { |
| 1623 | outSurface.clear(); |
| 1624 | } |
| 1625 | } catch (Exception e) { |
| 1626 | Log.w(TAG, "Exception thrown when creating surface for client " |
| 1627 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 1628 | e); |
| 1629 | Binder.restoreCallingIdentity(origId); |
| 1630 | return 0; |
| 1631 | } |
| 1632 | if (displayed) { |
| 1633 | focusMayChange = true; |
| 1634 | } |
| 1635 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 1636 | && mInputMethodWindow == null) { |
| 1637 | mInputMethodWindow = win; |
| 1638 | imMayMove = true; |
| 1639 | } |
| 1640 | } else { |
| 1641 | win.mEnterAnimationPending = false; |
| 1642 | if (win.mSurface != null) { |
| 1643 | // If we are not currently running the exit animation, we |
| 1644 | // need to see about starting one. |
| 1645 | if (!win.mExiting) { |
| 1646 | // Try starting an animation; if there isn't one, we |
| 1647 | // can destroy the surface right away. |
| 1648 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 1649 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 1650 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 1651 | } |
| 1652 | if (win.isWinVisibleLw() && |
| 1653 | applyAnimationLocked(win, transit, false)) { |
| 1654 | win.mExiting = true; |
| 1655 | mKeyWaiter.finishedKey(session, client, true, |
| 1656 | KeyWaiter.RETURN_NOTHING); |
| 1657 | } else if (win.isAnimating()) { |
| 1658 | // Currently in a hide animation... turn this into |
| 1659 | // an exit. |
| 1660 | win.mExiting = true; |
| 1661 | } else { |
| 1662 | if (mInputMethodWindow == win) { |
| 1663 | mInputMethodWindow = null; |
| 1664 | } |
| 1665 | win.destroySurfaceLocked(); |
| 1666 | } |
| 1667 | } |
| 1668 | } |
| 1669 | outSurface.clear(); |
| 1670 | } |
| 1671 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1672 | if (focusMayChange) { |
| 1673 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 1674 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1675 | imMayMove = false; |
| 1676 | } |
| 1677 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 1678 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1679 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1680 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 1681 | // reassign them at this point if the IM window state gets shuffled |
| 1682 | boolean assignLayers = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1683 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1684 | if (imMayMove) { |
| 1685 | if (moveInputMethodWindowsIfNeededLocked(false)) { |
| 1686 | assignLayers = true; |
| 1687 | } |
| 1688 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1689 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1690 | mLayoutNeeded = true; |
| 1691 | win.mGivenInsetsPending = insetsPending; |
| 1692 | if (assignLayers) { |
| 1693 | assignLayersLocked(); |
| 1694 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1695 | newConfig = updateOrientationFromAppTokensLocked(null, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1696 | performLayoutAndPlaceSurfacesLocked(); |
| 1697 | if (win.mAppToken != null) { |
| 1698 | win.mAppToken.updateReportedVisibilityLocked(); |
| 1699 | } |
| 1700 | outFrame.set(win.mFrame); |
| 1701 | outContentInsets.set(win.mContentInsets); |
| 1702 | outVisibleInsets.set(win.mVisibleInsets); |
| 1703 | if (localLOGV) Log.v( |
| 1704 | TAG, "Relayout given client " + client.asBinder() |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1705 | + ", requestedWidth=" + requestedWidth |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1706 | + ", requestedHeight=" + requestedHeight |
| 1707 | + ", viewVisibility=" + viewVisibility |
| 1708 | + "\nRelayout returning frame=" + outFrame |
| 1709 | + ", surface=" + outSurface); |
| 1710 | |
| 1711 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 1712 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 1713 | |
| 1714 | inTouchMode = mInTouchMode; |
| 1715 | } |
| 1716 | |
| 1717 | if (newConfig != null) { |
| 1718 | sendNewConfiguration(); |
| 1719 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1720 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1721 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1722 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1723 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 1724 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 1725 | } |
| 1726 | |
| 1727 | public void finishDrawingWindow(Session session, IWindow client) { |
| 1728 | final long origId = Binder.clearCallingIdentity(); |
| 1729 | synchronized(mWindowMap) { |
| 1730 | WindowState win = windowForClientLocked(session, client); |
| 1731 | if (win != null && win.finishDrawingLocked()) { |
| 1732 | mLayoutNeeded = true; |
| 1733 | performLayoutAndPlaceSurfacesLocked(); |
| 1734 | } |
| 1735 | } |
| 1736 | Binder.restoreCallingIdentity(origId); |
| 1737 | } |
| 1738 | |
| 1739 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
| 1740 | if (DEBUG_ANIM) Log.v(TAG, "Loading animations: params package=" |
| 1741 | + (lp != null ? lp.packageName : null) |
| 1742 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 1743 | if (lp != null && lp.windowAnimations != 0) { |
| 1744 | // If this is a system resource, don't try to load it from the |
| 1745 | // application resources. It is nice to avoid loading application |
| 1746 | // resources if we can. |
| 1747 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 1748 | int resId = lp.windowAnimations; |
| 1749 | if ((resId&0xFF000000) == 0x01000000) { |
| 1750 | packageName = "android"; |
| 1751 | } |
| 1752 | if (DEBUG_ANIM) Log.v(TAG, "Loading animations: picked package=" |
| 1753 | + packageName); |
| 1754 | return AttributeCache.instance().get(packageName, resId, |
| 1755 | com.android.internal.R.styleable.WindowAnimation); |
| 1756 | } |
| 1757 | return null; |
| 1758 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1759 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1760 | private void applyEnterAnimationLocked(WindowState win) { |
| 1761 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 1762 | if (win.mEnterAnimationPending) { |
| 1763 | win.mEnterAnimationPending = false; |
| 1764 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 1765 | } |
| 1766 | |
| 1767 | applyAnimationLocked(win, transit, true); |
| 1768 | } |
| 1769 | |
| 1770 | private boolean applyAnimationLocked(WindowState win, |
| 1771 | int transit, boolean isEntrance) { |
| 1772 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 1773 | // If we are trying to apply an animation, but already running |
| 1774 | // an animation of the same type, then just leave that one alone. |
| 1775 | return true; |
| 1776 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1777 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1778 | // Only apply an animation if the display isn't frozen. If it is |
| 1779 | // frozen, there is no reason to animate and it can cause strange |
| 1780 | // artifacts when we unfreeze the display if some different animation |
| 1781 | // is running. |
| 1782 | if (!mDisplayFrozen) { |
| 1783 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 1784 | int attr = -1; |
| 1785 | Animation a = null; |
| 1786 | if (anim != 0) { |
| 1787 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 1788 | } else { |
| 1789 | switch (transit) { |
| 1790 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 1791 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 1792 | break; |
| 1793 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 1794 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 1795 | break; |
| 1796 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 1797 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 1798 | break; |
| 1799 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 1800 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 1801 | break; |
| 1802 | } |
| 1803 | if (attr >= 0) { |
| 1804 | a = loadAnimation(win.mAttrs, attr); |
| 1805 | } |
| 1806 | } |
| 1807 | if (DEBUG_ANIM) Log.v(TAG, "applyAnimation: win=" + win |
| 1808 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 1809 | + " mAnimation=" + win.mAnimation |
| 1810 | + " isEntrance=" + isEntrance); |
| 1811 | if (a != null) { |
| 1812 | if (DEBUG_ANIM) { |
| 1813 | RuntimeException e = new RuntimeException(); |
| 1814 | e.fillInStackTrace(); |
| 1815 | Log.v(TAG, "Loaded animation " + a + " for " + win, e); |
| 1816 | } |
| 1817 | win.setAnimation(a); |
| 1818 | win.mAnimationIsEntrance = isEntrance; |
| 1819 | } |
| 1820 | } else { |
| 1821 | win.clearAnimation(); |
| 1822 | } |
| 1823 | |
| 1824 | return win.mAnimation != null; |
| 1825 | } |
| 1826 | |
| 1827 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 1828 | int anim = 0; |
| 1829 | Context context = mContext; |
| 1830 | if (animAttr >= 0) { |
| 1831 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 1832 | if (ent != null) { |
| 1833 | context = ent.context; |
| 1834 | anim = ent.array.getResourceId(animAttr, 0); |
| 1835 | } |
| 1836 | } |
| 1837 | if (anim != 0) { |
| 1838 | return AnimationUtils.loadAnimation(context, anim); |
| 1839 | } |
| 1840 | return null; |
| 1841 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1842 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1843 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 1844 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 1845 | // Only apply an animation if the display isn't frozen. If it is |
| 1846 | // frozen, there is no reason to animate and it can cause strange |
| 1847 | // artifacts when we unfreeze the display if some different animation |
| 1848 | // is running. |
| 1849 | if (!mDisplayFrozen) { |
| 1850 | int animAttr = 0; |
| 1851 | switch (transit) { |
| 1852 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 1853 | animAttr = enter |
| 1854 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 1855 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 1856 | break; |
| 1857 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 1858 | animAttr = enter |
| 1859 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 1860 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 1861 | break; |
| 1862 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 1863 | animAttr = enter |
| 1864 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 1865 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 1866 | break; |
| 1867 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 1868 | animAttr = enter |
| 1869 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 1870 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 1871 | break; |
| 1872 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 1873 | animAttr = enter |
| 1874 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 1875 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 1876 | break; |
| 1877 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 1878 | animAttr = enter |
| 1879 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
| 1880 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 1881 | break; |
| 1882 | } |
| 1883 | Animation a = loadAnimation(lp, animAttr); |
| 1884 | if (DEBUG_ANIM) Log.v(TAG, "applyAnimation: wtoken=" + wtoken |
| 1885 | + " anim=" + a |
| 1886 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 1887 | + " transit=" + transit); |
| 1888 | if (a != null) { |
| 1889 | if (DEBUG_ANIM) { |
| 1890 | RuntimeException e = new RuntimeException(); |
| 1891 | e.fillInStackTrace(); |
| 1892 | Log.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
| 1893 | } |
| 1894 | wtoken.setAnimation(a); |
| 1895 | } |
| 1896 | } else { |
| 1897 | wtoken.clearAnimation(); |
| 1898 | } |
| 1899 | |
| 1900 | return wtoken.animation != null; |
| 1901 | } |
| 1902 | |
| 1903 | // ------------------------------------------------------------- |
| 1904 | // Application Window Tokens |
| 1905 | // ------------------------------------------------------------- |
| 1906 | |
| 1907 | public void validateAppTokens(List tokens) { |
| 1908 | int v = tokens.size()-1; |
| 1909 | int m = mAppTokens.size()-1; |
| 1910 | while (v >= 0 && m >= 0) { |
| 1911 | AppWindowToken wtoken = mAppTokens.get(m); |
| 1912 | if (wtoken.removed) { |
| 1913 | m--; |
| 1914 | continue; |
| 1915 | } |
| 1916 | if (tokens.get(v) != wtoken.token) { |
| 1917 | Log.w(TAG, "Tokens out of sync: external is " + tokens.get(v) |
| 1918 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 1919 | } |
| 1920 | v--; |
| 1921 | m--; |
| 1922 | } |
| 1923 | while (v >= 0) { |
| 1924 | Log.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v); |
| 1925 | v--; |
| 1926 | } |
| 1927 | while (m >= 0) { |
| 1928 | AppWindowToken wtoken = mAppTokens.get(m); |
| 1929 | if (!wtoken.removed) { |
| 1930 | Log.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
| 1931 | } |
| 1932 | m--; |
| 1933 | } |
| 1934 | } |
| 1935 | |
| 1936 | boolean checkCallingPermission(String permission, String func) { |
| 1937 | // Quick check: if the calling permission is me, it's all okay. |
| 1938 | if (Binder.getCallingPid() == Process.myPid()) { |
| 1939 | return true; |
| 1940 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1941 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1942 | if (mContext.checkCallingPermission(permission) |
| 1943 | == PackageManager.PERMISSION_GRANTED) { |
| 1944 | return true; |
| 1945 | } |
| 1946 | String msg = "Permission Denial: " + func + " from pid=" |
| 1947 | + Binder.getCallingPid() |
| 1948 | + ", uid=" + Binder.getCallingUid() |
| 1949 | + " requires " + permission; |
| 1950 | Log.w(TAG, msg); |
| 1951 | return false; |
| 1952 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1953 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1954 | AppWindowToken findAppWindowToken(IBinder token) { |
| 1955 | WindowToken wtoken = mTokenMap.get(token); |
| 1956 | if (wtoken == null) { |
| 1957 | return null; |
| 1958 | } |
| 1959 | return wtoken.appWindowToken; |
| 1960 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1961 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1962 | public void addWindowToken(IBinder token, int type) { |
| 1963 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 1964 | "addWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 1965 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1966 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1967 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1968 | synchronized(mWindowMap) { |
| 1969 | WindowToken wtoken = mTokenMap.get(token); |
| 1970 | if (wtoken != null) { |
| 1971 | Log.w(TAG, "Attempted to add existing input method token: " + token); |
| 1972 | return; |
| 1973 | } |
| 1974 | wtoken = new WindowToken(token, type, true); |
| 1975 | mTokenMap.put(token, wtoken); |
| 1976 | mTokenList.add(wtoken); |
| 1977 | } |
| 1978 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1979 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1980 | public void removeWindowToken(IBinder token) { |
| 1981 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 1982 | "removeWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 1983 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | final long origId = Binder.clearCallingIdentity(); |
| 1987 | synchronized(mWindowMap) { |
| 1988 | WindowToken wtoken = mTokenMap.remove(token); |
| 1989 | mTokenList.remove(wtoken); |
| 1990 | if (wtoken != null) { |
| 1991 | boolean delayed = false; |
| 1992 | if (!wtoken.hidden) { |
| 1993 | wtoken.hidden = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1994 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1995 | final int N = wtoken.windows.size(); |
| 1996 | boolean changed = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1997 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1998 | for (int i=0; i<N; i++) { |
| 1999 | WindowState win = wtoken.windows.get(i); |
| 2000 | |
| 2001 | if (win.isAnimating()) { |
| 2002 | delayed = true; |
| 2003 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2004 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2005 | if (win.isVisibleNow()) { |
| 2006 | applyAnimationLocked(win, |
| 2007 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 2008 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 2009 | KeyWaiter.RETURN_NOTHING); |
| 2010 | changed = true; |
| 2011 | } |
| 2012 | } |
| 2013 | |
| 2014 | if (changed) { |
| 2015 | mLayoutNeeded = true; |
| 2016 | performLayoutAndPlaceSurfacesLocked(); |
| 2017 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2018 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2019 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2020 | if (delayed) { |
| 2021 | mExitingTokens.add(wtoken); |
| 2022 | } |
| 2023 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2024 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2025 | } else { |
| 2026 | Log.w(TAG, "Attempted to remove non-existing token: " + token); |
| 2027 | } |
| 2028 | } |
| 2029 | Binder.restoreCallingIdentity(origId); |
| 2030 | } |
| 2031 | |
| 2032 | public void addAppToken(int addPos, IApplicationToken token, |
| 2033 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 2034 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2035 | "addAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2036 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2037 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2038 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2039 | synchronized(mWindowMap) { |
| 2040 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 2041 | if (wtoken != null) { |
| 2042 | Log.w(TAG, "Attempted to add existing app token: " + token); |
| 2043 | return; |
| 2044 | } |
| 2045 | wtoken = new AppWindowToken(token); |
| 2046 | wtoken.groupId = groupId; |
| 2047 | wtoken.appFullscreen = fullscreen; |
| 2048 | wtoken.requestedOrientation = requestedOrientation; |
| 2049 | mAppTokens.add(addPos, wtoken); |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 2050 | 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] | 2051 | mTokenMap.put(token.asBinder(), wtoken); |
| 2052 | mTokenList.add(wtoken); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2053 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2054 | // Application tokens start out hidden. |
| 2055 | wtoken.hidden = true; |
| 2056 | wtoken.hiddenRequested = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2057 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2058 | //dump(); |
| 2059 | } |
| 2060 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2061 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2062 | public void setAppGroupId(IBinder token, int groupId) { |
| 2063 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2064 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2065 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | synchronized(mWindowMap) { |
| 2069 | AppWindowToken wtoken = findAppWindowToken(token); |
| 2070 | if (wtoken == null) { |
| 2071 | Log.w(TAG, "Attempted to set group id of non-existing app token: " + token); |
| 2072 | return; |
| 2073 | } |
| 2074 | wtoken.groupId = groupId; |
| 2075 | } |
| 2076 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2077 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2078 | public int getOrientationFromWindowsLocked() { |
| 2079 | int pos = mWindows.size() - 1; |
| 2080 | while (pos >= 0) { |
| 2081 | WindowState wtoken = (WindowState) mWindows.get(pos); |
| 2082 | pos--; |
| 2083 | if (wtoken.mAppToken != null) { |
| 2084 | // We hit an application window. so the orientation will be determined by the |
| 2085 | // app window. No point in continuing further. |
| 2086 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2087 | } |
| 2088 | if (!wtoken.isVisibleLw()) { |
| 2089 | continue; |
| 2090 | } |
| 2091 | int req = wtoken.mAttrs.screenOrientation; |
| 2092 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 2093 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 2094 | continue; |
| 2095 | } else { |
| 2096 | return req; |
| 2097 | } |
| 2098 | } |
| 2099 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2100 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2101 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2102 | public int getOrientationFromAppTokensLocked() { |
| 2103 | int pos = mAppTokens.size() - 1; |
| 2104 | int curGroup = 0; |
| 2105 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2106 | boolean findingBehind = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2107 | boolean haveGroup = false; |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2108 | boolean lastFullscreen = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2109 | while (pos >= 0) { |
| 2110 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 2111 | pos--; |
| Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2112 | // if we're about to tear down this window and not seek for |
| 2113 | // the behind activity, don't use it for orientation |
| 2114 | if (!findingBehind |
| 2115 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2116 | continue; |
| 2117 | } |
| 2118 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2119 | if (!haveGroup) { |
| 2120 | // We ignore any hidden applications on the top. |
| 2121 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
| 2122 | continue; |
| 2123 | } |
| 2124 | haveGroup = true; |
| 2125 | curGroup = wtoken.groupId; |
| 2126 | lastOrientation = wtoken.requestedOrientation; |
| 2127 | } else if (curGroup != wtoken.groupId) { |
| 2128 | // If we have hit a new application group, and the bottom |
| 2129 | // 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] | 2130 | // the orientation behind it, and the last app was |
| 2131 | // full screen, then we'll stick with the |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2132 | // user's orientation. |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2133 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 2134 | && lastFullscreen) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2135 | return lastOrientation; |
| 2136 | } |
| 2137 | } |
| 2138 | int or = wtoken.requestedOrientation; |
| Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2139 | // If this application is fullscreen, and didn't explicitly say |
| 2140 | // 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] | 2141 | // orientation it has and ignores whatever is under it. |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2142 | lastFullscreen = wtoken.appFullscreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2143 | if (lastFullscreen |
| Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2144 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2145 | return or; |
| 2146 | } |
| 2147 | // If this application has requested an explicit orientation, |
| 2148 | // then use it. |
| 2149 | if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || |
| 2150 | or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || |
| 2151 | or == ActivityInfo.SCREEN_ORIENTATION_SENSOR || |
| 2152 | or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR || |
| 2153 | or == ActivityInfo.SCREEN_ORIENTATION_USER) { |
| 2154 | return or; |
| 2155 | } |
| Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2156 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2157 | } |
| 2158 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2159 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2160 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2161 | public Configuration updateOrientationFromAppTokens( |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2162 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2163 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2164 | "updateOrientationFromAppTokens()")) { |
| 2165 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 2166 | } |
| 2167 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2168 | Configuration config; |
| 2169 | long ident = Binder.clearCallingIdentity(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2170 | config = updateOrientationFromAppTokensUnchecked(currentConfig, |
| 2171 | freezeThisOneIfNeeded); |
| 2172 | Binder.restoreCallingIdentity(ident); |
| 2173 | return config; |
| 2174 | } |
| 2175 | |
| 2176 | Configuration updateOrientationFromAppTokensUnchecked( |
| 2177 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| 2178 | Configuration config; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2179 | synchronized(mWindowMap) { |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2180 | config = updateOrientationFromAppTokensLocked(currentConfig, freezeThisOneIfNeeded); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2181 | } |
| 2182 | if (config != null) { |
| 2183 | mLayoutNeeded = true; |
| 2184 | performLayoutAndPlaceSurfacesLocked(); |
| 2185 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2186 | return config; |
| 2187 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2188 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2189 | /* |
| 2190 | * The orientation is computed from non-application windows first. If none of |
| 2191 | * the non-application windows specify orientation, the orientation is computed from |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2192 | * application tokens. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2193 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 2194 | * android.os.IBinder) |
| 2195 | */ |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2196 | Configuration updateOrientationFromAppTokensLocked( |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2197 | Configuration appConfig, IBinder freezeThisOneIfNeeded) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2198 | boolean changed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2199 | long ident = Binder.clearCallingIdentity(); |
| 2200 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2201 | int req = computeForcedAppOrientationLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2202 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2203 | if (req != mForcedAppOrientation) { |
| 2204 | changed = true; |
| 2205 | mForcedAppOrientation = req; |
| 2206 | //send a message to Policy indicating orientation change to take |
| 2207 | //action like disabling/enabling sensors etc., |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2208 | mPolicy.setCurrentOrientationLw(req); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2209 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2210 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2211 | if (changed) { |
| 2212 | changed = setRotationUncheckedLocked( |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 2213 | WindowManagerPolicy.USE_LAST_ROTATION, |
| 2214 | mLastRotationFlags & (~Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2215 | if (changed) { |
| 2216 | if (freezeThisOneIfNeeded != null) { |
| 2217 | AppWindowToken wtoken = findAppWindowToken( |
| 2218 | freezeThisOneIfNeeded); |
| 2219 | if (wtoken != null) { |
| 2220 | startAppFreezingScreenLocked(wtoken, |
| 2221 | ActivityInfo.CONFIG_ORIENTATION); |
| 2222 | } |
| 2223 | } |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 2224 | return computeNewConfigurationLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2225 | } |
| 2226 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2227 | |
| 2228 | // No obvious action we need to take, but if our current |
| 2229 | // state mismatches the activity maanager's, update it |
| 2230 | if (appConfig != null) { |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 2231 | mTempConfiguration.setToDefaults(); |
| 2232 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 2233 | if (appConfig.diff(mTempConfiguration) != 0) { |
| 2234 | Log.i(TAG, "Config changed: " + mTempConfiguration); |
| 2235 | return new Configuration(mTempConfiguration); |
| 2236 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2237 | } |
| 2238 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2239 | } finally { |
| 2240 | Binder.restoreCallingIdentity(ident); |
| 2241 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2242 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2243 | return null; |
| 2244 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2245 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2246 | int computeForcedAppOrientationLocked() { |
| 2247 | int req = getOrientationFromWindowsLocked(); |
| 2248 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 2249 | req = getOrientationFromAppTokensLocked(); |
| 2250 | } |
| 2251 | return req; |
| 2252 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2253 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2254 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 2255 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2256 | "setAppOrientation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2257 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | synchronized(mWindowMap) { |
| 2261 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 2262 | if (wtoken == null) { |
| 2263 | Log.w(TAG, "Attempted to set orientation of non-existing app token: " + token); |
| 2264 | return; |
| 2265 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2266 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2267 | wtoken.requestedOrientation = requestedOrientation; |
| 2268 | } |
| 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 int getAppOrientation(IApplicationToken token) { |
| 2272 | synchronized(mWindowMap) { |
| 2273 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 2274 | if (wtoken == null) { |
| 2275 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2276 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2277 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2278 | return wtoken.requestedOrientation; |
| 2279 | } |
| 2280 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2281 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2282 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 2283 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2284 | "setFocusedApp()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2285 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2286 | } |
| 2287 | |
| 2288 | synchronized(mWindowMap) { |
| 2289 | boolean changed = false; |
| 2290 | if (token == null) { |
| 2291 | if (DEBUG_FOCUS) Log.v(TAG, "Clearing focused app, was " + mFocusedApp); |
| 2292 | changed = mFocusedApp != null; |
| 2293 | mFocusedApp = null; |
| 2294 | mKeyWaiter.tickle(); |
| 2295 | } else { |
| 2296 | AppWindowToken newFocus = findAppWindowToken(token); |
| 2297 | if (newFocus == null) { |
| 2298 | Log.w(TAG, "Attempted to set focus to non-existing app token: " + token); |
| 2299 | return; |
| 2300 | } |
| 2301 | changed = mFocusedApp != newFocus; |
| 2302 | mFocusedApp = newFocus; |
| 2303 | if (DEBUG_FOCUS) Log.v(TAG, "Set focused app to: " + mFocusedApp); |
| 2304 | mKeyWaiter.tickle(); |
| 2305 | } |
| 2306 | |
| 2307 | if (moveFocusNow && changed) { |
| 2308 | final long origId = Binder.clearCallingIdentity(); |
| 2309 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2310 | Binder.restoreCallingIdentity(origId); |
| 2311 | } |
| 2312 | } |
| 2313 | } |
| 2314 | |
| 2315 | public void prepareAppTransition(int transit) { |
| 2316 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2317 | "prepareAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2318 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2319 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2320 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2321 | synchronized(mWindowMap) { |
| 2322 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 2323 | TAG, "Prepare app transition: transit=" + transit |
| 2324 | + " mNextAppTransition=" + mNextAppTransition); |
| 2325 | if (!mDisplayFrozen) { |
| 2326 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
| 2327 | mNextAppTransition = transit; |
| Dianne Hackborn | d7cd29d | 2009-07-01 11:22:45 -0700 | [diff] [blame] | 2328 | } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 2329 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 2330 | // Opening a new task always supersedes a close for the anim. |
| 2331 | mNextAppTransition = transit; |
| 2332 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 2333 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 2334 | // Opening a new activity always supersedes a close for the anim. |
| 2335 | mNextAppTransition = transit; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2336 | } |
| 2337 | mAppTransitionReady = false; |
| 2338 | mAppTransitionTimeout = false; |
| 2339 | mStartingIconInTransition = false; |
| 2340 | mSkipAppTransitionAnimation = false; |
| 2341 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 2342 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 2343 | 5000); |
| 2344 | } |
| 2345 | } |
| 2346 | } |
| 2347 | |
| 2348 | public int getPendingAppTransition() { |
| 2349 | return mNextAppTransition; |
| 2350 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2351 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2352 | public void executeAppTransition() { |
| 2353 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2354 | "executeAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2355 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2356 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2357 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2358 | synchronized(mWindowMap) { |
| 2359 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 2360 | TAG, "Execute app transition: mNextAppTransition=" + mNextAppTransition); |
| 2361 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) { |
| 2362 | mAppTransitionReady = true; |
| 2363 | final long origId = Binder.clearCallingIdentity(); |
| 2364 | performLayoutAndPlaceSurfacesLocked(); |
| 2365 | Binder.restoreCallingIdentity(origId); |
| 2366 | } |
| 2367 | } |
| 2368 | } |
| 2369 | |
| 2370 | public void setAppStartingWindow(IBinder token, String pkg, |
| 2371 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| 2372 | IBinder transferFrom, boolean createIfNeeded) { |
| 2373 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2374 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2375 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2376 | } |
| 2377 | |
| 2378 | synchronized(mWindowMap) { |
| 2379 | if (DEBUG_STARTING_WINDOW) Log.v( |
| 2380 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 2381 | + " transferFrom=" + transferFrom); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2382 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2383 | AppWindowToken wtoken = findAppWindowToken(token); |
| 2384 | if (wtoken == null) { |
| 2385 | Log.w(TAG, "Attempted to set icon of non-existing app token: " + token); |
| 2386 | return; |
| 2387 | } |
| 2388 | |
| 2389 | // If the display is frozen, we won't do anything until the |
| 2390 | // actual window is displayed so there is no reason to put in |
| 2391 | // the starting window. |
| 2392 | if (mDisplayFrozen) { |
| 2393 | return; |
| 2394 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2395 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2396 | if (wtoken.startingData != null) { |
| 2397 | return; |
| 2398 | } |
| 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 | if (transferFrom != null) { |
| 2401 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 2402 | if (ttoken != null) { |
| 2403 | WindowState startingWindow = ttoken.startingWindow; |
| 2404 | if (startingWindow != null) { |
| 2405 | if (mStartingIconInTransition) { |
| 2406 | // In this case, the starting icon has already |
| 2407 | // been displayed, so start letting windows get |
| 2408 | // shown immediately without any more transitions. |
| 2409 | mSkipAppTransitionAnimation = true; |
| 2410 | } |
| 2411 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 2412 | "Moving existing starting from " + ttoken |
| 2413 | + " to " + wtoken); |
| 2414 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2415 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2416 | // Transfer the starting window over to the new |
| 2417 | // token. |
| 2418 | wtoken.startingData = ttoken.startingData; |
| 2419 | wtoken.startingView = ttoken.startingView; |
| 2420 | wtoken.startingWindow = startingWindow; |
| 2421 | ttoken.startingData = null; |
| 2422 | ttoken.startingView = null; |
| 2423 | ttoken.startingWindow = null; |
| 2424 | ttoken.startingMoved = true; |
| 2425 | startingWindow.mToken = wtoken; |
| Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 2426 | startingWindow.mRootToken = wtoken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2427 | startingWindow.mAppToken = wtoken; |
| 2428 | mWindows.remove(startingWindow); |
| 2429 | ttoken.windows.remove(startingWindow); |
| 2430 | ttoken.allAppWindows.remove(startingWindow); |
| 2431 | addWindowToListInOrderLocked(startingWindow, true); |
| 2432 | wtoken.allAppWindows.add(startingWindow); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2433 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2434 | // Propagate other interesting state between the |
| 2435 | // tokens. If the old token is displayed, we should |
| 2436 | // immediately force the new one to be displayed. If |
| 2437 | // it is animating, we need to move that animation to |
| 2438 | // the new one. |
| 2439 | if (ttoken.allDrawn) { |
| 2440 | wtoken.allDrawn = true; |
| 2441 | } |
| 2442 | if (ttoken.firstWindowDrawn) { |
| 2443 | wtoken.firstWindowDrawn = true; |
| 2444 | } |
| 2445 | if (!ttoken.hidden) { |
| 2446 | wtoken.hidden = false; |
| 2447 | wtoken.hiddenRequested = false; |
| 2448 | wtoken.willBeHidden = false; |
| 2449 | } |
| 2450 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 2451 | wtoken.clientHidden = ttoken.clientHidden; |
| 2452 | wtoken.sendAppVisibilityToClients(); |
| 2453 | } |
| 2454 | if (ttoken.animation != null) { |
| 2455 | wtoken.animation = ttoken.animation; |
| 2456 | wtoken.animating = ttoken.animating; |
| 2457 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 2458 | ttoken.animation = null; |
| 2459 | ttoken.animLayerAdjustment = 0; |
| 2460 | wtoken.updateLayers(); |
| 2461 | ttoken.updateLayers(); |
| 2462 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2463 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2464 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2465 | mLayoutNeeded = true; |
| 2466 | performLayoutAndPlaceSurfacesLocked(); |
| 2467 | Binder.restoreCallingIdentity(origId); |
| 2468 | return; |
| 2469 | } else if (ttoken.startingData != null) { |
| 2470 | // The previous app was getting ready to show a |
| 2471 | // starting window, but hasn't yet done so. Steal it! |
| 2472 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 2473 | "Moving pending starting from " + ttoken |
| 2474 | + " to " + wtoken); |
| 2475 | wtoken.startingData = ttoken.startingData; |
| 2476 | ttoken.startingData = null; |
| 2477 | ttoken.startingMoved = true; |
| 2478 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 2479 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 2480 | // want to process the message ASAP, before any other queued |
| 2481 | // messages. |
| 2482 | mH.sendMessageAtFrontOfQueue(m); |
| 2483 | return; |
| 2484 | } |
| 2485 | } |
| 2486 | } |
| 2487 | |
| 2488 | // There is no existing starting window, and the caller doesn't |
| 2489 | // want us to create one, so that's it! |
| 2490 | if (!createIfNeeded) { |
| 2491 | return; |
| 2492 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2493 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2494 | mStartingIconInTransition = true; |
| 2495 | wtoken.startingData = new StartingData( |
| 2496 | pkg, theme, nonLocalizedLabel, |
| 2497 | labelRes, icon); |
| 2498 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 2499 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 2500 | // want to process the message ASAP, before any other queued |
| 2501 | // messages. |
| 2502 | mH.sendMessageAtFrontOfQueue(m); |
| 2503 | } |
| 2504 | } |
| 2505 | |
| 2506 | public void setAppWillBeHidden(IBinder token) { |
| 2507 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2508 | "setAppWillBeHidden()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2509 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2510 | } |
| 2511 | |
| 2512 | AppWindowToken wtoken; |
| 2513 | |
| 2514 | synchronized(mWindowMap) { |
| 2515 | wtoken = findAppWindowToken(token); |
| 2516 | if (wtoken == null) { |
| 2517 | Log.w(TAG, "Attempted to set will be hidden of non-existing app token: " + token); |
| 2518 | return; |
| 2519 | } |
| 2520 | wtoken.willBeHidden = true; |
| 2521 | } |
| 2522 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2523 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2524 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 2525 | boolean visible, int transit, boolean performLayout) { |
| 2526 | boolean delayed = false; |
| 2527 | |
| 2528 | if (wtoken.clientHidden == visible) { |
| 2529 | wtoken.clientHidden = !visible; |
| 2530 | wtoken.sendAppVisibilityToClients(); |
| 2531 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2532 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2533 | wtoken.willBeHidden = false; |
| 2534 | if (wtoken.hidden == visible) { |
| 2535 | final int N = wtoken.allAppWindows.size(); |
| 2536 | boolean changed = false; |
| 2537 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 2538 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 2539 | + " performLayout=" + performLayout); |
| 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 runningAppAnimation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2542 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2543 | if (transit != WindowManagerPolicy.TRANSIT_NONE) { |
| 2544 | if (wtoken.animation == sDummyAnimation) { |
| 2545 | wtoken.animation = null; |
| 2546 | } |
| 2547 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 2548 | changed = true; |
| 2549 | if (wtoken.animation != null) { |
| 2550 | delayed = runningAppAnimation = true; |
| 2551 | } |
| 2552 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2553 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2554 | for (int i=0; i<N; i++) { |
| 2555 | WindowState win = wtoken.allAppWindows.get(i); |
| 2556 | if (win == wtoken.startingWindow) { |
| 2557 | continue; |
| 2558 | } |
| 2559 | |
| 2560 | if (win.isAnimating()) { |
| 2561 | delayed = true; |
| 2562 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2563 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2564 | //Log.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
| 2565 | //win.dump(" "); |
| 2566 | if (visible) { |
| 2567 | if (!win.isVisibleNow()) { |
| 2568 | if (!runningAppAnimation) { |
| 2569 | applyAnimationLocked(win, |
| 2570 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 2571 | } |
| 2572 | changed = true; |
| 2573 | } |
| 2574 | } else if (win.isVisibleNow()) { |
| 2575 | if (!runningAppAnimation) { |
| 2576 | applyAnimationLocked(win, |
| 2577 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 2578 | } |
| 2579 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 2580 | KeyWaiter.RETURN_NOTHING); |
| 2581 | changed = true; |
| 2582 | } |
| 2583 | } |
| 2584 | |
| 2585 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 2586 | if (!visible) { |
| 2587 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 2588 | } else { |
| 2589 | // If we are being set visible, and the starting window is |
| 2590 | // not yet displayed, then make sure it doesn't get displayed. |
| 2591 | WindowState swin = wtoken.startingWindow; |
| 2592 | if (swin != null && (swin.mDrawPending |
| 2593 | || swin.mCommitDrawPending)) { |
| 2594 | swin.mPolicyVisibility = false; |
| 2595 | swin.mPolicyVisibilityAfterAnim = false; |
| 2596 | } |
| 2597 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2598 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2599 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "setTokenVisibilityLocked: " + wtoken |
| 2600 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 2601 | + wtoken.hiddenRequested); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2602 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2603 | if (changed && performLayout) { |
| 2604 | mLayoutNeeded = true; |
| 2605 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2606 | performLayoutAndPlaceSurfacesLocked(); |
| 2607 | } |
| 2608 | } |
| 2609 | |
| 2610 | if (wtoken.animation != null) { |
| 2611 | delayed = true; |
| 2612 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2613 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2614 | return delayed; |
| 2615 | } |
| 2616 | |
| 2617 | public void setAppVisibility(IBinder token, boolean visible) { |
| 2618 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2619 | "setAppVisibility()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2620 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2621 | } |
| 2622 | |
| 2623 | AppWindowToken wtoken; |
| 2624 | |
| 2625 | synchronized(mWindowMap) { |
| 2626 | wtoken = findAppWindowToken(token); |
| 2627 | if (wtoken == null) { |
| 2628 | Log.w(TAG, "Attempted to set visibility of non-existing app token: " + token); |
| 2629 | return; |
| 2630 | } |
| 2631 | |
| 2632 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
| 2633 | RuntimeException e = new RuntimeException(); |
| 2634 | e.fillInStackTrace(); |
| 2635 | Log.v(TAG, "setAppVisibility(" + token + ", " + visible |
| 2636 | + "): mNextAppTransition=" + mNextAppTransition |
| 2637 | + " hidden=" + wtoken.hidden |
| 2638 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 2639 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2640 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2641 | // If we are preparing an app transition, then delay changing |
| 2642 | // the visibility of this token until we execute that transition. |
| 2643 | if (!mDisplayFrozen && mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) { |
| 2644 | // Already in requested state, don't do anything more. |
| 2645 | if (wtoken.hiddenRequested != visible) { |
| 2646 | return; |
| 2647 | } |
| 2648 | wtoken.hiddenRequested = !visible; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2649 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2650 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 2651 | TAG, "Setting dummy animation on: " + wtoken); |
| 2652 | wtoken.setDummyAnimation(); |
| 2653 | mOpeningApps.remove(wtoken); |
| 2654 | mClosingApps.remove(wtoken); |
| 2655 | wtoken.inPendingTransaction = true; |
| 2656 | if (visible) { |
| 2657 | mOpeningApps.add(wtoken); |
| 2658 | wtoken.allDrawn = false; |
| 2659 | wtoken.startingDisplayed = false; |
| 2660 | wtoken.startingMoved = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2661 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2662 | if (wtoken.clientHidden) { |
| 2663 | // In the case where we are making an app visible |
| 2664 | // but holding off for a transition, we still need |
| 2665 | // to tell the client to make its windows visible so |
| 2666 | // they get drawn. Otherwise, we will wait on |
| 2667 | // performing the transition until all windows have |
| 2668 | // been drawn, they never will be, and we are sad. |
| 2669 | wtoken.clientHidden = false; |
| 2670 | wtoken.sendAppVisibilityToClients(); |
| 2671 | } |
| 2672 | } else { |
| 2673 | mClosingApps.add(wtoken); |
| 2674 | } |
| 2675 | return; |
| 2676 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2677 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2678 | final long origId = Binder.clearCallingIdentity(); |
| 2679 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_NONE, true); |
| 2680 | wtoken.updateReportedVisibilityLocked(); |
| 2681 | Binder.restoreCallingIdentity(origId); |
| 2682 | } |
| 2683 | } |
| 2684 | |
| 2685 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 2686 | boolean unfreezeSurfaceNow, boolean force) { |
| 2687 | if (wtoken.freezingScreen) { |
| 2688 | if (DEBUG_ORIENTATION) Log.v(TAG, "Clear freezing of " + wtoken |
| 2689 | + " force=" + force); |
| 2690 | final int N = wtoken.allAppWindows.size(); |
| 2691 | boolean unfrozeWindows = false; |
| 2692 | for (int i=0; i<N; i++) { |
| 2693 | WindowState w = wtoken.allAppWindows.get(i); |
| 2694 | if (w.mAppFreezing) { |
| 2695 | w.mAppFreezing = false; |
| 2696 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 2697 | w.mOrientationChanging = true; |
| 2698 | } |
| 2699 | unfrozeWindows = true; |
| 2700 | } |
| 2701 | } |
| 2702 | if (force || unfrozeWindows) { |
| 2703 | if (DEBUG_ORIENTATION) Log.v(TAG, "No longer freezing: " + wtoken); |
| 2704 | wtoken.freezingScreen = false; |
| 2705 | mAppsFreezingScreen--; |
| 2706 | } |
| 2707 | if (unfreezeSurfaceNow) { |
| 2708 | if (unfrozeWindows) { |
| 2709 | mLayoutNeeded = true; |
| 2710 | performLayoutAndPlaceSurfacesLocked(); |
| 2711 | } |
| 2712 | if (mAppsFreezingScreen == 0 && !mWindowsFreezingScreen) { |
| 2713 | stopFreezingDisplayLocked(); |
| 2714 | } |
| 2715 | } |
| 2716 | } |
| 2717 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2718 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2719 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 2720 | int configChanges) { |
| 2721 | if (DEBUG_ORIENTATION) { |
| 2722 | RuntimeException e = new RuntimeException(); |
| 2723 | e.fillInStackTrace(); |
| 2724 | Log.i(TAG, "Set freezing of " + wtoken.appToken |
| 2725 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 2726 | + wtoken.freezingScreen, e); |
| 2727 | } |
| 2728 | if (!wtoken.hiddenRequested) { |
| 2729 | if (!wtoken.freezingScreen) { |
| 2730 | wtoken.freezingScreen = true; |
| 2731 | mAppsFreezingScreen++; |
| 2732 | if (mAppsFreezingScreen == 1) { |
| 2733 | startFreezingDisplayLocked(); |
| 2734 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 2735 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 2736 | 5000); |
| 2737 | } |
| 2738 | } |
| 2739 | final int N = wtoken.allAppWindows.size(); |
| 2740 | for (int i=0; i<N; i++) { |
| 2741 | WindowState w = wtoken.allAppWindows.get(i); |
| 2742 | w.mAppFreezing = true; |
| 2743 | } |
| 2744 | } |
| 2745 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2746 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2747 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 2748 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2749 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2750 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2751 | } |
| 2752 | |
| 2753 | synchronized(mWindowMap) { |
| 2754 | if (configChanges == 0 && !mDisplayFrozen) { |
| 2755 | if (DEBUG_ORIENTATION) Log.v(TAG, "Skipping set freeze of " + token); |
| 2756 | return; |
| 2757 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2758 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2759 | AppWindowToken wtoken = findAppWindowToken(token); |
| 2760 | if (wtoken == null || wtoken.appToken == null) { |
| 2761 | Log.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken); |
| 2762 | return; |
| 2763 | } |
| 2764 | final long origId = Binder.clearCallingIdentity(); |
| 2765 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 2766 | Binder.restoreCallingIdentity(origId); |
| 2767 | } |
| 2768 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2769 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2770 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 2771 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2772 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2773 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2774 | } |
| 2775 | |
| 2776 | synchronized(mWindowMap) { |
| 2777 | AppWindowToken wtoken = findAppWindowToken(token); |
| 2778 | if (wtoken == null || wtoken.appToken == null) { |
| 2779 | return; |
| 2780 | } |
| 2781 | final long origId = Binder.clearCallingIdentity(); |
| 2782 | if (DEBUG_ORIENTATION) Log.v(TAG, "Clear freezing of " + token |
| 2783 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 2784 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 2785 | Binder.restoreCallingIdentity(origId); |
| 2786 | } |
| 2787 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2788 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2789 | public void removeAppToken(IBinder token) { |
| 2790 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2791 | "removeAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2792 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2793 | } |
| 2794 | |
| 2795 | AppWindowToken wtoken = null; |
| 2796 | AppWindowToken startingToken = null; |
| 2797 | boolean delayed = false; |
| 2798 | |
| 2799 | final long origId = Binder.clearCallingIdentity(); |
| 2800 | synchronized(mWindowMap) { |
| 2801 | WindowToken basewtoken = mTokenMap.remove(token); |
| 2802 | mTokenList.remove(basewtoken); |
| 2803 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
| 2804 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "Removing app token: " + wtoken); |
| 2805 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_NONE, true); |
| 2806 | wtoken.inPendingTransaction = false; |
| 2807 | mOpeningApps.remove(wtoken); |
| 2808 | if (mClosingApps.contains(wtoken)) { |
| 2809 | delayed = true; |
| 2810 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) { |
| 2811 | mClosingApps.add(wtoken); |
| 2812 | delayed = true; |
| 2813 | } |
| 2814 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 2815 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 2816 | + " animation=" + wtoken.animation |
| 2817 | + " animating=" + wtoken.animating); |
| 2818 | if (delayed) { |
| 2819 | // set the token aside because it has an active animation to be finished |
| 2820 | mExitingAppTokens.add(wtoken); |
| 2821 | } |
| 2822 | mAppTokens.remove(wtoken); |
| 2823 | wtoken.removed = true; |
| 2824 | if (wtoken.startingData != null) { |
| 2825 | startingToken = wtoken; |
| 2826 | } |
| 2827 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 2828 | if (mFocusedApp == wtoken) { |
| 2829 | if (DEBUG_FOCUS) Log.v(TAG, "Removing focused app token:" + wtoken); |
| 2830 | mFocusedApp = null; |
| 2831 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2832 | mKeyWaiter.tickle(); |
| 2833 | } |
| 2834 | } else { |
| 2835 | Log.w(TAG, "Attempted to remove non-existing app token: " + token); |
| 2836 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2837 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2838 | if (!delayed && wtoken != null) { |
| 2839 | wtoken.updateReportedVisibilityLocked(); |
| 2840 | } |
| 2841 | } |
| 2842 | Binder.restoreCallingIdentity(origId); |
| 2843 | |
| 2844 | if (startingToken != null) { |
| 2845 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Schedule remove starting " |
| 2846 | + startingToken + ": app token removed"); |
| 2847 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 2848 | mH.sendMessage(m); |
| 2849 | } |
| 2850 | } |
| 2851 | |
| 2852 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 2853 | final int NW = token.windows.size(); |
| 2854 | for (int i=0; i<NW; i++) { |
| 2855 | WindowState win = token.windows.get(i); |
| 2856 | mWindows.remove(win); |
| 2857 | int j = win.mChildWindows.size(); |
| 2858 | while (j > 0) { |
| 2859 | j--; |
| 2860 | mWindows.remove(win.mChildWindows.get(j)); |
| 2861 | } |
| 2862 | } |
| 2863 | return NW > 0; |
| 2864 | } |
| 2865 | |
| 2866 | void dumpAppTokensLocked() { |
| 2867 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| 2868 | Log.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
| 2869 | } |
| 2870 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2871 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2872 | void dumpWindowsLocked() { |
| 2873 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 2874 | Log.v(TAG, " #" + i + ": " + mWindows.get(i)); |
| 2875 | } |
| 2876 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2877 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2878 | private int findWindowOffsetLocked(int tokenPos) { |
| 2879 | final int NW = mWindows.size(); |
| 2880 | |
| 2881 | if (tokenPos >= mAppTokens.size()) { |
| 2882 | int i = NW; |
| 2883 | while (i > 0) { |
| 2884 | i--; |
| 2885 | WindowState win = (WindowState)mWindows.get(i); |
| 2886 | if (win.getAppToken() != null) { |
| 2887 | return i+1; |
| 2888 | } |
| 2889 | } |
| 2890 | } |
| 2891 | |
| 2892 | while (tokenPos > 0) { |
| 2893 | // Find the first app token below the new position that has |
| 2894 | // a window displayed. |
| 2895 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
| 2896 | if (DEBUG_REORDER) Log.v(TAG, "Looking for lower windows @ " |
| 2897 | + tokenPos + " -- " + wtoken.token); |
| 2898 | int i = wtoken.windows.size(); |
| 2899 | while (i > 0) { |
| 2900 | i--; |
| 2901 | WindowState win = wtoken.windows.get(i); |
| 2902 | int j = win.mChildWindows.size(); |
| 2903 | while (j > 0) { |
| 2904 | j--; |
| 2905 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| 2906 | if (cwin.mSubLayer >= 0 ) { |
| 2907 | for (int pos=NW-1; pos>=0; pos--) { |
| 2908 | if (mWindows.get(pos) == cwin) { |
| 2909 | if (DEBUG_REORDER) Log.v(TAG, |
| 2910 | "Found child win @" + (pos+1)); |
| 2911 | return pos+1; |
| 2912 | } |
| 2913 | } |
| 2914 | } |
| 2915 | } |
| 2916 | for (int pos=NW-1; pos>=0; pos--) { |
| 2917 | if (mWindows.get(pos) == win) { |
| 2918 | if (DEBUG_REORDER) Log.v(TAG, "Found win @" + (pos+1)); |
| 2919 | return pos+1; |
| 2920 | } |
| 2921 | } |
| 2922 | } |
| 2923 | tokenPos--; |
| 2924 | } |
| 2925 | |
| 2926 | return 0; |
| 2927 | } |
| 2928 | |
| 2929 | private final int reAddWindowLocked(int index, WindowState win) { |
| 2930 | final int NCW = win.mChildWindows.size(); |
| 2931 | boolean added = false; |
| 2932 | for (int j=0; j<NCW; j++) { |
| 2933 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| 2934 | if (!added && cwin.mSubLayer >= 0) { |
| 2935 | mWindows.add(index, win); |
| 2936 | index++; |
| 2937 | added = true; |
| 2938 | } |
| 2939 | mWindows.add(index, cwin); |
| 2940 | index++; |
| 2941 | } |
| 2942 | if (!added) { |
| 2943 | mWindows.add(index, win); |
| 2944 | index++; |
| 2945 | } |
| 2946 | return index; |
| 2947 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2948 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2949 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 2950 | final int NW = token.windows.size(); |
| 2951 | for (int i=0; i<NW; i++) { |
| 2952 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 2953 | } |
| 2954 | return index; |
| 2955 | } |
| 2956 | |
| 2957 | public void moveAppToken(int index, IBinder token) { |
| 2958 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2959 | "moveAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2960 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2961 | } |
| 2962 | |
| 2963 | synchronized(mWindowMap) { |
| 2964 | if (DEBUG_REORDER) Log.v(TAG, "Initial app tokens:"); |
| 2965 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 2966 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 2967 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
| 2968 | Log.w(TAG, "Attempting to reorder token that doesn't exist: " |
| 2969 | + token + " (" + wtoken + ")"); |
| 2970 | return; |
| 2971 | } |
| 2972 | mAppTokens.add(index, wtoken); |
| 2973 | if (DEBUG_REORDER) Log.v(TAG, "Moved " + token + " to " + index + ":"); |
| 2974 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2975 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2976 | final long origId = Binder.clearCallingIdentity(); |
| 2977 | if (DEBUG_REORDER) Log.v(TAG, "Removing windows in " + token + ":"); |
| 2978 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 2979 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
| 2980 | if (DEBUG_REORDER) Log.v(TAG, "Adding windows back in:"); |
| 2981 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 2982 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
| 2983 | if (DEBUG_REORDER) Log.v(TAG, "Final window list:"); |
| 2984 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 2985 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2986 | mLayoutNeeded = true; |
| 2987 | performLayoutAndPlaceSurfacesLocked(); |
| 2988 | } |
| 2989 | Binder.restoreCallingIdentity(origId); |
| 2990 | } |
| 2991 | } |
| 2992 | |
| 2993 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 2994 | // XXX This should be done more efficiently! |
| 2995 | // (take advantage of the fact that both lists should be |
| 2996 | // ordered in the same way.) |
| 2997 | int N = tokens.size(); |
| 2998 | for (int i=0; i<N; i++) { |
| 2999 | IBinder token = tokens.get(i); |
| 3000 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 3001 | if (!mAppTokens.remove(wtoken)) { |
| 3002 | Log.w(TAG, "Attempting to reorder token that doesn't exist: " |
| 3003 | + token + " (" + wtoken + ")"); |
| 3004 | i--; |
| 3005 | N--; |
| 3006 | } |
| 3007 | } |
| 3008 | } |
| 3009 | |
| 3010 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 3011 | // First remove all of the windows from the list. |
| 3012 | final int N = tokens.size(); |
| 3013 | int i; |
| 3014 | for (i=0; i<N; i++) { |
| 3015 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 3016 | if (token != null) { |
| 3017 | tmpRemoveAppWindowsLocked(token); |
| 3018 | } |
| 3019 | } |
| 3020 | |
| 3021 | // Where to start adding? |
| 3022 | int pos = findWindowOffsetLocked(tokenPos); |
| 3023 | |
| 3024 | // And now add them back at the correct place. |
| 3025 | for (i=0; i<N; i++) { |
| 3026 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 3027 | if (token != null) { |
| 3028 | pos = reAddAppWindowsLocked(pos, token); |
| 3029 | } |
| 3030 | } |
| 3031 | |
| 3032 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3033 | mLayoutNeeded = true; |
| 3034 | performLayoutAndPlaceSurfacesLocked(); |
| 3035 | |
| 3036 | //dump(); |
| 3037 | } |
| 3038 | |
| 3039 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 3040 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3041 | "moveAppTokensToTop()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3042 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3043 | } |
| 3044 | |
| 3045 | final long origId = Binder.clearCallingIdentity(); |
| 3046 | synchronized(mWindowMap) { |
| 3047 | removeAppTokensLocked(tokens); |
| 3048 | final int N = tokens.size(); |
| 3049 | for (int i=0; i<N; i++) { |
| 3050 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 3051 | if (wt != null) { |
| 3052 | mAppTokens.add(wt); |
| 3053 | } |
| 3054 | } |
| 3055 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 3056 | } |
| 3057 | Binder.restoreCallingIdentity(origId); |
| 3058 | } |
| 3059 | |
| 3060 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 3061 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3062 | "moveAppTokensToBottom()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3063 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3064 | } |
| 3065 | |
| 3066 | final long origId = Binder.clearCallingIdentity(); |
| 3067 | synchronized(mWindowMap) { |
| 3068 | removeAppTokensLocked(tokens); |
| 3069 | final int N = tokens.size(); |
| 3070 | int pos = 0; |
| 3071 | for (int i=0; i<N; i++) { |
| 3072 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 3073 | if (wt != null) { |
| 3074 | mAppTokens.add(pos, wt); |
| 3075 | pos++; |
| 3076 | } |
| 3077 | } |
| 3078 | moveAppWindowsLocked(tokens, 0); |
| 3079 | } |
| 3080 | Binder.restoreCallingIdentity(origId); |
| 3081 | } |
| 3082 | |
| 3083 | // ------------------------------------------------------------- |
| 3084 | // Misc IWindowSession methods |
| 3085 | // ------------------------------------------------------------- |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3086 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3087 | public void disableKeyguard(IBinder token, String tag) { |
| 3088 | if (mContext.checkCallingPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| 3089 | != PackageManager.PERMISSION_GRANTED) { |
| 3090 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 3091 | } |
| 3092 | mKeyguardDisabled.acquire(token, tag); |
| 3093 | } |
| 3094 | |
| 3095 | public void reenableKeyguard(IBinder token) { |
| 3096 | if (mContext.checkCallingPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| 3097 | != PackageManager.PERMISSION_GRANTED) { |
| 3098 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 3099 | } |
| 3100 | synchronized (mKeyguardDisabled) { |
| 3101 | mKeyguardDisabled.release(token); |
| 3102 | |
| 3103 | if (!mKeyguardDisabled.isAcquired()) { |
| 3104 | // if we are the last one to reenable the keyguard wait until |
| 3105 | // we have actaully finished reenabling until returning |
| 3106 | mWaitingUntilKeyguardReenabled = true; |
| 3107 | while (mWaitingUntilKeyguardReenabled) { |
| 3108 | try { |
| 3109 | mKeyguardDisabled.wait(); |
| 3110 | } catch (InterruptedException e) { |
| 3111 | Thread.currentThread().interrupt(); |
| 3112 | } |
| 3113 | } |
| 3114 | } |
| 3115 | } |
| 3116 | } |
| 3117 | |
| 3118 | /** |
| 3119 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 3120 | */ |
| 3121 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
| 3122 | if (mContext.checkCallingPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| 3123 | != PackageManager.PERMISSION_GRANTED) { |
| 3124 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 3125 | } |
| 3126 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 3127 | public void onKeyguardExitResult(boolean success) { |
| 3128 | try { |
| 3129 | callback.onKeyguardExitResult(success); |
| 3130 | } catch (RemoteException e) { |
| 3131 | // Client has died, we don't care. |
| 3132 | } |
| 3133 | } |
| 3134 | }); |
| 3135 | } |
| 3136 | |
| 3137 | public boolean inKeyguardRestrictedInputMode() { |
| 3138 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 3139 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3140 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3141 | static float fixScale(float scale) { |
| 3142 | if (scale < 0) scale = 0; |
| 3143 | else if (scale > 20) scale = 20; |
| 3144 | return Math.abs(scale); |
| 3145 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3146 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3147 | public void setAnimationScale(int which, float scale) { |
| 3148 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 3149 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3150 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3151 | } |
| 3152 | |
| 3153 | if (scale < 0) scale = 0; |
| 3154 | else if (scale > 20) scale = 20; |
| 3155 | scale = Math.abs(scale); |
| 3156 | switch (which) { |
| 3157 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 3158 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 3159 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3160 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3161 | // Persist setting |
| 3162 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 3163 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3164 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3165 | public void setAnimationScales(float[] scales) { |
| 3166 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 3167 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3168 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3169 | } |
| 3170 | |
| 3171 | if (scales != null) { |
| 3172 | if (scales.length >= 1) { |
| 3173 | mWindowAnimationScale = fixScale(scales[0]); |
| 3174 | } |
| 3175 | if (scales.length >= 2) { |
| 3176 | mTransitionAnimationScale = fixScale(scales[1]); |
| 3177 | } |
| 3178 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3179 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3180 | // Persist setting |
| 3181 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 3182 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3183 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3184 | public float getAnimationScale(int which) { |
| 3185 | switch (which) { |
| 3186 | case 0: return mWindowAnimationScale; |
| 3187 | case 1: return mTransitionAnimationScale; |
| 3188 | } |
| 3189 | return 0; |
| 3190 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3191 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3192 | public float[] getAnimationScales() { |
| 3193 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 3194 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3195 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3196 | public int getSwitchState(int sw) { |
| 3197 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 3198 | "getSwitchState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3199 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3200 | } |
| 3201 | return KeyInputQueue.getSwitchState(sw); |
| 3202 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3203 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3204 | public int getSwitchStateForDevice(int devid, int sw) { |
| 3205 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 3206 | "getSwitchStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3207 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3208 | } |
| 3209 | return KeyInputQueue.getSwitchState(devid, sw); |
| 3210 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3211 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3212 | public int getScancodeState(int sw) { |
| 3213 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 3214 | "getScancodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3215 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3216 | } |
| 3217 | return KeyInputQueue.getScancodeState(sw); |
| 3218 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3219 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3220 | public int getScancodeStateForDevice(int devid, int sw) { |
| 3221 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 3222 | "getScancodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3223 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3224 | } |
| 3225 | return KeyInputQueue.getScancodeState(devid, sw); |
| 3226 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3227 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3228 | public int getKeycodeState(int sw) { |
| 3229 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 3230 | "getKeycodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3231 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3232 | } |
| 3233 | return KeyInputQueue.getKeycodeState(sw); |
| 3234 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3235 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3236 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 3237 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 3238 | "getKeycodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3239 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3240 | } |
| 3241 | return KeyInputQueue.getKeycodeState(devid, sw); |
| 3242 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3243 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3244 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
| 3245 | return KeyInputQueue.hasKeys(keycodes, keyExists); |
| 3246 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3247 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3248 | public void enableScreenAfterBoot() { |
| 3249 | synchronized(mWindowMap) { |
| 3250 | if (mSystemBooted) { |
| 3251 | return; |
| 3252 | } |
| 3253 | mSystemBooted = true; |
| 3254 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3255 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3256 | performEnableScreen(); |
| 3257 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3258 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3259 | public void enableScreenIfNeededLocked() { |
| 3260 | if (mDisplayEnabled) { |
| 3261 | return; |
| 3262 | } |
| 3263 | if (!mSystemBooted) { |
| 3264 | return; |
| 3265 | } |
| 3266 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 3267 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3268 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3269 | public void performEnableScreen() { |
| 3270 | synchronized(mWindowMap) { |
| 3271 | if (mDisplayEnabled) { |
| 3272 | return; |
| 3273 | } |
| 3274 | if (!mSystemBooted) { |
| 3275 | return; |
| 3276 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3277 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3278 | // Don't enable the screen until all existing windows |
| 3279 | // have been drawn. |
| 3280 | final int N = mWindows.size(); |
| 3281 | for (int i=0; i<N; i++) { |
| 3282 | WindowState w = (WindowState)mWindows.get(i); |
| 3283 | if (w.isVisibleLw() && !w.isDisplayedLw()) { |
| 3284 | return; |
| 3285 | } |
| 3286 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3287 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3288 | mDisplayEnabled = true; |
| 3289 | if (false) { |
| 3290 | Log.i(TAG, "ENABLING SCREEN!"); |
| 3291 | StringWriter sw = new StringWriter(); |
| 3292 | PrintWriter pw = new PrintWriter(sw); |
| 3293 | this.dump(null, pw, null); |
| 3294 | Log.i(TAG, sw.toString()); |
| 3295 | } |
| 3296 | try { |
| 3297 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 3298 | if (surfaceFlinger != null) { |
| 3299 | //Log.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
| 3300 | Parcel data = Parcel.obtain(); |
| 3301 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 3302 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 3303 | data, null, 0); |
| 3304 | data.recycle(); |
| 3305 | } |
| 3306 | } catch (RemoteException ex) { |
| 3307 | Log.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
| 3308 | } |
| 3309 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3310 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3311 | mPolicy.enableScreenAfterBoot(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3312 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3313 | // Make sure the last requested orientation has been applied. |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 3314 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 3315 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3316 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3317 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3318 | public void setInTouchMode(boolean mode) { |
| 3319 | synchronized(mWindowMap) { |
| 3320 | mInTouchMode = mode; |
| 3321 | } |
| 3322 | } |
| 3323 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3324 | public void setRotation(int rotation, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3325 | boolean alwaysSendConfiguration, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3326 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3327 | "setRotation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3328 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3329 | } |
| 3330 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3331 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3332 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3333 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3334 | public void setRotationUnchecked(int rotation, |
| 3335 | boolean alwaysSendConfiguration, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3336 | if(DEBUG_ORIENTATION) Log.v(TAG, |
| 3337 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3338 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3339 | long origId = Binder.clearCallingIdentity(); |
| 3340 | boolean changed; |
| 3341 | synchronized(mWindowMap) { |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3342 | changed = setRotationUncheckedLocked(rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3343 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3344 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3345 | if (changed) { |
| 3346 | sendNewConfiguration(); |
| 3347 | synchronized(mWindowMap) { |
| 3348 | mLayoutNeeded = true; |
| 3349 | performLayoutAndPlaceSurfacesLocked(); |
| 3350 | } |
| 3351 | } else if (alwaysSendConfiguration) { |
| 3352 | //update configuration ignoring orientation change |
| 3353 | sendNewConfiguration(); |
| 3354 | } |
| 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 | Binder.restoreCallingIdentity(origId); |
| 3357 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3358 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3359 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3360 | boolean changed; |
| 3361 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 3362 | rotation = mRequestedRotation; |
| 3363 | } else { |
| 3364 | mRequestedRotation = rotation; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 3365 | mLastRotationFlags = animFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3366 | } |
| 3367 | 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] | 3368 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3369 | mRotation, mDisplayEnabled); |
| 3370 | if (DEBUG_ORIENTATION) Log.v(TAG, "new rotation is set to " + rotation); |
| 3371 | changed = mDisplayEnabled && mRotation != rotation; |
| 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 | if (changed) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3374 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3375 | "Rotation changed to " + rotation |
| 3376 | + " from " + mRotation |
| 3377 | + " (forceApp=" + mForcedAppOrientation |
| 3378 | + ", req=" + mRequestedRotation + ")"); |
| 3379 | mRotation = rotation; |
| 3380 | mWindowsFreezingScreen = true; |
| 3381 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 3382 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 3383 | 2000); |
| 3384 | startFreezingDisplayLocked(); |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3385 | Log.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3386 | mQueue.setOrientation(rotation); |
| 3387 | if (mDisplayEnabled) { |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 3388 | Surface.setOrientation(0, rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3389 | } |
| 3390 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 3391 | WindowState w = (WindowState)mWindows.get(i); |
| 3392 | if (w.mSurface != null) { |
| 3393 | w.mOrientationChanging = true; |
| 3394 | } |
| 3395 | } |
| 3396 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 3397 | try { |
| 3398 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 3399 | } catch (RemoteException e) { |
| 3400 | } |
| 3401 | } |
| 3402 | } //end if changed |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3403 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3404 | return changed; |
| 3405 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3406 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3407 | public int getRotation() { |
| 3408 | return mRotation; |
| 3409 | } |
| 3410 | |
| 3411 | public int watchRotation(IRotationWatcher watcher) { |
| 3412 | final IBinder watcherBinder = watcher.asBinder(); |
| 3413 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 3414 | public void binderDied() { |
| 3415 | synchronized (mWindowMap) { |
| 3416 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 3417 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 3418 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 3419 | if (removed != null) { |
| 3420 | removed.asBinder().unlinkToDeath(this, 0); |
| 3421 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3422 | i--; |
| 3423 | } |
| 3424 | } |
| 3425 | } |
| 3426 | } |
| 3427 | }; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3428 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3429 | synchronized (mWindowMap) { |
| 3430 | try { |
| 3431 | watcher.asBinder().linkToDeath(dr, 0); |
| 3432 | mRotationWatchers.add(watcher); |
| 3433 | } catch (RemoteException e) { |
| 3434 | // Client died, no cleanup needed. |
| 3435 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3436 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3437 | return mRotation; |
| 3438 | } |
| 3439 | } |
| 3440 | |
| 3441 | /** |
| 3442 | * Starts the view server on the specified port. |
| 3443 | * |
| 3444 | * @param port The port to listener to. |
| 3445 | * |
| 3446 | * @return True if the server was successfully started, false otherwise. |
| 3447 | * |
| 3448 | * @see com.android.server.ViewServer |
| 3449 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 3450 | */ |
| 3451 | public boolean startViewServer(int port) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3452 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3453 | return false; |
| 3454 | } |
| 3455 | |
| 3456 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 3457 | return false; |
| 3458 | } |
| 3459 | |
| 3460 | if (port < 1024) { |
| 3461 | return false; |
| 3462 | } |
| 3463 | |
| 3464 | if (mViewServer != null) { |
| 3465 | if (!mViewServer.isRunning()) { |
| 3466 | try { |
| 3467 | return mViewServer.start(); |
| 3468 | } catch (IOException e) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3469 | Log.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3470 | } |
| 3471 | } |
| 3472 | return false; |
| 3473 | } |
| 3474 | |
| 3475 | try { |
| 3476 | mViewServer = new ViewServer(this, port); |
| 3477 | return mViewServer.start(); |
| 3478 | } catch (IOException e) { |
| 3479 | Log.w(TAG, "View server did not start"); |
| 3480 | } |
| 3481 | return false; |
| 3482 | } |
| 3483 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3484 | private boolean isSystemSecure() { |
| 3485 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 3486 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 3487 | } |
| 3488 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3489 | /** |
| 3490 | * Stops the view server if it exists. |
| 3491 | * |
| 3492 | * @return True if the server stopped, false if it wasn't started or |
| 3493 | * couldn't be stopped. |
| 3494 | * |
| 3495 | * @see com.android.server.ViewServer |
| 3496 | */ |
| 3497 | public boolean stopViewServer() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3498 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3499 | return false; |
| 3500 | } |
| 3501 | |
| 3502 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 3503 | return false; |
| 3504 | } |
| 3505 | |
| 3506 | if (mViewServer != null) { |
| 3507 | return mViewServer.stop(); |
| 3508 | } |
| 3509 | return false; |
| 3510 | } |
| 3511 | |
| 3512 | /** |
| 3513 | * Indicates whether the view server is running. |
| 3514 | * |
| 3515 | * @return True if the server is running, false otherwise. |
| 3516 | * |
| 3517 | * @see com.android.server.ViewServer |
| 3518 | */ |
| 3519 | public boolean isViewServerRunning() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3520 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3521 | return false; |
| 3522 | } |
| 3523 | |
| 3524 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 3525 | return false; |
| 3526 | } |
| 3527 | |
| 3528 | return mViewServer != null && mViewServer.isRunning(); |
| 3529 | } |
| 3530 | |
| 3531 | /** |
| 3532 | * Lists all availble windows in the system. The listing is written in the |
| 3533 | * specified Socket's output stream with the following syntax: |
| 3534 | * windowHashCodeInHexadecimal windowName |
| 3535 | * Each line of the ouput represents a different window. |
| 3536 | * |
| 3537 | * @param client The remote client to send the listing to. |
| 3538 | * @return False if an error occured, true otherwise. |
| 3539 | */ |
| 3540 | boolean viewServerListWindows(Socket client) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3541 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3542 | return false; |
| 3543 | } |
| 3544 | |
| 3545 | boolean result = true; |
| 3546 | |
| 3547 | Object[] windows; |
| 3548 | synchronized (mWindowMap) { |
| 3549 | windows = new Object[mWindows.size()]; |
| 3550 | //noinspection unchecked |
| 3551 | windows = mWindows.toArray(windows); |
| 3552 | } |
| 3553 | |
| 3554 | BufferedWriter out = null; |
| 3555 | |
| 3556 | // Any uncaught exception will crash the system process |
| 3557 | try { |
| 3558 | OutputStream clientStream = client.getOutputStream(); |
| 3559 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 3560 | |
| 3561 | final int count = windows.length; |
| 3562 | for (int i = 0; i < count; i++) { |
| 3563 | final WindowState w = (WindowState) windows[i]; |
| 3564 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 3565 | out.write(' '); |
| 3566 | out.append(w.mAttrs.getTitle()); |
| 3567 | out.write('\n'); |
| 3568 | } |
| 3569 | |
| 3570 | out.write("DONE.\n"); |
| 3571 | out.flush(); |
| 3572 | } catch (Exception e) { |
| 3573 | result = false; |
| 3574 | } finally { |
| 3575 | if (out != null) { |
| 3576 | try { |
| 3577 | out.close(); |
| 3578 | } catch (IOException e) { |
| 3579 | result = false; |
| 3580 | } |
| 3581 | } |
| 3582 | } |
| 3583 | |
| 3584 | return result; |
| 3585 | } |
| 3586 | |
| 3587 | /** |
| 3588 | * Sends a command to a target window. The result of the command, if any, will be |
| 3589 | * written in the output stream of the specified socket. |
| 3590 | * |
| 3591 | * The parameters must follow this syntax: |
| 3592 | * windowHashcode extra |
| 3593 | * |
| 3594 | * Where XX is the length in characeters of the windowTitle. |
| 3595 | * |
| 3596 | * The first parameter is the target window. The window with the specified hashcode |
| 3597 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 3598 | * will be delivered to the target window and as parameters to the command itself. |
| 3599 | * |
| 3600 | * @param client The remote client to sent the result, if any, to. |
| 3601 | * @param command The command to execute. |
| 3602 | * @param parameters The command parameters. |
| 3603 | * |
| 3604 | * @return True if the command was successfully delivered, false otherwise. This does |
| 3605 | * not indicate whether the command itself was successful. |
| 3606 | */ |
| 3607 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3608 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3609 | return false; |
| 3610 | } |
| 3611 | |
| 3612 | boolean success = true; |
| 3613 | Parcel data = null; |
| 3614 | Parcel reply = null; |
| 3615 | |
| 3616 | // Any uncaught exception will crash the system process |
| 3617 | try { |
| 3618 | // Find the hashcode of the window |
| 3619 | int index = parameters.indexOf(' '); |
| 3620 | if (index == -1) { |
| 3621 | index = parameters.length(); |
| 3622 | } |
| 3623 | final String code = parameters.substring(0, index); |
| 3624 | int hashCode = "ffffffff".equals(code) ? -1 : Integer.parseInt(code, 16); |
| 3625 | |
| 3626 | // Extract the command's parameter after the window description |
| 3627 | if (index < parameters.length()) { |
| 3628 | parameters = parameters.substring(index + 1); |
| 3629 | } else { |
| 3630 | parameters = ""; |
| 3631 | } |
| 3632 | |
| 3633 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 3634 | if (window == null) { |
| 3635 | return false; |
| 3636 | } |
| 3637 | |
| 3638 | data = Parcel.obtain(); |
| 3639 | data.writeInterfaceToken("android.view.IWindow"); |
| 3640 | data.writeString(command); |
| 3641 | data.writeString(parameters); |
| 3642 | data.writeInt(1); |
| 3643 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 3644 | |
| 3645 | reply = Parcel.obtain(); |
| 3646 | |
| 3647 | final IBinder binder = window.mClient.asBinder(); |
| 3648 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 3649 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 3650 | |
| 3651 | reply.readException(); |
| 3652 | |
| 3653 | } catch (Exception e) { |
| 3654 | Log.w(TAG, "Could not send command " + command + " with parameters " + parameters, e); |
| 3655 | success = false; |
| 3656 | } finally { |
| 3657 | if (data != null) { |
| 3658 | data.recycle(); |
| 3659 | } |
| 3660 | if (reply != null) { |
| 3661 | reply.recycle(); |
| 3662 | } |
| 3663 | } |
| 3664 | |
| 3665 | return success; |
| 3666 | } |
| 3667 | |
| 3668 | private WindowState findWindow(int hashCode) { |
| 3669 | if (hashCode == -1) { |
| 3670 | return getFocusedWindow(); |
| 3671 | } |
| 3672 | |
| 3673 | synchronized (mWindowMap) { |
| 3674 | final ArrayList windows = mWindows; |
| 3675 | final int count = windows.size(); |
| 3676 | |
| 3677 | for (int i = 0; i < count; i++) { |
| 3678 | WindowState w = (WindowState) windows.get(i); |
| 3679 | if (System.identityHashCode(w) == hashCode) { |
| 3680 | return w; |
| 3681 | } |
| 3682 | } |
| 3683 | } |
| 3684 | |
| 3685 | return null; |
| 3686 | } |
| 3687 | |
| 3688 | /* |
| 3689 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 3690 | * that to config-changed listeners if appropriate. |
| 3691 | */ |
| 3692 | void sendNewConfiguration() { |
| 3693 | try { |
| 3694 | mActivityManager.updateConfiguration(null); |
| 3695 | } catch (RemoteException e) { |
| 3696 | } |
| 3697 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3698 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3699 | public Configuration computeNewConfiguration() { |
| 3700 | synchronized (mWindowMap) { |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 3701 | return computeNewConfigurationLocked(); |
| 3702 | } |
| 3703 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3704 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 3705 | Configuration computeNewConfigurationLocked() { |
| 3706 | Configuration config = new Configuration(); |
| 3707 | if (!computeNewConfigurationLocked(config)) { |
| 3708 | return null; |
| 3709 | } |
| 3710 | Log.i(TAG, "Config changed: " + config); |
| 3711 | long now = SystemClock.uptimeMillis(); |
| 3712 | //Log.i(TAG, "Config changing, gc pending: " + mFreezeGcPending + ", now " + now); |
| 3713 | if (mFreezeGcPending != 0) { |
| 3714 | if (now > (mFreezeGcPending+1000)) { |
| 3715 | //Log.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| 3716 | mH.removeMessages(H.FORCE_GC); |
| 3717 | Runtime.getRuntime().gc(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3718 | mFreezeGcPending = now; |
| 3719 | } |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 3720 | } else { |
| 3721 | mFreezeGcPending = now; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3722 | } |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 3723 | return config; |
| 3724 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3725 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 3726 | boolean computeNewConfigurationLocked(Configuration config) { |
| 3727 | if (mDisplay == null) { |
| 3728 | return false; |
| 3729 | } |
| 3730 | mQueue.getInputConfiguration(config); |
| 3731 | final int dw = mDisplay.getWidth(); |
| 3732 | final int dh = mDisplay.getHeight(); |
| 3733 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 3734 | if (dw < dh) { |
| 3735 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 3736 | } else if (dw > dh) { |
| 3737 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 3738 | } |
| 3739 | config.orientation = orientation; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 3740 | |
| 3741 | if (screenLayout == Configuration.SCREENLAYOUT_UNDEFINED) { |
| 3742 | // Note we only do this once because at this point we don't |
| 3743 | // expect the screen to change in this way at runtime, and want |
| 3744 | // to avoid all of this computation for every config change. |
| 3745 | DisplayMetrics dm = new DisplayMetrics(); |
| 3746 | mDisplay.getMetrics(dm); |
| 3747 | int longSize = dw; |
| 3748 | int shortSize = dh; |
| 3749 | if (longSize < shortSize) { |
| 3750 | int tmp = longSize; |
| 3751 | longSize = shortSize; |
| 3752 | shortSize = tmp; |
| 3753 | } |
| 3754 | longSize = (int)(longSize/dm.density); |
| 3755 | shortSize = (int)(shortSize/dm.density); |
| 3756 | |
| 3757 | // These semi-magic numbers define our compatibility modes for |
| 3758 | // applications with different screens. Don't change unless you |
| 3759 | // make sure to test lots and lots of apps! |
| 3760 | if (longSize < 470) { |
| 3761 | // This is shorter than an HVGA normal density screen (which |
| 3762 | // is 480 pixels on its long side). |
| 3763 | screenLayout = Configuration.SCREENLAYOUT_SMALL; |
| 3764 | } else if (longSize > 490 && shortSize > 330) { |
| 3765 | // This is larger than an HVGA normal density screen (which |
| 3766 | // is 480x320 pixels). |
| 3767 | screenLayout = Configuration.SCREENLAYOUT_LARGE; |
| 3768 | } else { |
| 3769 | screenLayout = Configuration.SCREENLAYOUT_NORMAL; |
| 3770 | } |
| 3771 | } |
| 3772 | config.screenLayout = screenLayout; |
| 3773 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 3774 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 3775 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 3776 | mPolicy.adjustConfigurationLw(config); |
| 3777 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3778 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3779 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3780 | // ------------------------------------------------------------- |
| 3781 | // Input Events and Focus Management |
| 3782 | // ------------------------------------------------------------- |
| 3783 | |
| 3784 | private final void wakeupIfNeeded(WindowState targetWin, int eventType) { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 3785 | long curTime = SystemClock.uptimeMillis(); |
| 3786 | |
| 3787 | if (eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) { |
| 3788 | if (mLastTouchEventType == eventType && |
| 3789 | (curTime - mLastUserActivityCallTime) < MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 3790 | return; |
| 3791 | } |
| 3792 | mLastUserActivityCallTime = curTime; |
| 3793 | mLastTouchEventType = eventType; |
| 3794 | } |
| 3795 | |
| 3796 | if (targetWin == null |
| 3797 | || targetWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) { |
| 3798 | mPowerManager.userActivity(curTime, false, eventType, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3799 | } |
| 3800 | } |
| 3801 | |
| 3802 | // tells if it's a cheek event or not -- this function is stateful |
| 3803 | private static final int EVENT_NONE = 0; |
| 3804 | private static final int EVENT_UNKNOWN = 0; |
| 3805 | private static final int EVENT_CHEEK = 0; |
| 3806 | private static final int EVENT_IGNORE_DURATION = 300; // ms |
| 3807 | private static final float CHEEK_THRESHOLD = 0.6f; |
| 3808 | private int mEventState = EVENT_NONE; |
| 3809 | private float mEventSize; |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 3810 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3811 | private int eventType(MotionEvent ev) { |
| 3812 | float size = ev.getSize(); |
| 3813 | switch (ev.getAction()) { |
| 3814 | case MotionEvent.ACTION_DOWN: |
| 3815 | mEventSize = size; |
| 3816 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_EVENT; |
| 3817 | case MotionEvent.ACTION_UP: |
| 3818 | if (size > mEventSize) mEventSize = size; |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 3819 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_UP_EVENT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3820 | case MotionEvent.ACTION_MOVE: |
| 3821 | final int N = ev.getHistorySize(); |
| 3822 | if (size > mEventSize) mEventSize = size; |
| 3823 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 3824 | for (int i=0; i<N; i++) { |
| 3825 | size = ev.getHistoricalSize(i); |
| 3826 | if (size > mEventSize) mEventSize = size; |
| 3827 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 3828 | } |
| 3829 | if (ev.getEventTime() < ev.getDownTime() + EVENT_IGNORE_DURATION) { |
| 3830 | return TOUCH_EVENT; |
| 3831 | } else { |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 3832 | return LONG_TOUCH_EVENT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3833 | } |
| 3834 | default: |
| 3835 | // not good |
| 3836 | return OTHER_EVENT; |
| 3837 | } |
| 3838 | } |
| 3839 | |
| 3840 | /** |
| 3841 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 3842 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3843 | 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] | 3844 | if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Log.v(TAG, |
| 3845 | "dispatchPointer " + ev); |
| 3846 | |
| 3847 | Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 3848 | ev, true, false, pid, uid); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3849 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3850 | int action = ev.getAction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3851 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3852 | if (action == MotionEvent.ACTION_UP) { |
| 3853 | // let go of our target |
| 3854 | mKeyWaiter.mMotionTarget = null; |
| 3855 | mPowerManager.logPointerUpEvent(); |
| 3856 | } else if (action == MotionEvent.ACTION_DOWN) { |
| 3857 | mPowerManager.logPointerDownEvent(); |
| 3858 | } |
| 3859 | |
| 3860 | if (targetObj == null) { |
| 3861 | // In this case we are either dropping the event, or have received |
| 3862 | // a move or up without a down. It is common to receive move |
| 3863 | // events in such a way, since this means the user is moving the |
| 3864 | // pointer without actually pressing down. All other cases should |
| 3865 | // be atypical, so let's log them. |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 3866 | if (action != MotionEvent.ACTION_MOVE) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3867 | Log.w(TAG, "No window to dispatch pointer action " + ev.getAction()); |
| 3868 | } |
| 3869 | if (qev != null) { |
| 3870 | mQueue.recycleEvent(qev); |
| 3871 | } |
| 3872 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3873 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3874 | } |
| 3875 | if (targetObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| 3876 | if (qev != null) { |
| 3877 | mQueue.recycleEvent(qev); |
| 3878 | } |
| 3879 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3880 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3881 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3882 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3883 | WindowState target = (WindowState)targetObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3884 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3885 | final long eventTime = ev.getEventTime(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3886 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3887 | //Log.i(TAG, "Sending " + ev + " to " + target); |
| 3888 | |
| 3889 | if (uid != 0 && uid != target.mSession.mUid) { |
| 3890 | if (mContext.checkPermission( |
| 3891 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 3892 | != PackageManager.PERMISSION_GRANTED) { |
| 3893 | Log.w(TAG, "Permission denied: injecting pointer event from pid " |
| 3894 | + pid + " uid " + uid + " to window " + target |
| 3895 | + " owned by uid " + target.mSession.mUid); |
| 3896 | if (qev != null) { |
| 3897 | mQueue.recycleEvent(qev); |
| 3898 | } |
| 3899 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3900 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3901 | } |
| 3902 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3903 | |
| 3904 | if ((target.mAttrs.flags & |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3905 | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES) != 0) { |
| 3906 | //target wants to ignore fat touch events |
| 3907 | boolean cheekPress = mPolicy.isCheekPressedAgainstScreen(ev); |
| 3908 | //explicit flag to return without processing event further |
| 3909 | boolean returnFlag = false; |
| 3910 | if((action == MotionEvent.ACTION_DOWN)) { |
| 3911 | mFatTouch = false; |
| 3912 | if(cheekPress) { |
| 3913 | mFatTouch = true; |
| 3914 | returnFlag = true; |
| 3915 | } |
| 3916 | } else { |
| 3917 | if(action == MotionEvent.ACTION_UP) { |
| 3918 | if(mFatTouch) { |
| 3919 | //earlier even was invalid doesnt matter if current up is cheekpress or not |
| 3920 | mFatTouch = false; |
| 3921 | returnFlag = true; |
| 3922 | } else if(cheekPress) { |
| 3923 | //cancel the earlier event |
| 3924 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 3925 | action = MotionEvent.ACTION_CANCEL; |
| 3926 | } |
| 3927 | } else if(action == MotionEvent.ACTION_MOVE) { |
| 3928 | if(mFatTouch) { |
| 3929 | //two cases here |
| 3930 | //an invalid down followed by 0 or moves(valid or invalid) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3931 | //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] | 3932 | returnFlag = true; |
| 3933 | } else if(cheekPress) { |
| 3934 | //valid down followed by invalid moves |
| 3935 | //an invalid move have to cancel earlier action |
| 3936 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 3937 | action = MotionEvent.ACTION_CANCEL; |
| 3938 | if (DEBUG_INPUT) Log.v(TAG, "Sending cancel for invalid ACTION_MOVE"); |
| 3939 | //note that the subsequent invalid moves will not get here |
| 3940 | mFatTouch = true; |
| 3941 | } |
| 3942 | } |
| 3943 | } //else if action |
| 3944 | if(returnFlag) { |
| 3945 | //recycle que, ev |
| 3946 | if (qev != null) { |
| 3947 | mQueue.recycleEvent(qev); |
| 3948 | } |
| 3949 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3950 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3951 | } |
| 3952 | } //end if target |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 3953 | |
| 3954 | // TODO remove once we settle on a value or make it app specific |
| 3955 | if (action == MotionEvent.ACTION_DOWN) { |
| 3956 | int max_events_per_sec = 35; |
| 3957 | try { |
| 3958 | max_events_per_sec = Integer.parseInt(SystemProperties |
| 3959 | .get("windowsmgr.max_events_per_sec")); |
| 3960 | if (max_events_per_sec < 1) { |
| 3961 | max_events_per_sec = 35; |
| 3962 | } |
| 3963 | } catch (NumberFormatException e) { |
| 3964 | } |
| 3965 | mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec; |
| 3966 | } |
| 3967 | |
| 3968 | /* |
| 3969 | * Throttle events to minimize CPU usage when there's a flood of events |
| 3970 | * e.g. constant contact with the screen |
| 3971 | */ |
| 3972 | if (action == MotionEvent.ACTION_MOVE) { |
| 3973 | long nextEventTime = mLastTouchEventTime + mMinWaitTimeBetweenTouchEvents; |
| 3974 | long now = SystemClock.uptimeMillis(); |
| 3975 | if (now < nextEventTime) { |
| 3976 | try { |
| 3977 | Thread.sleep(nextEventTime - now); |
| 3978 | } catch (InterruptedException e) { |
| 3979 | } |
| 3980 | mLastTouchEventTime = nextEventTime; |
| 3981 | } else { |
| 3982 | mLastTouchEventTime = now; |
| 3983 | } |
| 3984 | } |
| 3985 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3986 | synchronized(mWindowMap) { |
| 3987 | if (qev != null && action == MotionEvent.ACTION_MOVE) { |
| 3988 | mKeyWaiter.bindTargetWindowLocked(target, |
| 3989 | KeyWaiter.RETURN_PENDING_POINTER, qev); |
| 3990 | ev = null; |
| 3991 | } else { |
| 3992 | if (action == MotionEvent.ACTION_DOWN) { |
| 3993 | WindowState out = mKeyWaiter.mOutsideTouchTargets; |
| 3994 | if (out != null) { |
| 3995 | MotionEvent oev = MotionEvent.obtain(ev); |
| 3996 | oev.setAction(MotionEvent.ACTION_OUTSIDE); |
| 3997 | do { |
| 3998 | final Rect frame = out.mFrame; |
| 3999 | oev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 4000 | try { |
| 4001 | out.mClient.dispatchPointer(oev, eventTime); |
| 4002 | } catch (android.os.RemoteException e) { |
| 4003 | Log.i(TAG, "WINDOW DIED during outside motion dispatch: " + out); |
| 4004 | } |
| 4005 | oev.offsetLocation((float)frame.left, (float)frame.top); |
| 4006 | out = out.mNextOutsideTouch; |
| 4007 | } while (out != null); |
| 4008 | mKeyWaiter.mOutsideTouchTargets = null; |
| 4009 | } |
| 4010 | } |
| 4011 | final Rect frame = target.mFrame; |
| 4012 | ev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 4013 | mKeyWaiter.bindTargetWindowLocked(target); |
| 4014 | } |
| 4015 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4016 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4017 | // finally offset the event to the target's coordinate system and |
| 4018 | // dispatch the event. |
| 4019 | try { |
| 4020 | if (DEBUG_INPUT || DEBUG_FOCUS || WindowManagerPolicy.WATCH_POINTER) { |
| 4021 | Log.v(TAG, "Delivering pointer " + qev + " to " + target); |
| 4022 | } |
| 4023 | target.mClient.dispatchPointer(ev, eventTime); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4024 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4025 | } catch (android.os.RemoteException e) { |
| 4026 | Log.i(TAG, "WINDOW DIED during motion dispatch: " + target); |
| 4027 | mKeyWaiter.mMotionTarget = null; |
| 4028 | try { |
| 4029 | removeWindow(target.mSession, target.mClient); |
| 4030 | } catch (java.util.NoSuchElementException ex) { |
| 4031 | // This will happen if the window has already been |
| 4032 | // removed. |
| 4033 | } |
| 4034 | } |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4035 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4036 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4037 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4038 | /** |
| 4039 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4040 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4041 | 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] | 4042 | if (DEBUG_INPUT) Log.v( |
| 4043 | TAG, "dispatchTrackball [" + ev.getAction() +"] <" + ev.getX() + ", " + ev.getY() + ">"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4044 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4045 | Object focusObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4046 | ev, false, false, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4047 | if (focusObj == null) { |
| 4048 | Log.w(TAG, "No focus window, dropping trackball: " + ev); |
| 4049 | if (qev != null) { |
| 4050 | mQueue.recycleEvent(qev); |
| 4051 | } |
| 4052 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4053 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4054 | } |
| 4055 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| 4056 | if (qev != null) { |
| 4057 | mQueue.recycleEvent(qev); |
| 4058 | } |
| 4059 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4060 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4061 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4062 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4063 | WindowState focus = (WindowState)focusObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4064 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4065 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 4066 | if (mContext.checkPermission( |
| 4067 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 4068 | != PackageManager.PERMISSION_GRANTED) { |
| 4069 | Log.w(TAG, "Permission denied: injecting key event from pid " |
| 4070 | + pid + " uid " + uid + " to window " + focus |
| 4071 | + " owned by uid " + focus.mSession.mUid); |
| 4072 | if (qev != null) { |
| 4073 | mQueue.recycleEvent(qev); |
| 4074 | } |
| 4075 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4076 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4077 | } |
| 4078 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4079 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4080 | final long eventTime = ev.getEventTime(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4081 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4082 | synchronized(mWindowMap) { |
| 4083 | if (qev != null && ev.getAction() == MotionEvent.ACTION_MOVE) { |
| 4084 | mKeyWaiter.bindTargetWindowLocked(focus, |
| 4085 | KeyWaiter.RETURN_PENDING_TRACKBALL, qev); |
| 4086 | // We don't deliver movement events to the client, we hold |
| 4087 | // them and wait for them to call back. |
| 4088 | ev = null; |
| 4089 | } else { |
| 4090 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 4091 | } |
| 4092 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4093 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4094 | try { |
| 4095 | focus.mClient.dispatchTrackball(ev, eventTime); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4096 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4097 | } catch (android.os.RemoteException e) { |
| 4098 | Log.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| 4099 | try { |
| 4100 | removeWindow(focus.mSession, focus.mClient); |
| 4101 | } catch (java.util.NoSuchElementException ex) { |
| 4102 | // This will happen if the window has already been |
| 4103 | // removed. |
| 4104 | } |
| 4105 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4106 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4107 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4108 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4109 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4110 | /** |
| 4111 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4112 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4113 | private int dispatchKey(KeyEvent event, int pid, int uid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4114 | if (DEBUG_INPUT) Log.v(TAG, "Dispatch key: " + event); |
| 4115 | |
| 4116 | Object focusObj = mKeyWaiter.waitForNextEventTarget(event, null, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4117 | null, false, false, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4118 | if (focusObj == null) { |
| 4119 | Log.w(TAG, "No focus window, dropping: " + event); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4120 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4121 | } |
| 4122 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4123 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4124 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4125 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4126 | WindowState focus = (WindowState)focusObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4127 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4128 | if (DEBUG_INPUT) Log.v( |
| 4129 | TAG, "Dispatching to " + focus + ": " + event); |
| 4130 | |
| 4131 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 4132 | if (mContext.checkPermission( |
| 4133 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 4134 | != PackageManager.PERMISSION_GRANTED) { |
| 4135 | Log.w(TAG, "Permission denied: injecting key event from pid " |
| 4136 | + pid + " uid " + uid + " to window " + focus |
| 4137 | + " owned by uid " + focus.mSession.mUid); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4138 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4139 | } |
| 4140 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4141 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4142 | synchronized(mWindowMap) { |
| 4143 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 4144 | } |
| 4145 | |
| 4146 | // NOSHIP extra state logging |
| 4147 | mKeyWaiter.recordDispatchState(event, focus); |
| 4148 | // END NOSHIP |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4149 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4150 | try { |
| 4151 | if (DEBUG_INPUT || DEBUG_FOCUS) { |
| 4152 | Log.v(TAG, "Delivering key " + event.getKeyCode() |
| 4153 | + " to " + focus); |
| 4154 | } |
| 4155 | focus.mClient.dispatchKey(event); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4156 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4157 | } catch (android.os.RemoteException e) { |
| 4158 | Log.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| 4159 | try { |
| 4160 | removeWindow(focus.mSession, focus.mClient); |
| 4161 | } catch (java.util.NoSuchElementException ex) { |
| 4162 | // This will happen if the window has already been |
| 4163 | // removed. |
| 4164 | } |
| 4165 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4166 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4167 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4168 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4169 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4170 | public void pauseKeyDispatching(IBinder _token) { |
| 4171 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4172 | "pauseKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4173 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4174 | } |
| 4175 | |
| 4176 | synchronized (mWindowMap) { |
| 4177 | WindowToken token = mTokenMap.get(_token); |
| 4178 | if (token != null) { |
| 4179 | mKeyWaiter.pauseDispatchingLocked(token); |
| 4180 | } |
| 4181 | } |
| 4182 | } |
| 4183 | |
| 4184 | public void resumeKeyDispatching(IBinder _token) { |
| 4185 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4186 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4187 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4188 | } |
| 4189 | |
| 4190 | synchronized (mWindowMap) { |
| 4191 | WindowToken token = mTokenMap.get(_token); |
| 4192 | if (token != null) { |
| 4193 | mKeyWaiter.resumeDispatchingLocked(token); |
| 4194 | } |
| 4195 | } |
| 4196 | } |
| 4197 | |
| 4198 | public void setEventDispatching(boolean enabled) { |
| 4199 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4200 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4201 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4202 | } |
| 4203 | |
| 4204 | synchronized (mWindowMap) { |
| 4205 | mKeyWaiter.setEventDispatchingLocked(enabled); |
| 4206 | } |
| 4207 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4208 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4209 | /** |
| 4210 | * Injects a keystroke event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4211 | * |
| 4212 | * @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] | 4213 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 4214 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 4215 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4216 | */ |
| 4217 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 4218 | long downTime = ev.getDownTime(); |
| 4219 | long eventTime = ev.getEventTime(); |
| 4220 | |
| 4221 | int action = ev.getAction(); |
| 4222 | int code = ev.getKeyCode(); |
| 4223 | int repeatCount = ev.getRepeatCount(); |
| 4224 | int metaState = ev.getMetaState(); |
| 4225 | int deviceId = ev.getDeviceId(); |
| 4226 | int scancode = ev.getScanCode(); |
| 4227 | |
| 4228 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 4229 | if (downTime == 0) downTime = eventTime; |
| 4230 | |
| 4231 | 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] | 4232 | deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4233 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4234 | final int pid = Binder.getCallingPid(); |
| 4235 | final int uid = Binder.getCallingUid(); |
| 4236 | final long ident = Binder.clearCallingIdentity(); |
| 4237 | final int result = dispatchKey(newEvent, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4238 | if (sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4239 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4240 | } |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4241 | Binder.restoreCallingIdentity(ident); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4242 | switch (result) { |
| 4243 | case INJECT_NO_PERMISSION: |
| 4244 | throw new SecurityException( |
| 4245 | "Injecting to another application requires INJECT_EVENT permission"); |
| 4246 | case INJECT_SUCCEEDED: |
| 4247 | return true; |
| 4248 | } |
| 4249 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4250 | } |
| 4251 | |
| 4252 | /** |
| 4253 | * Inject a pointer (touch) event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4254 | * |
| 4255 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 4256 | * {@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] | 4257 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 4258 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 4259 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4260 | */ |
| 4261 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4262 | final int pid = Binder.getCallingPid(); |
| 4263 | final int uid = Binder.getCallingUid(); |
| 4264 | final long ident = Binder.clearCallingIdentity(); |
| 4265 | final int result = dispatchPointer(null, ev, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4266 | if (sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4267 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4268 | } |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4269 | Binder.restoreCallingIdentity(ident); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4270 | switch (result) { |
| 4271 | case INJECT_NO_PERMISSION: |
| 4272 | throw new SecurityException( |
| 4273 | "Injecting to another application requires INJECT_EVENT permission"); |
| 4274 | case INJECT_SUCCEEDED: |
| 4275 | return true; |
| 4276 | } |
| 4277 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4278 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4279 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4280 | /** |
| 4281 | * Inject a trackball (navigation device) event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4282 | * |
| 4283 | * @param ev A motion event describing the trackball action. (As noted in |
| 4284 | * {@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] | 4285 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 4286 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 4287 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4288 | */ |
| 4289 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4290 | final int pid = Binder.getCallingPid(); |
| 4291 | final int uid = Binder.getCallingUid(); |
| 4292 | final long ident = Binder.clearCallingIdentity(); |
| 4293 | final int result = dispatchTrackball(null, ev, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4294 | if (sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4295 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4296 | } |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4297 | Binder.restoreCallingIdentity(ident); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4298 | switch (result) { |
| 4299 | case INJECT_NO_PERMISSION: |
| 4300 | throw new SecurityException( |
| 4301 | "Injecting to another application requires INJECT_EVENT permission"); |
| 4302 | case INJECT_SUCCEEDED: |
| 4303 | return true; |
| 4304 | } |
| 4305 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4306 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4307 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4308 | private WindowState getFocusedWindow() { |
| 4309 | synchronized (mWindowMap) { |
| 4310 | return getFocusedWindowLocked(); |
| 4311 | } |
| 4312 | } |
| 4313 | |
| 4314 | private WindowState getFocusedWindowLocked() { |
| 4315 | return mCurrentFocus; |
| 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 | * This class holds the state for dispatching key events. This state |
| 4320 | * is protected by the KeyWaiter instance, NOT by the window lock. You |
| 4321 | * can be holding the main window lock while acquire the KeyWaiter lock, |
| 4322 | * but not the other way around. |
| 4323 | */ |
| 4324 | final class KeyWaiter { |
| 4325 | // NOSHIP debugging |
| 4326 | public class DispatchState { |
| 4327 | private KeyEvent event; |
| 4328 | private WindowState focus; |
| 4329 | private long time; |
| 4330 | private WindowState lastWin; |
| 4331 | private IBinder lastBinder; |
| 4332 | private boolean finished; |
| 4333 | private boolean gotFirstWindow; |
| 4334 | private boolean eventDispatching; |
| 4335 | private long timeToSwitch; |
| 4336 | private boolean wasFrozen; |
| 4337 | private boolean focusPaused; |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 4338 | private WindowState curFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4339 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4340 | DispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 4341 | focus = theFocus; |
| 4342 | event = theEvent; |
| 4343 | time = System.currentTimeMillis(); |
| 4344 | // snapshot KeyWaiter state |
| 4345 | lastWin = mLastWin; |
| 4346 | lastBinder = mLastBinder; |
| 4347 | finished = mFinished; |
| 4348 | gotFirstWindow = mGotFirstWindow; |
| 4349 | eventDispatching = mEventDispatching; |
| 4350 | timeToSwitch = mTimeToSwitch; |
| 4351 | wasFrozen = mWasFrozen; |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 4352 | curFocus = mCurrentFocus; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4353 | // cache the paused state at ctor time as well |
| 4354 | if (theFocus == null || theFocus.mToken == null) { |
| 4355 | Log.i(TAG, "focus " + theFocus + " mToken is null at event dispatch!"); |
| 4356 | focusPaused = false; |
| 4357 | } else { |
| 4358 | focusPaused = theFocus.mToken.paused; |
| 4359 | } |
| 4360 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4361 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4362 | public String toString() { |
| 4363 | return "{{" + event + " to " + focus + " @ " + time |
| 4364 | + " lw=" + lastWin + " lb=" + lastBinder |
| 4365 | + " fin=" + finished + " gfw=" + gotFirstWindow |
| 4366 | + " ed=" + eventDispatching + " tts=" + timeToSwitch |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 4367 | + " wf=" + wasFrozen + " fp=" + focusPaused |
| 4368 | + " mcf=" + mCurrentFocus + "}}"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4369 | } |
| 4370 | }; |
| 4371 | private DispatchState mDispatchState = null; |
| 4372 | public void recordDispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 4373 | mDispatchState = new DispatchState(theEvent, theFocus); |
| 4374 | } |
| 4375 | // END NOSHIP |
| 4376 | |
| 4377 | public static final int RETURN_NOTHING = 0; |
| 4378 | public static final int RETURN_PENDING_POINTER = 1; |
| 4379 | public static final int RETURN_PENDING_TRACKBALL = 2; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4380 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4381 | final Object SKIP_TARGET_TOKEN = new Object(); |
| 4382 | final Object CONSUMED_EVENT_TOKEN = new Object(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4383 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4384 | private WindowState mLastWin = null; |
| 4385 | private IBinder mLastBinder = null; |
| 4386 | private boolean mFinished = true; |
| 4387 | private boolean mGotFirstWindow = false; |
| 4388 | private boolean mEventDispatching = true; |
| 4389 | private long mTimeToSwitch = 0; |
| 4390 | /* package */ boolean mWasFrozen = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4391 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4392 | // Target of Motion events |
| 4393 | WindowState mMotionTarget; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4394 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4395 | // Windows above the target who would like to receive an "outside" |
| 4396 | // touch event for any down events outside of them. |
| 4397 | WindowState mOutsideTouchTargets; |
| 4398 | |
| 4399 | /** |
| 4400 | * Wait for the last event dispatch to complete, then find the next |
| 4401 | * target that should receive the given event and wait for that one |
| 4402 | * to be ready to receive it. |
| 4403 | */ |
| 4404 | Object waitForNextEventTarget(KeyEvent nextKey, QueuedEvent qev, |
| 4405 | MotionEvent nextMotion, boolean isPointerEvent, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4406 | boolean failIfTimeout, int callingPid, int callingUid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4407 | long startTime = SystemClock.uptimeMillis(); |
| 4408 | long keyDispatchingTimeout = 5 * 1000; |
| 4409 | long waitedFor = 0; |
| 4410 | |
| 4411 | while (true) { |
| 4412 | // Figure out which window we care about. It is either the |
| 4413 | // last window we are waiting to have process the event or, |
| 4414 | // if none, then the next window we think the event should go |
| 4415 | // to. Note: we retrieve mLastWin outside of the lock, so |
| 4416 | // it may change before we lock. Thus we must check it again. |
| 4417 | WindowState targetWin = mLastWin; |
| 4418 | boolean targetIsNew = targetWin == null; |
| 4419 | if (DEBUG_INPUT) Log.v( |
| 4420 | TAG, "waitForLastKey: mFinished=" + mFinished + |
| 4421 | ", mLastWin=" + mLastWin); |
| 4422 | if (targetIsNew) { |
| 4423 | Object target = findTargetWindow(nextKey, qev, nextMotion, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4424 | isPointerEvent, callingPid, callingUid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4425 | if (target == SKIP_TARGET_TOKEN) { |
| 4426 | // The user has pressed a special key, and we are |
| 4427 | // dropping all pending events before it. |
| 4428 | if (DEBUG_INPUT) Log.v(TAG, "Skipping: " + nextKey |
| 4429 | + " " + nextMotion); |
| 4430 | return null; |
| 4431 | } |
| 4432 | if (target == CONSUMED_EVENT_TOKEN) { |
| 4433 | if (DEBUG_INPUT) Log.v(TAG, "Consumed: " + nextKey |
| 4434 | + " " + nextMotion); |
| 4435 | return target; |
| 4436 | } |
| 4437 | targetWin = (WindowState)target; |
| 4438 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4439 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4440 | AppWindowToken targetApp = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4441 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4442 | // Now: is it okay to send the next event to this window? |
| 4443 | synchronized (this) { |
| 4444 | // First: did we come here based on the last window not |
| 4445 | // being null, but it changed by the time we got here? |
| 4446 | // If so, try again. |
| 4447 | if (!targetIsNew && mLastWin == null) { |
| 4448 | continue; |
| 4449 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4450 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4451 | // We never dispatch events if not finished with the |
| 4452 | // last one, or the display is frozen. |
| 4453 | if (mFinished && !mDisplayFrozen) { |
| 4454 | // If event dispatching is disabled, then we |
| 4455 | // just consume the events. |
| 4456 | if (!mEventDispatching) { |
| 4457 | if (DEBUG_INPUT) Log.v(TAG, |
| 4458 | "Skipping event; dispatching disabled: " |
| 4459 | + nextKey + " " + nextMotion); |
| 4460 | return null; |
| 4461 | } |
| 4462 | if (targetWin != null) { |
| 4463 | // If this is a new target, and that target is not |
| 4464 | // paused or unresponsive, then all looks good to |
| 4465 | // handle the event. |
| 4466 | if (targetIsNew && !targetWin.mToken.paused) { |
| 4467 | return targetWin; |
| 4468 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4469 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4470 | // If we didn't find a target window, and there is no |
| 4471 | // focused app window, then just eat the events. |
| 4472 | } else if (mFocusedApp == null) { |
| 4473 | if (DEBUG_INPUT) Log.v(TAG, |
| 4474 | "Skipping event; no focused app: " |
| 4475 | + nextKey + " " + nextMotion); |
| 4476 | return null; |
| 4477 | } |
| 4478 | } |
| 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 | if (DEBUG_INPUT) Log.v( |
| 4481 | TAG, "Waiting for last key in " + mLastBinder |
| 4482 | + " target=" + targetWin |
| 4483 | + " mFinished=" + mFinished |
| 4484 | + " mDisplayFrozen=" + mDisplayFrozen |
| 4485 | + " targetIsNew=" + targetIsNew |
| 4486 | + " paused=" |
| 4487 | + (targetWin != null ? targetWin.mToken.paused : false) |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 4488 | + " mFocusedApp=" + mFocusedApp |
| 4489 | + " mCurrentFocus=" + mCurrentFocus); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4490 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4491 | targetApp = targetWin != null |
| 4492 | ? targetWin.mAppToken : mFocusedApp; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4493 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4494 | long curTimeout = keyDispatchingTimeout; |
| 4495 | if (mTimeToSwitch != 0) { |
| 4496 | long now = SystemClock.uptimeMillis(); |
| 4497 | if (mTimeToSwitch <= now) { |
| 4498 | // If an app switch key has been pressed, and we have |
| 4499 | // waited too long for the current app to finish |
| 4500 | // processing keys, then wait no more! |
| 4501 | doFinishedKeyLocked(true); |
| 4502 | continue; |
| 4503 | } |
| 4504 | long switchTimeout = mTimeToSwitch - now; |
| 4505 | if (curTimeout > switchTimeout) { |
| 4506 | curTimeout = switchTimeout; |
| 4507 | } |
| 4508 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4509 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4510 | try { |
| 4511 | // after that continue |
| 4512 | // processing keys, so we don't get stuck. |
| 4513 | if (DEBUG_INPUT) Log.v( |
| 4514 | TAG, "Waiting for key dispatch: " + curTimeout); |
| 4515 | wait(curTimeout); |
| 4516 | if (DEBUG_INPUT) Log.v(TAG, "Finished waiting @" |
| 4517 | + SystemClock.uptimeMillis() + " startTime=" |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 4518 | + startTime + " switchTime=" + mTimeToSwitch |
| 4519 | + " target=" + targetWin + " mLW=" + mLastWin |
| 4520 | + " mLB=" + mLastBinder + " fin=" + mFinished |
| 4521 | + " mCurrentFocus=" + mCurrentFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4522 | } catch (InterruptedException e) { |
| 4523 | } |
| 4524 | } |
| 4525 | |
| 4526 | // If we were frozen during configuration change, restart the |
| 4527 | // timeout checks from now; otherwise look at whether we timed |
| 4528 | // out before awakening. |
| 4529 | if (mWasFrozen) { |
| 4530 | waitedFor = 0; |
| 4531 | mWasFrozen = false; |
| 4532 | } else { |
| 4533 | waitedFor = SystemClock.uptimeMillis() - startTime; |
| 4534 | } |
| 4535 | |
| 4536 | if (waitedFor >= keyDispatchingTimeout && mTimeToSwitch == 0) { |
| 4537 | IApplicationToken at = null; |
| 4538 | synchronized (this) { |
| 4539 | Log.w(TAG, "Key dispatching timed out sending to " + |
| 4540 | (targetWin != null ? targetWin.mAttrs.getTitle() |
| 4541 | : "<null>")); |
| 4542 | // NOSHIP debugging |
| 4543 | Log.w(TAG, "Dispatch state: " + mDispatchState); |
| 4544 | Log.w(TAG, "Current state: " + new DispatchState(nextKey, targetWin)); |
| 4545 | // END NOSHIP |
| 4546 | //dump(); |
| 4547 | if (targetWin != null) { |
| 4548 | at = targetWin.getAppToken(); |
| 4549 | } else if (targetApp != null) { |
| 4550 | at = targetApp.appToken; |
| 4551 | } |
| 4552 | } |
| 4553 | |
| 4554 | boolean abort = true; |
| 4555 | if (at != null) { |
| 4556 | try { |
| 4557 | long timeout = at.getKeyDispatchingTimeout(); |
| 4558 | if (timeout > waitedFor) { |
| 4559 | // we did not wait the proper amount of time for this application. |
| 4560 | // set the timeout to be the real timeout and wait again. |
| 4561 | keyDispatchingTimeout = timeout - waitedFor; |
| 4562 | continue; |
| 4563 | } else { |
| 4564 | abort = at.keyDispatchingTimedOut(); |
| 4565 | } |
| 4566 | } catch (RemoteException ex) { |
| 4567 | } |
| 4568 | } |
| 4569 | |
| 4570 | synchronized (this) { |
| 4571 | if (abort && (mLastWin == targetWin || targetWin == null)) { |
| 4572 | mFinished = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4573 | if (mLastWin != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4574 | if (DEBUG_INPUT) Log.v(TAG, |
| 4575 | "Window " + mLastWin + |
| 4576 | " timed out on key input"); |
| 4577 | if (mLastWin.mToken.paused) { |
| 4578 | Log.w(TAG, "Un-pausing dispatching to this window"); |
| 4579 | mLastWin.mToken.paused = false; |
| 4580 | } |
| 4581 | } |
| 4582 | if (mMotionTarget == targetWin) { |
| 4583 | mMotionTarget = null; |
| 4584 | } |
| 4585 | mLastWin = null; |
| 4586 | mLastBinder = null; |
| 4587 | if (failIfTimeout || targetWin == null) { |
| 4588 | return null; |
| 4589 | } |
| 4590 | } else { |
| 4591 | Log.w(TAG, "Continuing to wait for key to be dispatched"); |
| 4592 | startTime = SystemClock.uptimeMillis(); |
| 4593 | } |
| 4594 | } |
| 4595 | } |
| 4596 | } |
| 4597 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4598 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4599 | Object findTargetWindow(KeyEvent nextKey, QueuedEvent qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4600 | MotionEvent nextMotion, boolean isPointerEvent, |
| 4601 | int callingPid, int callingUid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4602 | mOutsideTouchTargets = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4603 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4604 | if (nextKey != null) { |
| 4605 | // Find the target window for a normal key event. |
| 4606 | final int keycode = nextKey.getKeyCode(); |
| 4607 | final int repeatCount = nextKey.getRepeatCount(); |
| 4608 | final boolean down = nextKey.getAction() != KeyEvent.ACTION_UP; |
| 4609 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(keycode); |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4610 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4611 | if (!dispatch) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4612 | if (callingUid == 0 || |
| 4613 | mContext.checkPermission( |
| 4614 | android.Manifest.permission.INJECT_EVENTS, |
| 4615 | callingPid, callingUid) |
| 4616 | == PackageManager.PERMISSION_GRANTED) { |
| 4617 | mPolicy.interceptKeyTi(null, keycode, |
| 4618 | nextKey.getMetaState(), down, repeatCount); |
| 4619 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4620 | Log.w(TAG, "Event timeout during app switch: dropping " |
| 4621 | + nextKey); |
| 4622 | return SKIP_TARGET_TOKEN; |
| 4623 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4624 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4625 | // System.out.println("##### [" + SystemClock.uptimeMillis() + "] WindowManagerService.dispatchKey(" + keycode + ", " + down + ", " + repeatCount + ")"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4626 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4627 | WindowState focus = null; |
| 4628 | synchronized(mWindowMap) { |
| 4629 | focus = getFocusedWindowLocked(); |
| 4630 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4631 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4632 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4633 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4634 | if (callingUid == 0 || |
| 4635 | (focus != null && callingUid == focus.mSession.mUid) || |
| 4636 | mContext.checkPermission( |
| 4637 | android.Manifest.permission.INJECT_EVENTS, |
| 4638 | callingPid, callingUid) |
| 4639 | == PackageManager.PERMISSION_GRANTED) { |
| 4640 | if (mPolicy.interceptKeyTi(focus, |
| 4641 | keycode, nextKey.getMetaState(), down, repeatCount)) { |
| 4642 | return CONSUMED_EVENT_TOKEN; |
| 4643 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4644 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4645 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4646 | return focus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4647 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4648 | } else if (!isPointerEvent) { |
| 4649 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(-1); |
| 4650 | if (!dispatch) { |
| 4651 | Log.w(TAG, "Event timeout during app switch: dropping trackball " |
| 4652 | + nextMotion); |
| 4653 | return SKIP_TARGET_TOKEN; |
| 4654 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4655 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4656 | WindowState focus = null; |
| 4657 | synchronized(mWindowMap) { |
| 4658 | focus = getFocusedWindowLocked(); |
| 4659 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4660 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4661 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
| 4662 | return focus; |
| 4663 | } |
| 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 | if (nextMotion == null) { |
| 4666 | return SKIP_TARGET_TOKEN; |
| 4667 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4668 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4669 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey( |
| 4670 | KeyEvent.KEYCODE_UNKNOWN); |
| 4671 | if (!dispatch) { |
| 4672 | Log.w(TAG, "Event timeout during app switch: dropping pointer " |
| 4673 | + nextMotion); |
| 4674 | return SKIP_TARGET_TOKEN; |
| 4675 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4676 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4677 | // Find the target window for a pointer event. |
| 4678 | int action = nextMotion.getAction(); |
| 4679 | final float xf = nextMotion.getX(); |
| 4680 | final float yf = nextMotion.getY(); |
| 4681 | final long eventTime = nextMotion.getEventTime(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4682 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4683 | final boolean screenWasOff = qev != null |
| 4684 | && (qev.flags&WindowManagerPolicy.FLAG_BRIGHT_HERE) != 0; |
| 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 | WindowState target = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4687 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4688 | synchronized(mWindowMap) { |
| 4689 | synchronized (this) { |
| 4690 | if (action == MotionEvent.ACTION_DOWN) { |
| 4691 | if (mMotionTarget != null) { |
| 4692 | // this is weird, we got a pen down, but we thought it was |
| 4693 | // already down! |
| 4694 | // XXX: We should probably send an ACTION_UP to the current |
| 4695 | // target. |
| 4696 | Log.w(TAG, "Pointer down received while already down in: " |
| 4697 | + mMotionTarget); |
| 4698 | mMotionTarget = null; |
| 4699 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4700 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4701 | // ACTION_DOWN is special, because we need to lock next events to |
| 4702 | // the window we'll land onto. |
| 4703 | final int x = (int)xf; |
| 4704 | final int y = (int)yf; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4705 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4706 | final ArrayList windows = mWindows; |
| 4707 | final int N = windows.size(); |
| 4708 | WindowState topErrWindow = null; |
| 4709 | final Rect tmpRect = mTempRect; |
| 4710 | for (int i=N-1; i>=0; i--) { |
| 4711 | WindowState child = (WindowState)windows.get(i); |
| 4712 | //Log.i(TAG, "Checking dispatch to: " + child); |
| 4713 | final int flags = child.mAttrs.flags; |
| 4714 | if ((flags & WindowManager.LayoutParams.FLAG_SYSTEM_ERROR) != 0) { |
| 4715 | if (topErrWindow == null) { |
| 4716 | topErrWindow = child; |
| 4717 | } |
| 4718 | } |
| 4719 | if (!child.isVisibleLw()) { |
| 4720 | //Log.i(TAG, "Not visible!"); |
| 4721 | continue; |
| 4722 | } |
| 4723 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 4724 | //Log.i(TAG, "Not touchable!"); |
| 4725 | if ((flags & WindowManager.LayoutParams |
| 4726 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 4727 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 4728 | mOutsideTouchTargets = child; |
| 4729 | } |
| 4730 | continue; |
| 4731 | } |
| 4732 | tmpRect.set(child.mFrame); |
| 4733 | if (child.mTouchableInsets == ViewTreeObserver |
| 4734 | .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) { |
| 4735 | // The touch is inside of the window if it is |
| 4736 | // inside the frame, AND the content part of that |
| 4737 | // frame that was given by the application. |
| 4738 | tmpRect.left += child.mGivenContentInsets.left; |
| 4739 | tmpRect.top += child.mGivenContentInsets.top; |
| 4740 | tmpRect.right -= child.mGivenContentInsets.right; |
| 4741 | tmpRect.bottom -= child.mGivenContentInsets.bottom; |
| 4742 | } else if (child.mTouchableInsets == ViewTreeObserver |
| 4743 | .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) { |
| 4744 | // The touch is inside of the window if it is |
| 4745 | // inside the frame, AND the visible part of that |
| 4746 | // frame that was given by the application. |
| 4747 | tmpRect.left += child.mGivenVisibleInsets.left; |
| 4748 | tmpRect.top += child.mGivenVisibleInsets.top; |
| 4749 | tmpRect.right -= child.mGivenVisibleInsets.right; |
| 4750 | tmpRect.bottom -= child.mGivenVisibleInsets.bottom; |
| 4751 | } |
| 4752 | final int touchFlags = flags & |
| 4753 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 4754 | |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 4755 | if (tmpRect.contains(x, y) || touchFlags == 0) { |
| 4756 | //Log.i(TAG, "Using this target!"); |
| 4757 | if (!screenWasOff || (flags & |
| 4758 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING) != 0) { |
| 4759 | mMotionTarget = child; |
| 4760 | } else { |
| 4761 | //Log.i(TAG, "Waking, skip!"); |
| 4762 | mMotionTarget = null; |
| 4763 | } |
| 4764 | break; |
| 4765 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4766 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4767 | if ((flags & WindowManager.LayoutParams |
| 4768 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 4769 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 4770 | mOutsideTouchTargets = child; |
| 4771 | //Log.i(TAG, "Adding to outside target list: " + child); |
| 4772 | } |
| 4773 | } |
| 4774 | |
| 4775 | // if there's an error window but it's not accepting |
| 4776 | // focus (typically because it is not yet visible) just |
| 4777 | // wait for it -- any other focused window may in fact |
| 4778 | // be in ANR state. |
| 4779 | if (topErrWindow != null && mMotionTarget != topErrWindow) { |
| 4780 | mMotionTarget = null; |
| 4781 | } |
| 4782 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4783 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4784 | target = mMotionTarget; |
| 4785 | } |
| 4786 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4787 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4788 | wakeupIfNeeded(target, eventType(nextMotion)); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4789 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4790 | // Pointer events are a little different -- if there isn't a |
| 4791 | // target found for any event, then just drop it. |
| 4792 | return target != null ? target : SKIP_TARGET_TOKEN; |
| 4793 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4794 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4795 | boolean checkShouldDispatchKey(int keycode) { |
| 4796 | synchronized (this) { |
| 4797 | if (mPolicy.isAppSwitchKeyTqTiLwLi(keycode)) { |
| 4798 | mTimeToSwitch = 0; |
| 4799 | return true; |
| 4800 | } |
| 4801 | if (mTimeToSwitch != 0 |
| 4802 | && mTimeToSwitch < SystemClock.uptimeMillis()) { |
| 4803 | return false; |
| 4804 | } |
| 4805 | return true; |
| 4806 | } |
| 4807 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4808 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4809 | void bindTargetWindowLocked(WindowState win, |
| 4810 | int pendingWhat, QueuedEvent pendingMotion) { |
| 4811 | synchronized (this) { |
| 4812 | bindTargetWindowLockedLocked(win, pendingWhat, pendingMotion); |
| 4813 | } |
| 4814 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4815 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4816 | void bindTargetWindowLocked(WindowState win) { |
| 4817 | synchronized (this) { |
| 4818 | bindTargetWindowLockedLocked(win, RETURN_NOTHING, null); |
| 4819 | } |
| 4820 | } |
| 4821 | |
| 4822 | void bindTargetWindowLockedLocked(WindowState win, |
| 4823 | int pendingWhat, QueuedEvent pendingMotion) { |
| 4824 | mLastWin = win; |
| 4825 | mLastBinder = win.mClient.asBinder(); |
| 4826 | mFinished = false; |
| 4827 | if (pendingMotion != null) { |
| 4828 | final Session s = win.mSession; |
| 4829 | if (pendingWhat == RETURN_PENDING_POINTER) { |
| 4830 | releasePendingPointerLocked(s); |
| 4831 | s.mPendingPointerMove = pendingMotion; |
| 4832 | s.mPendingPointerWindow = win; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4833 | if (DEBUG_INPUT) Log.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4834 | "bindTargetToWindow " + s.mPendingPointerMove); |
| 4835 | } else if (pendingWhat == RETURN_PENDING_TRACKBALL) { |
| 4836 | releasePendingTrackballLocked(s); |
| 4837 | s.mPendingTrackballMove = pendingMotion; |
| 4838 | s.mPendingTrackballWindow = win; |
| 4839 | } |
| 4840 | } |
| 4841 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4842 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4843 | void releasePendingPointerLocked(Session s) { |
| 4844 | if (DEBUG_INPUT) Log.v(TAG, |
| 4845 | "releasePendingPointer " + s.mPendingPointerMove); |
| 4846 | if (s.mPendingPointerMove != null) { |
| 4847 | mQueue.recycleEvent(s.mPendingPointerMove); |
| 4848 | s.mPendingPointerMove = null; |
| 4849 | } |
| 4850 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4851 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4852 | void releasePendingTrackballLocked(Session s) { |
| 4853 | if (s.mPendingTrackballMove != null) { |
| 4854 | mQueue.recycleEvent(s.mPendingTrackballMove); |
| 4855 | s.mPendingTrackballMove = null; |
| 4856 | } |
| 4857 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4858 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4859 | MotionEvent finishedKey(Session session, IWindow client, boolean force, |
| 4860 | int returnWhat) { |
| 4861 | if (DEBUG_INPUT) Log.v( |
| 4862 | TAG, "finishedKey: client=" + client + ", force=" + force); |
| 4863 | |
| 4864 | if (client == null) { |
| 4865 | return null; |
| 4866 | } |
| 4867 | |
| 4868 | synchronized (this) { |
| 4869 | if (DEBUG_INPUT) Log.v( |
| 4870 | TAG, "finishedKey: client=" + client.asBinder() |
| 4871 | + ", force=" + force + ", last=" + mLastBinder |
| 4872 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) + ")"); |
| 4873 | |
| 4874 | QueuedEvent qev = null; |
| 4875 | WindowState win = null; |
| 4876 | if (returnWhat == RETURN_PENDING_POINTER) { |
| 4877 | qev = session.mPendingPointerMove; |
| 4878 | win = session.mPendingPointerWindow; |
| 4879 | session.mPendingPointerMove = null; |
| 4880 | session.mPendingPointerWindow = null; |
| 4881 | } else if (returnWhat == RETURN_PENDING_TRACKBALL) { |
| 4882 | qev = session.mPendingTrackballMove; |
| 4883 | win = session.mPendingTrackballWindow; |
| 4884 | session.mPendingTrackballMove = null; |
| 4885 | session.mPendingTrackballWindow = null; |
| 4886 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4887 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4888 | if (mLastBinder == client.asBinder()) { |
| 4889 | if (DEBUG_INPUT) Log.v( |
| 4890 | TAG, "finishedKey: last paused=" |
| 4891 | + ((mLastWin != null) ? mLastWin.mToken.paused : "null")); |
| 4892 | if (mLastWin != null && (!mLastWin.mToken.paused || force |
| 4893 | || !mEventDispatching)) { |
| 4894 | doFinishedKeyLocked(false); |
| 4895 | } else { |
| 4896 | // Make sure to wake up anyone currently waiting to |
| 4897 | // dispatch a key, so they can re-evaluate their |
| 4898 | // current situation. |
| 4899 | mFinished = true; |
| 4900 | notifyAll(); |
| 4901 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4902 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4903 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4904 | if (qev != null) { |
| 4905 | MotionEvent res = (MotionEvent)qev.event; |
| 4906 | if (DEBUG_INPUT) Log.v(TAG, |
| 4907 | "Returning pending motion: " + res); |
| 4908 | mQueue.recycleEvent(qev); |
| 4909 | if (win != null && returnWhat == RETURN_PENDING_POINTER) { |
| 4910 | res.offsetLocation(-win.mFrame.left, -win.mFrame.top); |
| 4911 | } |
| 4912 | return res; |
| 4913 | } |
| 4914 | return null; |
| 4915 | } |
| 4916 | } |
| 4917 | |
| 4918 | void tickle() { |
| 4919 | synchronized (this) { |
| 4920 | notifyAll(); |
| 4921 | } |
| 4922 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4923 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4924 | void handleNewWindowLocked(WindowState newWindow) { |
| 4925 | if (!newWindow.canReceiveKeys()) { |
| 4926 | return; |
| 4927 | } |
| 4928 | synchronized (this) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 4929 | if (DEBUG_INPUT) Log.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4930 | TAG, "New key dispatch window: win=" |
| 4931 | + newWindow.mClient.asBinder() |
| 4932 | + ", last=" + mLastBinder |
| 4933 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 4934 | + "), finished=" + mFinished + ", paused=" |
| 4935 | + newWindow.mToken.paused); |
| 4936 | |
| 4937 | // Displaying a window implicitly causes dispatching to |
| 4938 | // be unpaused. (This is to protect against bugs if someone |
| 4939 | // pauses dispatching but forgets to resume.) |
| 4940 | newWindow.mToken.paused = false; |
| 4941 | |
| 4942 | mGotFirstWindow = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4943 | |
| 4944 | if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) { |
| 4945 | if (DEBUG_INPUT) Log.v(TAG, |
| 4946 | "New SYSTEM_ERROR window; resetting state"); |
| 4947 | mLastWin = null; |
| 4948 | mLastBinder = null; |
| 4949 | mMotionTarget = null; |
| 4950 | mFinished = true; |
| 4951 | } else if (mLastWin != null) { |
| 4952 | // If the new window is above the window we are |
| 4953 | // waiting on, then stop waiting and let key dispatching |
| 4954 | // start on the new guy. |
| 4955 | if (DEBUG_INPUT) Log.v( |
| 4956 | TAG, "Last win layer=" + mLastWin.mLayer |
| 4957 | + ", new win layer=" + newWindow.mLayer); |
| 4958 | if (newWindow.mLayer >= mLastWin.mLayer) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 4959 | // The new window is above the old; finish pending input to the last |
| 4960 | // window and start directing it to the new one. |
| 4961 | mLastWin.mToken.paused = false; |
| 4962 | doFinishedKeyLocked(true); // does a notifyAll() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4963 | } |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 4964 | // Either the new window is lower, so there is no need to wake key waiters, |
| 4965 | // or we just finished key input to the previous window, which implicitly |
| 4966 | // notified the key waiters. In both cases, we don't need to issue the |
| 4967 | // notification here. |
| 4968 | return; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4969 | } |
| 4970 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 4971 | // Now that we've put a new window state in place, make the event waiter |
| 4972 | // take notice and retarget its attentions. |
| 4973 | notifyAll(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4974 | } |
| 4975 | } |
| 4976 | |
| 4977 | void pauseDispatchingLocked(WindowToken token) { |
| 4978 | synchronized (this) |
| 4979 | { |
| 4980 | if (DEBUG_INPUT) Log.v(TAG, "Pausing WindowToken " + token); |
| 4981 | token.paused = true; |
| 4982 | |
| 4983 | /* |
| 4984 | if (mLastWin != null && !mFinished && mLastWin.mBaseLayer <= layer) { |
| 4985 | mPaused = true; |
| 4986 | } else { |
| 4987 | if (mLastWin == null) { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 4988 | 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] | 4989 | } else if (mFinished) { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 4990 | 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] | 4991 | } else { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 4992 | 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] | 4993 | } |
| 4994 | } |
| 4995 | */ |
| 4996 | } |
| 4997 | } |
| 4998 | |
| 4999 | void resumeDispatchingLocked(WindowToken token) { |
| 5000 | synchronized (this) { |
| 5001 | if (token.paused) { |
| 5002 | if (DEBUG_INPUT) Log.v( |
| 5003 | TAG, "Resuming WindowToken " + token |
| 5004 | + ", last=" + mLastBinder |
| 5005 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 5006 | + "), finished=" + mFinished + ", paused=" |
| 5007 | + token.paused); |
| 5008 | token.paused = false; |
| 5009 | if (mLastWin != null && mLastWin.mToken == token && mFinished) { |
| 5010 | doFinishedKeyLocked(true); |
| 5011 | } else { |
| 5012 | notifyAll(); |
| 5013 | } |
| 5014 | } |
| 5015 | } |
| 5016 | } |
| 5017 | |
| 5018 | void setEventDispatchingLocked(boolean enabled) { |
| 5019 | synchronized (this) { |
| 5020 | mEventDispatching = enabled; |
| 5021 | notifyAll(); |
| 5022 | } |
| 5023 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5024 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5025 | void appSwitchComing() { |
| 5026 | synchronized (this) { |
| 5027 | // Don't wait for more than .5 seconds for app to finish |
| 5028 | // processing the pending events. |
| 5029 | long now = SystemClock.uptimeMillis() + 500; |
| 5030 | if (DEBUG_INPUT) Log.v(TAG, "appSwitchComing: " + now); |
| 5031 | if (mTimeToSwitch == 0 || now < mTimeToSwitch) { |
| 5032 | mTimeToSwitch = now; |
| 5033 | } |
| 5034 | notifyAll(); |
| 5035 | } |
| 5036 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5037 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5038 | private final void doFinishedKeyLocked(boolean doRecycle) { |
| 5039 | if (mLastWin != null) { |
| 5040 | releasePendingPointerLocked(mLastWin.mSession); |
| 5041 | releasePendingTrackballLocked(mLastWin.mSession); |
| 5042 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5043 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5044 | if (mLastWin == null || !mLastWin.mToken.paused |
| 5045 | || !mLastWin.isVisibleLw()) { |
| 5046 | // If the current window has been paused, we aren't -really- |
| 5047 | // finished... so let the waiters still wait. |
| 5048 | mLastWin = null; |
| 5049 | mLastBinder = null; |
| 5050 | } |
| 5051 | mFinished = true; |
| 5052 | notifyAll(); |
| 5053 | } |
| 5054 | } |
| 5055 | |
| 5056 | private class KeyQ extends KeyInputQueue |
| 5057 | implements KeyInputQueue.FilterCallback { |
| 5058 | PowerManager.WakeLock mHoldingScreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5059 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5060 | KeyQ() { |
| 5061 | super(mContext); |
| 5062 | PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE); |
| 5063 | mHoldingScreen = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 5064 | "KEEP_SCREEN_ON_FLAG"); |
| 5065 | mHoldingScreen.setReferenceCounted(false); |
| 5066 | } |
| 5067 | |
| 5068 | @Override |
| 5069 | boolean preprocessEvent(InputDevice device, RawInputEvent event) { |
| 5070 | if (mPolicy.preprocessInputEventTq(event)) { |
| 5071 | return true; |
| 5072 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5073 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5074 | switch (event.type) { |
| 5075 | case RawInputEvent.EV_KEY: { |
| 5076 | // XXX begin hack |
| 5077 | if (DEBUG) { |
| 5078 | if (event.keycode == KeyEvent.KEYCODE_G) { |
| 5079 | if (event.value != 0) { |
| 5080 | // G down |
| 5081 | mPolicy.screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 5082 | } |
| 5083 | return false; |
| 5084 | } |
| 5085 | if (event.keycode == KeyEvent.KEYCODE_D) { |
| 5086 | if (event.value != 0) { |
| 5087 | //dump(); |
| 5088 | } |
| 5089 | return false; |
| 5090 | } |
| 5091 | } |
| 5092 | // XXX end hack |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5093 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5094 | boolean screenIsOff = !mPowerManager.screenIsOn(); |
| 5095 | boolean screenIsDim = !mPowerManager.screenIsBright(); |
| 5096 | int actions = mPolicy.interceptKeyTq(event, !screenIsOff); |
| 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 | if ((actions & WindowManagerPolicy.ACTION_GO_TO_SLEEP) != 0) { |
| 5099 | mPowerManager.goToSleep(event.when); |
| 5100 | } |
| 5101 | |
| 5102 | if (screenIsOff) { |
| 5103 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 5104 | } |
| 5105 | if (screenIsDim) { |
| 5106 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 5107 | } |
| 5108 | if ((actions & WindowManagerPolicy.ACTION_POKE_USER_ACTIVITY) != 0) { |
| 5109 | mPowerManager.userActivity(event.when, false, |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5110 | LocalPowerManager.BUTTON_EVENT, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5111 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5112 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5113 | if ((actions & WindowManagerPolicy.ACTION_PASS_TO_USER) != 0) { |
| 5114 | if (event.value != 0 && mPolicy.isAppSwitchKeyTqTiLwLi(event.keycode)) { |
| 5115 | filterQueue(this); |
| 5116 | mKeyWaiter.appSwitchComing(); |
| 5117 | } |
| 5118 | return true; |
| 5119 | } else { |
| 5120 | return false; |
| 5121 | } |
| 5122 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5123 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5124 | case RawInputEvent.EV_REL: { |
| 5125 | boolean screenIsOff = !mPowerManager.screenIsOn(); |
| 5126 | boolean screenIsDim = !mPowerManager.screenIsBright(); |
| 5127 | if (screenIsOff) { |
| 5128 | if (!mPolicy.isWakeRelMovementTq(event.deviceId, |
| 5129 | device.classes, event)) { |
| 5130 | //Log.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| 5131 | return false; |
| 5132 | } |
| 5133 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 5134 | } |
| 5135 | if (screenIsDim) { |
| 5136 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 5137 | } |
| 5138 | return true; |
| 5139 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5140 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5141 | case RawInputEvent.EV_ABS: { |
| 5142 | boolean screenIsOff = !mPowerManager.screenIsOn(); |
| 5143 | boolean screenIsDim = !mPowerManager.screenIsBright(); |
| 5144 | if (screenIsOff) { |
| 5145 | if (!mPolicy.isWakeAbsMovementTq(event.deviceId, |
| 5146 | device.classes, event)) { |
| 5147 | //Log.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| 5148 | return false; |
| 5149 | } |
| 5150 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 5151 | } |
| 5152 | if (screenIsDim) { |
| 5153 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 5154 | } |
| 5155 | return true; |
| 5156 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5157 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5158 | default: |
| 5159 | return true; |
| 5160 | } |
| 5161 | } |
| 5162 | |
| 5163 | public int filterEvent(QueuedEvent ev) { |
| 5164 | switch (ev.classType) { |
| 5165 | case RawInputEvent.CLASS_KEYBOARD: |
| 5166 | KeyEvent ke = (KeyEvent)ev.event; |
| 5167 | if (mPolicy.isMovementKeyTi(ke.getKeyCode())) { |
| 5168 | Log.w(TAG, "Dropping movement key during app switch: " |
| 5169 | + ke.getKeyCode() + ", action=" + ke.getAction()); |
| 5170 | return FILTER_REMOVE; |
| 5171 | } |
| 5172 | return FILTER_ABORT; |
| 5173 | default: |
| 5174 | return FILTER_KEEP; |
| 5175 | } |
| 5176 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5177 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5178 | /** |
| 5179 | * Must be called with the main window manager lock held. |
| 5180 | */ |
| 5181 | void setHoldScreenLocked(boolean holding) { |
| 5182 | boolean state = mHoldingScreen.isHeld(); |
| 5183 | if (holding != state) { |
| 5184 | if (holding) { |
| 5185 | mHoldingScreen.acquire(); |
| 5186 | } else { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 5187 | mPolicy.screenOnStoppedLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5188 | mHoldingScreen.release(); |
| 5189 | } |
| 5190 | } |
| 5191 | } |
| 5192 | }; |
| 5193 | |
| 5194 | public boolean detectSafeMode() { |
| 5195 | mSafeMode = mPolicy.detectSafeMode(); |
| 5196 | return mSafeMode; |
| 5197 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5198 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5199 | public void systemReady() { |
| 5200 | mPolicy.systemReady(); |
| 5201 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5202 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5203 | private final class InputDispatcherThread extends Thread { |
| 5204 | // Time to wait when there is nothing to do: 9999 seconds. |
| 5205 | static final int LONG_WAIT=9999*1000; |
| 5206 | |
| 5207 | public InputDispatcherThread() { |
| 5208 | super("InputDispatcher"); |
| 5209 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5210 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5211 | @Override |
| 5212 | public void run() { |
| 5213 | while (true) { |
| 5214 | try { |
| 5215 | process(); |
| 5216 | } catch (Exception e) { |
| 5217 | Log.e(TAG, "Exception in input dispatcher", e); |
| 5218 | } |
| 5219 | } |
| 5220 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5221 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5222 | private void process() { |
| 5223 | android.os.Process.setThreadPriority( |
| 5224 | android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5225 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5226 | // The last key event we saw |
| 5227 | KeyEvent lastKey = null; |
| 5228 | |
| 5229 | // Last keydown time for auto-repeating keys |
| 5230 | long lastKeyTime = SystemClock.uptimeMillis(); |
| 5231 | long nextKeyTime = lastKeyTime+LONG_WAIT; |
| 5232 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5233 | // How many successive repeats we generated |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5234 | int keyRepeatCount = 0; |
| 5235 | |
| 5236 | // Need to report that configuration has changed? |
| 5237 | boolean configChanged = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5238 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5239 | while (true) { |
| 5240 | long curTime = SystemClock.uptimeMillis(); |
| 5241 | |
| 5242 | if (DEBUG_INPUT) Log.v( |
| 5243 | TAG, "Waiting for next key: now=" + curTime |
| 5244 | + ", repeat @ " + nextKeyTime); |
| 5245 | |
| 5246 | // Retrieve next event, waiting only as long as the next |
| 5247 | // repeat timeout. If the configuration has changed, then |
| 5248 | // don't wait at all -- we'll report the change as soon as |
| 5249 | // we have processed all events. |
| 5250 | QueuedEvent ev = mQueue.getEvent( |
| 5251 | (int)((!configChanged && curTime < nextKeyTime) |
| 5252 | ? (nextKeyTime-curTime) : 0)); |
| 5253 | |
| 5254 | if (DEBUG_INPUT && ev != null) Log.v( |
| 5255 | TAG, "Event: type=" + ev.classType + " data=" + ev.event); |
| 5256 | |
| 5257 | try { |
| 5258 | if (ev != null) { |
| 5259 | curTime = ev.when; |
| 5260 | int eventType; |
| 5261 | if (ev.classType == RawInputEvent.CLASS_TOUCHSCREEN) { |
| 5262 | eventType = eventType((MotionEvent)ev.event); |
| 5263 | } else if (ev.classType == RawInputEvent.CLASS_KEYBOARD || |
| 5264 | ev.classType == RawInputEvent.CLASS_TRACKBALL) { |
| 5265 | eventType = LocalPowerManager.BUTTON_EVENT; |
| 5266 | } else { |
| 5267 | eventType = LocalPowerManager.OTHER_EVENT; |
| 5268 | } |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5269 | try { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5270 | long now = SystemClock.uptimeMillis(); |
| 5271 | |
| 5272 | if ((now - mLastBatteryStatsCallTime) |
| 5273 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 5274 | mLastBatteryStatsCallTime = now; |
| 5275 | mBatteryStats.noteInputEvent(); |
| 5276 | } |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5277 | } catch (RemoteException e) { |
| 5278 | // Ignore |
| 5279 | } |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5280 | mPowerManager.userActivity(curTime, false, eventType, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5281 | switch (ev.classType) { |
| 5282 | case RawInputEvent.CLASS_KEYBOARD: |
| 5283 | KeyEvent ke = (KeyEvent)ev.event; |
| 5284 | if (ke.isDown()) { |
| 5285 | lastKey = ke; |
| 5286 | keyRepeatCount = 0; |
| 5287 | lastKeyTime = curTime; |
| 5288 | nextKeyTime = lastKeyTime |
| 5289 | + KEY_REPEAT_FIRST_DELAY; |
| 5290 | if (DEBUG_INPUT) Log.v( |
| 5291 | TAG, "Received key down: first repeat @ " |
| 5292 | + nextKeyTime); |
| 5293 | } else { |
| 5294 | lastKey = null; |
| 5295 | // Arbitrary long timeout. |
| 5296 | lastKeyTime = curTime; |
| 5297 | nextKeyTime = curTime + LONG_WAIT; |
| 5298 | if (DEBUG_INPUT) Log.v( |
| 5299 | TAG, "Received key up: ignore repeat @ " |
| 5300 | + nextKeyTime); |
| 5301 | } |
| 5302 | dispatchKey((KeyEvent)ev.event, 0, 0); |
| 5303 | mQueue.recycleEvent(ev); |
| 5304 | break; |
| 5305 | case RawInputEvent.CLASS_TOUCHSCREEN: |
| 5306 | //Log.i(TAG, "Read next event " + ev); |
| 5307 | dispatchPointer(ev, (MotionEvent)ev.event, 0, 0); |
| 5308 | break; |
| 5309 | case RawInputEvent.CLASS_TRACKBALL: |
| 5310 | dispatchTrackball(ev, (MotionEvent)ev.event, 0, 0); |
| 5311 | break; |
| 5312 | case RawInputEvent.CLASS_CONFIGURATION_CHANGED: |
| 5313 | configChanged = true; |
| 5314 | break; |
| 5315 | default: |
| 5316 | mQueue.recycleEvent(ev); |
| 5317 | break; |
| 5318 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5319 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5320 | } else if (configChanged) { |
| 5321 | configChanged = false; |
| 5322 | sendNewConfiguration(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5323 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5324 | } else if (lastKey != null) { |
| 5325 | curTime = SystemClock.uptimeMillis(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5326 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5327 | // Timeout occurred while key was down. If it is at or |
| 5328 | // past the key repeat time, dispatch the repeat. |
| 5329 | if (DEBUG_INPUT) Log.v( |
| 5330 | TAG, "Key timeout: repeat=" + nextKeyTime |
| 5331 | + ", now=" + curTime); |
| 5332 | if (curTime < nextKeyTime) { |
| 5333 | continue; |
| 5334 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5335 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5336 | lastKeyTime = nextKeyTime; |
| 5337 | nextKeyTime = nextKeyTime + KEY_REPEAT_DELAY; |
| 5338 | keyRepeatCount++; |
| 5339 | if (DEBUG_INPUT) Log.v( |
| 5340 | TAG, "Key repeat: count=" + keyRepeatCount |
| 5341 | + ", next @ " + nextKeyTime); |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5342 | dispatchKey(KeyEvent.changeTimeRepeat(lastKey, curTime, keyRepeatCount), 0, 0); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5343 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5344 | } else { |
| 5345 | curTime = SystemClock.uptimeMillis(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5346 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5347 | lastKeyTime = curTime; |
| 5348 | nextKeyTime = curTime + LONG_WAIT; |
| 5349 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5350 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5351 | } catch (Exception e) { |
| 5352 | Log.e(TAG, |
| 5353 | "Input thread received uncaught exception: " + e, e); |
| 5354 | } |
| 5355 | } |
| 5356 | } |
| 5357 | } |
| 5358 | |
| 5359 | // ------------------------------------------------------------- |
| 5360 | // Client Session State |
| 5361 | // ------------------------------------------------------------- |
| 5362 | |
| 5363 | private final class Session extends IWindowSession.Stub |
| 5364 | implements IBinder.DeathRecipient { |
| 5365 | final IInputMethodClient mClient; |
| 5366 | final IInputContext mInputContext; |
| 5367 | final int mUid; |
| 5368 | final int mPid; |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5369 | final String mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5370 | SurfaceSession mSurfaceSession; |
| 5371 | int mNumWindow = 0; |
| 5372 | boolean mClientDead = false; |
| 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 | /** |
| 5375 | * Current pointer move event being dispatched to client window... must |
| 5376 | * hold key lock to access. |
| 5377 | */ |
| 5378 | QueuedEvent mPendingPointerMove; |
| 5379 | WindowState mPendingPointerWindow; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5380 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5381 | /** |
| 5382 | * Current trackball move event being dispatched to client window... must |
| 5383 | * hold key lock to access. |
| 5384 | */ |
| 5385 | QueuedEvent mPendingTrackballMove; |
| 5386 | WindowState mPendingTrackballWindow; |
| 5387 | |
| 5388 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 5389 | mClient = client; |
| 5390 | mInputContext = inputContext; |
| 5391 | mUid = Binder.getCallingUid(); |
| 5392 | mPid = Binder.getCallingPid(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5393 | StringBuilder sb = new StringBuilder(); |
| 5394 | sb.append("Session{"); |
| 5395 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 5396 | sb.append(" uid "); |
| 5397 | sb.append(mUid); |
| 5398 | sb.append("}"); |
| 5399 | mStringName = sb.toString(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5400 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5401 | synchronized (mWindowMap) { |
| 5402 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 5403 | IBinder b = ServiceManager.getService( |
| 5404 | Context.INPUT_METHOD_SERVICE); |
| 5405 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 5406 | } |
| 5407 | } |
| 5408 | long ident = Binder.clearCallingIdentity(); |
| 5409 | try { |
| 5410 | // Note: it is safe to call in to the input method manager |
| 5411 | // here because we are not holding our lock. |
| 5412 | if (mInputMethodManager != null) { |
| 5413 | mInputMethodManager.addClient(client, inputContext, |
| 5414 | mUid, mPid); |
| 5415 | } else { |
| 5416 | client.setUsingInputMethod(false); |
| 5417 | } |
| 5418 | client.asBinder().linkToDeath(this, 0); |
| 5419 | } catch (RemoteException e) { |
| 5420 | // The caller has died, so we can just forget about this. |
| 5421 | try { |
| 5422 | if (mInputMethodManager != null) { |
| 5423 | mInputMethodManager.removeClient(client); |
| 5424 | } |
| 5425 | } catch (RemoteException ee) { |
| 5426 | } |
| 5427 | } finally { |
| 5428 | Binder.restoreCallingIdentity(ident); |
| 5429 | } |
| 5430 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5431 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5432 | @Override |
| 5433 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 5434 | throws RemoteException { |
| 5435 | try { |
| 5436 | return super.onTransact(code, data, reply, flags); |
| 5437 | } catch (RuntimeException e) { |
| 5438 | // Log all 'real' exceptions thrown to the caller |
| 5439 | if (!(e instanceof SecurityException)) { |
| 5440 | Log.e(TAG, "Window Session Crash", e); |
| 5441 | } |
| 5442 | throw e; |
| 5443 | } |
| 5444 | } |
| 5445 | |
| 5446 | public void binderDied() { |
| 5447 | // Note: it is safe to call in to the input method manager |
| 5448 | // here because we are not holding our lock. |
| 5449 | try { |
| 5450 | if (mInputMethodManager != null) { |
| 5451 | mInputMethodManager.removeClient(mClient); |
| 5452 | } |
| 5453 | } catch (RemoteException e) { |
| 5454 | } |
| 5455 | synchronized(mWindowMap) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 5456 | mClient.asBinder().unlinkToDeath(this, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5457 | mClientDead = true; |
| 5458 | killSessionLocked(); |
| 5459 | } |
| 5460 | } |
| 5461 | |
| 5462 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
| 5463 | int viewVisibility, Rect outContentInsets) { |
| 5464 | return addWindow(this, window, attrs, viewVisibility, outContentInsets); |
| 5465 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5466 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5467 | public void remove(IWindow window) { |
| 5468 | removeWindow(this, window); |
| 5469 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5470 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5471 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 5472 | int requestedWidth, int requestedHeight, int viewFlags, |
| 5473 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
| 5474 | Rect outVisibleInsets, Surface outSurface) { |
| 5475 | return relayoutWindow(this, window, attrs, |
| 5476 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
| 5477 | outFrame, outContentInsets, outVisibleInsets, outSurface); |
| 5478 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5479 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5480 | public void setTransparentRegion(IWindow window, Region region) { |
| 5481 | setTransparentRegionWindow(this, window, region); |
| 5482 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5483 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5484 | public void setInsets(IWindow window, int touchableInsets, |
| 5485 | Rect contentInsets, Rect visibleInsets) { |
| 5486 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 5487 | visibleInsets); |
| 5488 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5489 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5490 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 5491 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 5492 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5493 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5494 | public void finishDrawing(IWindow window) { |
| 5495 | if (localLOGV) Log.v( |
| 5496 | TAG, "IWindow finishDrawing called for " + window); |
| 5497 | finishDrawingWindow(this, window); |
| 5498 | } |
| 5499 | |
| 5500 | public void finishKey(IWindow window) { |
| 5501 | if (localLOGV) Log.v( |
| 5502 | TAG, "IWindow finishKey called for " + window); |
| 5503 | mKeyWaiter.finishedKey(this, window, false, |
| 5504 | KeyWaiter.RETURN_NOTHING); |
| 5505 | } |
| 5506 | |
| 5507 | public MotionEvent getPendingPointerMove(IWindow window) { |
| 5508 | if (localLOGV) Log.v( |
| 5509 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 5510 | return mKeyWaiter.finishedKey(this, window, false, |
| 5511 | KeyWaiter.RETURN_PENDING_POINTER); |
| 5512 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5513 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5514 | public MotionEvent getPendingTrackballMove(IWindow window) { |
| 5515 | if (localLOGV) Log.v( |
| 5516 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 5517 | return mKeyWaiter.finishedKey(this, window, false, |
| 5518 | KeyWaiter.RETURN_PENDING_TRACKBALL); |
| 5519 | } |
| 5520 | |
| 5521 | public void setInTouchMode(boolean mode) { |
| 5522 | synchronized(mWindowMap) { |
| 5523 | mInTouchMode = mode; |
| 5524 | } |
| 5525 | } |
| 5526 | |
| 5527 | public boolean getInTouchMode() { |
| 5528 | synchronized(mWindowMap) { |
| 5529 | return mInTouchMode; |
| 5530 | } |
| 5531 | } |
| 5532 | |
| 5533 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 5534 | boolean always) { |
| 5535 | synchronized(mWindowMap) { |
| 5536 | long ident = Binder.clearCallingIdentity(); |
| 5537 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 5538 | return mPolicy.performHapticFeedbackLw( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5539 | windowForClientLocked(this, window), effectId, always); |
| 5540 | } finally { |
| 5541 | Binder.restoreCallingIdentity(ident); |
| 5542 | } |
| 5543 | } |
| 5544 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5545 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5546 | void windowAddedLocked() { |
| 5547 | if (mSurfaceSession == null) { |
| 5548 | if (localLOGV) Log.v( |
| 5549 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 5550 | mSurfaceSession = new SurfaceSession(); |
| 5551 | mSessions.add(this); |
| 5552 | } |
| 5553 | mNumWindow++; |
| 5554 | } |
| 5555 | |
| 5556 | void windowRemovedLocked() { |
| 5557 | mNumWindow--; |
| 5558 | killSessionLocked(); |
| 5559 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5560 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5561 | void killSessionLocked() { |
| 5562 | if (mNumWindow <= 0 && mClientDead) { |
| 5563 | mSessions.remove(this); |
| 5564 | if (mSurfaceSession != null) { |
| 5565 | if (localLOGV) Log.v( |
| 5566 | TAG, "Last window removed from " + this |
| 5567 | + ", destroying " + mSurfaceSession); |
| 5568 | try { |
| 5569 | mSurfaceSession.kill(); |
| 5570 | } catch (Exception e) { |
| 5571 | Log.w(TAG, "Exception thrown when killing surface session " |
| 5572 | + mSurfaceSession + " in session " + this |
| 5573 | + ": " + e.toString()); |
| 5574 | } |
| 5575 | mSurfaceSession = null; |
| 5576 | } |
| 5577 | } |
| 5578 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5579 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5580 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5581 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 5582 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 5583 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
| 5584 | if (mPendingPointerWindow != null || mPendingPointerMove != null) { |
| 5585 | pw.print(prefix); |
| 5586 | pw.print("mPendingPointerWindow="); pw.print(mPendingPointerWindow); |
| 5587 | pw.print(" mPendingPointerMove="); pw.println(mPendingPointerMove); |
| 5588 | } |
| 5589 | if (mPendingTrackballWindow != null || mPendingTrackballMove != null) { |
| 5590 | pw.print(prefix); |
| 5591 | pw.print("mPendingTrackballWindow="); pw.print(mPendingTrackballWindow); |
| 5592 | pw.print(" mPendingTrackballMove="); pw.println(mPendingTrackballMove); |
| 5593 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5594 | } |
| 5595 | |
| 5596 | @Override |
| 5597 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5598 | return mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5599 | } |
| 5600 | } |
| 5601 | |
| 5602 | // ------------------------------------------------------------- |
| 5603 | // Client Window State |
| 5604 | // ------------------------------------------------------------- |
| 5605 | |
| 5606 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 5607 | final Session mSession; |
| 5608 | final IWindow mClient; |
| 5609 | WindowToken mToken; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5610 | WindowToken mRootToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5611 | AppWindowToken mAppToken; |
| 5612 | AppWindowToken mTargetAppToken; |
| 5613 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 5614 | final DeathRecipient mDeathRecipient; |
| 5615 | final WindowState mAttachedWindow; |
| 5616 | final ArrayList mChildWindows = new ArrayList(); |
| 5617 | final int mBaseLayer; |
| 5618 | final int mSubLayer; |
| 5619 | final boolean mLayoutAttached; |
| 5620 | final boolean mIsImWindow; |
| 5621 | int mViewVisibility; |
| 5622 | boolean mPolicyVisibility = true; |
| 5623 | boolean mPolicyVisibilityAfterAnim = true; |
| 5624 | boolean mAppFreezing; |
| 5625 | Surface mSurface; |
| 5626 | boolean mAttachedHidden; // is our parent window hidden? |
| 5627 | boolean mLastHidden; // was this window last hidden? |
| 5628 | int mRequestedWidth; |
| 5629 | int mRequestedHeight; |
| 5630 | int mLastRequestedWidth; |
| 5631 | int mLastRequestedHeight; |
| 5632 | int mReqXPos; |
| 5633 | int mReqYPos; |
| 5634 | int mLayer; |
| 5635 | int mAnimLayer; |
| 5636 | int mLastLayer; |
| 5637 | boolean mHaveFrame; |
| 5638 | |
| 5639 | WindowState mNextOutsideTouch; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5640 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5641 | // Actual frame shown on-screen (may be modified by animation) |
| 5642 | final Rect mShownFrame = new Rect(); |
| 5643 | final Rect mLastShownFrame = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5644 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5645 | /** |
| 5646 | * Insets that determine the actually visible area |
| 5647 | */ |
| 5648 | final Rect mVisibleInsets = new Rect(); |
| 5649 | final Rect mLastVisibleInsets = new Rect(); |
| 5650 | boolean mVisibleInsetsChanged; |
| 5651 | |
| 5652 | /** |
| 5653 | * Insets that are covered by system windows |
| 5654 | */ |
| 5655 | final Rect mContentInsets = new Rect(); |
| 5656 | final Rect mLastContentInsets = new Rect(); |
| 5657 | boolean mContentInsetsChanged; |
| 5658 | |
| 5659 | /** |
| 5660 | * Set to true if we are waiting for this window to receive its |
| 5661 | * given internal insets before laying out other windows based on it. |
| 5662 | */ |
| 5663 | boolean mGivenInsetsPending; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5664 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5665 | /** |
| 5666 | * These are the content insets that were given during layout for |
| 5667 | * this window, to be applied to windows behind it. |
| 5668 | */ |
| 5669 | final Rect mGivenContentInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5670 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5671 | /** |
| 5672 | * These are the visible insets that were given during layout for |
| 5673 | * this window, to be applied to windows behind it. |
| 5674 | */ |
| 5675 | final Rect mGivenVisibleInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5676 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5677 | /** |
| 5678 | * Flag indicating whether the touchable region should be adjusted by |
| 5679 | * the visible insets; if false the area outside the visible insets is |
| 5680 | * NOT touchable, so we must use those to adjust the frame during hit |
| 5681 | * tests. |
| 5682 | */ |
| 5683 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5684 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5685 | // Current transformation being applied. |
| 5686 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 5687 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 5688 | float mHScale=1, mVScale=1; |
| 5689 | float mLastHScale=1, mLastVScale=1; |
| 5690 | final Matrix mTmpMatrix = new Matrix(); |
| 5691 | |
| 5692 | // "Real" frame that the application sees. |
| 5693 | final Rect mFrame = new Rect(); |
| 5694 | final Rect mLastFrame = new Rect(); |
| 5695 | |
| 5696 | final Rect mContainingFrame = new Rect(); |
| 5697 | final Rect mDisplayFrame = new Rect(); |
| 5698 | final Rect mContentFrame = new Rect(); |
| 5699 | final Rect mVisibleFrame = new Rect(); |
| 5700 | |
| 5701 | float mShownAlpha = 1; |
| 5702 | float mAlpha = 1; |
| 5703 | float mLastAlpha = 1; |
| 5704 | |
| 5705 | // Set to true if, when the window gets displayed, it should perform |
| 5706 | // an enter animation. |
| 5707 | boolean mEnterAnimationPending; |
| 5708 | |
| 5709 | // Currently running animation. |
| 5710 | boolean mAnimating; |
| 5711 | boolean mLocalAnimating; |
| 5712 | Animation mAnimation; |
| 5713 | boolean mAnimationIsEntrance; |
| 5714 | boolean mHasTransformation; |
| 5715 | boolean mHasLocalTransformation; |
| 5716 | final Transformation mTransformation = new Transformation(); |
| 5717 | |
| 5718 | // This is set after IWindowSession.relayout() has been called at |
| 5719 | // least once for the window. It allows us to detect the situation |
| 5720 | // where we don't yet have a surface, but should have one soon, so |
| 5721 | // we can give the window focus before waiting for the relayout. |
| 5722 | boolean mRelayoutCalled; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5723 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5724 | // This is set after the Surface has been created but before the |
| 5725 | // window has been drawn. During this time the surface is hidden. |
| 5726 | boolean mDrawPending; |
| 5727 | |
| 5728 | // This is set after the window has finished drawing for the first |
| 5729 | // time but before its surface is shown. The surface will be |
| 5730 | // displayed when the next layout is run. |
| 5731 | boolean mCommitDrawPending; |
| 5732 | |
| 5733 | // This is set during the time after the window's drawing has been |
| 5734 | // committed, and before its surface is actually shown. It is used |
| 5735 | // to delay showing the surface until all windows in a token are ready |
| 5736 | // to be shown. |
| 5737 | boolean mReadyToShow; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5738 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5739 | // Set when the window has been shown in the screen the first time. |
| 5740 | boolean mHasDrawn; |
| 5741 | |
| 5742 | // Currently running an exit animation? |
| 5743 | boolean mExiting; |
| 5744 | |
| 5745 | // Currently on the mDestroySurface list? |
| 5746 | boolean mDestroying; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5747 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5748 | // Completely remove from window manager after exit animation? |
| 5749 | boolean mRemoveOnExit; |
| 5750 | |
| 5751 | // Set when the orientation is changing and this window has not yet |
| 5752 | // been updated for the new orientation. |
| 5753 | boolean mOrientationChanging; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5754 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5755 | // Is this window now (or just being) removed? |
| 5756 | boolean mRemoved; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5757 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5758 | WindowState(Session s, IWindow c, WindowToken token, |
| 5759 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 5760 | int viewVisibility) { |
| 5761 | mSession = s; |
| 5762 | mClient = c; |
| 5763 | mToken = token; |
| 5764 | mAttrs.copyFrom(a); |
| 5765 | mViewVisibility = viewVisibility; |
| 5766 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 5767 | mAlpha = a.alpha; |
| 5768 | if (localLOGV) Log.v( |
| 5769 | TAG, "Window " + this + " client=" + c.asBinder() |
| 5770 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 5771 | try { |
| 5772 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 5773 | } catch (RemoteException e) { |
| 5774 | mDeathRecipient = null; |
| 5775 | mAttachedWindow = null; |
| 5776 | mLayoutAttached = false; |
| 5777 | mIsImWindow = false; |
| 5778 | mBaseLayer = 0; |
| 5779 | mSubLayer = 0; |
| 5780 | return; |
| 5781 | } |
| 5782 | mDeathRecipient = deathRecipient; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5783 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5784 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 5785 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 5786 | // The multiplier here is to reserve space for multiple |
| 5787 | // windows in the same type layer. |
| 5788 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 5789 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 5790 | + TYPE_LAYER_OFFSET; |
| 5791 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 5792 | mAttachedWindow = attachedWindow; |
| 5793 | mAttachedWindow.mChildWindows.add(this); |
| 5794 | mLayoutAttached = mAttrs.type != |
| 5795 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 5796 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 5797 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| 5798 | } else { |
| 5799 | // The multiplier here is to reserve space for multiple |
| 5800 | // windows in the same type layer. |
| 5801 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 5802 | * TYPE_LAYER_MULTIPLIER |
| 5803 | + TYPE_LAYER_OFFSET; |
| 5804 | mSubLayer = 0; |
| 5805 | mAttachedWindow = null; |
| 5806 | mLayoutAttached = false; |
| 5807 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 5808 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| 5809 | } |
| 5810 | |
| 5811 | WindowState appWin = this; |
| 5812 | while (appWin.mAttachedWindow != null) { |
| 5813 | appWin = mAttachedWindow; |
| 5814 | } |
| 5815 | WindowToken appToken = appWin.mToken; |
| 5816 | while (appToken.appWindowToken == null) { |
| 5817 | WindowToken parent = mTokenMap.get(appToken.token); |
| 5818 | if (parent == null || appToken == parent) { |
| 5819 | break; |
| 5820 | } |
| 5821 | appToken = parent; |
| 5822 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5823 | mRootToken = appToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5824 | mAppToken = appToken.appWindowToken; |
| 5825 | |
| 5826 | mSurface = null; |
| 5827 | mRequestedWidth = 0; |
| 5828 | mRequestedHeight = 0; |
| 5829 | mLastRequestedWidth = 0; |
| 5830 | mLastRequestedHeight = 0; |
| 5831 | mReqXPos = 0; |
| 5832 | mReqYPos = 0; |
| 5833 | mLayer = 0; |
| 5834 | mAnimLayer = 0; |
| 5835 | mLastLayer = 0; |
| 5836 | } |
| 5837 | |
| 5838 | void attach() { |
| 5839 | if (localLOGV) Log.v( |
| 5840 | TAG, "Attaching " + this + " token=" + mToken |
| 5841 | + ", list=" + mToken.windows); |
| 5842 | mSession.windowAddedLocked(); |
| 5843 | } |
| 5844 | |
| 5845 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 5846 | mHaveFrame = true; |
| 5847 | |
| 5848 | final int pw = pf.right-pf.left; |
| 5849 | final int ph = pf.bottom-pf.top; |
| 5850 | |
| 5851 | int w,h; |
| 5852 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 5853 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 5854 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 5855 | } else { |
| 5856 | w = mAttrs.width == mAttrs.FILL_PARENT ? pw : mRequestedWidth; |
| 5857 | h = mAttrs.height== mAttrs.FILL_PARENT ? ph : mRequestedHeight; |
| 5858 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5859 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5860 | final Rect container = mContainingFrame; |
| 5861 | container.set(pf); |
| 5862 | |
| 5863 | final Rect display = mDisplayFrame; |
| 5864 | display.set(df); |
| 5865 | |
| 5866 | final Rect content = mContentFrame; |
| 5867 | content.set(cf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5868 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5869 | final Rect visible = mVisibleFrame; |
| 5870 | visible.set(vf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5871 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5872 | final Rect frame = mFrame; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5873 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5874 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 5875 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 5876 | |
| 5877 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 5878 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 5879 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 5880 | |
| 5881 | //System.out.println("Out: " + mFrame); |
| 5882 | |
| 5883 | // Now make sure the window fits in the overall display. |
| 5884 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5885 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5886 | // Make sure the content and visible frames are inside of the |
| 5887 | // final window frame. |
| 5888 | if (content.left < frame.left) content.left = frame.left; |
| 5889 | if (content.top < frame.top) content.top = frame.top; |
| 5890 | if (content.right > frame.right) content.right = frame.right; |
| 5891 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 5892 | if (visible.left < frame.left) visible.left = frame.left; |
| 5893 | if (visible.top < frame.top) visible.top = frame.top; |
| 5894 | if (visible.right > frame.right) visible.right = frame.right; |
| 5895 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5896 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5897 | final Rect contentInsets = mContentInsets; |
| 5898 | contentInsets.left = content.left-frame.left; |
| 5899 | contentInsets.top = content.top-frame.top; |
| 5900 | contentInsets.right = frame.right-content.right; |
| 5901 | contentInsets.bottom = frame.bottom-content.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5902 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5903 | final Rect visibleInsets = mVisibleInsets; |
| 5904 | visibleInsets.left = visible.left-frame.left; |
| 5905 | visibleInsets.top = visible.top-frame.top; |
| 5906 | visibleInsets.right = frame.right-visible.right; |
| 5907 | visibleInsets.bottom = frame.bottom-visible.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5908 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5909 | if (localLOGV) { |
| 5910 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 5911 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
| 5912 | Log.v(TAG, "Resolving (mRequestedWidth=" |
| 5913 | + mRequestedWidth + ", mRequestedheight=" |
| 5914 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 5915 | + "): frame=" + mFrame.toShortString() |
| 5916 | + " ci=" + contentInsets.toShortString() |
| 5917 | + " vi=" + visibleInsets.toShortString()); |
| 5918 | //} |
| 5919 | } |
| 5920 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5921 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5922 | public Rect getFrameLw() { |
| 5923 | return mFrame; |
| 5924 | } |
| 5925 | |
| 5926 | public Rect getShownFrameLw() { |
| 5927 | return mShownFrame; |
| 5928 | } |
| 5929 | |
| 5930 | public Rect getDisplayFrameLw() { |
| 5931 | return mDisplayFrame; |
| 5932 | } |
| 5933 | |
| 5934 | public Rect getContentFrameLw() { |
| 5935 | return mContentFrame; |
| 5936 | } |
| 5937 | |
| 5938 | public Rect getVisibleFrameLw() { |
| 5939 | return mVisibleFrame; |
| 5940 | } |
| 5941 | |
| 5942 | public boolean getGivenInsetsPendingLw() { |
| 5943 | return mGivenInsetsPending; |
| 5944 | } |
| 5945 | |
| 5946 | public Rect getGivenContentInsetsLw() { |
| 5947 | return mGivenContentInsets; |
| 5948 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5949 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5950 | public Rect getGivenVisibleInsetsLw() { |
| 5951 | return mGivenVisibleInsets; |
| 5952 | } |
| 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 | public WindowManager.LayoutParams getAttrs() { |
| 5955 | return mAttrs; |
| 5956 | } |
| 5957 | |
| 5958 | public int getSurfaceLayer() { |
| 5959 | return mLayer; |
| 5960 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5961 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5962 | public IApplicationToken getAppToken() { |
| 5963 | return mAppToken != null ? mAppToken.appToken : null; |
| 5964 | } |
| 5965 | |
| 5966 | public boolean hasAppShownWindows() { |
| 5967 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 5968 | } |
| 5969 | |
| 5970 | public boolean hasAppStartingIcon() { |
| 5971 | return mAppToken != null ? (mAppToken.startingData != null) : false; |
| 5972 | } |
| 5973 | |
| 5974 | public WindowManagerPolicy.WindowState getAppStartingWindow() { |
| 5975 | return mAppToken != null ? mAppToken.startingWindow : null; |
| 5976 | } |
| 5977 | |
| 5978 | public void setAnimation(Animation anim) { |
| 5979 | if (localLOGV) Log.v( |
| 5980 | TAG, "Setting animation in " + this + ": " + anim); |
| 5981 | mAnimating = false; |
| 5982 | mLocalAnimating = false; |
| 5983 | mAnimation = anim; |
| 5984 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 5985 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 5986 | } |
| 5987 | |
| 5988 | public void clearAnimation() { |
| 5989 | if (mAnimation != null) { |
| 5990 | mAnimating = true; |
| 5991 | mLocalAnimating = false; |
| 5992 | mAnimation = null; |
| 5993 | } |
| 5994 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5995 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5996 | Surface createSurfaceLocked() { |
| 5997 | if (mSurface == null) { |
| 5998 | mDrawPending = true; |
| 5999 | mCommitDrawPending = false; |
| 6000 | mReadyToShow = false; |
| 6001 | if (mAppToken != null) { |
| 6002 | mAppToken.allDrawn = false; |
| 6003 | } |
| 6004 | |
| 6005 | int flags = 0; |
| 6006 | if (mAttrs.memoryType == MEMORY_TYPE_HARDWARE) { |
| 6007 | flags |= Surface.HARDWARE; |
| 6008 | } else if (mAttrs.memoryType == MEMORY_TYPE_GPU) { |
| 6009 | flags |= Surface.GPU; |
| 6010 | } else if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
| 6011 | flags |= Surface.PUSH_BUFFERS; |
| 6012 | } |
| 6013 | |
| 6014 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 6015 | flags |= Surface.SECURE; |
| 6016 | } |
| 6017 | if (DEBUG_VISIBILITY) Log.v( |
| 6018 | TAG, "Creating surface in session " |
| 6019 | + mSession.mSurfaceSession + " window " + this |
| 6020 | + " w=" + mFrame.width() |
| 6021 | + " h=" + mFrame.height() + " format=" |
| 6022 | + mAttrs.format + " flags=" + flags); |
| 6023 | |
| 6024 | int w = mFrame.width(); |
| 6025 | int h = mFrame.height(); |
| 6026 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 6027 | // for a scaled surface, we always want the requested |
| 6028 | // size. |
| 6029 | w = mRequestedWidth; |
| 6030 | h = mRequestedHeight; |
| 6031 | } |
| 6032 | |
| 6033 | try { |
| 6034 | mSurface = new Surface( |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6035 | mSession.mSurfaceSession, mSession.mPid, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6036 | 0, w, h, mAttrs.format, flags); |
| 6037 | } catch (Surface.OutOfResourcesException e) { |
| 6038 | Log.w(TAG, "OutOfResourcesException creating surface"); |
| 6039 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 6040 | return null; |
| 6041 | } catch (Exception e) { |
| 6042 | Log.e(TAG, "Exception creating surface", e); |
| 6043 | return null; |
| 6044 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6045 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6046 | if (localLOGV) Log.v( |
| 6047 | TAG, "Got surface: " + mSurface |
| 6048 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 6049 | + ", animLayer=" + mAnimLayer); |
| 6050 | if (SHOW_TRANSACTIONS) { |
| 6051 | Log.i(TAG, ">>> OPEN TRANSACTION"); |
| 6052 | Log.i(TAG, " SURFACE " + mSurface + ": CREATE (" |
| 6053 | + mAttrs.getTitle() + ") pos=(" + |
| 6054 | mFrame.left + "," + mFrame.top + ") (" + |
| 6055 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 6056 | mAnimLayer + " HIDE"); |
| 6057 | } |
| 6058 | Surface.openTransaction(); |
| 6059 | try { |
| 6060 | try { |
| 6061 | mSurface.setPosition(mFrame.left, mFrame.top); |
| 6062 | mSurface.setLayer(mAnimLayer); |
| 6063 | mSurface.hide(); |
| 6064 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
| 6065 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 6066 | Surface.SURFACE_DITHER); |
| 6067 | } |
| 6068 | } catch (RuntimeException e) { |
| 6069 | Log.w(TAG, "Error creating surface in " + w, e); |
| 6070 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 6071 | } |
| 6072 | mLastHidden = true; |
| 6073 | } finally { |
| 6074 | if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION"); |
| 6075 | Surface.closeTransaction(); |
| 6076 | } |
| 6077 | if (localLOGV) Log.v( |
| 6078 | TAG, "Created surface " + this); |
| 6079 | } |
| 6080 | return mSurface; |
| 6081 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6082 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6083 | void destroySurfaceLocked() { |
| 6084 | // Window is no longer on-screen, so can no longer receive |
| 6085 | // key events... if we were waiting for it to finish |
| 6086 | // handling a key event, the wait is over! |
| 6087 | mKeyWaiter.finishedKey(mSession, mClient, true, |
| 6088 | KeyWaiter.RETURN_NOTHING); |
| 6089 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 6090 | mKeyWaiter.releasePendingTrackballLocked(mSession); |
| 6091 | |
| 6092 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 6093 | mAppToken.startingDisplayed = false; |
| 6094 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6095 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6096 | if (localLOGV) Log.v( |
| 6097 | TAG, "Window " + this |
| 6098 | + " destroying surface " + mSurface + ", session " + mSession); |
| 6099 | if (mSurface != null) { |
| 6100 | try { |
| 6101 | if (SHOW_TRANSACTIONS) { |
| 6102 | RuntimeException ex = new RuntimeException(); |
| 6103 | ex.fillInStackTrace(); |
| 6104 | Log.i(TAG, " SURFACE " + mSurface + ": DESTROY (" |
| 6105 | + mAttrs.getTitle() + ")", ex); |
| 6106 | } |
| 6107 | mSurface.clear(); |
| 6108 | } catch (RuntimeException e) { |
| 6109 | Log.w(TAG, "Exception thrown when destroying Window " + this |
| 6110 | + " surface " + mSurface + " session " + mSession |
| 6111 | + ": " + e.toString()); |
| 6112 | } |
| 6113 | mSurface = null; |
| 6114 | mDrawPending = false; |
| 6115 | mCommitDrawPending = false; |
| 6116 | mReadyToShow = false; |
| 6117 | |
| 6118 | int i = mChildWindows.size(); |
| 6119 | while (i > 0) { |
| 6120 | i--; |
| 6121 | WindowState c = (WindowState)mChildWindows.get(i); |
| 6122 | c.mAttachedHidden = true; |
| 6123 | } |
| 6124 | } |
| 6125 | } |
| 6126 | |
| 6127 | boolean finishDrawingLocked() { |
| 6128 | if (mDrawPending) { |
| 6129 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Log.v( |
| 6130 | TAG, "finishDrawingLocked: " + mSurface); |
| 6131 | mCommitDrawPending = true; |
| 6132 | mDrawPending = false; |
| 6133 | return true; |
| 6134 | } |
| 6135 | return false; |
| 6136 | } |
| 6137 | |
| 6138 | // This must be called while inside a transaction. |
| 6139 | void commitFinishDrawingLocked(long currentTime) { |
| 6140 | //Log.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
| 6141 | if (!mCommitDrawPending) { |
| 6142 | return; |
| 6143 | } |
| 6144 | mCommitDrawPending = false; |
| 6145 | mReadyToShow = true; |
| 6146 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 6147 | final AppWindowToken atoken = mAppToken; |
| 6148 | if (atoken == null || atoken.allDrawn || starting) { |
| 6149 | performShowLocked(); |
| 6150 | } |
| 6151 | } |
| 6152 | |
| 6153 | // This must be called while inside a transaction. |
| 6154 | boolean performShowLocked() { |
| 6155 | if (DEBUG_VISIBILITY) { |
| 6156 | RuntimeException e = new RuntimeException(); |
| 6157 | e.fillInStackTrace(); |
| 6158 | Log.v(TAG, "performShow on " + this |
| 6159 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 6160 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 6161 | } |
| 6162 | if (mReadyToShow && isReadyForDisplay()) { |
| 6163 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Log.i( |
| 6164 | TAG, " SURFACE " + mSurface + ": SHOW (performShowLocked)"); |
| 6165 | if (DEBUG_VISIBILITY) Log.v(TAG, "Showing " + this |
| 6166 | + " during animation: policyVis=" + mPolicyVisibility |
| 6167 | + " attHidden=" + mAttachedHidden |
| 6168 | + " tok.hiddenRequested=" |
| 6169 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
| 6170 | + " tok.idden=" |
| 6171 | + (mAppToken != null ? mAppToken.hidden : false) |
| 6172 | + " animating=" + mAnimating |
| 6173 | + " tok animating=" |
| 6174 | + (mAppToken != null ? mAppToken.animating : false)); |
| 6175 | if (!showSurfaceRobustlyLocked(this)) { |
| 6176 | return false; |
| 6177 | } |
| 6178 | mLastAlpha = -1; |
| 6179 | mHasDrawn = true; |
| 6180 | mLastHidden = false; |
| 6181 | mReadyToShow = false; |
| 6182 | enableScreenIfNeededLocked(); |
| 6183 | |
| 6184 | applyEnterAnimationLocked(this); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6185 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6186 | int i = mChildWindows.size(); |
| 6187 | while (i > 0) { |
| 6188 | i--; |
| 6189 | WindowState c = (WindowState)mChildWindows.get(i); |
| 6190 | if (c.mSurface != null && c.mAttachedHidden) { |
| 6191 | c.mAttachedHidden = false; |
| 6192 | c.performShowLocked(); |
| 6193 | } |
| 6194 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6195 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6196 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 6197 | && mAppToken != null) { |
| 6198 | mAppToken.firstWindowDrawn = true; |
| 6199 | if (mAnimation == null && mAppToken.startingData != null) { |
| 6200 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Finish starting " |
| 6201 | + mToken |
| 6202 | + ": first real window is shown, no animation"); |
| 6203 | mFinishedStarting.add(mAppToken); |
| 6204 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 6205 | } |
| 6206 | mAppToken.updateReportedVisibilityLocked(); |
| 6207 | } |
| 6208 | } |
| 6209 | return true; |
| 6210 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6211 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6212 | // This must be called while inside a transaction. Returns true if |
| 6213 | // there is more animation to run. |
| 6214 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| 6215 | if (!mDisplayFrozen) { |
| 6216 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6217 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6218 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 6219 | mHasTransformation = true; |
| 6220 | mHasLocalTransformation = true; |
| 6221 | if (!mLocalAnimating) { |
| 6222 | if (DEBUG_ANIM) Log.v( |
| 6223 | TAG, "Starting animation in " + this + |
| 6224 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 6225 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 6226 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 6227 | mAnimation.setStartTime(currentTime); |
| 6228 | mLocalAnimating = true; |
| 6229 | mAnimating = true; |
| 6230 | } |
| 6231 | mTransformation.clear(); |
| 6232 | final boolean more = mAnimation.getTransformation( |
| 6233 | currentTime, mTransformation); |
| 6234 | if (DEBUG_ANIM) Log.v( |
| 6235 | TAG, "Stepped animation in " + this + |
| 6236 | ": more=" + more + ", xform=" + mTransformation); |
| 6237 | if (more) { |
| 6238 | // we're not done! |
| 6239 | return true; |
| 6240 | } |
| 6241 | if (DEBUG_ANIM) Log.v( |
| 6242 | TAG, "Finished animation in " + this + |
| 6243 | " @ " + currentTime); |
| 6244 | mAnimation = null; |
| 6245 | //WindowManagerService.this.dump(); |
| 6246 | } |
| 6247 | mHasLocalTransformation = false; |
| 6248 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
| 6249 | && mAppToken.hasTransformation) { |
| 6250 | // When our app token is animating, we kind-of pretend like |
| 6251 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 6252 | // part of this check means that we will only do this if |
| 6253 | // our window is not currently exiting, or it is not |
| 6254 | // locally animating itself. The idea being that one that |
| 6255 | // is exiting and doing a local animation should be removed |
| 6256 | // once that animation is done. |
| 6257 | mAnimating = true; |
| 6258 | mHasTransformation = true; |
| 6259 | mTransformation.clear(); |
| 6260 | return false; |
| 6261 | } else if (mHasTransformation) { |
| 6262 | // Little trick to get through the path below to act like |
| 6263 | // we have finished an animation. |
| 6264 | mAnimating = true; |
| 6265 | } else if (isAnimating()) { |
| 6266 | mAnimating = true; |
| 6267 | } |
| 6268 | } else if (mAnimation != null) { |
| 6269 | // If the display is frozen, and there is a pending animation, |
| 6270 | // clear it and make sure we run the cleanup code. |
| 6271 | mAnimating = true; |
| 6272 | mLocalAnimating = true; |
| 6273 | mAnimation = null; |
| 6274 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6275 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6276 | if (!mAnimating && !mLocalAnimating) { |
| 6277 | return false; |
| 6278 | } |
| 6279 | |
| 6280 | if (DEBUG_ANIM) Log.v( |
| 6281 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 6282 | + ", reportedVisible=" |
| 6283 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6284 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6285 | mAnimating = false; |
| 6286 | mLocalAnimating = false; |
| 6287 | mAnimation = null; |
| 6288 | mAnimLayer = mLayer; |
| 6289 | if (mIsImWindow) { |
| 6290 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
| 6291 | } |
| 6292 | if (DEBUG_LAYERS) Log.v(TAG, "Stepping win " + this |
| 6293 | + " anim layer: " + mAnimLayer); |
| 6294 | mHasTransformation = false; |
| 6295 | mHasLocalTransformation = false; |
| 6296 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 6297 | mTransformation.clear(); |
| 6298 | if (mHasDrawn |
| 6299 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 6300 | && mAppToken != null |
| 6301 | && mAppToken.firstWindowDrawn |
| 6302 | && mAppToken.startingData != null) { |
| 6303 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Finish starting " |
| 6304 | + mToken + ": first real window done animating"); |
| 6305 | mFinishedStarting.add(mAppToken); |
| 6306 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 6307 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6308 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6309 | finishExit(); |
| 6310 | |
| 6311 | if (mAppToken != null) { |
| 6312 | mAppToken.updateReportedVisibilityLocked(); |
| 6313 | } |
| 6314 | |
| 6315 | return false; |
| 6316 | } |
| 6317 | |
| 6318 | void finishExit() { |
| 6319 | if (DEBUG_ANIM) Log.v( |
| 6320 | TAG, "finishExit in " + this |
| 6321 | + ": exiting=" + mExiting |
| 6322 | + " remove=" + mRemoveOnExit |
| 6323 | + " windowAnimating=" + isWindowAnimating()); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6324 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6325 | final int N = mChildWindows.size(); |
| 6326 | for (int i=0; i<N; i++) { |
| 6327 | ((WindowState)mChildWindows.get(i)).finishExit(); |
| 6328 | } |
| 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 | if (!mExiting) { |
| 6331 | return; |
| 6332 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6333 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6334 | if (isWindowAnimating()) { |
| 6335 | return; |
| 6336 | } |
| 6337 | |
| 6338 | if (localLOGV) Log.v( |
| 6339 | TAG, "Exit animation finished in " + this |
| 6340 | + ": remove=" + mRemoveOnExit); |
| 6341 | if (mSurface != null) { |
| 6342 | mDestroySurface.add(this); |
| 6343 | mDestroying = true; |
| 6344 | if (SHOW_TRANSACTIONS) Log.i( |
| 6345 | TAG, " SURFACE " + mSurface + ": HIDE (finishExit)"); |
| 6346 | try { |
| 6347 | mSurface.hide(); |
| 6348 | } catch (RuntimeException e) { |
| 6349 | Log.w(TAG, "Error hiding surface in " + this, e); |
| 6350 | } |
| 6351 | mLastHidden = true; |
| 6352 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 6353 | } |
| 6354 | mExiting = false; |
| 6355 | if (mRemoveOnExit) { |
| 6356 | mPendingRemove.add(this); |
| 6357 | mRemoveOnExit = false; |
| 6358 | } |
| 6359 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6360 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6361 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 6362 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 6363 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 6364 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 6365 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 6366 | return true; |
| 6367 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6368 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6369 | void computeShownFrameLocked() { |
| 6370 | final boolean selfTransformation = mHasLocalTransformation; |
| 6371 | Transformation attachedTransformation = |
| 6372 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 6373 | ? mAttachedWindow.mTransformation : null; |
| 6374 | Transformation appTransformation = |
| 6375 | (mAppToken != null && mAppToken.hasTransformation) |
| 6376 | ? mAppToken.transformation : null; |
| 6377 | if (selfTransformation || attachedTransformation != null |
| 6378 | || appTransformation != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6379 | // cache often used attributes locally |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6380 | final Rect frame = mFrame; |
| 6381 | final float tmpFloats[] = mTmpFloats; |
| 6382 | final Matrix tmpMatrix = mTmpMatrix; |
| 6383 | |
| 6384 | // Compute the desired transformation. |
| 6385 | tmpMatrix.setTranslate(frame.left, frame.top); |
| 6386 | if (selfTransformation) { |
| 6387 | tmpMatrix.preConcat(mTransformation.getMatrix()); |
| 6388 | } |
| 6389 | if (attachedTransformation != null) { |
| 6390 | tmpMatrix.preConcat(attachedTransformation.getMatrix()); |
| 6391 | } |
| 6392 | if (appTransformation != null) { |
| 6393 | tmpMatrix.preConcat(appTransformation.getMatrix()); |
| 6394 | } |
| 6395 | |
| 6396 | // "convert" it into SurfaceFlinger's format |
| 6397 | // (a 2x2 matrix + an offset) |
| 6398 | // Here we must not transform the position of the surface |
| 6399 | // since it is already included in the transformation. |
| 6400 | //Log.i(TAG, "Transform: " + matrix); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6401 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6402 | tmpMatrix.getValues(tmpFloats); |
| 6403 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 6404 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 6405 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 6406 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
| 6407 | int x = (int)tmpFloats[Matrix.MTRANS_X]; |
| 6408 | int y = (int)tmpFloats[Matrix.MTRANS_Y]; |
| 6409 | int w = frame.width(); |
| 6410 | int h = frame.height(); |
| 6411 | mShownFrame.set(x, y, x+w, y+h); |
| 6412 | |
| 6413 | // Now set the alpha... but because our current hardware |
| 6414 | // can't do alpha transformation on a non-opaque surface, |
| 6415 | // turn it off if we are running an animation that is also |
| 6416 | // transforming since it is more important to have that |
| 6417 | // animation be smooth. |
| 6418 | mShownAlpha = mAlpha; |
| 6419 | if (!mLimitedAlphaCompositing |
| 6420 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 6421 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 6422 | && x == frame.left && y == frame.top))) { |
| 6423 | //Log.i(TAG, "Applying alpha transform"); |
| 6424 | if (selfTransformation) { |
| 6425 | mShownAlpha *= mTransformation.getAlpha(); |
| 6426 | } |
| 6427 | if (attachedTransformation != null) { |
| 6428 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 6429 | } |
| 6430 | if (appTransformation != null) { |
| 6431 | mShownAlpha *= appTransformation.getAlpha(); |
| 6432 | } |
| 6433 | } else { |
| 6434 | //Log.i(TAG, "Not applying alpha transform"); |
| 6435 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6436 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6437 | if (localLOGV) Log.v( |
| 6438 | TAG, "Continuing animation in " + this + |
| 6439 | ": " + mShownFrame + |
| 6440 | ", alpha=" + mTransformation.getAlpha()); |
| 6441 | return; |
| 6442 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6443 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6444 | mShownFrame.set(mFrame); |
| 6445 | mShownAlpha = mAlpha; |
| 6446 | mDsDx = 1; |
| 6447 | mDtDx = 0; |
| 6448 | mDsDy = 0; |
| 6449 | mDtDy = 1; |
| 6450 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6451 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6452 | /** |
| 6453 | * Is this window visible? It is not visible if there is no |
| 6454 | * surface, or we are in the process of running an exit animation |
| 6455 | * that will remove the surface, or its app token has been hidden. |
| 6456 | */ |
| 6457 | public boolean isVisibleLw() { |
| 6458 | final AppWindowToken atoken = mAppToken; |
| 6459 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 6460 | && (atoken == null || !atoken.hiddenRequested) |
| 6461 | && !mExiting && !mDestroying; |
| 6462 | } |
| 6463 | |
| 6464 | /** |
| 6465 | * Is this window visible, ignoring its app token? It is not visible |
| 6466 | * if there is no surface, or we are in the process of running an exit animation |
| 6467 | * that will remove the surface. |
| 6468 | */ |
| 6469 | public boolean isWinVisibleLw() { |
| 6470 | final AppWindowToken atoken = mAppToken; |
| 6471 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 6472 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 6473 | && !mExiting && !mDestroying; |
| 6474 | } |
| 6475 | |
| 6476 | /** |
| 6477 | * The same as isVisible(), but follows the current hidden state of |
| 6478 | * the associated app token, not the pending requested hidden state. |
| 6479 | */ |
| 6480 | boolean isVisibleNow() { |
| 6481 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6482 | && !mRootToken.hidden && !mExiting && !mDestroying; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6483 | } |
| 6484 | |
| 6485 | /** |
| 6486 | * Same as isVisible(), but we also count it as visible between the |
| 6487 | * call to IWindowSession.add() and the first relayout(). |
| 6488 | */ |
| 6489 | boolean isVisibleOrAdding() { |
| 6490 | final AppWindowToken atoken = mAppToken; |
| 6491 | return (mSurface != null |
| 6492 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 6493 | && mPolicyVisibility && !mAttachedHidden |
| 6494 | && (atoken == null || !atoken.hiddenRequested) |
| 6495 | && !mExiting && !mDestroying; |
| 6496 | } |
| 6497 | |
| 6498 | /** |
| 6499 | * Is this window currently on-screen? It is on-screen either if it |
| 6500 | * is visible or it is currently running an animation before no longer |
| 6501 | * being visible. |
| 6502 | */ |
| 6503 | boolean isOnScreen() { |
| 6504 | final AppWindowToken atoken = mAppToken; |
| 6505 | if (atoken != null) { |
| 6506 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 6507 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
| 6508 | || mAnimating || atoken.animating); |
| 6509 | } else { |
| 6510 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 6511 | && (!mAttachedHidden || mAnimating); |
| 6512 | } |
| 6513 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6514 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6515 | /** |
| 6516 | * Like isOnScreen(), but we don't return true if the window is part |
| 6517 | * of a transition that has not yet been started. |
| 6518 | */ |
| 6519 | boolean isReadyForDisplay() { |
| 6520 | final AppWindowToken atoken = mAppToken; |
| 6521 | final boolean animating = atoken != null ? atoken.animating : false; |
| 6522 | return mSurface != null && mPolicyVisibility && !mDestroying |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6523 | && ((!mAttachedHidden && !mRootToken.hidden) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6524 | || mAnimating || animating); |
| 6525 | } |
| 6526 | |
| 6527 | /** Is the window or its container currently animating? */ |
| 6528 | boolean isAnimating() { |
| 6529 | final WindowState attached = mAttachedWindow; |
| 6530 | final AppWindowToken atoken = mAppToken; |
| 6531 | return mAnimation != null |
| 6532 | || (attached != null && attached.mAnimation != null) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6533 | || (atoken != null && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6534 | (atoken.animation != null |
| 6535 | || atoken.inPendingTransaction)); |
| 6536 | } |
| 6537 | |
| 6538 | /** Is this window currently animating? */ |
| 6539 | boolean isWindowAnimating() { |
| 6540 | return mAnimation != null; |
| 6541 | } |
| 6542 | |
| 6543 | /** |
| 6544 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 6545 | * been drawn. |
| 6546 | */ |
| 6547 | public boolean isDisplayedLw() { |
| 6548 | final AppWindowToken atoken = mAppToken; |
| 6549 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 6550 | && !mDrawPending && !mCommitDrawPending |
| 6551 | && ((!mAttachedHidden && |
| 6552 | (atoken == null || !atoken.hiddenRequested)) |
| 6553 | || mAnimating); |
| 6554 | } |
| 6555 | |
| 6556 | public boolean fillsScreenLw(int screenWidth, int screenHeight, |
| 6557 | boolean shownFrame, boolean onlyOpaque) { |
| 6558 | if (mSurface == null) { |
| 6559 | return false; |
| 6560 | } |
| 6561 | if (mAppToken != null && !mAppToken.appFullscreen) { |
| 6562 | return false; |
| 6563 | } |
| 6564 | if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) { |
| 6565 | return false; |
| 6566 | } |
| 6567 | final Rect frame = shownFrame ? mShownFrame : mFrame; |
| 6568 | if (frame.left <= 0 && frame.top <= 0 |
| 6569 | && frame.right >= screenWidth |
| 6570 | && frame.bottom >= screenHeight) { |
| 6571 | return true; |
| 6572 | } |
| 6573 | return false; |
| 6574 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6575 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6576 | boolean isFullscreenOpaque(int screenWidth, int screenHeight) { |
| 6577 | if (mAttrs.format != PixelFormat.OPAQUE || mSurface == null |
| 6578 | || mAnimation != null || mDrawPending || mCommitDrawPending) { |
| 6579 | return false; |
| 6580 | } |
| 6581 | if (mFrame.left <= 0 && mFrame.top <= 0 && |
| 6582 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight) { |
| 6583 | return true; |
| 6584 | } |
| 6585 | return false; |
| 6586 | } |
| 6587 | |
| 6588 | void removeLocked() { |
| 6589 | if (mAttachedWindow != null) { |
| 6590 | mAttachedWindow.mChildWindows.remove(this); |
| 6591 | } |
| 6592 | destroySurfaceLocked(); |
| 6593 | mSession.windowRemovedLocked(); |
| 6594 | try { |
| 6595 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 6596 | } catch (RuntimeException e) { |
| 6597 | // Ignore if it has already been removed (usually because |
| 6598 | // we are doing this as part of processing a death note.) |
| 6599 | } |
| 6600 | } |
| 6601 | |
| 6602 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 6603 | public void binderDied() { |
| 6604 | try { |
| 6605 | synchronized(mWindowMap) { |
| 6606 | WindowState win = windowForClientLocked(mSession, mClient); |
| 6607 | Log.i(TAG, "WIN DEATH: " + win); |
| 6608 | if (win != null) { |
| 6609 | removeWindowLocked(mSession, win); |
| 6610 | } |
| 6611 | } |
| 6612 | } catch (IllegalArgumentException ex) { |
| 6613 | // This will happen if the window has already been |
| 6614 | // removed. |
| 6615 | } |
| 6616 | } |
| 6617 | } |
| 6618 | |
| 6619 | /** Returns true if this window desires key events. */ |
| 6620 | public final boolean canReceiveKeys() { |
| 6621 | return isVisibleOrAdding() |
| 6622 | && (mViewVisibility == View.VISIBLE) |
| 6623 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 6624 | } |
| 6625 | |
| 6626 | public boolean hasDrawnLw() { |
| 6627 | return mHasDrawn; |
| 6628 | } |
| 6629 | |
| 6630 | public boolean showLw(boolean doAnimation) { |
| 6631 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim) { |
| 6632 | mPolicyVisibility = true; |
| 6633 | mPolicyVisibilityAfterAnim = true; |
| 6634 | if (doAnimation) { |
| 6635 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 6636 | } |
| 6637 | requestAnimationLocked(0); |
| 6638 | return true; |
| 6639 | } |
| 6640 | return false; |
| 6641 | } |
| 6642 | |
| 6643 | public boolean hideLw(boolean doAnimation) { |
| 6644 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 6645 | : mPolicyVisibility; |
| 6646 | if (current) { |
| 6647 | if (doAnimation) { |
| 6648 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 6649 | if (mAnimation == null) { |
| 6650 | doAnimation = false; |
| 6651 | } |
| 6652 | } |
| 6653 | if (doAnimation) { |
| 6654 | mPolicyVisibilityAfterAnim = false; |
| 6655 | } else { |
| 6656 | mPolicyVisibilityAfterAnim = false; |
| 6657 | mPolicyVisibility = false; |
| 6658 | } |
| 6659 | requestAnimationLocked(0); |
| 6660 | return true; |
| 6661 | } |
| 6662 | return false; |
| 6663 | } |
| 6664 | |
| 6665 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6666 | StringBuilder sb = new StringBuilder(64); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6667 | |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6668 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 6669 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 6670 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 6671 | if (mAttachedWindow != null || mLayoutAttached) { |
| 6672 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 6673 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 6674 | } |
| 6675 | if (mIsImWindow) { |
| 6676 | pw.print(prefix); pw.print("mIsImWindow="); pw.println(mIsImWindow); |
| 6677 | } |
| 6678 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 6679 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 6680 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 6681 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 6682 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 6683 | pw.print("="); pw.print(mAnimLayer); |
| 6684 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 6685 | if (mSurface != null) { |
| 6686 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
| 6687 | } |
| 6688 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 6689 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 6690 | if (mAppToken != null) { |
| 6691 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 6692 | } |
| 6693 | if (mTargetAppToken != null) { |
| 6694 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 6695 | } |
| 6696 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 6697 | pw.print(Integer.toHexString(mViewVisibility)); |
| 6698 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
| 6699 | pw.print(" mHaveFrame="); pw.println(mHaveFrame); |
| 6700 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 6701 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 6702 | pw.print(mPolicyVisibility); |
| 6703 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 6704 | pw.print(mPolicyVisibilityAfterAnim); |
| 6705 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 6706 | } |
| 6707 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
| 6708 | pw.print(" h="); pw.print(mRequestedHeight); |
| 6709 | pw.print(" x="); pw.print(mReqXPos); |
| 6710 | pw.print(" y="); pw.println(mReqYPos); |
| 6711 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 6712 | mGivenContentInsets.printShortString(pw); |
| 6713 | pw.print(" mGivenVisibleInsets="); |
| 6714 | mGivenVisibleInsets.printShortString(pw); |
| 6715 | pw.println(); |
| 6716 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 6717 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 6718 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 6719 | } |
| 6720 | pw.print(prefix); pw.print("mShownFrame="); |
| 6721 | mShownFrame.printShortString(pw); |
| 6722 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 6723 | pw.println(); |
| 6724 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 6725 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 6726 | pw.println(); |
| 6727 | pw.print(prefix); pw.print("mContainingFrame="); |
| 6728 | mContainingFrame.printShortString(pw); |
| 6729 | pw.print(" mDisplayFrame="); |
| 6730 | mDisplayFrame.printShortString(pw); |
| 6731 | pw.println(); |
| 6732 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 6733 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 6734 | pw.println(); |
| 6735 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 6736 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 6737 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 6738 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 6739 | pw.println(); |
| 6740 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 6741 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 6742 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 6743 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 6744 | } |
| 6745 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 6746 | || mAnimation != null) { |
| 6747 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 6748 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 6749 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 6750 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 6751 | } |
| 6752 | if (mHasTransformation || mHasLocalTransformation) { |
| 6753 | pw.print(prefix); pw.print("XForm: has="); |
| 6754 | pw.print(mHasTransformation); |
| 6755 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 6756 | pw.print(" "); mTransformation.printShortString(pw); |
| 6757 | pw.println(); |
| 6758 | } |
| 6759 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 6760 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 6761 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 6762 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 6763 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 6764 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 6765 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 6766 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 6767 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 6768 | } |
| 6769 | if (mOrientationChanging || mAppFreezing) { |
| 6770 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 6771 | pw.print(mOrientationChanging); |
| 6772 | pw.print(" mAppFreezing="); pw.println(mAppFreezing); |
| 6773 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6774 | } |
| 6775 | |
| 6776 | @Override |
| 6777 | public String toString() { |
| 6778 | return "Window{" |
| 6779 | + Integer.toHexString(System.identityHashCode(this)) |
| 6780 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 6781 | } |
| 6782 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6783 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6784 | // ------------------------------------------------------------- |
| 6785 | // Window Token State |
| 6786 | // ------------------------------------------------------------- |
| 6787 | |
| 6788 | class WindowToken { |
| 6789 | // The actual token. |
| 6790 | final IBinder token; |
| 6791 | |
| 6792 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 6793 | final int windowType; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6794 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6795 | // Set if this token was explicitly added by a client, so should |
| 6796 | // not be removed when all windows are removed. |
| 6797 | final boolean explicit; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6798 | |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6799 | // For printing. |
| 6800 | String stringName; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6801 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6802 | // If this is an AppWindowToken, this is non-null. |
| 6803 | AppWindowToken appWindowToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6804 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6805 | // All of the windows associated with this token. |
| 6806 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 6807 | |
| 6808 | // Is key dispatching paused for this token? |
| 6809 | boolean paused = false; |
| 6810 | |
| 6811 | // Should this token's windows be hidden? |
| 6812 | boolean hidden; |
| 6813 | |
| 6814 | // Temporary for finding which tokens no longer have visible windows. |
| 6815 | boolean hasVisible; |
| 6816 | |
| 6817 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 6818 | token = _token; |
| 6819 | windowType = type; |
| 6820 | explicit = _explicit; |
| 6821 | } |
| 6822 | |
| 6823 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6824 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 6825 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 6826 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 6827 | pw.print(" hidden="); pw.print(hidden); |
| 6828 | pw.print(" hasVisible="); pw.println(hasVisible); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6829 | } |
| 6830 | |
| 6831 | @Override |
| 6832 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6833 | if (stringName == null) { |
| 6834 | StringBuilder sb = new StringBuilder(); |
| 6835 | sb.append("WindowToken{"); |
| 6836 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 6837 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 6838 | stringName = sb.toString(); |
| 6839 | } |
| 6840 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6841 | } |
| 6842 | }; |
| 6843 | |
| 6844 | class AppWindowToken extends WindowToken { |
| 6845 | // Non-null only for application tokens. |
| 6846 | final IApplicationToken appToken; |
| 6847 | |
| 6848 | // All of the windows and child windows that are included in this |
| 6849 | // application token. Note this list is NOT sorted! |
| 6850 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 6851 | |
| 6852 | int groupId = -1; |
| 6853 | boolean appFullscreen; |
| 6854 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6855 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6856 | // These are used for determining when all windows associated with |
| 6857 | // an activity have been drawn, so they can be made visible together |
| 6858 | // at the same time. |
| 6859 | int lastTransactionSequence = mTransactionSequence-1; |
| 6860 | int numInterestingWindows; |
| 6861 | int numDrawnWindows; |
| 6862 | boolean inPendingTransaction; |
| 6863 | boolean allDrawn; |
| 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 | // Is this token going to be hidden in a little while? If so, it |
| 6866 | // won't be taken into account for setting the screen orientation. |
| 6867 | boolean willBeHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6868 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6869 | // Is this window's surface needed? This is almost like hidden, except |
| 6870 | // it will sometimes be true a little earlier: when the token has |
| 6871 | // been shown, but is still waiting for its app transition to execute |
| 6872 | // before making its windows shown. |
| 6873 | boolean hiddenRequested; |
| 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 | // Have we told the window clients to hide themselves? |
| 6876 | boolean clientHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6877 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6878 | // Last visibility state we reported to the app token. |
| 6879 | boolean reportedVisible; |
| 6880 | |
| 6881 | // Set to true when the token has been removed from the window mgr. |
| 6882 | boolean removed; |
| 6883 | |
| 6884 | // Have we been asked to have this token keep the screen frozen? |
| 6885 | boolean freezingScreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6886 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6887 | boolean animating; |
| 6888 | Animation animation; |
| 6889 | boolean hasTransformation; |
| 6890 | final Transformation transformation = new Transformation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6891 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6892 | // Offset to the window of all layers in the token, for use by |
| 6893 | // AppWindowToken animations. |
| 6894 | int animLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6895 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6896 | // Information about an application starting window if displayed. |
| 6897 | StartingData startingData; |
| 6898 | WindowState startingWindow; |
| 6899 | View startingView; |
| 6900 | boolean startingDisplayed; |
| 6901 | boolean startingMoved; |
| 6902 | boolean firstWindowDrawn; |
| 6903 | |
| 6904 | AppWindowToken(IApplicationToken _token) { |
| 6905 | super(_token.asBinder(), |
| 6906 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 6907 | appWindowToken = this; |
| 6908 | appToken = _token; |
| 6909 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6910 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6911 | public void setAnimation(Animation anim) { |
| 6912 | if (localLOGV) Log.v( |
| 6913 | TAG, "Setting animation in " + this + ": " + anim); |
| 6914 | animation = anim; |
| 6915 | animating = false; |
| 6916 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 6917 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 6918 | int zorder = anim.getZAdjustment(); |
| 6919 | int adj = 0; |
| 6920 | if (zorder == Animation.ZORDER_TOP) { |
| 6921 | adj = TYPE_LAYER_OFFSET; |
| 6922 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 6923 | adj = -TYPE_LAYER_OFFSET; |
| 6924 | } |
| 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 | if (animLayerAdjustment != adj) { |
| 6927 | animLayerAdjustment = adj; |
| 6928 | updateLayers(); |
| 6929 | } |
| 6930 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6931 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6932 | public void setDummyAnimation() { |
| 6933 | if (animation == null) { |
| 6934 | if (localLOGV) Log.v( |
| 6935 | TAG, "Setting dummy animation in " + this); |
| 6936 | animation = sDummyAnimation; |
| 6937 | } |
| 6938 | } |
| 6939 | |
| 6940 | public void clearAnimation() { |
| 6941 | if (animation != null) { |
| 6942 | animation = null; |
| 6943 | animating = true; |
| 6944 | } |
| 6945 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6946 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6947 | void updateLayers() { |
| 6948 | final int N = allAppWindows.size(); |
| 6949 | final int adj = animLayerAdjustment; |
| 6950 | for (int i=0; i<N; i++) { |
| 6951 | WindowState w = allAppWindows.get(i); |
| 6952 | w.mAnimLayer = w.mLayer + adj; |
| 6953 | if (DEBUG_LAYERS) Log.v(TAG, "Updating layer " + w + ": " |
| 6954 | + w.mAnimLayer); |
| 6955 | if (w == mInputMethodTarget) { |
| 6956 | setInputMethodAnimLayerAdjustment(adj); |
| 6957 | } |
| 6958 | } |
| 6959 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6960 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6961 | void sendAppVisibilityToClients() { |
| 6962 | final int N = allAppWindows.size(); |
| 6963 | for (int i=0; i<N; i++) { |
| 6964 | WindowState win = allAppWindows.get(i); |
| 6965 | if (win == startingWindow && clientHidden) { |
| 6966 | // Don't hide the starting window. |
| 6967 | continue; |
| 6968 | } |
| 6969 | try { |
| 6970 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 6971 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 6972 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 6973 | } catch (RemoteException e) { |
| 6974 | } |
| 6975 | } |
| 6976 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6977 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6978 | void showAllWindowsLocked() { |
| 6979 | final int NW = allAppWindows.size(); |
| 6980 | for (int i=0; i<NW; i++) { |
| 6981 | WindowState w = allAppWindows.get(i); |
| 6982 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 6983 | "performing show on: " + w); |
| 6984 | w.performShowLocked(); |
| 6985 | } |
| 6986 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6987 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6988 | // This must be called while inside a transaction. |
| 6989 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| 6990 | if (!mDisplayFrozen) { |
| 6991 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6992 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6993 | if (animation == sDummyAnimation) { |
| 6994 | // This guy is going to animate, but not yet. For now count |
| 6995 | // it is not animating for purposes of scheduling transactions; |
| 6996 | // when it is really time to animate, this will be set to |
| 6997 | // a real animation and the next call will execute normally. |
| 6998 | return false; |
| 6999 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7000 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7001 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 7002 | if (!animating) { |
| 7003 | if (DEBUG_ANIM) Log.v( |
| 7004 | TAG, "Starting animation in " + this + |
| 7005 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 7006 | + " scale=" + mTransitionAnimationScale |
| 7007 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 7008 | animation.initialize(dw, dh, dw, dh); |
| 7009 | animation.setStartTime(currentTime); |
| 7010 | animating = true; |
| 7011 | } |
| 7012 | transformation.clear(); |
| 7013 | final boolean more = animation.getTransformation( |
| 7014 | currentTime, transformation); |
| 7015 | if (DEBUG_ANIM) Log.v( |
| 7016 | TAG, "Stepped animation in " + this + |
| 7017 | ": more=" + more + ", xform=" + transformation); |
| 7018 | if (more) { |
| 7019 | // we're done! |
| 7020 | hasTransformation = true; |
| 7021 | return true; |
| 7022 | } |
| 7023 | if (DEBUG_ANIM) Log.v( |
| 7024 | TAG, "Finished animation in " + this + |
| 7025 | " @ " + currentTime); |
| 7026 | animation = null; |
| 7027 | } |
| 7028 | } else if (animation != null) { |
| 7029 | // If the display is frozen, and there is a pending animation, |
| 7030 | // clear it and make sure we run the cleanup code. |
| 7031 | animating = true; |
| 7032 | animation = null; |
| 7033 | } |
| 7034 | |
| 7035 | hasTransformation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7036 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7037 | if (!animating) { |
| 7038 | return false; |
| 7039 | } |
| 7040 | |
| 7041 | clearAnimation(); |
| 7042 | animating = false; |
| 7043 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 7044 | moveInputMethodWindowsIfNeededLocked(true); |
| 7045 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7046 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7047 | if (DEBUG_ANIM) Log.v( |
| 7048 | TAG, "Animation done in " + this |
| 7049 | + ": reportedVisible=" + reportedVisible); |
| 7050 | |
| 7051 | transformation.clear(); |
| 7052 | if (animLayerAdjustment != 0) { |
| 7053 | animLayerAdjustment = 0; |
| 7054 | updateLayers(); |
| 7055 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7056 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7057 | final int N = windows.size(); |
| 7058 | for (int i=0; i<N; i++) { |
| 7059 | ((WindowState)windows.get(i)).finishExit(); |
| 7060 | } |
| 7061 | updateReportedVisibilityLocked(); |
| 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 | return false; |
| 7064 | } |
| 7065 | |
| 7066 | void updateReportedVisibilityLocked() { |
| 7067 | if (appToken == null) { |
| 7068 | return; |
| 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 | int numInteresting = 0; |
| 7072 | int numVisible = 0; |
| 7073 | boolean nowGone = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7074 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7075 | if (DEBUG_VISIBILITY) Log.v(TAG, "Update reported visibility: " + this); |
| 7076 | final int N = allAppWindows.size(); |
| 7077 | for (int i=0; i<N; i++) { |
| 7078 | WindowState win = allAppWindows.get(i); |
| 7079 | if (win == startingWindow || win.mAppFreezing) { |
| 7080 | continue; |
| 7081 | } |
| 7082 | if (DEBUG_VISIBILITY) { |
| 7083 | Log.v(TAG, "Win " + win + ": isDisplayed=" |
| 7084 | + win.isDisplayedLw() |
| 7085 | + ", isAnimating=" + win.isAnimating()); |
| 7086 | if (!win.isDisplayedLw()) { |
| 7087 | Log.v(TAG, "Not displayed: s=" + win.mSurface |
| 7088 | + " pv=" + win.mPolicyVisibility |
| 7089 | + " dp=" + win.mDrawPending |
| 7090 | + " cdp=" + win.mCommitDrawPending |
| 7091 | + " ah=" + win.mAttachedHidden |
| 7092 | + " th=" |
| 7093 | + (win.mAppToken != null |
| 7094 | ? win.mAppToken.hiddenRequested : false) |
| 7095 | + " a=" + win.mAnimating); |
| 7096 | } |
| 7097 | } |
| 7098 | numInteresting++; |
| 7099 | if (win.isDisplayedLw()) { |
| 7100 | if (!win.isAnimating()) { |
| 7101 | numVisible++; |
| 7102 | } |
| 7103 | nowGone = false; |
| 7104 | } else if (win.isAnimating()) { |
| 7105 | nowGone = false; |
| 7106 | } |
| 7107 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7108 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7109 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
| 7110 | if (DEBUG_VISIBILITY) Log.v(TAG, "VIS " + this + ": interesting=" |
| 7111 | + numInteresting + " visible=" + numVisible); |
| 7112 | if (nowVisible != reportedVisible) { |
| 7113 | if (DEBUG_VISIBILITY) Log.v( |
| 7114 | TAG, "Visibility changed in " + this |
| 7115 | + ": vis=" + nowVisible); |
| 7116 | reportedVisible = nowVisible; |
| 7117 | Message m = mH.obtainMessage( |
| 7118 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 7119 | nowVisible ? 1 : 0, |
| 7120 | nowGone ? 1 : 0, |
| 7121 | this); |
| 7122 | mH.sendMessage(m); |
| 7123 | } |
| 7124 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7125 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7126 | void dump(PrintWriter pw, String prefix) { |
| 7127 | super.dump(pw, prefix); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7128 | if (appToken != null) { |
| 7129 | pw.print(prefix); pw.println("app=true"); |
| 7130 | } |
| 7131 | if (allAppWindows.size() > 0) { |
| 7132 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 7133 | } |
| 7134 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
| 7135 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 7136 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 7137 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 7138 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 7139 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 7140 | if (paused || freezingScreen) { |
| 7141 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 7142 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 7143 | } |
| 7144 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 7145 | || inPendingTransaction || allDrawn) { |
| 7146 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 7147 | pw.print(numInterestingWindows); |
| 7148 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 7149 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 7150 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 7151 | } |
| 7152 | if (animating || animation != null) { |
| 7153 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 7154 | pw.print(" animation="); pw.println(animation); |
| 7155 | } |
| 7156 | if (animLayerAdjustment != 0) { |
| 7157 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 7158 | } |
| 7159 | if (hasTransformation) { |
| 7160 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 7161 | pw.print(" transformation="); transformation.printShortString(pw); |
| 7162 | pw.println(); |
| 7163 | } |
| 7164 | if (startingData != null || removed || firstWindowDrawn) { |
| 7165 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 7166 | pw.print(" removed="); pw.print(removed); |
| 7167 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 7168 | } |
| 7169 | if (startingWindow != null || startingView != null |
| 7170 | || startingDisplayed || startingMoved) { |
| 7171 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 7172 | pw.print(" startingView="); pw.print(startingView); |
| 7173 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 7174 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 7175 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7176 | } |
| 7177 | |
| 7178 | @Override |
| 7179 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7180 | if (stringName == null) { |
| 7181 | StringBuilder sb = new StringBuilder(); |
| 7182 | sb.append("AppWindowToken{"); |
| 7183 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7184 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 7185 | stringName = sb.toString(); |
| 7186 | } |
| 7187 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7188 | } |
| 7189 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7190 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7191 | public static WindowManager.LayoutParams findAnimations( |
| 7192 | ArrayList<AppWindowToken> order, |
| 7193 | ArrayList<AppWindowToken> tokenList1, |
| 7194 | ArrayList<AppWindowToken> tokenList2) { |
| 7195 | // We need to figure out which animation to use... |
| 7196 | WindowManager.LayoutParams animParams = null; |
| 7197 | int animSrc = 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7198 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7199 | //Log.i(TAG, "Looking for animations..."); |
| 7200 | for (int i=order.size()-1; i>=0; i--) { |
| 7201 | AppWindowToken wtoken = order.get(i); |
| 7202 | //Log.i(TAG, "Token " + wtoken + " with " + wtoken.windows.size() + " windows"); |
| 7203 | if (tokenList1.contains(wtoken) || tokenList2.contains(wtoken)) { |
| 7204 | int j = wtoken.windows.size(); |
| 7205 | while (j > 0) { |
| 7206 | j--; |
| 7207 | WindowState win = wtoken.windows.get(j); |
| 7208 | //Log.i(TAG, "Window " + win + ": type=" + win.mAttrs.type); |
| 7209 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 7210 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 7211 | //Log.i(TAG, "Found base or application window, done!"); |
| 7212 | if (wtoken.appFullscreen) { |
| 7213 | return win.mAttrs; |
| 7214 | } |
| 7215 | if (animSrc < 2) { |
| 7216 | animParams = win.mAttrs; |
| 7217 | animSrc = 2; |
| 7218 | } |
| 7219 | } else if (animSrc < 1 && win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION) { |
| 7220 | //Log.i(TAG, "Found normal window, we may use this..."); |
| 7221 | animParams = win.mAttrs; |
| 7222 | animSrc = 1; |
| 7223 | } |
| 7224 | } |
| 7225 | } |
| 7226 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7227 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7228 | return animParams; |
| 7229 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7230 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7231 | // ------------------------------------------------------------- |
| 7232 | // DummyAnimation |
| 7233 | // ------------------------------------------------------------- |
| 7234 | |
| 7235 | // This is an animation that does nothing: it just immediately finishes |
| 7236 | // itself every time it is called. It is used as a stub animation in cases |
| 7237 | // where we want to synchronize multiple things that may be animating. |
| 7238 | static final class DummyAnimation extends Animation { |
| 7239 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 7240 | return false; |
| 7241 | } |
| 7242 | } |
| 7243 | static final Animation sDummyAnimation = new DummyAnimation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7244 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7245 | // ------------------------------------------------------------- |
| 7246 | // Async Handler |
| 7247 | // ------------------------------------------------------------- |
| 7248 | |
| 7249 | static final class StartingData { |
| 7250 | final String pkg; |
| 7251 | final int theme; |
| 7252 | final CharSequence nonLocalizedLabel; |
| 7253 | final int labelRes; |
| 7254 | final int icon; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7255 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7256 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 7257 | int _labelRes, int _icon) { |
| 7258 | pkg = _pkg; |
| 7259 | theme = _theme; |
| 7260 | nonLocalizedLabel = _nonLocalizedLabel; |
| 7261 | labelRes = _labelRes; |
| 7262 | icon = _icon; |
| 7263 | } |
| 7264 | } |
| 7265 | |
| 7266 | private final class H extends Handler { |
| 7267 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 7268 | public static final int REPORT_LOSING_FOCUS = 3; |
| 7269 | public static final int ANIMATE = 4; |
| 7270 | public static final int ADD_STARTING = 5; |
| 7271 | public static final int REMOVE_STARTING = 6; |
| 7272 | public static final int FINISHED_STARTING = 7; |
| 7273 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7274 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 7275 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 7276 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 7277 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 7278 | public static final int FORCE_GC = 15; |
| 7279 | public static final int ENABLE_SCREEN = 16; |
| 7280 | public static final int APP_FREEZE_TIMEOUT = 17; |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 7281 | public static final int COMPUTE_AND_SEND_NEW_CONFIGURATION = 18; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7282 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7283 | private Session mLastReportedHold; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7284 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7285 | public H() { |
| 7286 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7287 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7288 | @Override |
| 7289 | public void handleMessage(Message msg) { |
| 7290 | switch (msg.what) { |
| 7291 | case REPORT_FOCUS_CHANGE: { |
| 7292 | WindowState lastFocus; |
| 7293 | WindowState newFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7294 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7295 | synchronized(mWindowMap) { |
| 7296 | lastFocus = mLastFocus; |
| 7297 | newFocus = mCurrentFocus; |
| 7298 | if (lastFocus == newFocus) { |
| 7299 | // Focus is not changing, so nothing to do. |
| 7300 | return; |
| 7301 | } |
| 7302 | mLastFocus = newFocus; |
| 7303 | //Log.i(TAG, "Focus moving from " + lastFocus |
| 7304 | // + " to " + newFocus); |
| 7305 | if (newFocus != null && lastFocus != null |
| 7306 | && !newFocus.isDisplayedLw()) { |
| 7307 | //Log.i(TAG, "Delaying loss of focus..."); |
| 7308 | mLosingFocus.add(lastFocus); |
| 7309 | lastFocus = null; |
| 7310 | } |
| 7311 | } |
| 7312 | |
| 7313 | if (lastFocus != newFocus) { |
| 7314 | //System.out.println("Changing focus from " + lastFocus |
| 7315 | // + " to " + newFocus); |
| 7316 | if (newFocus != null) { |
| 7317 | try { |
| 7318 | //Log.i(TAG, "Gaining focus: " + newFocus); |
| 7319 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 7320 | } catch (RemoteException e) { |
| 7321 | // Ignore if process has died. |
| 7322 | } |
| 7323 | } |
| 7324 | |
| 7325 | if (lastFocus != null) { |
| 7326 | try { |
| 7327 | //Log.i(TAG, "Losing focus: " + lastFocus); |
| 7328 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 7329 | } catch (RemoteException e) { |
| 7330 | // Ignore if process has died. |
| 7331 | } |
| 7332 | } |
| 7333 | } |
| 7334 | } break; |
| 7335 | |
| 7336 | case REPORT_LOSING_FOCUS: { |
| 7337 | ArrayList<WindowState> losers; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7338 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7339 | synchronized(mWindowMap) { |
| 7340 | losers = mLosingFocus; |
| 7341 | mLosingFocus = new ArrayList<WindowState>(); |
| 7342 | } |
| 7343 | |
| 7344 | final int N = losers.size(); |
| 7345 | for (int i=0; i<N; i++) { |
| 7346 | try { |
| 7347 | //Log.i(TAG, "Losing delayed focus: " + losers.get(i)); |
| 7348 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 7349 | } catch (RemoteException e) { |
| 7350 | // Ignore if process has died. |
| 7351 | } |
| 7352 | } |
| 7353 | } break; |
| 7354 | |
| 7355 | case ANIMATE: { |
| 7356 | synchronized(mWindowMap) { |
| 7357 | mAnimationPending = false; |
| 7358 | performLayoutAndPlaceSurfacesLocked(); |
| 7359 | } |
| 7360 | } break; |
| 7361 | |
| 7362 | case ADD_STARTING: { |
| 7363 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7364 | final StartingData sd = wtoken.startingData; |
| 7365 | |
| 7366 | if (sd == null) { |
| 7367 | // Animation has been canceled... do nothing. |
| 7368 | return; |
| 7369 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7370 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7371 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Add starting " |
| 7372 | + wtoken + ": pkg=" + sd.pkg); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7373 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7374 | View view = null; |
| 7375 | try { |
| 7376 | view = mPolicy.addStartingWindow( |
| 7377 | wtoken.token, sd.pkg, |
| 7378 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 7379 | sd.icon); |
| 7380 | } catch (Exception e) { |
| 7381 | Log.w(TAG, "Exception when adding starting window", e); |
| 7382 | } |
| 7383 | |
| 7384 | if (view != null) { |
| 7385 | boolean abort = false; |
| 7386 | |
| 7387 | synchronized(mWindowMap) { |
| 7388 | if (wtoken.removed || wtoken.startingData == null) { |
| 7389 | // If the window was successfully added, then |
| 7390 | // we need to remove it. |
| 7391 | if (wtoken.startingWindow != null) { |
| 7392 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 7393 | "Aborted starting " + wtoken |
| 7394 | + ": removed=" + wtoken.removed |
| 7395 | + " startingData=" + wtoken.startingData); |
| 7396 | wtoken.startingWindow = null; |
| 7397 | wtoken.startingData = null; |
| 7398 | abort = true; |
| 7399 | } |
| 7400 | } else { |
| 7401 | wtoken.startingView = view; |
| 7402 | } |
| 7403 | if (DEBUG_STARTING_WINDOW && !abort) Log.v(TAG, |
| 7404 | "Added starting " + wtoken |
| 7405 | + ": startingWindow=" |
| 7406 | + wtoken.startingWindow + " startingView=" |
| 7407 | + wtoken.startingView); |
| 7408 | } |
| 7409 | |
| 7410 | if (abort) { |
| 7411 | try { |
| 7412 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 7413 | } catch (Exception e) { |
| 7414 | Log.w(TAG, "Exception when removing starting window", e); |
| 7415 | } |
| 7416 | } |
| 7417 | } |
| 7418 | } break; |
| 7419 | |
| 7420 | case REMOVE_STARTING: { |
| 7421 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7422 | IBinder token = null; |
| 7423 | View view = null; |
| 7424 | synchronized (mWindowMap) { |
| 7425 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Remove starting " |
| 7426 | + wtoken + ": startingWindow=" |
| 7427 | + wtoken.startingWindow + " startingView=" |
| 7428 | + wtoken.startingView); |
| 7429 | if (wtoken.startingWindow != null) { |
| 7430 | view = wtoken.startingView; |
| 7431 | token = wtoken.token; |
| 7432 | wtoken.startingData = null; |
| 7433 | wtoken.startingView = null; |
| 7434 | wtoken.startingWindow = null; |
| 7435 | } |
| 7436 | } |
| 7437 | if (view != null) { |
| 7438 | try { |
| 7439 | mPolicy.removeStartingWindow(token, view); |
| 7440 | } catch (Exception e) { |
| 7441 | Log.w(TAG, "Exception when removing starting window", e); |
| 7442 | } |
| 7443 | } |
| 7444 | } break; |
| 7445 | |
| 7446 | case FINISHED_STARTING: { |
| 7447 | IBinder token = null; |
| 7448 | View view = null; |
| 7449 | while (true) { |
| 7450 | synchronized (mWindowMap) { |
| 7451 | final int N = mFinishedStarting.size(); |
| 7452 | if (N <= 0) { |
| 7453 | break; |
| 7454 | } |
| 7455 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 7456 | |
| 7457 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 7458 | "Finished starting " + wtoken |
| 7459 | + ": startingWindow=" + wtoken.startingWindow |
| 7460 | + " startingView=" + wtoken.startingView); |
| 7461 | |
| 7462 | if (wtoken.startingWindow == null) { |
| 7463 | continue; |
| 7464 | } |
| 7465 | |
| 7466 | view = wtoken.startingView; |
| 7467 | token = wtoken.token; |
| 7468 | wtoken.startingData = null; |
| 7469 | wtoken.startingView = null; |
| 7470 | wtoken.startingWindow = null; |
| 7471 | } |
| 7472 | |
| 7473 | try { |
| 7474 | mPolicy.removeStartingWindow(token, view); |
| 7475 | } catch (Exception e) { |
| 7476 | Log.w(TAG, "Exception when removing starting window", e); |
| 7477 | } |
| 7478 | } |
| 7479 | } break; |
| 7480 | |
| 7481 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 7482 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7483 | |
| 7484 | boolean nowVisible = msg.arg1 != 0; |
| 7485 | boolean nowGone = msg.arg2 != 0; |
| 7486 | |
| 7487 | try { |
| 7488 | if (DEBUG_VISIBILITY) Log.v( |
| 7489 | TAG, "Reporting visible in " + wtoken |
| 7490 | + " visible=" + nowVisible |
| 7491 | + " gone=" + nowGone); |
| 7492 | if (nowVisible) { |
| 7493 | wtoken.appToken.windowsVisible(); |
| 7494 | } else { |
| 7495 | wtoken.appToken.windowsGone(); |
| 7496 | } |
| 7497 | } catch (RemoteException ex) { |
| 7498 | } |
| 7499 | } break; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7500 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7501 | case WINDOW_FREEZE_TIMEOUT: { |
| 7502 | synchronized (mWindowMap) { |
| 7503 | Log.w(TAG, "Window freeze timeout expired."); |
| 7504 | int i = mWindows.size(); |
| 7505 | while (i > 0) { |
| 7506 | i--; |
| 7507 | WindowState w = (WindowState)mWindows.get(i); |
| 7508 | if (w.mOrientationChanging) { |
| 7509 | w.mOrientationChanging = false; |
| 7510 | Log.w(TAG, "Force clearing orientation change: " + w); |
| 7511 | } |
| 7512 | } |
| 7513 | performLayoutAndPlaceSurfacesLocked(); |
| 7514 | } |
| 7515 | break; |
| 7516 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7517 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7518 | case HOLD_SCREEN_CHANGED: { |
| 7519 | Session oldHold; |
| 7520 | Session newHold; |
| 7521 | synchronized (mWindowMap) { |
| 7522 | oldHold = mLastReportedHold; |
| 7523 | newHold = (Session)msg.obj; |
| 7524 | mLastReportedHold = newHold; |
| 7525 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7526 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7527 | if (oldHold != newHold) { |
| 7528 | try { |
| 7529 | if (oldHold != null) { |
| 7530 | mBatteryStats.noteStopWakelock(oldHold.mUid, |
| 7531 | "window", |
| 7532 | BatteryStats.WAKE_TYPE_WINDOW); |
| 7533 | } |
| 7534 | if (newHold != null) { |
| 7535 | mBatteryStats.noteStartWakelock(newHold.mUid, |
| 7536 | "window", |
| 7537 | BatteryStats.WAKE_TYPE_WINDOW); |
| 7538 | } |
| 7539 | } catch (RemoteException e) { |
| 7540 | } |
| 7541 | } |
| 7542 | break; |
| 7543 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7544 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7545 | case APP_TRANSITION_TIMEOUT: { |
| 7546 | synchronized (mWindowMap) { |
| 7547 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) { |
| 7548 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 7549 | "*** APP TRANSITION TIMEOUT"); |
| 7550 | mAppTransitionReady = true; |
| 7551 | mAppTransitionTimeout = true; |
| 7552 | performLayoutAndPlaceSurfacesLocked(); |
| 7553 | } |
| 7554 | } |
| 7555 | break; |
| 7556 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7557 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7558 | case PERSIST_ANIMATION_SCALE: { |
| 7559 | Settings.System.putFloat(mContext.getContentResolver(), |
| 7560 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 7561 | Settings.System.putFloat(mContext.getContentResolver(), |
| 7562 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 7563 | break; |
| 7564 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7565 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7566 | case FORCE_GC: { |
| 7567 | synchronized(mWindowMap) { |
| 7568 | if (mAnimationPending) { |
| 7569 | // If we are animating, don't do the gc now but |
| 7570 | // delay a bit so we don't interrupt the animation. |
| 7571 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 7572 | 2000); |
| 7573 | return; |
| 7574 | } |
| 7575 | // If we are currently rotating the display, it will |
| 7576 | // schedule a new message when done. |
| 7577 | if (mDisplayFrozen) { |
| 7578 | return; |
| 7579 | } |
| 7580 | mFreezeGcPending = 0; |
| 7581 | } |
| 7582 | Runtime.getRuntime().gc(); |
| 7583 | break; |
| 7584 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7585 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7586 | case ENABLE_SCREEN: { |
| 7587 | performEnableScreen(); |
| 7588 | break; |
| 7589 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7590 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7591 | case APP_FREEZE_TIMEOUT: { |
| 7592 | synchronized (mWindowMap) { |
| 7593 | Log.w(TAG, "App freeze timeout expired."); |
| 7594 | int i = mAppTokens.size(); |
| 7595 | while (i > 0) { |
| 7596 | i--; |
| 7597 | AppWindowToken tok = mAppTokens.get(i); |
| 7598 | if (tok.freezingScreen) { |
| 7599 | Log.w(TAG, "Force clearing freeze: " + tok); |
| 7600 | unsetAppFreezingScreenLocked(tok, true, true); |
| 7601 | } |
| 7602 | } |
| 7603 | } |
| 7604 | break; |
| 7605 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7606 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 7607 | case COMPUTE_AND_SEND_NEW_CONFIGURATION: { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 7608 | if (updateOrientationFromAppTokensUnchecked(null, null) != null) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 7609 | sendNewConfiguration(); |
| 7610 | } |
| 7611 | break; |
| 7612 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7613 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7614 | } |
| 7615 | } |
| 7616 | } |
| 7617 | |
| 7618 | // ------------------------------------------------------------- |
| 7619 | // IWindowManager API |
| 7620 | // ------------------------------------------------------------- |
| 7621 | |
| 7622 | public IWindowSession openSession(IInputMethodClient client, |
| 7623 | IInputContext inputContext) { |
| 7624 | if (client == null) throw new IllegalArgumentException("null client"); |
| 7625 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
| 7626 | return new Session(client, inputContext); |
| 7627 | } |
| 7628 | |
| 7629 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 7630 | synchronized (mWindowMap) { |
| 7631 | // The focus for the client is the window immediately below |
| 7632 | // where we would place the input method window. |
| 7633 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 7634 | WindowState imFocus; |
| 7635 | if (idx > 0) { |
| 7636 | imFocus = (WindowState)mWindows.get(idx-1); |
| 7637 | if (imFocus != null) { |
| 7638 | if (imFocus.mSession.mClient != null && |
| 7639 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 7640 | return true; |
| 7641 | } |
| 7642 | } |
| 7643 | } |
| 7644 | } |
| 7645 | return false; |
| 7646 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7647 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7648 | // ------------------------------------------------------------- |
| 7649 | // Internals |
| 7650 | // ------------------------------------------------------------- |
| 7651 | |
| 7652 | final WindowState windowForClientLocked(Session session, IWindow client) { |
| 7653 | return windowForClientLocked(session, client.asBinder()); |
| 7654 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7655 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7656 | final WindowState windowForClientLocked(Session session, IBinder client) { |
| 7657 | WindowState win = mWindowMap.get(client); |
| 7658 | if (localLOGV) Log.v( |
| 7659 | TAG, "Looking up client " + client + ": " + win); |
| 7660 | if (win == null) { |
| 7661 | RuntimeException ex = new RuntimeException(); |
| 7662 | Log.w(TAG, "Requested window " + client + " does not exist", ex); |
| 7663 | return null; |
| 7664 | } |
| 7665 | if (session != null && win.mSession != session) { |
| 7666 | RuntimeException ex = new RuntimeException(); |
| 7667 | Log.w(TAG, "Requested window " + client + " is in session " + |
| 7668 | win.mSession + ", not " + session, ex); |
| 7669 | return null; |
| 7670 | } |
| 7671 | |
| 7672 | return win; |
| 7673 | } |
| 7674 | |
| 7675 | private final void assignLayersLocked() { |
| 7676 | int N = mWindows.size(); |
| 7677 | int curBaseLayer = 0; |
| 7678 | int curLayer = 0; |
| 7679 | int i; |
| 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 | for (i=0; i<N; i++) { |
| 7682 | WindowState w = (WindowState)mWindows.get(i); |
| 7683 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow) { |
| 7684 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 7685 | w.mLayer = curLayer; |
| 7686 | } else { |
| 7687 | curBaseLayer = curLayer = w.mBaseLayer; |
| 7688 | w.mLayer = curLayer; |
| 7689 | } |
| 7690 | if (w.mTargetAppToken != null) { |
| 7691 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 7692 | } else if (w.mAppToken != null) { |
| 7693 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 7694 | } else { |
| 7695 | w.mAnimLayer = w.mLayer; |
| 7696 | } |
| 7697 | if (w.mIsImWindow) { |
| 7698 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
| 7699 | } |
| 7700 | if (DEBUG_LAYERS) Log.v(TAG, "Assign layer " + w + ": " |
| 7701 | + w.mAnimLayer); |
| 7702 | //System.out.println( |
| 7703 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 7704 | } |
| 7705 | } |
| 7706 | |
| 7707 | private boolean mInLayout = false; |
| 7708 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 7709 | if (mInLayout) { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 7710 | if (DEBUG) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7711 | throw new RuntimeException("Recursive call!"); |
| 7712 | } |
| 7713 | Log.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
| 7714 | return; |
| 7715 | } |
| 7716 | |
| 7717 | boolean recoveringMemory = false; |
| 7718 | if (mForceRemoves != null) { |
| 7719 | recoveringMemory = true; |
| 7720 | // Wait a little it for things to settle down, and off we go. |
| 7721 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 7722 | WindowState ws = mForceRemoves.get(i); |
| 7723 | Log.i(TAG, "Force removing: " + ws); |
| 7724 | removeWindowInnerLocked(ws.mSession, ws); |
| 7725 | } |
| 7726 | mForceRemoves = null; |
| 7727 | Log.w(TAG, "Due to memory failure, waiting a bit for next layout"); |
| 7728 | Object tmp = new Object(); |
| 7729 | synchronized (tmp) { |
| 7730 | try { |
| 7731 | tmp.wait(250); |
| 7732 | } catch (InterruptedException e) { |
| 7733 | } |
| 7734 | } |
| 7735 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7736 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7737 | mInLayout = true; |
| 7738 | try { |
| 7739 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7740 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7741 | int i = mPendingRemove.size()-1; |
| 7742 | if (i >= 0) { |
| 7743 | while (i >= 0) { |
| 7744 | WindowState w = mPendingRemove.get(i); |
| 7745 | removeWindowInnerLocked(w.mSession, w); |
| 7746 | i--; |
| 7747 | } |
| 7748 | mPendingRemove.clear(); |
| 7749 | |
| 7750 | mInLayout = false; |
| 7751 | assignLayersLocked(); |
| 7752 | mLayoutNeeded = true; |
| 7753 | performLayoutAndPlaceSurfacesLocked(); |
| 7754 | |
| 7755 | } else { |
| 7756 | mInLayout = false; |
| 7757 | if (mLayoutNeeded) { |
| 7758 | requestAnimationLocked(0); |
| 7759 | } |
| 7760 | } |
| 7761 | } catch (RuntimeException e) { |
| 7762 | mInLayout = false; |
| 7763 | Log.e(TAG, "Unhandled exception while layout out windows", e); |
| 7764 | } |
| 7765 | } |
| 7766 | |
| 7767 | private final void performLayoutLockedInner() { |
| 7768 | final int dw = mDisplay.getWidth(); |
| 7769 | final int dh = mDisplay.getHeight(); |
| 7770 | |
| 7771 | final int N = mWindows.size(); |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 7772 | int repeats = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7773 | int i; |
| 7774 | |
| 7775 | // FIRST LOOP: Perform a layout, if needed. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7776 | |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 7777 | while (mLayoutNeeded) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7778 | mPolicy.beginLayoutLw(dw, dh); |
| 7779 | |
| 7780 | // First perform layout of any root windows (not attached |
| 7781 | // to another window). |
| 7782 | int topAttached = -1; |
| 7783 | for (i = N-1; i >= 0; i--) { |
| 7784 | WindowState win = (WindowState) mWindows.get(i); |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 7785 | |
| 7786 | // Don't do layout of a window if it is not visible, or |
| 7787 | // soon won't be visible, to avoid wasting time and funky |
| 7788 | // changes while a window is animating away. |
| 7789 | final AppWindowToken atoken = win.mAppToken; |
| 7790 | final boolean gone = win.mViewVisibility == View.GONE |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7791 | || !win.mRelayoutCalled |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 7792 | || win.mRootToken.hidden |
| 7793 | || (atoken != null && atoken.hiddenRequested) |
| 7794 | || !win.mPolicyVisibility |
| 7795 | || win.mAttachedHidden |
| 7796 | || win.mExiting || win.mDestroying; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7797 | |
| 7798 | // If this view is GONE, then skip it -- keep the current |
| 7799 | // frame, and let the caller know so they can ignore it |
| 7800 | // if they want. (We do the normal layout for INVISIBLE |
| 7801 | // windows, since that means "perform layout as normal, |
| 7802 | // just don't display"). |
| 7803 | if (!gone || !win.mHaveFrame) { |
| 7804 | if (!win.mLayoutAttached) { |
| 7805 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 7806 | } else { |
| 7807 | if (topAttached < 0) topAttached = i; |
| 7808 | } |
| 7809 | } |
| 7810 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7811 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7812 | // Now perform layout of attached windows, which usually |
| 7813 | // depend on the position of the window they are attached to. |
| 7814 | // XXX does not deal with windows that are attached to windows |
| 7815 | // that are themselves attached. |
| 7816 | for (i = topAttached; i >= 0; i--) { |
| 7817 | WindowState win = (WindowState) mWindows.get(i); |
| 7818 | |
| 7819 | // If this view is GONE, then skip it -- keep the current |
| 7820 | // frame, and let the caller know so they can ignore it |
| 7821 | // if they want. (We do the normal layout for INVISIBLE |
| 7822 | // windows, since that means "perform layout as normal, |
| 7823 | // just don't display"). |
| 7824 | if (win.mLayoutAttached) { |
| 7825 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 7826 | || !win.mHaveFrame) { |
| 7827 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 7828 | } |
| 7829 | } |
| 7830 | } |
| 7831 | |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 7832 | if (!mPolicy.finishLayoutLw()) { |
| 7833 | mLayoutNeeded = false; |
| 7834 | } else if (repeats > 2) { |
| 7835 | Log.w(TAG, "Layout repeat aborted after too many iterations"); |
| 7836 | mLayoutNeeded = false; |
| 7837 | } else { |
| 7838 | repeats++; |
| 7839 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7840 | } |
| 7841 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7842 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7843 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 7844 | boolean recoveringMemory) { |
| 7845 | final long currentTime = SystemClock.uptimeMillis(); |
| 7846 | final int dw = mDisplay.getWidth(); |
| 7847 | final int dh = mDisplay.getHeight(); |
| 7848 | |
| 7849 | final int N = mWindows.size(); |
| 7850 | int i; |
| 7851 | |
| 7852 | // FIRST LOOP: Perform a layout, if needed. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7853 | performLayoutLockedInner(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7854 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7855 | if (mFxSession == null) { |
| 7856 | mFxSession = new SurfaceSession(); |
| 7857 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7858 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7859 | if (SHOW_TRANSACTIONS) Log.i(TAG, ">>> OPEN TRANSACTION"); |
| 7860 | |
| 7861 | // Initialize state of exiting tokens. |
| 7862 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 7863 | mExitingTokens.get(i).hasVisible = false; |
| 7864 | } |
| 7865 | |
| 7866 | // Initialize state of exiting applications. |
| 7867 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 7868 | mExitingAppTokens.get(i).hasVisible = false; |
| 7869 | } |
| 7870 | |
| 7871 | // SECOND LOOP: Execute animations and update visibility of windows. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7872 | boolean orientationChangeComplete = true; |
| 7873 | Session holdScreen = null; |
| 7874 | float screenBrightness = -1; |
| 7875 | boolean focusDisplayed = false; |
| 7876 | boolean animating = false; |
| 7877 | |
| 7878 | Surface.openTransaction(); |
| 7879 | try { |
| 7880 | boolean restart; |
| 7881 | |
| 7882 | do { |
| 7883 | final int transactionSequence = ++mTransactionSequence; |
| 7884 | |
| 7885 | // Update animations of all applications, including those |
| 7886 | // associated with exiting/removed apps |
| 7887 | boolean tokensAnimating = false; |
| 7888 | final int NAT = mAppTokens.size(); |
| 7889 | for (i=0; i<NAT; i++) { |
| 7890 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 7891 | tokensAnimating = true; |
| 7892 | } |
| 7893 | } |
| 7894 | final int NEAT = mExitingAppTokens.size(); |
| 7895 | for (i=0; i<NEAT; i++) { |
| 7896 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 7897 | tokensAnimating = true; |
| 7898 | } |
| 7899 | } |
| 7900 | |
| 7901 | animating = tokensAnimating; |
| 7902 | restart = false; |
| 7903 | |
| 7904 | boolean tokenMayBeDrawn = false; |
| 7905 | |
| 7906 | mPolicy.beginAnimationLw(dw, dh); |
| 7907 | |
| 7908 | for (i=N-1; i>=0; i--) { |
| 7909 | WindowState w = (WindowState)mWindows.get(i); |
| 7910 | |
| 7911 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 7912 | |
| 7913 | if (w.mSurface != null) { |
| 7914 | // Execute animation. |
| 7915 | w.commitFinishDrawingLocked(currentTime); |
| 7916 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 7917 | animating = true; |
| 7918 | //w.dump(" "); |
| 7919 | } |
| 7920 | |
| 7921 | mPolicy.animatingWindowLw(w, attrs); |
| 7922 | } |
| 7923 | |
| 7924 | final AppWindowToken atoken = w.mAppToken; |
| 7925 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 7926 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 7927 | atoken.lastTransactionSequence = transactionSequence; |
| 7928 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 7929 | atoken.startingDisplayed = false; |
| 7930 | } |
| 7931 | if ((w.isOnScreen() || w.mAttrs.type |
| 7932 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 7933 | && !w.mExiting && !w.mDestroying) { |
| 7934 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
| 7935 | Log.v(TAG, "Eval win " + w + ": isDisplayed=" |
| 7936 | + w.isDisplayedLw() |
| 7937 | + ", isAnimating=" + w.isAnimating()); |
| 7938 | if (!w.isDisplayedLw()) { |
| 7939 | Log.v(TAG, "Not displayed: s=" + w.mSurface |
| 7940 | + " pv=" + w.mPolicyVisibility |
| 7941 | + " dp=" + w.mDrawPending |
| 7942 | + " cdp=" + w.mCommitDrawPending |
| 7943 | + " ah=" + w.mAttachedHidden |
| 7944 | + " th=" + atoken.hiddenRequested |
| 7945 | + " a=" + w.mAnimating); |
| 7946 | } |
| 7947 | } |
| 7948 | if (w != atoken.startingWindow) { |
| 7949 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 7950 | atoken.numInterestingWindows++; |
| 7951 | if (w.isDisplayedLw()) { |
| 7952 | atoken.numDrawnWindows++; |
| 7953 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Log.v(TAG, |
| 7954 | "tokenMayBeDrawn: " + atoken |
| 7955 | + " freezingScreen=" + atoken.freezingScreen |
| 7956 | + " mAppFreezing=" + w.mAppFreezing); |
| 7957 | tokenMayBeDrawn = true; |
| 7958 | } |
| 7959 | } |
| 7960 | } else if (w.isDisplayedLw()) { |
| 7961 | atoken.startingDisplayed = true; |
| 7962 | } |
| 7963 | } |
| 7964 | } else if (w.mReadyToShow) { |
| 7965 | w.performShowLocked(); |
| 7966 | } |
| 7967 | } |
| 7968 | |
| 7969 | if (mPolicy.finishAnimationLw()) { |
| 7970 | restart = true; |
| 7971 | } |
| 7972 | |
| 7973 | if (tokenMayBeDrawn) { |
| 7974 | // See if any windows have been drawn, so they (and others |
| 7975 | // associated with them) can now be shown. |
| 7976 | final int NT = mTokenList.size(); |
| 7977 | for (i=0; i<NT; i++) { |
| 7978 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 7979 | if (wtoken == null) { |
| 7980 | continue; |
| 7981 | } |
| 7982 | if (wtoken.freezingScreen) { |
| 7983 | int numInteresting = wtoken.numInterestingWindows; |
| 7984 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| 7985 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 7986 | "allDrawn: " + wtoken |
| 7987 | + " interesting=" + numInteresting |
| 7988 | + " drawn=" + wtoken.numDrawnWindows); |
| 7989 | wtoken.showAllWindowsLocked(); |
| 7990 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 7991 | orientationChangeComplete = true; |
| 7992 | } |
| 7993 | } else if (!wtoken.allDrawn) { |
| 7994 | int numInteresting = wtoken.numInterestingWindows; |
| 7995 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| 7996 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 7997 | "allDrawn: " + wtoken |
| 7998 | + " interesting=" + numInteresting |
| 7999 | + " drawn=" + wtoken.numDrawnWindows); |
| 8000 | wtoken.allDrawn = true; |
| 8001 | restart = true; |
| 8002 | |
| 8003 | // We can now show all of the drawn windows! |
| 8004 | if (!mOpeningApps.contains(wtoken)) { |
| 8005 | wtoken.showAllWindowsLocked(); |
| 8006 | } |
| 8007 | } |
| 8008 | } |
| 8009 | } |
| 8010 | } |
| 8011 | |
| 8012 | // If we are ready to perform an app transition, check through |
| 8013 | // all of the app tokens to be shown and see if they are ready |
| 8014 | // to go. |
| 8015 | if (mAppTransitionReady) { |
| 8016 | int NN = mOpeningApps.size(); |
| 8017 | boolean goodToGo = true; |
| 8018 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 8019 | "Checking " + NN + " opening apps (frozen=" |
| 8020 | + mDisplayFrozen + " timeout=" |
| 8021 | + mAppTransitionTimeout + ")..."); |
| 8022 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 8023 | // If the display isn't frozen, wait to do anything until |
| 8024 | // all of the apps are ready. Otherwise just go because |
| 8025 | // we'll unfreeze the display when everyone is ready. |
| 8026 | for (i=0; i<NN && goodToGo; i++) { |
| 8027 | AppWindowToken wtoken = mOpeningApps.get(i); |
| 8028 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 8029 | "Check opening app" + wtoken + ": allDrawn=" |
| 8030 | + wtoken.allDrawn + " startingDisplayed=" |
| 8031 | + wtoken.startingDisplayed); |
| 8032 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 8033 | && !wtoken.startingMoved) { |
| 8034 | goodToGo = false; |
| 8035 | } |
| 8036 | } |
| 8037 | } |
| 8038 | if (goodToGo) { |
| 8039 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "**** GOOD TO GO"); |
| 8040 | int transit = mNextAppTransition; |
| 8041 | if (mSkipAppTransitionAnimation) { |
| 8042 | transit = WindowManagerPolicy.TRANSIT_NONE; |
| 8043 | } |
| 8044 | mNextAppTransition = WindowManagerPolicy.TRANSIT_NONE; |
| 8045 | mAppTransitionReady = false; |
| 8046 | mAppTransitionTimeout = false; |
| 8047 | mStartingIconInTransition = false; |
| 8048 | mSkipAppTransitionAnimation = false; |
| 8049 | |
| 8050 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 8051 | |
| 8052 | // We need to figure out which animation to use... |
| 8053 | WindowManager.LayoutParams lp = findAnimations(mAppTokens, |
| 8054 | mOpeningApps, mClosingApps); |
| 8055 | |
| 8056 | NN = mOpeningApps.size(); |
| 8057 | for (i=0; i<NN; i++) { |
| 8058 | AppWindowToken wtoken = mOpeningApps.get(i); |
| 8059 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 8060 | "Now opening app" + wtoken); |
| 8061 | wtoken.reportedVisible = false; |
| 8062 | wtoken.inPendingTransaction = false; |
| 8063 | setTokenVisibilityLocked(wtoken, lp, true, transit, false); |
| 8064 | wtoken.updateReportedVisibilityLocked(); |
| 8065 | wtoken.showAllWindowsLocked(); |
| 8066 | } |
| 8067 | NN = mClosingApps.size(); |
| 8068 | for (i=0; i<NN; i++) { |
| 8069 | AppWindowToken wtoken = mClosingApps.get(i); |
| 8070 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 8071 | "Now closing app" + wtoken); |
| 8072 | wtoken.inPendingTransaction = false; |
| 8073 | setTokenVisibilityLocked(wtoken, lp, false, transit, false); |
| 8074 | wtoken.updateReportedVisibilityLocked(); |
| 8075 | // Force the allDrawn flag, because we want to start |
| 8076 | // this guy's animations regardless of whether it's |
| 8077 | // gotten drawn. |
| 8078 | wtoken.allDrawn = true; |
| 8079 | } |
| 8080 | |
| 8081 | mOpeningApps.clear(); |
| 8082 | mClosingApps.clear(); |
| 8083 | |
| 8084 | // This has changed the visibility of windows, so perform |
| 8085 | // a new layout to get them all up-to-date. |
| 8086 | mLayoutNeeded = true; |
| 8087 | moveInputMethodWindowsIfNeededLocked(true); |
| 8088 | performLayoutLockedInner(); |
| 8089 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
| 8090 | |
| 8091 | restart = true; |
| 8092 | } |
| 8093 | } |
| 8094 | } while (restart); |
| 8095 | |
| 8096 | // THIRD LOOP: Update the surfaces of all windows. |
| 8097 | |
| 8098 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 8099 | |
| 8100 | boolean obscured = false; |
| 8101 | boolean blurring = false; |
| 8102 | boolean dimming = false; |
| 8103 | boolean covered = false; |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 8104 | boolean syswin = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8105 | |
| 8106 | for (i=N-1; i>=0; i--) { |
| 8107 | WindowState w = (WindowState)mWindows.get(i); |
| 8108 | |
| 8109 | boolean displayed = false; |
| 8110 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 8111 | final int attrFlags = attrs.flags; |
| 8112 | |
| 8113 | if (w.mSurface != null) { |
| 8114 | w.computeShownFrameLocked(); |
| 8115 | if (localLOGV) Log.v( |
| 8116 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 8117 | + ": new=" + w.mShownFrame + ", old=" |
| 8118 | + w.mLastShownFrame); |
| 8119 | |
| 8120 | boolean resize; |
| 8121 | int width, height; |
| 8122 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 8123 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 8124 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 8125 | // for a scaled surface, we just want to use |
| 8126 | // the requested size. |
| 8127 | width = w.mRequestedWidth; |
| 8128 | height = w.mRequestedHeight; |
| 8129 | w.mLastRequestedWidth = width; |
| 8130 | w.mLastRequestedHeight = height; |
| 8131 | w.mLastShownFrame.set(w.mShownFrame); |
| 8132 | try { |
| 8133 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 8134 | } catch (RuntimeException e) { |
| 8135 | Log.w(TAG, "Error positioning surface in " + w, e); |
| 8136 | if (!recoveringMemory) { |
| 8137 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 8138 | } |
| 8139 | } |
| 8140 | } else { |
| 8141 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 8142 | width = w.mShownFrame.width(); |
| 8143 | height = w.mShownFrame.height(); |
| 8144 | w.mLastShownFrame.set(w.mShownFrame); |
| 8145 | if (resize) { |
| 8146 | if (SHOW_TRANSACTIONS) Log.i( |
| 8147 | TAG, " SURFACE " + w.mSurface + ": (" |
| 8148 | + w.mShownFrame.left + "," |
| 8149 | + w.mShownFrame.top + ") (" |
| 8150 | + w.mShownFrame.width() + "x" |
| 8151 | + w.mShownFrame.height() + ")"); |
| 8152 | } |
| 8153 | } |
| 8154 | |
| 8155 | if (resize) { |
| 8156 | if (width < 1) width = 1; |
| 8157 | if (height < 1) height = 1; |
| 8158 | if (w.mSurface != null) { |
| 8159 | try { |
| 8160 | w.mSurface.setSize(width, height); |
| 8161 | w.mSurface.setPosition(w.mShownFrame.left, |
| 8162 | w.mShownFrame.top); |
| 8163 | } catch (RuntimeException e) { |
| 8164 | // If something goes wrong with the surface (such |
| 8165 | // as running out of memory), don't take down the |
| 8166 | // entire system. |
| 8167 | Log.e(TAG, "Failure updating surface of " + w |
| 8168 | + "size=(" + width + "x" + height |
| 8169 | + "), pos=(" + w.mShownFrame.left |
| 8170 | + "," + w.mShownFrame.top + ")", e); |
| 8171 | if (!recoveringMemory) { |
| 8172 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 8173 | } |
| 8174 | } |
| 8175 | } |
| 8176 | } |
| 8177 | if (!w.mAppFreezing) { |
| 8178 | w.mContentInsetsChanged = |
| 8179 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 8180 | w.mVisibleInsetsChanged = |
| 8181 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8182 | if (!w.mLastFrame.equals(w.mFrame) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8183 | || w.mContentInsetsChanged |
| 8184 | || w.mVisibleInsetsChanged) { |
| 8185 | w.mLastFrame.set(w.mFrame); |
| 8186 | w.mLastContentInsets.set(w.mContentInsets); |
| 8187 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
| 8188 | // If the orientation is changing, then we need to |
| 8189 | // hold off on unfreezing the display until this |
| 8190 | // window has been redrawn; to do that, we need |
| 8191 | // to go through the process of getting informed |
| 8192 | // by the application when it has finished drawing. |
| 8193 | if (w.mOrientationChanging) { |
| 8194 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 8195 | "Orientation start waiting for draw in " |
| 8196 | + w + ", surface " + w.mSurface); |
| 8197 | w.mDrawPending = true; |
| 8198 | w.mCommitDrawPending = false; |
| 8199 | w.mReadyToShow = false; |
| 8200 | if (w.mAppToken != null) { |
| 8201 | w.mAppToken.allDrawn = false; |
| 8202 | } |
| 8203 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8204 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8205 | "Resizing window " + w + " to " + w.mFrame); |
| 8206 | mResizingWindows.add(w); |
| 8207 | } else if (w.mOrientationChanging) { |
| 8208 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
| 8209 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 8210 | "Orientation not waiting for draw in " |
| 8211 | + w + ", surface " + w.mSurface); |
| 8212 | w.mOrientationChanging = false; |
| 8213 | } |
| 8214 | } |
| 8215 | } |
| 8216 | |
| 8217 | if (w.mAttachedHidden) { |
| 8218 | if (!w.mLastHidden) { |
| 8219 | //dump(); |
| 8220 | w.mLastHidden = true; |
| 8221 | if (SHOW_TRANSACTIONS) Log.i( |
| 8222 | TAG, " SURFACE " + w.mSurface + ": HIDE (performLayout-attached)"); |
| 8223 | if (w.mSurface != null) { |
| 8224 | try { |
| 8225 | w.mSurface.hide(); |
| 8226 | } catch (RuntimeException e) { |
| 8227 | Log.w(TAG, "Exception hiding surface in " + w); |
| 8228 | } |
| 8229 | } |
| 8230 | mKeyWaiter.releasePendingPointerLocked(w.mSession); |
| 8231 | } |
| 8232 | // If we are waiting for this window to handle an |
| 8233 | // orientation change, well, it is hidden, so |
| 8234 | // doesn't really matter. Note that this does |
| 8235 | // introduce a potential glitch if the window |
| 8236 | // becomes unhidden before it has drawn for the |
| 8237 | // new orientation. |
| 8238 | if (w.mOrientationChanging) { |
| 8239 | w.mOrientationChanging = false; |
| 8240 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 8241 | "Orientation change skips hidden " + w); |
| 8242 | } |
| 8243 | } else if (!w.isReadyForDisplay()) { |
| 8244 | if (!w.mLastHidden) { |
| 8245 | //dump(); |
| 8246 | w.mLastHidden = true; |
| 8247 | if (SHOW_TRANSACTIONS) Log.i( |
| 8248 | TAG, " SURFACE " + w.mSurface + ": HIDE (performLayout-ready)"); |
| 8249 | if (w.mSurface != null) { |
| 8250 | try { |
| 8251 | w.mSurface.hide(); |
| 8252 | } catch (RuntimeException e) { |
| 8253 | Log.w(TAG, "Exception exception hiding surface in " + w); |
| 8254 | } |
| 8255 | } |
| 8256 | mKeyWaiter.releasePendingPointerLocked(w.mSession); |
| 8257 | } |
| 8258 | // If we are waiting for this window to handle an |
| 8259 | // orientation change, well, it is hidden, so |
| 8260 | // doesn't really matter. Note that this does |
| 8261 | // introduce a potential glitch if the window |
| 8262 | // becomes unhidden before it has drawn for the |
| 8263 | // new orientation. |
| 8264 | if (w.mOrientationChanging) { |
| 8265 | w.mOrientationChanging = false; |
| 8266 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 8267 | "Orientation change skips hidden " + w); |
| 8268 | } |
| 8269 | } else if (w.mLastLayer != w.mAnimLayer |
| 8270 | || w.mLastAlpha != w.mShownAlpha |
| 8271 | || w.mLastDsDx != w.mDsDx |
| 8272 | || w.mLastDtDx != w.mDtDx |
| 8273 | || w.mLastDsDy != w.mDsDy |
| 8274 | || w.mLastDtDy != w.mDtDy |
| 8275 | || w.mLastHScale != w.mHScale |
| 8276 | || w.mLastVScale != w.mVScale |
| 8277 | || w.mLastHidden) { |
| 8278 | displayed = true; |
| 8279 | w.mLastAlpha = w.mShownAlpha; |
| 8280 | w.mLastLayer = w.mAnimLayer; |
| 8281 | w.mLastDsDx = w.mDsDx; |
| 8282 | w.mLastDtDx = w.mDtDx; |
| 8283 | w.mLastDsDy = w.mDsDy; |
| 8284 | w.mLastDtDy = w.mDtDy; |
| 8285 | w.mLastHScale = w.mHScale; |
| 8286 | w.mLastVScale = w.mVScale; |
| 8287 | if (SHOW_TRANSACTIONS) Log.i( |
| 8288 | TAG, " SURFACE " + w.mSurface + ": alpha=" |
| 8289 | + w.mShownAlpha + " layer=" + w.mAnimLayer); |
| 8290 | if (w.mSurface != null) { |
| 8291 | try { |
| 8292 | w.mSurface.setAlpha(w.mShownAlpha); |
| 8293 | w.mSurface.setLayer(w.mAnimLayer); |
| 8294 | w.mSurface.setMatrix( |
| 8295 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 8296 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 8297 | } catch (RuntimeException e) { |
| 8298 | Log.w(TAG, "Error updating surface in " + w, e); |
| 8299 | if (!recoveringMemory) { |
| 8300 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 8301 | } |
| 8302 | } |
| 8303 | } |
| 8304 | |
| 8305 | if (w.mLastHidden && !w.mDrawPending |
| 8306 | && !w.mCommitDrawPending |
| 8307 | && !w.mReadyToShow) { |
| 8308 | if (SHOW_TRANSACTIONS) Log.i( |
| 8309 | TAG, " SURFACE " + w.mSurface + ": SHOW (performLayout)"); |
| 8310 | if (DEBUG_VISIBILITY) Log.v(TAG, "Showing " + w |
| 8311 | + " during relayout"); |
| 8312 | if (showSurfaceRobustlyLocked(w)) { |
| 8313 | w.mHasDrawn = true; |
| 8314 | w.mLastHidden = false; |
| 8315 | } else { |
| 8316 | w.mOrientationChanging = false; |
| 8317 | } |
| 8318 | } |
| 8319 | if (w.mSurface != null) { |
| 8320 | w.mToken.hasVisible = true; |
| 8321 | } |
| 8322 | } else { |
| 8323 | displayed = true; |
| 8324 | } |
| 8325 | |
| 8326 | if (displayed) { |
| 8327 | if (!covered) { |
| 8328 | if (attrs.width == LayoutParams.FILL_PARENT |
| 8329 | && attrs.height == LayoutParams.FILL_PARENT) { |
| 8330 | covered = true; |
| 8331 | } |
| 8332 | } |
| 8333 | if (w.mOrientationChanging) { |
| 8334 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 8335 | orientationChangeComplete = false; |
| 8336 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 8337 | "Orientation continue waiting for draw in " + w); |
| 8338 | } else { |
| 8339 | w.mOrientationChanging = false; |
| 8340 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 8341 | "Orientation change complete in " + w); |
| 8342 | } |
| 8343 | } |
| 8344 | w.mToken.hasVisible = true; |
| 8345 | } |
| 8346 | } else if (w.mOrientationChanging) { |
| 8347 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 8348 | "Orientation change skips hidden " + w); |
| 8349 | w.mOrientationChanging = false; |
| 8350 | } |
| 8351 | |
| 8352 | final boolean canBeSeen = w.isDisplayedLw(); |
| 8353 | |
| 8354 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 8355 | focusDisplayed = true; |
| 8356 | } |
| 8357 | |
| 8358 | // Update effect. |
| 8359 | if (!obscured) { |
| 8360 | if (w.mSurface != null) { |
| 8361 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 8362 | holdScreen = w.mSession; |
| 8363 | } |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 8364 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 8365 | && screenBrightness < 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8366 | screenBrightness = w.mAttrs.screenBrightness; |
| 8367 | } |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 8368 | if (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 8369 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 8370 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR) { |
| 8371 | syswin = true; |
| 8372 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8373 | } |
| 8374 | if (w.isFullscreenOpaque(dw, dh)) { |
| 8375 | // This window completely covers everything behind it, |
| 8376 | // so we want to leave all of them as unblurred (for |
| 8377 | // performance reasons). |
| 8378 | obscured = true; |
| 8379 | } else if (canBeSeen && !obscured && |
| 8380 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
| 8381 | if (localLOGV) Log.v(TAG, "Win " + w |
| 8382 | + ": blurring=" + blurring |
| 8383 | + " obscured=" + obscured |
| 8384 | + " displayed=" + displayed); |
| 8385 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 8386 | if (!dimming) { |
| 8387 | //Log.i(TAG, "DIM BEHIND: " + w); |
| 8388 | dimming = true; |
| 8389 | mDimShown = true; |
| 8390 | if (mDimSurface == null) { |
| 8391 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 8392 | + mDimSurface + ": CREATE"); |
| 8393 | try { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8394 | mDimSurface = new Surface(mFxSession, 0, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8395 | -1, 16, 16, |
| 8396 | PixelFormat.OPAQUE, |
| 8397 | Surface.FX_SURFACE_DIM); |
| 8398 | } catch (Exception e) { |
| 8399 | Log.e(TAG, "Exception creating Dim surface", e); |
| 8400 | } |
| 8401 | } |
| 8402 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 8403 | + mDimSurface + ": SHOW pos=(0,0) (" + |
| 8404 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
| 8405 | if (mDimSurface != null) { |
| 8406 | try { |
| 8407 | mDimSurface.setPosition(0, 0); |
| 8408 | mDimSurface.setSize(dw, dh); |
| 8409 | mDimSurface.show(); |
| 8410 | } catch (RuntimeException e) { |
| 8411 | Log.w(TAG, "Failure showing dim surface", e); |
| 8412 | } |
| 8413 | } |
| 8414 | } |
| 8415 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 8416 | final float target = w.mExiting ? 0 : attrs.dimAmount; |
| 8417 | if (mDimTargetAlpha != target) { |
| 8418 | // If the desired dim level has changed, then |
| 8419 | // start an animation to it. |
| 8420 | mLastDimAnimTime = currentTime; |
| 8421 | long duration = (w.mAnimating && w.mAnimation != null) |
| 8422 | ? w.mAnimation.computeDurationHint() |
| 8423 | : DEFAULT_DIM_DURATION; |
| 8424 | if (target > mDimTargetAlpha) { |
| 8425 | // This is happening behind the activity UI, |
| 8426 | // so we can make it run a little longer to |
| 8427 | // give a stronger impression without disrupting |
| 8428 | // the user. |
| 8429 | duration *= DIM_DURATION_MULTIPLIER; |
| 8430 | } |
| 8431 | if (duration < 1) { |
| 8432 | // Don't divide by zero |
| 8433 | duration = 1; |
| 8434 | } |
| 8435 | mDimTargetAlpha = target; |
| 8436 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) |
| 8437 | / duration; |
| 8438 | } |
| 8439 | } |
| 8440 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 8441 | if (!blurring) { |
| 8442 | //Log.i(TAG, "BLUR BEHIND: " + w); |
| 8443 | blurring = true; |
| 8444 | mBlurShown = true; |
| 8445 | if (mBlurSurface == null) { |
| 8446 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " |
| 8447 | + mBlurSurface + ": CREATE"); |
| 8448 | try { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8449 | mBlurSurface = new Surface(mFxSession, 0, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8450 | -1, 16, 16, |
| 8451 | PixelFormat.OPAQUE, |
| 8452 | Surface.FX_SURFACE_BLUR); |
| 8453 | } catch (Exception e) { |
| 8454 | Log.e(TAG, "Exception creating Blur surface", e); |
| 8455 | } |
| 8456 | } |
| 8457 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " |
| 8458 | + mBlurSurface + ": SHOW pos=(0,0) (" + |
| 8459 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
| 8460 | if (mBlurSurface != null) { |
| 8461 | mBlurSurface.setPosition(0, 0); |
| 8462 | mBlurSurface.setSize(dw, dh); |
| 8463 | try { |
| 8464 | mBlurSurface.show(); |
| 8465 | } catch (RuntimeException e) { |
| 8466 | Log.w(TAG, "Failure showing blur surface", e); |
| 8467 | } |
| 8468 | } |
| 8469 | } |
| 8470 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 8471 | } |
| 8472 | } |
| 8473 | } |
| 8474 | } |
| 8475 | |
| 8476 | if (!dimming && mDimShown) { |
| 8477 | // Time to hide the dim surface... start fading. |
| 8478 | if (mDimTargetAlpha != 0) { |
| 8479 | mLastDimAnimTime = currentTime; |
| 8480 | mDimTargetAlpha = 0; |
| 8481 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 8482 | } |
| 8483 | } |
| 8484 | |
| 8485 | if (mDimShown && mLastDimAnimTime != 0) { |
| 8486 | mDimCurrentAlpha += mDimDeltaPerMs |
| 8487 | * (currentTime-mLastDimAnimTime); |
| 8488 | boolean more = true; |
| 8489 | if (mDisplayFrozen) { |
| 8490 | // If the display is frozen, there is no reason to animate. |
| 8491 | more = false; |
| 8492 | } else if (mDimDeltaPerMs > 0) { |
| 8493 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 8494 | more = false; |
| 8495 | } |
| 8496 | } else if (mDimDeltaPerMs < 0) { |
| 8497 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 8498 | more = false; |
| 8499 | } |
| 8500 | } else { |
| 8501 | more = false; |
| 8502 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8503 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8504 | // Do we need to continue animating? |
| 8505 | if (more) { |
| 8506 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 8507 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 8508 | mLastDimAnimTime = currentTime; |
| 8509 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 8510 | animating = true; |
| 8511 | } else { |
| 8512 | mDimCurrentAlpha = mDimTargetAlpha; |
| 8513 | mLastDimAnimTime = 0; |
| 8514 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 8515 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 8516 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 8517 | if (!dimming) { |
| 8518 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface |
| 8519 | + ": HIDE"); |
| 8520 | try { |
| 8521 | mDimSurface.hide(); |
| 8522 | } catch (RuntimeException e) { |
| 8523 | Log.w(TAG, "Illegal argument exception hiding dim surface"); |
| 8524 | } |
| 8525 | mDimShown = false; |
| 8526 | } |
| 8527 | } |
| 8528 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8529 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8530 | if (!blurring && mBlurShown) { |
| 8531 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " + mBlurSurface |
| 8532 | + ": HIDE"); |
| 8533 | try { |
| 8534 | mBlurSurface.hide(); |
| 8535 | } catch (IllegalArgumentException e) { |
| 8536 | Log.w(TAG, "Illegal argument exception hiding blur surface"); |
| 8537 | } |
| 8538 | mBlurShown = false; |
| 8539 | } |
| 8540 | |
| 8541 | if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION"); |
| 8542 | } catch (RuntimeException e) { |
| 8543 | Log.e(TAG, "Unhandled exception in Window Manager", e); |
| 8544 | } |
| 8545 | |
| 8546 | Surface.closeTransaction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8547 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8548 | if (DEBUG_ORIENTATION && mDisplayFrozen) Log.v(TAG, |
| 8549 | "With display frozen, orientationChangeComplete=" |
| 8550 | + orientationChangeComplete); |
| 8551 | if (orientationChangeComplete) { |
| 8552 | if (mWindowsFreezingScreen) { |
| 8553 | mWindowsFreezingScreen = false; |
| 8554 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 8555 | } |
| 8556 | if (mAppsFreezingScreen == 0) { |
| 8557 | stopFreezingDisplayLocked(); |
| 8558 | } |
| 8559 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8560 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8561 | i = mResizingWindows.size(); |
| 8562 | if (i > 0) { |
| 8563 | do { |
| 8564 | i--; |
| 8565 | WindowState win = mResizingWindows.get(i); |
| 8566 | try { |
| 8567 | win.mClient.resized(win.mFrame.width(), |
| 8568 | win.mFrame.height(), win.mLastContentInsets, |
| 8569 | win.mLastVisibleInsets, win.mDrawPending); |
| 8570 | win.mContentInsetsChanged = false; |
| 8571 | win.mVisibleInsetsChanged = false; |
| 8572 | } catch (RemoteException e) { |
| 8573 | win.mOrientationChanging = false; |
| 8574 | } |
| 8575 | } while (i > 0); |
| 8576 | mResizingWindows.clear(); |
| 8577 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8578 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8579 | // Destroy the surface of any windows that are no longer visible. |
| 8580 | i = mDestroySurface.size(); |
| 8581 | if (i > 0) { |
| 8582 | do { |
| 8583 | i--; |
| 8584 | WindowState win = mDestroySurface.get(i); |
| 8585 | win.mDestroying = false; |
| 8586 | if (mInputMethodWindow == win) { |
| 8587 | mInputMethodWindow = null; |
| 8588 | } |
| 8589 | win.destroySurfaceLocked(); |
| 8590 | } while (i > 0); |
| 8591 | mDestroySurface.clear(); |
| 8592 | } |
| 8593 | |
| 8594 | // Time to remove any exiting tokens? |
| 8595 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 8596 | WindowToken token = mExitingTokens.get(i); |
| 8597 | if (!token.hasVisible) { |
| 8598 | mExitingTokens.remove(i); |
| 8599 | } |
| 8600 | } |
| 8601 | |
| 8602 | // Time to remove any exiting applications? |
| 8603 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 8604 | AppWindowToken token = mExitingAppTokens.get(i); |
| 8605 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
| 8606 | mAppTokens.remove(token); |
| 8607 | mExitingAppTokens.remove(i); |
| 8608 | } |
| 8609 | } |
| 8610 | |
| 8611 | if (focusDisplayed) { |
| 8612 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 8613 | } |
| 8614 | if (animating) { |
| 8615 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 8616 | } |
| 8617 | mQueue.setHoldScreenLocked(holdScreen != null); |
| 8618 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 8619 | mPowerManager.setScreenBrightnessOverride(-1); |
| 8620 | } else { |
| 8621 | mPowerManager.setScreenBrightnessOverride((int) |
| 8622 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 8623 | } |
| 8624 | if (holdScreen != mHoldingScreenOn) { |
| 8625 | mHoldingScreenOn = holdScreen; |
| 8626 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 8627 | mH.sendMessage(m); |
| 8628 | } |
| 8629 | } |
| 8630 | |
| 8631 | void requestAnimationLocked(long delay) { |
| 8632 | if (!mAnimationPending) { |
| 8633 | mAnimationPending = true; |
| 8634 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 8635 | } |
| 8636 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8637 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8638 | /** |
| 8639 | * Have the surface flinger show a surface, robustly dealing with |
| 8640 | * error conditions. In particular, if there is not enough memory |
| 8641 | * to show the surface, then we will try to get rid of other surfaces |
| 8642 | * in order to succeed. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8643 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8644 | * @return Returns true if the surface was successfully shown. |
| 8645 | */ |
| 8646 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 8647 | try { |
| 8648 | if (win.mSurface != null) { |
| 8649 | win.mSurface.show(); |
| 8650 | } |
| 8651 | return true; |
| 8652 | } catch (RuntimeException e) { |
| 8653 | Log.w(TAG, "Failure showing surface " + win.mSurface + " in " + win); |
| 8654 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8655 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8656 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8657 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8658 | return false; |
| 8659 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8660 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8661 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 8662 | final Surface surface = win.mSurface; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8663 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8664 | EventLog.writeEvent(LOG_WM_NO_SURFACE_MEMORY, win.toString(), |
| 8665 | win.mSession.mPid, operation); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8666 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8667 | if (mForceRemoves == null) { |
| 8668 | mForceRemoves = new ArrayList<WindowState>(); |
| 8669 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8670 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8671 | long callingIdentity = Binder.clearCallingIdentity(); |
| 8672 | try { |
| 8673 | // There was some problem... first, do a sanity check of the |
| 8674 | // window list to make sure we haven't left any dangling surfaces |
| 8675 | // around. |
| 8676 | int N = mWindows.size(); |
| 8677 | boolean leakedSurface = false; |
| 8678 | Log.i(TAG, "Out of memory for surface! Looking for leaks..."); |
| 8679 | for (int i=0; i<N; i++) { |
| 8680 | WindowState ws = (WindowState)mWindows.get(i); |
| 8681 | if (ws.mSurface != null) { |
| 8682 | if (!mSessions.contains(ws.mSession)) { |
| 8683 | Log.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
| 8684 | + ws + " surface=" + ws.mSurface |
| 8685 | + " token=" + win.mToken |
| 8686 | + " pid=" + ws.mSession.mPid |
| 8687 | + " uid=" + ws.mSession.mUid); |
| 8688 | ws.mSurface.clear(); |
| 8689 | ws.mSurface = null; |
| 8690 | mForceRemoves.add(ws); |
| 8691 | i--; |
| 8692 | N--; |
| 8693 | leakedSurface = true; |
| 8694 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
| 8695 | Log.w(TAG, "LEAKED SURFACE (app token hidden): " |
| 8696 | + ws + " surface=" + ws.mSurface |
| 8697 | + " token=" + win.mAppToken); |
| 8698 | ws.mSurface.clear(); |
| 8699 | ws.mSurface = null; |
| 8700 | leakedSurface = true; |
| 8701 | } |
| 8702 | } |
| 8703 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8704 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8705 | boolean killedApps = false; |
| 8706 | if (!leakedSurface) { |
| 8707 | Log.w(TAG, "No leaked surfaces; killing applicatons!"); |
| 8708 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 8709 | for (int i=0; i<N; i++) { |
| 8710 | WindowState ws = (WindowState)mWindows.get(i); |
| 8711 | if (ws.mSurface != null) { |
| 8712 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 8713 | } |
| 8714 | } |
| 8715 | if (pidCandidates.size() > 0) { |
| 8716 | int[] pids = new int[pidCandidates.size()]; |
| 8717 | for (int i=0; i<pids.length; i++) { |
| 8718 | pids[i] = pidCandidates.keyAt(i); |
| 8719 | } |
| 8720 | try { |
| 8721 | if (mActivityManager.killPidsForMemory(pids)) { |
| 8722 | killedApps = true; |
| 8723 | } |
| 8724 | } catch (RemoteException e) { |
| 8725 | } |
| 8726 | } |
| 8727 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8728 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8729 | if (leakedSurface || killedApps) { |
| 8730 | // We managed to reclaim some memory, so get rid of the trouble |
| 8731 | // surface and ask the app to request another one. |
| 8732 | Log.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry."); |
| 8733 | if (surface != null) { |
| 8734 | surface.clear(); |
| 8735 | win.mSurface = null; |
| 8736 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8737 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8738 | try { |
| 8739 | win.mClient.dispatchGetNewSurface(); |
| 8740 | } catch (RemoteException e) { |
| 8741 | } |
| 8742 | } |
| 8743 | } finally { |
| 8744 | Binder.restoreCallingIdentity(callingIdentity); |
| 8745 | } |
| 8746 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8747 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8748 | private boolean updateFocusedWindowLocked(int mode) { |
| 8749 | WindowState newFocus = computeFocusedWindowLocked(); |
| 8750 | if (mCurrentFocus != newFocus) { |
| 8751 | // This check makes sure that we don't already have the focus |
| 8752 | // change message pending. |
| 8753 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 8754 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
| 8755 | if (localLOGV) Log.v( |
| 8756 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 8757 | final WindowState oldFocus = mCurrentFocus; |
| 8758 | mCurrentFocus = newFocus; |
| 8759 | mLosingFocus.remove(newFocus); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8760 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8761 | final WindowState imWindow = mInputMethodWindow; |
| 8762 | if (newFocus != imWindow && oldFocus != imWindow) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 8763 | if (moveInputMethodWindowsIfNeededLocked( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8764 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 8765 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 8766 | mLayoutNeeded = true; |
| 8767 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8768 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 8769 | performLayoutLockedInner(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 8770 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 8771 | // Client will do the layout, but we need to assign layers |
| 8772 | // for handleNewWindowLocked() below. |
| 8773 | assignLayersLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8774 | } |
| 8775 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8776 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 8777 | if (newFocus != null && mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 8778 | mKeyWaiter.handleNewWindowLocked(newFocus); |
| 8779 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8780 | return true; |
| 8781 | } |
| 8782 | return false; |
| 8783 | } |
| 8784 | |
| 8785 | private WindowState computeFocusedWindowLocked() { |
| 8786 | WindowState result = null; |
| 8787 | WindowState win; |
| 8788 | |
| 8789 | int i = mWindows.size() - 1; |
| 8790 | int nextAppIndex = mAppTokens.size()-1; |
| 8791 | WindowToken nextApp = nextAppIndex >= 0 |
| 8792 | ? mAppTokens.get(nextAppIndex) : null; |
| 8793 | |
| 8794 | while (i >= 0) { |
| 8795 | win = (WindowState)mWindows.get(i); |
| 8796 | |
| 8797 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 8798 | TAG, "Looking for focus: " + i |
| 8799 | + " = " + win |
| 8800 | + ", flags=" + win.mAttrs.flags |
| 8801 | + ", canReceive=" + win.canReceiveKeys()); |
| 8802 | |
| 8803 | AppWindowToken thisApp = win.mAppToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8804 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8805 | // If this window's application has been removed, just skip it. |
| 8806 | if (thisApp != null && thisApp.removed) { |
| 8807 | i--; |
| 8808 | continue; |
| 8809 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8810 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8811 | // If there is a focused app, don't allow focus to go to any |
| 8812 | // windows below it. If this is an application window, step |
| 8813 | // through the app tokens until we find its app. |
| 8814 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 8815 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 8816 | int origAppIndex = nextAppIndex; |
| 8817 | while (nextAppIndex > 0) { |
| 8818 | if (nextApp == mFocusedApp) { |
| 8819 | // Whoops, we are below the focused app... no focus |
| 8820 | // for you! |
| 8821 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 8822 | TAG, "Reached focused app: " + mFocusedApp); |
| 8823 | return null; |
| 8824 | } |
| 8825 | nextAppIndex--; |
| 8826 | nextApp = mAppTokens.get(nextAppIndex); |
| 8827 | if (nextApp == thisApp) { |
| 8828 | break; |
| 8829 | } |
| 8830 | } |
| 8831 | if (thisApp != nextApp) { |
| 8832 | // Uh oh, the app token doesn't exist! This shouldn't |
| 8833 | // happen, but if it does we can get totally hosed... |
| 8834 | // so restart at the original app. |
| 8835 | nextAppIndex = origAppIndex; |
| 8836 | nextApp = mAppTokens.get(nextAppIndex); |
| 8837 | } |
| 8838 | } |
| 8839 | |
| 8840 | // Dispatch to this window if it is wants key events. |
| 8841 | if (win.canReceiveKeys()) { |
| 8842 | if (DEBUG_FOCUS) Log.v( |
| 8843 | TAG, "Found focus @ " + i + " = " + win); |
| 8844 | result = win; |
| 8845 | break; |
| 8846 | } |
| 8847 | |
| 8848 | i--; |
| 8849 | } |
| 8850 | |
| 8851 | return result; |
| 8852 | } |
| 8853 | |
| 8854 | private void startFreezingDisplayLocked() { |
| 8855 | if (mDisplayFrozen) { |
| Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 8856 | // Freezing the display also suspends key event delivery, to |
| 8857 | // keep events from going astray while the display is reconfigured. |
| 8858 | // If someone has changed orientation again while the screen is |
| 8859 | // still frozen, the events will continue to be blocked while the |
| 8860 | // successive orientation change is processed. To prevent spurious |
| 8861 | // ANRs, we reset the event dispatch timeout in this case. |
| 8862 | synchronized (mKeyWaiter) { |
| 8863 | mKeyWaiter.mWasFrozen = true; |
| 8864 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8865 | return; |
| 8866 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8867 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8868 | mScreenFrozenLock.acquire(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8869 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8870 | long now = SystemClock.uptimeMillis(); |
| 8871 | //Log.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
| 8872 | if (mFreezeGcPending != 0) { |
| 8873 | if (now > (mFreezeGcPending+1000)) { |
| 8874 | //Log.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| 8875 | mH.removeMessages(H.FORCE_GC); |
| 8876 | Runtime.getRuntime().gc(); |
| 8877 | mFreezeGcPending = now; |
| 8878 | } |
| 8879 | } else { |
| 8880 | mFreezeGcPending = now; |
| 8881 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8882 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8883 | mDisplayFrozen = true; |
| 8884 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) { |
| 8885 | mNextAppTransition = WindowManagerPolicy.TRANSIT_NONE; |
| 8886 | mAppTransitionReady = true; |
| 8887 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8888 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8889 | if (PROFILE_ORIENTATION) { |
| 8890 | File file = new File("/data/system/frozen"); |
| 8891 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 8892 | } |
| 8893 | Surface.freezeDisplay(0); |
| 8894 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8895 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8896 | private void stopFreezingDisplayLocked() { |
| 8897 | if (!mDisplayFrozen) { |
| 8898 | return; |
| 8899 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8900 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8901 | mDisplayFrozen = false; |
| 8902 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 8903 | if (PROFILE_ORIENTATION) { |
| 8904 | Debug.stopMethodTracing(); |
| 8905 | } |
| 8906 | Surface.unfreezeDisplay(0); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8907 | |
| Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 8908 | // Reset the key delivery timeout on unfreeze, too. We force a wakeup here |
| 8909 | // too because regular key delivery processing should resume immediately. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8910 | synchronized (mKeyWaiter) { |
| 8911 | mKeyWaiter.mWasFrozen = true; |
| 8912 | mKeyWaiter.notifyAll(); |
| 8913 | } |
| 8914 | |
| 8915 | // A little kludge: a lot could have happened while the |
| 8916 | // display was frozen, so now that we are coming back we |
| 8917 | // do a gc so that any remote references the system |
| 8918 | // processes holds on others can be released if they are |
| 8919 | // no longer needed. |
| 8920 | mH.removeMessages(H.FORCE_GC); |
| 8921 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 8922 | 2000); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8923 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8924 | mScreenFrozenLock.release(); |
| 8925 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8926 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8927 | @Override |
| 8928 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 8929 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 8930 | != PackageManager.PERMISSION_GRANTED) { |
| 8931 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 8932 | + Binder.getCallingPid() |
| 8933 | + ", uid=" + Binder.getCallingUid()); |
| 8934 | return; |
| 8935 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8936 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8937 | synchronized(mWindowMap) { |
| 8938 | pw.println("Current Window Manager state:"); |
| 8939 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 8940 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8941 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 8942 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8943 | w.dump(pw, " "); |
| 8944 | } |
| 8945 | if (mInputMethodDialogs.size() > 0) { |
| 8946 | pw.println(" "); |
| 8947 | pw.println(" Input method dialogs:"); |
| 8948 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 8949 | WindowState w = mInputMethodDialogs.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8950 | 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] | 8951 | } |
| 8952 | } |
| 8953 | if (mPendingRemove.size() > 0) { |
| 8954 | pw.println(" "); |
| 8955 | pw.println(" Remove pending for:"); |
| 8956 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 8957 | WindowState w = mPendingRemove.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8958 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 8959 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8960 | w.dump(pw, " "); |
| 8961 | } |
| 8962 | } |
| 8963 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 8964 | pw.println(" "); |
| 8965 | pw.println(" Windows force removing:"); |
| 8966 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 8967 | WindowState w = mForceRemoves.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8968 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 8969 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8970 | w.dump(pw, " "); |
| 8971 | } |
| 8972 | } |
| 8973 | if (mDestroySurface.size() > 0) { |
| 8974 | pw.println(" "); |
| 8975 | pw.println(" Windows waiting to destroy their surface:"); |
| 8976 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 8977 | WindowState w = mDestroySurface.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8978 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 8979 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8980 | w.dump(pw, " "); |
| 8981 | } |
| 8982 | } |
| 8983 | if (mLosingFocus.size() > 0) { |
| 8984 | pw.println(" "); |
| 8985 | pw.println(" Windows losing focus:"); |
| 8986 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 8987 | WindowState w = mLosingFocus.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8988 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 8989 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8990 | w.dump(pw, " "); |
| 8991 | } |
| 8992 | } |
| 8993 | if (mSessions.size() > 0) { |
| 8994 | pw.println(" "); |
| 8995 | pw.println(" All active sessions:"); |
| 8996 | Iterator<Session> it = mSessions.iterator(); |
| 8997 | while (it.hasNext()) { |
| 8998 | Session s = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8999 | pw.print(" Session "); pw.print(s); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9000 | s.dump(pw, " "); |
| 9001 | } |
| 9002 | } |
| 9003 | if (mTokenMap.size() > 0) { |
| 9004 | pw.println(" "); |
| 9005 | pw.println(" All tokens:"); |
| 9006 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 9007 | while (it.hasNext()) { |
| 9008 | WindowToken token = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9009 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9010 | token.dump(pw, " "); |
| 9011 | } |
| 9012 | } |
| 9013 | if (mTokenList.size() > 0) { |
| 9014 | pw.println(" "); |
| 9015 | pw.println(" Window token list:"); |
| 9016 | for (int i=0; i<mTokenList.size(); i++) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9017 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 9018 | pw.println(mTokenList.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9019 | } |
| 9020 | } |
| 9021 | if (mAppTokens.size() > 0) { |
| 9022 | pw.println(" "); |
| 9023 | pw.println(" Application tokens in Z order:"); |
| 9024 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9025 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 9026 | pw.println(mAppTokens.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9027 | } |
| 9028 | } |
| 9029 | if (mFinishedStarting.size() > 0) { |
| 9030 | pw.println(" "); |
| 9031 | pw.println(" Finishing start of application tokens:"); |
| 9032 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 9033 | WindowToken token = mFinishedStarting.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9034 | pw.print(" Finished Starting #"); pw.print(i); |
| 9035 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9036 | token.dump(pw, " "); |
| 9037 | } |
| 9038 | } |
| 9039 | if (mExitingTokens.size() > 0) { |
| 9040 | pw.println(" "); |
| 9041 | pw.println(" Exiting tokens:"); |
| 9042 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 9043 | WindowToken token = mExitingTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9044 | pw.print(" Exiting #"); pw.print(i); |
| 9045 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9046 | token.dump(pw, " "); |
| 9047 | } |
| 9048 | } |
| 9049 | if (mExitingAppTokens.size() > 0) { |
| 9050 | pw.println(" "); |
| 9051 | pw.println(" Exiting application tokens:"); |
| 9052 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9053 | WindowToken token = mExitingAppTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9054 | pw.print(" Exiting App #"); pw.print(i); |
| 9055 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9056 | token.dump(pw, " "); |
| 9057 | } |
| 9058 | } |
| 9059 | pw.println(" "); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9060 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 9061 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 9062 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 9063 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 9064 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
| 9065 | pw.print(" mInTouchMode="); pw.println(mInTouchMode); |
| 9066 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 9067 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 9068 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 9069 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
| 9070 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 9071 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 9072 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 9073 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 9074 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 9075 | pw.print(" mInputMethodAnimLayerAdjustment="); |
| 9076 | pw.println(mInputMethodAnimLayerAdjustment); |
| 9077 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 9078 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
| 9079 | pw.print(" mAppsFreezingScreen="); pw.println(mAppsFreezingScreen); |
| 9080 | pw.print(" mRotation="); pw.print(mRotation); |
| 9081 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 9082 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 9083 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 9084 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 9085 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 9086 | pw.print(" mNextAppTransition=0x"); |
| 9087 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 9088 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
| 9089 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
| 9090 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 9091 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| 9092 | if (mOpeningApps.size() > 0) { |
| 9093 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 9094 | } |
| 9095 | if (mClosingApps.size() > 0) { |
| 9096 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 9097 | } |
| 9098 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 9099 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9100 | pw.println(" KeyWaiter state:"); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9101 | pw.print(" mLastWin="); pw.print(mKeyWaiter.mLastWin); |
| 9102 | pw.print(" mLastBinder="); pw.println(mKeyWaiter.mLastBinder); |
| 9103 | pw.print(" mFinished="); pw.print(mKeyWaiter.mFinished); |
| 9104 | pw.print(" mGotFirstWindow="); pw.print(mKeyWaiter.mGotFirstWindow); |
| 9105 | pw.print(" mEventDispatching="); pw.print(mKeyWaiter.mEventDispatching); |
| 9106 | pw.print(" mTimeToSwitch="); pw.println(mKeyWaiter.mTimeToSwitch); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9107 | } |
| 9108 | } |
| 9109 | |
| 9110 | public void monitor() { |
| 9111 | synchronized (mWindowMap) { } |
| 9112 | synchronized (mKeyguardDisabled) { } |
| 9113 | synchronized (mKeyWaiter) { } |
| 9114 | } |
| 9115 | } |