The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server; |
| 18 | |
| 19 | import static android.os.LocalPowerManager.CHEEK_EVENT; |
| 20 | import static android.os.LocalPowerManager.OTHER_EVENT; |
| 21 | import static android.os.LocalPowerManager.TOUCH_EVENT; |
Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 22 | import static android.os.LocalPowerManager.LONG_TOUCH_EVENT; |
| 23 | import static android.os.LocalPowerManager.TOUCH_UP_EVENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
| 25 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
| 26 | import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 27 | import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND; |
| 29 | import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 30 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR; |
| 32 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 33 | import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 34 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 36 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS; |
| 38 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 39 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 40 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 41 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 42 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | |
| 44 | import com.android.internal.app.IBatteryStats; |
| 45 | import com.android.internal.policy.PolicyManager; |
| 46 | import com.android.internal.view.IInputContext; |
| 47 | import com.android.internal.view.IInputMethodClient; |
| 48 | import com.android.internal.view.IInputMethodManager; |
| 49 | import com.android.server.KeyInputQueue.QueuedEvent; |
| 50 | import com.android.server.am.BatteryStatsService; |
| 51 | |
| 52 | import android.Manifest; |
| 53 | import android.app.ActivityManagerNative; |
| 54 | import android.app.IActivityManager; |
| 55 | import android.content.Context; |
| 56 | import android.content.pm.ActivityInfo; |
| 57 | import android.content.pm.PackageManager; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 58 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import android.content.res.Configuration; |
| 60 | import android.graphics.Matrix; |
| 61 | import android.graphics.PixelFormat; |
| 62 | import android.graphics.Rect; |
| 63 | import android.graphics.Region; |
| 64 | import android.os.BatteryStats; |
| 65 | import android.os.Binder; |
| 66 | import android.os.Debug; |
| 67 | import android.os.Handler; |
| 68 | import android.os.IBinder; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 69 | import android.os.LatencyTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | import android.os.LocalPowerManager; |
| 71 | import android.os.Looper; |
| 72 | import android.os.Message; |
| 73 | import android.os.Parcel; |
| 74 | import android.os.ParcelFileDescriptor; |
| 75 | import android.os.Power; |
| 76 | import android.os.PowerManager; |
| 77 | import android.os.Process; |
| 78 | import android.os.RemoteException; |
| 79 | import android.os.ServiceManager; |
| 80 | import android.os.SystemClock; |
| 81 | import android.os.SystemProperties; |
| 82 | import android.os.TokenWatcher; |
| 83 | import android.provider.Settings; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 84 | import android.util.DisplayMetrics; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | import android.util.EventLog; |
| 86 | import android.util.Log; |
| 87 | import android.util.SparseIntArray; |
| 88 | import android.view.Display; |
| 89 | import android.view.Gravity; |
| 90 | import android.view.IApplicationToken; |
| 91 | import android.view.IOnKeyguardExitResult; |
| 92 | import android.view.IRotationWatcher; |
| 93 | import android.view.IWindow; |
| 94 | import android.view.IWindowManager; |
| 95 | import android.view.IWindowSession; |
| 96 | import android.view.KeyEvent; |
| 97 | import android.view.MotionEvent; |
| 98 | import android.view.RawInputEvent; |
| 99 | import android.view.Surface; |
| 100 | import android.view.SurfaceSession; |
| 101 | import android.view.View; |
| 102 | import android.view.ViewTreeObserver; |
| 103 | import android.view.WindowManager; |
| 104 | import android.view.WindowManagerImpl; |
| 105 | import android.view.WindowManagerPolicy; |
| 106 | import android.view.WindowManager.LayoutParams; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 107 | import android.view.animation.AccelerateInterpolator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | import android.view.animation.Animation; |
| 109 | import android.view.animation.AnimationUtils; |
| 110 | import android.view.animation.Transformation; |
| 111 | |
| 112 | import java.io.BufferedWriter; |
| 113 | import java.io.File; |
| 114 | import java.io.FileDescriptor; |
| 115 | import java.io.IOException; |
| 116 | import java.io.OutputStream; |
| 117 | import java.io.OutputStreamWriter; |
| 118 | import java.io.PrintWriter; |
| 119 | import java.io.StringWriter; |
| 120 | import java.net.Socket; |
| 121 | import java.util.ArrayList; |
| 122 | import java.util.HashMap; |
| 123 | import java.util.HashSet; |
| 124 | import java.util.Iterator; |
| 125 | import java.util.List; |
| 126 | |
| 127 | /** {@hide} */ |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 128 | public class WindowManagerService extends IWindowManager.Stub |
| 129 | implements Watchdog.Monitor, KeyInputQueue.HapticFeedbackCallback { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | static final String TAG = "WindowManager"; |
| 131 | static final boolean DEBUG = false; |
| 132 | static final boolean DEBUG_FOCUS = false; |
| 133 | static final boolean DEBUG_ANIM = false; |
| 134 | static final boolean DEBUG_LAYERS = false; |
| 135 | static final boolean DEBUG_INPUT = false; |
| 136 | static final boolean DEBUG_INPUT_METHOD = false; |
| 137 | static final boolean DEBUG_VISIBILITY = false; |
| 138 | static final boolean DEBUG_ORIENTATION = false; |
| 139 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 140 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 141 | static final boolean DEBUG_REORDER = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 142 | static final boolean DEBUG_WALLPAPER = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | static final boolean SHOW_TRANSACTIONS = false; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 144 | static final boolean MEASURE_LATENCY = false; |
| 145 | static private LatencyTimer lt; |
| 146 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | static final boolean PROFILE_ORIENTATION = false; |
| 148 | static final boolean BLUR = true; |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 149 | static final boolean localLOGV = DEBUG; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 150 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | static final int LOG_WM_NO_SURFACE_MEMORY = 31000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 152 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | /** How long to wait for first key repeat, in milliseconds */ |
| 154 | static final int KEY_REPEAT_FIRST_DELAY = 750; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 155 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | /** How long to wait for subsequent key repeats, in milliseconds */ |
| 157 | static final int KEY_REPEAT_DELAY = 50; |
| 158 | |
| 159 | /** How much to multiply the policy's type layer, to reserve room |
| 160 | * for multiple windows of the same type and Z-ordering adjustment |
| 161 | * with TYPE_LAYER_OFFSET. */ |
| 162 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
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 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 165 | * or below others in the same layer. */ |
| 166 | static final int TYPE_LAYER_OFFSET = 1000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 167 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | /** How much to increment the layer for each window, to reserve room |
| 169 | * for effect surfaces between them. |
| 170 | */ |
| 171 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 172 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | /** The maximum length we will accept for a loaded animation duration: |
| 174 | * this is 10 seconds. |
| 175 | */ |
| 176 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 177 | |
| 178 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 179 | * value to another, when no window animation is driving it. |
| 180 | */ |
| 181 | static final int DEFAULT_DIM_DURATION = 200; |
| 182 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 183 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 184 | * compatible windows. |
| 185 | */ |
| 186 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 187 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | /** Adjustment to time to perform a dim, to make it more dramatic. |
| 189 | */ |
| 190 | static final int DIM_DURATION_MULTIPLIER = 6; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 191 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 192 | static final int INJECT_FAILED = 0; |
| 193 | static final int INJECT_SUCCEEDED = 1; |
| 194 | static final int INJECT_NO_PERMISSION = -1; |
| 195 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 197 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 198 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 199 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 200 | |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 201 | /** The minimum time between dispatching touch events. */ |
| 202 | int mMinWaitTimeBetweenTouchEvents = 1000 / 35; |
| 203 | |
| 204 | // Last touch event time |
| 205 | long mLastTouchEventTime = 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 206 | |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 207 | // Last touch event type |
| 208 | int mLastTouchEventType = OTHER_EVENT; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 209 | |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 210 | // Time to wait before calling useractivity again. This saves CPU usage |
| 211 | // when we get a flood of touch events. |
| 212 | static final int MIN_TIME_BETWEEN_USERACTIVITIES = 1000; |
| 213 | |
| 214 | // Last time we call user activity |
| 215 | long mLastUserActivityCallTime = 0; |
| 216 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 217 | // Last time we updated battery stats |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 218 | long mLastBatteryStatsCallTime = 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 219 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 220 | private static final String SYSTEM_SECURE = "ro.secure"; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 221 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | |
| 223 | /** |
| 224 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 225 | * the window policy has finished. |
| 226 | */ |
| 227 | private boolean mWaitingUntilKeyguardReenabled = false; |
| 228 | |
| 229 | |
| 230 | final TokenWatcher mKeyguardDisabled = new TokenWatcher( |
| 231 | new Handler(), "WindowManagerService.mKeyguardDisabled") { |
| 232 | public void acquired() { |
| 233 | mPolicy.enableKeyguard(false); |
| 234 | } |
| 235 | public void released() { |
| 236 | synchronized (mKeyguardDisabled) { |
| 237 | mPolicy.enableKeyguard(true); |
| 238 | mWaitingUntilKeyguardReenabled = false; |
| 239 | mKeyguardDisabled.notifyAll(); |
| 240 | } |
| 241 | } |
| 242 | }; |
| 243 | |
| 244 | final Context mContext; |
| 245 | |
| 246 | final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 247 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | final boolean mLimitedAlphaCompositing; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 249 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 251 | |
| 252 | final IActivityManager mActivityManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 253 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | final IBatteryStats mBatteryStats; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 255 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 256 | /** |
| 257 | * All currently active sessions with clients. |
| 258 | */ |
| 259 | final HashSet<Session> mSessions = new HashSet<Session>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 260 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | /** |
| 262 | * Mapping from an IWindow IBinder to the server's Window object. |
| 263 | * This is also used as the lock for all of our state. |
| 264 | */ |
| 265 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 266 | |
| 267 | /** |
| 268 | * Mapping from a token IBinder to a WindowToken object. |
| 269 | */ |
| 270 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 271 | new HashMap<IBinder, WindowToken>(); |
| 272 | |
| 273 | /** |
| 274 | * The same tokens as mTokenMap, stored in a list for efficient iteration |
| 275 | * over them. |
| 276 | */ |
| 277 | final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 278 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 279 | /** |
| 280 | * Window tokens that are in the process of exiting, but still |
| 281 | * on screen for animations. |
| 282 | */ |
| 283 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 284 | |
| 285 | /** |
| 286 | * Z-ordered (bottom-most first) list of all application tokens, for |
| 287 | * controlling the ordering of windows in different applications. This |
| 288 | * contains WindowToken objects. |
| 289 | */ |
| 290 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 291 | |
| 292 | /** |
| 293 | * Application tokens that are in the process of exiting, but still |
| 294 | * on screen for animations. |
| 295 | */ |
| 296 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 297 | |
| 298 | /** |
| 299 | * List of window tokens that have finished starting their application, |
| 300 | * and now need to have the policy remove their windows. |
| 301 | */ |
| 302 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 303 | |
| 304 | /** |
| 305 | * Z-ordered (bottom-most first) list of all Window objects. |
| 306 | */ |
| 307 | final ArrayList mWindows = new ArrayList(); |
| 308 | |
| 309 | /** |
| 310 | * Windows that are being resized. Used so we can tell the client about |
| 311 | * the resize after closing the transaction in which we resized the |
| 312 | * underlying surface. |
| 313 | */ |
| 314 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 315 | |
| 316 | /** |
| 317 | * Windows whose animations have ended and now must be removed. |
| 318 | */ |
| 319 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 320 | |
| 321 | /** |
| 322 | * Windows whose surface should be destroyed. |
| 323 | */ |
| 324 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 325 | |
| 326 | /** |
| 327 | * Windows that have lost input focus and are waiting for the new |
| 328 | * focus window to be displayed before they are told about this. |
| 329 | */ |
| 330 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 331 | |
| 332 | /** |
| 333 | * This is set when we have run out of memory, and will either be an empty |
| 334 | * list or contain windows that need to be force removed. |
| 335 | */ |
| 336 | ArrayList<WindowState> mForceRemoves; |
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 | IInputMethodManager mInputMethodManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 339 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 340 | SurfaceSession mFxSession; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 341 | private DimAnimator mDimAnimator = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | Surface mBlurSurface; |
| 343 | boolean mBlurShown; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 344 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 345 | int mTransactionSequence = 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 346 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | final float[] mTmpFloats = new float[9]; |
| 348 | |
| 349 | boolean mSafeMode; |
| 350 | boolean mDisplayEnabled = false; |
| 351 | boolean mSystemBooted = false; |
| 352 | int mRotation = 0; |
| 353 | int mRequestedRotation = 0; |
| 354 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 355 | int mLastRotationFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 356 | ArrayList<IRotationWatcher> mRotationWatchers |
| 357 | = new ArrayList<IRotationWatcher>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 358 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 359 | boolean mLayoutNeeded = true; |
| 360 | boolean mAnimationPending = false; |
| 361 | boolean mDisplayFrozen = false; |
| 362 | boolean mWindowsFreezingScreen = false; |
| 363 | long mFreezeGcPending = 0; |
| 364 | int mAppsFreezingScreen = 0; |
| 365 | |
| 366 | // This is held as long as we have the screen frozen, to give us time to |
| 367 | // perform a rotation animation when turning off shows the lock screen which |
| 368 | // changes the orientation. |
| 369 | PowerManager.WakeLock mScreenFrozenLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 370 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 371 | // State management of app transitions. When we are preparing for a |
| 372 | // transition, mNextAppTransition will be the kind of transition to |
| 373 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 374 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 375 | // made visible or hidden at the next transition. |
| 376 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_NONE; |
| 377 | boolean mAppTransitionReady = false; |
| 378 | boolean mAppTransitionTimeout = false; |
| 379 | boolean mStartingIconInTransition = false; |
| 380 | boolean mSkipAppTransitionAnimation = false; |
| 381 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 382 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
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 | //flag to detect fat touch events |
| 385 | boolean mFatTouch = false; |
| 386 | Display mDisplay; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 387 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | H mH = new H(); |
| 389 | |
| 390 | WindowState mCurrentFocus = null; |
| 391 | WindowState mLastFocus = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 392 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | // This just indicates the window the input method is on top of, not |
| 394 | // necessarily the window its input is going to. |
| 395 | WindowState mInputMethodTarget = null; |
| 396 | WindowState mUpcomingInputMethodTarget = null; |
| 397 | boolean mInputMethodTargetWaitingAnim; |
| 398 | int mInputMethodAnimLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 399 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 400 | WindowState mInputMethodWindow = null; |
| 401 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 402 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 403 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
| 404 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 405 | // If non-null, this is the currently visible window that is associated |
| 406 | // with the wallpaper. |
| 407 | WindowState mWallpaperTarget = null; |
| 408 | int mWallpaperAnimLayerAdjustment; |
| 409 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 410 | AppWindowToken mFocusedApp = null; |
| 411 | |
| 412 | PowerManagerService mPowerManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | float mWindowAnimationScale = 1.0f; |
| 415 | float mTransitionAnimationScale = 1.0f; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 416 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | final KeyWaiter mKeyWaiter = new KeyWaiter(); |
| 418 | final KeyQ mQueue; |
| 419 | final InputDispatcherThread mInputThread; |
| 420 | |
| 421 | // Who is holding the screen on. |
| 422 | Session mHoldingScreenOn; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 423 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 424 | /** |
| 425 | * Whether the UI is currently running in touch mode (not showing |
| 426 | * navigational focus because the user is directly pressing the screen). |
| 427 | */ |
| 428 | boolean mInTouchMode = false; |
| 429 | |
| 430 | private ViewServer mViewServer; |
| 431 | |
| 432 | final Rect mTempRect = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 433 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 434 | final Configuration mTempConfiguration = new Configuration(); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 435 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 436 | |
| 437 | // The frame use to limit the size of the app running in compatibility mode. |
| 438 | Rect mCompatibleScreenFrame = new Rect(); |
| 439 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 440 | Surface mBackgroundFillerSurface = null; |
| 441 | boolean mBackgroundFillerShown = false; |
| 442 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | public static WindowManagerService main(Context context, |
| 444 | PowerManagerService pm, boolean haveInputMethods) { |
| 445 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 446 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 447 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | synchronized (thr) { |
| 449 | while (thr.mService == null) { |
| 450 | try { |
| 451 | thr.wait(); |
| 452 | } catch (InterruptedException e) { |
| 453 | } |
| 454 | } |
| 455 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 456 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 457 | return thr.mService; |
| 458 | } |
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 | static class WMThread extends Thread { |
| 461 | WindowManagerService mService; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 462 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 463 | private final Context mContext; |
| 464 | private final PowerManagerService mPM; |
| 465 | private final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 466 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 467 | public WMThread(Context context, PowerManagerService pm, |
| 468 | boolean haveInputMethods) { |
| 469 | super("WindowManager"); |
| 470 | mContext = context; |
| 471 | mPM = pm; |
| 472 | mHaveInputMethods = haveInputMethods; |
| 473 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 474 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 475 | public void run() { |
| 476 | Looper.prepare(); |
| 477 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 478 | mHaveInputMethods); |
| 479 | android.os.Process.setThreadPriority( |
| 480 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 481 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 482 | synchronized (this) { |
| 483 | mService = s; |
| 484 | notifyAll(); |
| 485 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 486 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 487 | Looper.loop(); |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | static class PolicyThread extends Thread { |
| 492 | private final WindowManagerPolicy mPolicy; |
| 493 | private final WindowManagerService mService; |
| 494 | private final Context mContext; |
| 495 | private final PowerManagerService mPM; |
| 496 | boolean mRunning = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 497 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 498 | public PolicyThread(WindowManagerPolicy policy, |
| 499 | WindowManagerService service, Context context, |
| 500 | PowerManagerService pm) { |
| 501 | super("WindowManagerPolicy"); |
| 502 | mPolicy = policy; |
| 503 | mService = service; |
| 504 | mContext = context; |
| 505 | mPM = pm; |
| 506 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 507 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 508 | public void run() { |
| 509 | Looper.prepare(); |
| 510 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
| 511 | // Log.VERBOSE, "WindowManagerPolicy")); |
| 512 | android.os.Process.setThreadPriority( |
| 513 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
| 514 | mPolicy.init(mContext, mService, mPM); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 515 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 516 | synchronized (this) { |
| 517 | mRunning = true; |
| 518 | notifyAll(); |
| 519 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 520 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 521 | Looper.loop(); |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | private WindowManagerService(Context context, PowerManagerService pm, |
| 526 | boolean haveInputMethods) { |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 527 | if (MEASURE_LATENCY) { |
| 528 | lt = new LatencyTimer(100, 1000); |
| 529 | } |
| 530 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 531 | mContext = context; |
| 532 | mHaveInputMethods = haveInputMethods; |
| 533 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 534 | com.android.internal.R.bool.config_sf_limitedAlpha); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 535 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 536 | mPowerManager = pm; |
| 537 | mPowerManager.setPolicy(mPolicy); |
| 538 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 539 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 540 | "SCREEN_FROZEN"); |
| 541 | mScreenFrozenLock.setReferenceCounted(false); |
| 542 | |
| 543 | mActivityManager = ActivityManagerNative.getDefault(); |
| 544 | mBatteryStats = BatteryStatsService.getService(); |
| 545 | |
| 546 | // Get persisted window scale setting |
| 547 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 548 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 549 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 550 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 551 | |
Michael Chan | 9f028e6 | 2009-08-04 17:37:46 -0700 | [diff] [blame] | 552 | int max_events_per_sec = 35; |
| 553 | try { |
| 554 | max_events_per_sec = Integer.parseInt(SystemProperties |
| 555 | .get("windowsmgr.max_events_per_sec")); |
| 556 | if (max_events_per_sec < 1) { |
| 557 | max_events_per_sec = 35; |
| 558 | } |
| 559 | } catch (NumberFormatException e) { |
| 560 | } |
| 561 | mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec; |
| 562 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 563 | mQueue = new KeyQ(); |
| 564 | |
| 565 | mInputThread = new InputDispatcherThread(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 566 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 567 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 568 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 569 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 570 | synchronized (thr) { |
| 571 | while (!thr.mRunning) { |
| 572 | try { |
| 573 | thr.wait(); |
| 574 | } catch (InterruptedException e) { |
| 575 | } |
| 576 | } |
| 577 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 578 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 579 | mInputThread.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 580 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 581 | // Add ourself to the Watchdog monitors. |
| 582 | Watchdog.getInstance().addMonitor(this); |
| 583 | } |
| 584 | |
| 585 | @Override |
| 586 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 587 | throws RemoteException { |
| 588 | try { |
| 589 | return super.onTransact(code, data, reply, flags); |
| 590 | } catch (RuntimeException e) { |
| 591 | // The window manager only throws security exceptions, so let's |
| 592 | // log all others. |
| 593 | if (!(e instanceof SecurityException)) { |
| 594 | Log.e(TAG, "Window Manager Crash", e); |
| 595 | } |
| 596 | throw e; |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | private void placeWindowAfter(Object pos, WindowState window) { |
| 601 | final int i = mWindows.indexOf(pos); |
| 602 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 603 | TAG, "Adding window " + window + " at " |
| 604 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 605 | mWindows.add(i+1, window); |
| 606 | } |
| 607 | |
| 608 | private void placeWindowBefore(Object pos, WindowState window) { |
| 609 | final int i = mWindows.indexOf(pos); |
| 610 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 611 | TAG, "Adding window " + window + " at " |
| 612 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 613 | mWindows.add(i, window); |
| 614 | } |
| 615 | |
| 616 | //This method finds out the index of a window that has the same app token as |
| 617 | //win. used for z ordering the windows in mWindows |
| 618 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 619 | //use a local variable to cache mWindows |
| 620 | ArrayList localmWindows = mWindows; |
| 621 | int jmax = localmWindows.size(); |
| 622 | if(jmax == 0) { |
| 623 | return -1; |
| 624 | } |
| 625 | for(int j = (jmax-1); j >= 0; j--) { |
| 626 | WindowState wentry = (WindowState)localmWindows.get(j); |
| 627 | if(wentry.mAppToken == win.mAppToken) { |
| 628 | return j; |
| 629 | } |
| 630 | } |
| 631 | return -1; |
| 632 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 633 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 634 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 635 | final IWindow client = win.mClient; |
| 636 | final WindowToken token = win.mToken; |
| 637 | final ArrayList localmWindows = mWindows; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 638 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 639 | final int N = localmWindows.size(); |
| 640 | final WindowState attached = win.mAttachedWindow; |
| 641 | int i; |
| 642 | if (attached == null) { |
| 643 | int tokenWindowsPos = token.windows.size(); |
| 644 | if (token.appWindowToken != null) { |
| 645 | int index = tokenWindowsPos-1; |
| 646 | if (index >= 0) { |
| 647 | // If this application has existing windows, we |
| 648 | // simply place the new window on top of them... but |
| 649 | // keep the starting window on top. |
| 650 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 651 | // Base windows go behind everything else. |
| 652 | placeWindowBefore(token.windows.get(0), win); |
| 653 | tokenWindowsPos = 0; |
| 654 | } else { |
| 655 | AppWindowToken atoken = win.mAppToken; |
| 656 | if (atoken != null && |
| 657 | token.windows.get(index) == atoken.startingWindow) { |
| 658 | placeWindowBefore(token.windows.get(index), win); |
| 659 | tokenWindowsPos--; |
| 660 | } else { |
| 661 | int newIdx = findIdxBasedOnAppTokens(win); |
| 662 | if(newIdx != -1) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 663 | //there is a window above this one associated with the same |
| 664 | //apptoken note that the window could be a floating window |
| 665 | //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] | 666 | //windows associated with this token. |
| 667 | localmWindows.add(newIdx+1, win); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 668 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 669 | } |
| 670 | } |
| 671 | } else { |
| 672 | if (localLOGV) Log.v( |
| 673 | TAG, "Figuring out where to add app window " |
| 674 | + client.asBinder() + " (token=" + token + ")"); |
| 675 | // Figure out where the window should go, based on the |
| 676 | // order of applications. |
| 677 | final int NA = mAppTokens.size(); |
| 678 | Object pos = null; |
| 679 | for (i=NA-1; i>=0; i--) { |
| 680 | AppWindowToken t = mAppTokens.get(i); |
| 681 | if (t == token) { |
| 682 | i--; |
| 683 | break; |
| 684 | } |
| 685 | if (t.windows.size() > 0) { |
| 686 | pos = t.windows.get(0); |
| 687 | } |
| 688 | } |
| 689 | // We now know the index into the apps. If we found |
| 690 | // an app window above, that gives us the position; else |
| 691 | // we need to look some more. |
| 692 | if (pos != null) { |
| 693 | // Move behind any windows attached to this one. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 694 | WindowToken atoken = |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 695 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 696 | if (atoken != null) { |
| 697 | final int NC = atoken.windows.size(); |
| 698 | if (NC > 0) { |
| 699 | WindowState bottom = atoken.windows.get(0); |
| 700 | if (bottom.mSubLayer < 0) { |
| 701 | pos = bottom; |
| 702 | } |
| 703 | } |
| 704 | } |
| 705 | placeWindowBefore(pos, win); |
| 706 | } else { |
| 707 | while (i >= 0) { |
| 708 | AppWindowToken t = mAppTokens.get(i); |
| 709 | final int NW = t.windows.size(); |
| 710 | if (NW > 0) { |
| 711 | pos = t.windows.get(NW-1); |
| 712 | break; |
| 713 | } |
| 714 | i--; |
| 715 | } |
| 716 | if (pos != null) { |
| 717 | // Move in front of any windows attached to this |
| 718 | // one. |
| 719 | WindowToken atoken = |
| 720 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 721 | if (atoken != null) { |
| 722 | final int NC = atoken.windows.size(); |
| 723 | if (NC > 0) { |
| 724 | WindowState top = atoken.windows.get(NC-1); |
| 725 | if (top.mSubLayer >= 0) { |
| 726 | pos = top; |
| 727 | } |
| 728 | } |
| 729 | } |
| 730 | placeWindowAfter(pos, win); |
| 731 | } else { |
| 732 | // Just search for the start of this layer. |
| 733 | final int myLayer = win.mBaseLayer; |
| 734 | for (i=0; i<N; i++) { |
| 735 | WindowState w = (WindowState)localmWindows.get(i); |
| 736 | if (w.mBaseLayer > myLayer) { |
| 737 | break; |
| 738 | } |
| 739 | } |
| 740 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 741 | TAG, "Adding window " + win + " at " |
| 742 | + i + " of " + N); |
| 743 | localmWindows.add(i, win); |
| 744 | } |
| 745 | } |
| 746 | } |
| 747 | } else { |
| 748 | // Figure out where window should go, based on layer. |
| 749 | final int myLayer = win.mBaseLayer; |
| 750 | for (i=N-1; i>=0; i--) { |
| 751 | if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) { |
| 752 | i++; |
| 753 | break; |
| 754 | } |
| 755 | } |
| 756 | if (i < 0) i = 0; |
| 757 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 758 | TAG, "Adding window " + win + " at " |
| 759 | + i + " of " + N); |
| 760 | localmWindows.add(i, win); |
| 761 | } |
| 762 | if (addToToken) { |
| 763 | token.windows.add(tokenWindowsPos, win); |
| 764 | } |
| 765 | |
| 766 | } else { |
| 767 | // Figure out this window's ordering relative to the window |
| 768 | // it is attached to. |
| 769 | final int NA = token.windows.size(); |
| 770 | final int sublayer = win.mSubLayer; |
| 771 | int largestSublayer = Integer.MIN_VALUE; |
| 772 | WindowState windowWithLargestSublayer = null; |
| 773 | for (i=0; i<NA; i++) { |
| 774 | WindowState w = token.windows.get(i); |
| 775 | final int wSublayer = w.mSubLayer; |
| 776 | if (wSublayer >= largestSublayer) { |
| 777 | largestSublayer = wSublayer; |
| 778 | windowWithLargestSublayer = w; |
| 779 | } |
| 780 | if (sublayer < 0) { |
| 781 | // For negative sublayers, we go below all windows |
| 782 | // in the same sublayer. |
| 783 | if (wSublayer >= sublayer) { |
| 784 | if (addToToken) { |
| 785 | token.windows.add(i, win); |
| 786 | } |
| 787 | placeWindowBefore( |
| 788 | wSublayer >= 0 ? attached : w, win); |
| 789 | break; |
| 790 | } |
| 791 | } else { |
| 792 | // For positive sublayers, we go above all windows |
| 793 | // in the same sublayer. |
| 794 | if (wSublayer > sublayer) { |
| 795 | if (addToToken) { |
| 796 | token.windows.add(i, win); |
| 797 | } |
| 798 | placeWindowBefore(w, win); |
| 799 | break; |
| 800 | } |
| 801 | } |
| 802 | } |
| 803 | if (i >= NA) { |
| 804 | if (addToToken) { |
| 805 | token.windows.add(win); |
| 806 | } |
| 807 | if (sublayer < 0) { |
| 808 | placeWindowBefore(attached, win); |
| 809 | } else { |
| 810 | placeWindowAfter(largestSublayer >= 0 |
| 811 | ? windowWithLargestSublayer |
| 812 | : attached, |
| 813 | win); |
| 814 | } |
| 815 | } |
| 816 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 817 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 818 | if (win.mAppToken != null && addToToken) { |
| 819 | win.mAppToken.allAppWindows.add(win); |
| 820 | } |
| 821 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 822 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 823 | static boolean canBeImeTarget(WindowState w) { |
| 824 | final int fl = w.mAttrs.flags |
| 825 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 826 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 827 | return w.isVisibleOrAdding(); |
| 828 | } |
| 829 | return false; |
| 830 | } |
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 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
| 833 | final ArrayList localmWindows = mWindows; |
| 834 | final int N = localmWindows.size(); |
| 835 | WindowState w = null; |
| 836 | int i = N; |
| 837 | while (i > 0) { |
| 838 | i--; |
| 839 | w = (WindowState)localmWindows.get(i); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 840 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 841 | //Log.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
| 842 | // + Integer.toHexString(w.mAttrs.flags)); |
| 843 | if (canBeImeTarget(w)) { |
| 844 | //Log.i(TAG, "Putting input method here!"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 845 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 846 | // Yet more tricksyness! If this window is a "starting" |
| 847 | // window, we do actually want to be on top of it, but |
| 848 | // it is not -really- where input will go. So if the caller |
| 849 | // is not actually looking to move the IME, look down below |
| 850 | // for a real window to target... |
| 851 | if (!willMove |
| 852 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 853 | && i > 0) { |
| 854 | WindowState wb = (WindowState)localmWindows.get(i-1); |
| 855 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 856 | i--; |
| 857 | w = wb; |
| 858 | } |
| 859 | } |
| 860 | break; |
| 861 | } |
| 862 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 863 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 864 | mUpcomingInputMethodTarget = w; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 865 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 866 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Desired input method target=" |
| 867 | + w + " willMove=" + willMove); |
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 (willMove && w != null) { |
| 870 | final WindowState curTarget = mInputMethodTarget; |
| 871 | if (curTarget != null && curTarget.mAppToken != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 872 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 873 | // Now some fun for dealing with window animations that |
| 874 | // modify the Z order. We need to look at all windows below |
| 875 | // the current target that are in this app, finding the highest |
| 876 | // visible one in layering. |
| 877 | AppWindowToken token = curTarget.mAppToken; |
| 878 | WindowState highestTarget = null; |
| 879 | int highestPos = 0; |
| 880 | if (token.animating || token.animation != null) { |
| 881 | int pos = 0; |
| 882 | pos = localmWindows.indexOf(curTarget); |
| 883 | while (pos >= 0) { |
| 884 | WindowState win = (WindowState)localmWindows.get(pos); |
| 885 | if (win.mAppToken != token) { |
| 886 | break; |
| 887 | } |
| 888 | if (!win.mRemoved) { |
| 889 | if (highestTarget == null || win.mAnimLayer > |
| 890 | highestTarget.mAnimLayer) { |
| 891 | highestTarget = win; |
| 892 | highestPos = pos; |
| 893 | } |
| 894 | } |
| 895 | pos--; |
| 896 | } |
| 897 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 898 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 899 | if (highestTarget != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 900 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "mNextAppTransition=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 901 | + mNextAppTransition + " " + highestTarget |
| 902 | + " animating=" + highestTarget.isAnimating() |
| 903 | + " layer=" + highestTarget.mAnimLayer |
| 904 | + " new layer=" + w.mAnimLayer); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 905 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 906 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) { |
| 907 | // If we are currently setting up for an animation, |
| 908 | // hold everything until we can find out what will happen. |
| 909 | mInputMethodTargetWaitingAnim = true; |
| 910 | mInputMethodTarget = highestTarget; |
| 911 | return highestPos + 1; |
| 912 | } else if (highestTarget.isAnimating() && |
| 913 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 914 | // If the window we are currently targeting is involved |
| 915 | // with an animation, and it is on top of the next target |
| 916 | // we will be over, then hold off on moving until |
| 917 | // that is done. |
| 918 | mInputMethodTarget = highestTarget; |
| 919 | return highestPos + 1; |
| 920 | } |
| 921 | } |
| 922 | } |
| 923 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 924 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 925 | //Log.i(TAG, "Placing input method @" + (i+1)); |
| 926 | if (w != null) { |
| 927 | if (willMove) { |
| 928 | RuntimeException e = new RuntimeException(); |
| 929 | e.fillInStackTrace(); |
| 930 | if (DEBUG_INPUT_METHOD) Log.w(TAG, "Moving IM target from " |
| 931 | + mInputMethodTarget + " to " + w, e); |
| 932 | mInputMethodTarget = w; |
| 933 | if (w.mAppToken != null) { |
| 934 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 935 | } else { |
| 936 | setInputMethodAnimLayerAdjustment(0); |
| 937 | } |
| 938 | } |
| 939 | return i+1; |
| 940 | } |
| 941 | if (willMove) { |
| 942 | RuntimeException e = new RuntimeException(); |
| 943 | e.fillInStackTrace(); |
| 944 | if (DEBUG_INPUT_METHOD) Log.w(TAG, "Moving IM target from " |
| 945 | + mInputMethodTarget + " to null", e); |
| 946 | mInputMethodTarget = null; |
| 947 | setInputMethodAnimLayerAdjustment(0); |
| 948 | } |
| 949 | return -1; |
| 950 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 951 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 952 | void addInputMethodWindowToListLocked(WindowState win) { |
| 953 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 954 | if (pos >= 0) { |
| 955 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 956 | mWindows.add(pos, win); |
| 957 | moveInputMethodDialogsLocked(pos+1); |
| 958 | return; |
| 959 | } |
| 960 | win.mTargetAppToken = null; |
| 961 | addWindowToListInOrderLocked(win, true); |
| 962 | moveInputMethodDialogsLocked(pos); |
| 963 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 964 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 965 | void setInputMethodAnimLayerAdjustment(int adj) { |
| 966 | if (DEBUG_LAYERS) Log.v(TAG, "Setting im layer adj to " + adj); |
| 967 | mInputMethodAnimLayerAdjustment = adj; |
| 968 | WindowState imw = mInputMethodWindow; |
| 969 | if (imw != null) { |
| 970 | imw.mAnimLayer = imw.mLayer + adj; |
| 971 | if (DEBUG_LAYERS) Log.v(TAG, "IM win " + imw |
| 972 | + " anim layer: " + imw.mAnimLayer); |
| 973 | int wi = imw.mChildWindows.size(); |
| 974 | while (wi > 0) { |
| 975 | wi--; |
| 976 | WindowState cw = (WindowState)imw.mChildWindows.get(wi); |
| 977 | cw.mAnimLayer = cw.mLayer + adj; |
| 978 | if (DEBUG_LAYERS) Log.v(TAG, "IM win " + cw |
| 979 | + " anim layer: " + cw.mAnimLayer); |
| 980 | } |
| 981 | } |
| 982 | int di = mInputMethodDialogs.size(); |
| 983 | while (di > 0) { |
| 984 | di --; |
| 985 | imw = mInputMethodDialogs.get(di); |
| 986 | imw.mAnimLayer = imw.mLayer + adj; |
| 987 | if (DEBUG_LAYERS) Log.v(TAG, "IM win " + imw |
| 988 | + " anim layer: " + imw.mAnimLayer); |
| 989 | } |
| 990 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 991 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 992 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 993 | int wpos = mWindows.indexOf(win); |
| 994 | if (wpos >= 0) { |
| 995 | if (wpos < interestingPos) interestingPos--; |
| 996 | mWindows.remove(wpos); |
| 997 | int NC = win.mChildWindows.size(); |
| 998 | while (NC > 0) { |
| 999 | NC--; |
| 1000 | WindowState cw = (WindowState)win.mChildWindows.get(NC); |
| 1001 | int cpos = mWindows.indexOf(cw); |
| 1002 | if (cpos >= 0) { |
| 1003 | if (cpos < interestingPos) interestingPos--; |
| 1004 | mWindows.remove(cpos); |
| 1005 | } |
| 1006 | } |
| 1007 | } |
| 1008 | return interestingPos; |
| 1009 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1010 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1011 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1012 | addWindowToListInOrderLocked(win, false); |
| 1013 | // This is a hack to get all of the child windows added as well |
| 1014 | // at the right position. Child windows should be rare and |
| 1015 | // this case should be rare, so it shouldn't be that big a deal. |
| 1016 | int wpos = mWindows.indexOf(win); |
| 1017 | if (wpos >= 0) { |
| 1018 | mWindows.remove(wpos); |
| 1019 | reAddWindowLocked(wpos, win); |
| 1020 | } |
| 1021 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1022 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1023 | void logWindowList(String prefix) { |
| 1024 | int N = mWindows.size(); |
| 1025 | while (N > 0) { |
| 1026 | N--; |
| 1027 | Log.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
| 1028 | } |
| 1029 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1030 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1031 | void moveInputMethodDialogsLocked(int pos) { |
| 1032 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1033 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1034 | final int N = dialogs.size(); |
| 1035 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Removing " + N + " dialogs w/pos=" + pos); |
| 1036 | for (int i=0; i<N; i++) { |
| 1037 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1038 | } |
| 1039 | if (DEBUG_INPUT_METHOD) { |
| 1040 | Log.v(TAG, "Window list w/pos=" + pos); |
| 1041 | logWindowList(" "); |
| 1042 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1043 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1044 | if (pos >= 0) { |
| 1045 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1046 | if (pos < mWindows.size()) { |
| 1047 | WindowState wp = (WindowState)mWindows.get(pos); |
| 1048 | if (wp == mInputMethodWindow) { |
| 1049 | pos++; |
| 1050 | } |
| 1051 | } |
| 1052 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Adding " + N + " dialogs at pos=" + pos); |
| 1053 | for (int i=0; i<N; i++) { |
| 1054 | WindowState win = dialogs.get(i); |
| 1055 | win.mTargetAppToken = targetAppToken; |
| 1056 | pos = reAddWindowLocked(pos, win); |
| 1057 | } |
| 1058 | if (DEBUG_INPUT_METHOD) { |
| 1059 | Log.v(TAG, "Final window list:"); |
| 1060 | logWindowList(" "); |
| 1061 | } |
| 1062 | return; |
| 1063 | } |
| 1064 | for (int i=0; i<N; i++) { |
| 1065 | WindowState win = dialogs.get(i); |
| 1066 | win.mTargetAppToken = null; |
| 1067 | reAddWindowToListInOrderLocked(win); |
| 1068 | if (DEBUG_INPUT_METHOD) { |
| 1069 | Log.v(TAG, "No IM target, final list:"); |
| 1070 | logWindowList(" "); |
| 1071 | } |
| 1072 | } |
| 1073 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1074 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1075 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1076 | final WindowState imWin = mInputMethodWindow; |
| 1077 | final int DN = mInputMethodDialogs.size(); |
| 1078 | if (imWin == null && DN == 0) { |
| 1079 | return false; |
| 1080 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1081 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1082 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1083 | if (imPos >= 0) { |
| 1084 | // In this case, the input method windows are to be placed |
| 1085 | // immediately above the window they are targeting. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1086 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1087 | // First check to see if the input method windows are already |
| 1088 | // located here, and contiguous. |
| 1089 | final int N = mWindows.size(); |
| 1090 | WindowState firstImWin = imPos < N |
| 1091 | ? (WindowState)mWindows.get(imPos) : null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1092 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1093 | // Figure out the actual input method window that should be |
| 1094 | // at the bottom of their stack. |
| 1095 | WindowState baseImWin = imWin != null |
| 1096 | ? imWin : mInputMethodDialogs.get(0); |
| 1097 | if (baseImWin.mChildWindows.size() > 0) { |
| 1098 | WindowState cw = (WindowState)baseImWin.mChildWindows.get(0); |
| 1099 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1100 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1101 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1102 | if (firstImWin == baseImWin) { |
| 1103 | // The windows haven't moved... but are they still contiguous? |
| 1104 | // First find the top IM window. |
| 1105 | int pos = imPos+1; |
| 1106 | while (pos < N) { |
| 1107 | if (!((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1108 | break; |
| 1109 | } |
| 1110 | pos++; |
| 1111 | } |
| 1112 | pos++; |
| 1113 | // Now there should be no more input method windows above. |
| 1114 | while (pos < N) { |
| 1115 | if (((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1116 | break; |
| 1117 | } |
| 1118 | pos++; |
| 1119 | } |
| 1120 | if (pos >= N) { |
| 1121 | // All is good! |
| 1122 | return false; |
| 1123 | } |
| 1124 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1125 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1126 | if (imWin != null) { |
| 1127 | if (DEBUG_INPUT_METHOD) { |
| 1128 | Log.v(TAG, "Moving IM from " + imPos); |
| 1129 | logWindowList(" "); |
| 1130 | } |
| 1131 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1132 | if (DEBUG_INPUT_METHOD) { |
| 1133 | Log.v(TAG, "List after moving with new pos " + imPos + ":"); |
| 1134 | logWindowList(" "); |
| 1135 | } |
| 1136 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1137 | reAddWindowLocked(imPos, imWin); |
| 1138 | if (DEBUG_INPUT_METHOD) { |
| 1139 | Log.v(TAG, "List after moving IM to " + imPos + ":"); |
| 1140 | logWindowList(" "); |
| 1141 | } |
| 1142 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1143 | } else { |
| 1144 | moveInputMethodDialogsLocked(imPos); |
| 1145 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1146 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1147 | } else { |
| 1148 | // In this case, the input method windows go in a fixed layer, |
| 1149 | // because they aren't currently associated with a focus window. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1150 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1151 | if (imWin != null) { |
| 1152 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Moving IM from " + imPos); |
| 1153 | tmpRemoveWindowLocked(0, imWin); |
| 1154 | imWin.mTargetAppToken = null; |
| 1155 | reAddWindowToListInOrderLocked(imWin); |
| 1156 | if (DEBUG_INPUT_METHOD) { |
| 1157 | Log.v(TAG, "List with no IM target:"); |
| 1158 | logWindowList(" "); |
| 1159 | } |
| 1160 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1161 | } else { |
| 1162 | moveInputMethodDialogsLocked(-1);; |
| 1163 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1164 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1165 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1166 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1167 | if (needAssignLayers) { |
| 1168 | assignLayersLocked(); |
| 1169 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1170 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1171 | return true; |
| 1172 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1174 | void adjustInputMethodDialogsLocked() { |
| 1175 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1176 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1177 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1178 | boolean adjustWallpaperWindowsLocked() { |
| 1179 | boolean changed = false; |
| 1180 | |
| 1181 | // First find top-most window that has asked to be on top of the |
| 1182 | // wallpaper; all wallpapers go behind it. |
| 1183 | final ArrayList localmWindows = mWindows; |
| 1184 | int N = localmWindows.size(); |
| 1185 | WindowState w = null; |
| 1186 | int i = N; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1187 | boolean visible = false; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1188 | while (i > 0) { |
| 1189 | i--; |
| 1190 | w = (WindowState)localmWindows.get(i); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1191 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
| 1192 | && !w.mDrawPending && !w.mCommitDrawPending) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1193 | visible = true; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1194 | break; |
| 1195 | } |
| 1196 | } |
| 1197 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1198 | if (!visible) w = null; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1199 | if (DEBUG_WALLPAPER && mWallpaperTarget != w) { |
| 1200 | Log.v(TAG, "New wallpaper target: " + w); |
| 1201 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1202 | mWallpaperTarget = w; |
| 1203 | |
| 1204 | if (visible) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1205 | // The window is visible to the compositor... but is it visible |
| 1206 | // to the user? That is what the wallpaper cares about. |
| 1207 | visible = !w.mObscured; |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame^] | 1208 | if (DEBUG_WALLPAPER) Log.v(TAG, "Wallpaper visibility: " + visible); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1209 | |
| 1210 | // If the wallpaper target is animating, we may need to copy |
| 1211 | // its layer adjustment. |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1212 | mWallpaperAnimLayerAdjustment = w.mAppToken != null |
| 1213 | ? w.mAppToken.animLayerAdjustment : 0; |
| 1214 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1215 | // Now w is the window we are supposed to be behind... but we |
| 1216 | // need to be sure to also be behind any of its attached windows, |
| 1217 | // AND any starting window associated with it. |
| 1218 | while (i > 0) { |
| 1219 | WindowState wb = (WindowState)localmWindows.get(i-1); |
| 1220 | if (wb.mAttachedWindow != w && |
| 1221 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
| 1222 | wb.mToken != w.mToken)) { |
| 1223 | // This window is not related to the previous one in any |
| 1224 | // interesting way, so stop here. |
| 1225 | break; |
| 1226 | } |
| 1227 | w = wb; |
| 1228 | i--; |
| 1229 | } |
| 1230 | } |
| 1231 | |
| 1232 | // Okay i is the position immediately above the wallpaper. Look at |
| 1233 | // what is below it for later. |
| 1234 | w = i > 0 ? (WindowState)localmWindows.get(i-1) : null; |
| 1235 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1236 | final int dw = mDisplay.getWidth(); |
| 1237 | final int dh = mDisplay.getHeight(); |
| 1238 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1239 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1240 | // are correctly placed. |
| 1241 | int curTokenIndex = mWallpaperTokens.size(); |
| 1242 | while (curTokenIndex > 0) { |
| 1243 | curTokenIndex--; |
| 1244 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1245 | int curWallpaperIndex = token.windows.size(); |
| 1246 | while (curWallpaperIndex > 0) { |
| 1247 | curWallpaperIndex--; |
| 1248 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1249 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1250 | if (visible) { |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1251 | updateWallpaperOffsetLocked(mWallpaperTarget, |
| 1252 | wallpaper, dw, dh); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1253 | } |
| 1254 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1255 | // First, make sure the client has the current visibility |
| 1256 | // state. |
| 1257 | if (wallpaper.mWallpaperVisible != visible) { |
| 1258 | wallpaper.mWallpaperVisible = visible; |
| 1259 | try { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1260 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Log.v(TAG, |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1261 | "Setting visibility of wallpaper " + wallpaper |
| 1262 | + ": " + visible); |
| 1263 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1264 | } catch (RemoteException e) { |
| 1265 | } |
| 1266 | } |
| 1267 | |
| 1268 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1269 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Log.v(TAG, "Wallpaper win " |
| 1270 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1271 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1272 | // First, if this window is at the current index, then all |
| 1273 | // is well. |
| 1274 | if (wallpaper == w) { |
| 1275 | i--; |
| 1276 | w = i > 0 ? (WindowState)localmWindows.get(i-1) : null; |
| 1277 | continue; |
| 1278 | } |
| 1279 | |
| 1280 | // The window didn't match... the current wallpaper window, |
| 1281 | // wherever it is, is in the wrong place, so make sure it is |
| 1282 | // not in the list. |
| 1283 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1284 | if (oldIndex >= 0) { |
| 1285 | localmWindows.remove(oldIndex); |
| 1286 | if (oldIndex < i) { |
| 1287 | i--; |
| 1288 | } |
| 1289 | } |
| 1290 | |
| 1291 | // Now stick it in. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1292 | if (DEBUG_WALLPAPER) Log.v(TAG, "Moving wallpaper " + wallpaper |
| 1293 | + " from " + oldIndex + " to " + i); |
| 1294 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1295 | localmWindows.add(i, wallpaper); |
| 1296 | changed = true; |
| 1297 | } |
| 1298 | } |
| 1299 | |
| 1300 | return changed; |
| 1301 | } |
| 1302 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1303 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1304 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Log.v(TAG, |
| 1305 | "Setting wallpaper layer adj to " + adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1306 | mWallpaperAnimLayerAdjustment = adj; |
| 1307 | int curTokenIndex = mWallpaperTokens.size(); |
| 1308 | while (curTokenIndex > 0) { |
| 1309 | curTokenIndex--; |
| 1310 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1311 | int curWallpaperIndex = token.windows.size(); |
| 1312 | while (curWallpaperIndex > 0) { |
| 1313 | curWallpaperIndex--; |
| 1314 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1315 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1316 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Log.v(TAG, "Wallpaper win " |
| 1317 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1318 | } |
| 1319 | } |
| 1320 | } |
| 1321 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1322 | boolean updateWallpaperOffsetLocked(WindowState target, |
| 1323 | WindowState wallpaperWin, int dw, int dh) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1324 | boolean changed = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1325 | boolean rawChanged = false; |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1326 | if (target.mWallpaperX >= 0) { |
| 1327 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 1328 | int offset = availw > 0 ? -(int)(availw*target.mWallpaperX+.5f) : 0; |
| 1329 | changed = wallpaperWin.mXOffset != offset; |
| 1330 | if (changed) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1331 | if (DEBUG_WALLPAPER) Log.v(TAG, "Update wallpaper " |
| 1332 | + wallpaperWin + " x: " + offset); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1333 | wallpaperWin.mXOffset = offset; |
| 1334 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1335 | if (wallpaperWin.mWallpaperX != target.mWallpaperX) { |
| 1336 | wallpaperWin.mWallpaperX = target.mWallpaperX; |
| 1337 | rawChanged = true; |
| 1338 | } |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1339 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1340 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1341 | if (target.mWallpaperY >= 0) { |
| 1342 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 1343 | int offset = availh > 0 ? -(int)(availh*target.mWallpaperY+.5f) : 0; |
| 1344 | if (wallpaperWin.mYOffset != offset) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1345 | if (DEBUG_WALLPAPER) Log.v(TAG, "Update wallpaper " |
| 1346 | + wallpaperWin + " y: " + offset); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1347 | changed = true; |
| 1348 | wallpaperWin.mYOffset = offset; |
| 1349 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1350 | if (wallpaperWin.mWallpaperY != target.mWallpaperY) { |
| 1351 | wallpaperWin.mWallpaperY = target.mWallpaperY; |
| 1352 | rawChanged = true; |
| 1353 | } |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1354 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1355 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1356 | if (rawChanged) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1357 | try { |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame^] | 1358 | if (DEBUG_WALLPAPER) Log.v(TAG, "Report new wp offset " |
| 1359 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 1360 | + " y=" + wallpaperWin.mWallpaperY); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1361 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
| 1362 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY); |
| 1363 | } catch (RemoteException e) { |
| 1364 | } |
| 1365 | } |
| 1366 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1367 | return changed; |
| 1368 | } |
| 1369 | |
| 1370 | boolean updateWallpaperOffsetLocked() { |
| 1371 | final int dw = mDisplay.getWidth(); |
| 1372 | final int dh = mDisplay.getHeight(); |
| 1373 | |
| 1374 | boolean changed = false; |
| 1375 | |
| 1376 | WindowState target = mWallpaperTarget; |
| 1377 | if (target != null) { |
| 1378 | int curTokenIndex = mWallpaperTokens.size(); |
| 1379 | while (curTokenIndex > 0) { |
| 1380 | curTokenIndex--; |
| 1381 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1382 | int curWallpaperIndex = token.windows.size(); |
| 1383 | while (curWallpaperIndex > 0) { |
| 1384 | curWallpaperIndex--; |
| 1385 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1386 | if (updateWallpaperOffsetLocked(target, wallpaper, dw, dh)) { |
| 1387 | wallpaper.computeShownFrameLocked(); |
| 1388 | changed = true; |
| 1389 | } |
| 1390 | } |
| 1391 | } |
| 1392 | } |
| 1393 | |
| 1394 | return changed; |
| 1395 | } |
| 1396 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame^] | 1397 | void updateWallpaperVisibilityLocked() { |
| 1398 | final boolean visible = mWallpaperTarget != null |
| 1399 | && !mWallpaperTarget.mObscured; |
| 1400 | final int dw = mDisplay.getWidth(); |
| 1401 | final int dh = mDisplay.getHeight(); |
| 1402 | |
| 1403 | int curTokenIndex = mWallpaperTokens.size(); |
| 1404 | while (curTokenIndex > 0) { |
| 1405 | curTokenIndex--; |
| 1406 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1407 | int curWallpaperIndex = token.windows.size(); |
| 1408 | while (curWallpaperIndex > 0) { |
| 1409 | curWallpaperIndex--; |
| 1410 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1411 | if (visible) { |
| 1412 | updateWallpaperOffsetLocked(mWallpaperTarget, |
| 1413 | wallpaper, dw, dh); |
| 1414 | } |
| 1415 | |
| 1416 | if (wallpaper.mWallpaperVisible != visible) { |
| 1417 | wallpaper.mWallpaperVisible = visible; |
| 1418 | try { |
| 1419 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Log.v(TAG, |
| 1420 | "Setting visibility of wallpaper " + wallpaper |
| 1421 | + ": " + visible); |
| 1422 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1423 | } catch (RemoteException e) { |
| 1424 | } |
| 1425 | } |
| 1426 | } |
| 1427 | } |
| 1428 | } |
| 1429 | |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1430 | void sendPointerToWallpaperLocked(WindowState srcWin, |
| 1431 | MotionEvent pointer, long eventTime) { |
| 1432 | int curTokenIndex = mWallpaperTokens.size(); |
| 1433 | while (curTokenIndex > 0) { |
| 1434 | curTokenIndex--; |
| 1435 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1436 | int curWallpaperIndex = token.windows.size(); |
| 1437 | while (curWallpaperIndex > 0) { |
| 1438 | curWallpaperIndex--; |
| 1439 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1440 | if ((wallpaper.mAttrs.flags & |
| 1441 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 1442 | continue; |
| 1443 | } |
| 1444 | try { |
| 1445 | MotionEvent ev = MotionEvent.obtainNoHistory(pointer); |
| 1446 | ev.offsetLocation(srcWin.mFrame.left-wallpaper.mFrame.left, |
| 1447 | srcWin.mFrame.top-wallpaper.mFrame.top); |
| 1448 | wallpaper.mClient.dispatchPointer(ev, eventTime, false); |
| 1449 | } catch (RemoteException e) { |
| 1450 | Log.w(TAG, "Failure sending pointer to wallpaper", e); |
| 1451 | } |
| 1452 | } |
| 1453 | } |
| 1454 | } |
| 1455 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1456 | public int addWindow(Session session, IWindow client, |
| 1457 | WindowManager.LayoutParams attrs, int viewVisibility, |
| 1458 | Rect outContentInsets) { |
| 1459 | int res = mPolicy.checkAddPermission(attrs); |
| 1460 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1461 | return res; |
| 1462 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1463 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1464 | boolean reportNewConfig = false; |
| 1465 | WindowState attachedWindow = null; |
| 1466 | WindowState win = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1467 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1468 | synchronized(mWindowMap) { |
| 1469 | // Instantiating a Display requires talking with the simulator, |
| 1470 | // so don't do it until we know the system is mostly up and |
| 1471 | // running. |
| 1472 | if (mDisplay == null) { |
| 1473 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 1474 | mDisplay = wm.getDefaultDisplay(); |
| 1475 | mQueue.setDisplay(mDisplay); |
| 1476 | reportNewConfig = true; |
| 1477 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1478 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1479 | if (mWindowMap.containsKey(client.asBinder())) { |
| 1480 | Log.w(TAG, "Window " + client + " is already added"); |
| 1481 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 1482 | } |
| 1483 | |
| 1484 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1485 | attachedWindow = windowForClientLocked(null, attrs.token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1486 | if (attachedWindow == null) { |
| 1487 | Log.w(TAG, "Attempted to add window with token that is not a window: " |
| 1488 | + attrs.token + ". Aborting."); |
| 1489 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1490 | } |
| 1491 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 1492 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
| 1493 | Log.w(TAG, "Attempted to add window with token that is a sub-window: " |
| 1494 | + attrs.token + ". Aborting."); |
| 1495 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1496 | } |
| 1497 | } |
| 1498 | |
| 1499 | boolean addToken = false; |
| 1500 | WindowToken token = mTokenMap.get(attrs.token); |
| 1501 | if (token == null) { |
| 1502 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1503 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1504 | Log.w(TAG, "Attempted to add application window with unknown token " |
| 1505 | + attrs.token + ". Aborting."); |
| 1506 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1507 | } |
| 1508 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 1509 | Log.w(TAG, "Attempted to add input method window with unknown token " |
| 1510 | + attrs.token + ". Aborting."); |
| 1511 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1512 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1513 | if (attrs.type == TYPE_WALLPAPER) { |
| 1514 | Log.w(TAG, "Attempted to add wallpaper window with unknown token " |
| 1515 | + attrs.token + ". Aborting."); |
| 1516 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1517 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1518 | token = new WindowToken(attrs.token, -1, false); |
| 1519 | addToken = true; |
| 1520 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1521 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1522 | AppWindowToken atoken = token.appWindowToken; |
| 1523 | if (atoken == null) { |
| 1524 | Log.w(TAG, "Attempted to add window with non-application token " |
| 1525 | + token + ". Aborting."); |
| 1526 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 1527 | } else if (atoken.removed) { |
| 1528 | Log.w(TAG, "Attempted to add window with exiting application token " |
| 1529 | + token + ". Aborting."); |
| 1530 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1531 | } |
| 1532 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 1533 | // No need for this guy! |
| 1534 | if (localLOGV) Log.v( |
| 1535 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 1536 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 1537 | } |
| 1538 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 1539 | if (token.windowType != TYPE_INPUT_METHOD) { |
| 1540 | Log.w(TAG, "Attempted to add input method window with bad token " |
| 1541 | + attrs.token + ". Aborting."); |
| 1542 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1543 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1544 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 1545 | if (token.windowType != TYPE_WALLPAPER) { |
| 1546 | Log.w(TAG, "Attempted to add wallpaper window with bad token " |
| 1547 | + attrs.token + ". Aborting."); |
| 1548 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1549 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | win = new WindowState(session, client, token, |
| 1553 | attachedWindow, attrs, viewVisibility); |
| 1554 | if (win.mDeathRecipient == null) { |
| 1555 | // Client has apparently died, so there is no reason to |
| 1556 | // continue. |
| 1557 | Log.w(TAG, "Adding window client " + client.asBinder() |
| 1558 | + " that is dead, aborting."); |
| 1559 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1560 | } |
| 1561 | |
| 1562 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1563 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1564 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 1565 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1566 | return res; |
| 1567 | } |
| 1568 | |
| 1569 | // From now on, no exceptions or errors allowed! |
| 1570 | |
| 1571 | res = WindowManagerImpl.ADD_OKAY; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1572 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1573 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1574 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1575 | if (addToken) { |
| 1576 | mTokenMap.put(attrs.token, token); |
| 1577 | mTokenList.add(token); |
| 1578 | } |
| 1579 | win.attach(); |
| 1580 | mWindowMap.put(client.asBinder(), win); |
| 1581 | |
| 1582 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 1583 | token.appWindowToken != null) { |
| 1584 | token.appWindowToken.startingWindow = win; |
| 1585 | } |
| 1586 | |
| 1587 | boolean imMayMove = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1588 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1589 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 1590 | mInputMethodWindow = win; |
| 1591 | addInputMethodWindowToListLocked(win); |
| 1592 | imMayMove = false; |
| 1593 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 1594 | mInputMethodDialogs.add(win); |
| 1595 | addWindowToListInOrderLocked(win, true); |
| 1596 | adjustInputMethodDialogsLocked(); |
| 1597 | imMayMove = false; |
| 1598 | } else { |
| 1599 | addWindowToListInOrderLocked(win, true); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1600 | if (attrs.type == TYPE_WALLPAPER || |
| 1601 | (attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 1602 | adjustWallpaperWindowsLocked(); |
| 1603 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1604 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1605 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1606 | win.mEnterAnimationPending = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1607 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1608 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1609 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1610 | if (mInTouchMode) { |
| 1611 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 1612 | } |
| 1613 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 1614 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 1615 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1616 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1617 | boolean focusChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1618 | if (win.canReceiveKeys()) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1619 | if ((focusChanged=updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS)) |
| 1620 | == true) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1621 | imMayMove = false; |
| 1622 | } |
| 1623 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1624 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1625 | if (imMayMove) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1626 | moveInputMethodWindowsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1627 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1628 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1629 | assignLayersLocked(); |
| 1630 | // Don't do layout here, the window must call |
| 1631 | // relayout to be displayed, so we'll do it there. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1632 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1633 | //dump(); |
| 1634 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1635 | if (focusChanged) { |
| 1636 | if (mCurrentFocus != null) { |
| 1637 | mKeyWaiter.handleNewWindowLocked(mCurrentFocus); |
| 1638 | } |
| 1639 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1640 | if (localLOGV) Log.v( |
| 1641 | TAG, "New client " + client.asBinder() |
| 1642 | + ": window=" + win); |
| 1643 | } |
| 1644 | |
| 1645 | // sendNewConfiguration() checks caller permissions so we must call it with |
| 1646 | // privilege. updateOrientationFromAppTokens() clears and resets the caller |
| 1647 | // identity anyway, so it's safe to just clear & restore around this whole |
| 1648 | // block. |
| 1649 | final long origId = Binder.clearCallingIdentity(); |
| 1650 | if (reportNewConfig) { |
| 1651 | sendNewConfiguration(); |
| 1652 | } else { |
| 1653 | // Update Orientation after adding a window, only if the window needs to be |
| 1654 | // displayed right away |
| 1655 | if (win.isVisibleOrAdding()) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 1656 | if (updateOrientationFromAppTokensUnchecked(null, null) != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1657 | sendNewConfiguration(); |
| 1658 | } |
| 1659 | } |
| 1660 | } |
| 1661 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1662 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1663 | return res; |
| 1664 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1665 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1666 | public void removeWindow(Session session, IWindow client) { |
| 1667 | synchronized(mWindowMap) { |
| 1668 | WindowState win = windowForClientLocked(session, client); |
| 1669 | if (win == null) { |
| 1670 | return; |
| 1671 | } |
| 1672 | removeWindowLocked(session, win); |
| 1673 | } |
| 1674 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1675 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1676 | public void removeWindowLocked(Session session, WindowState win) { |
| 1677 | |
| 1678 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 1679 | TAG, "Remove " + win + " client=" |
| 1680 | + Integer.toHexString(System.identityHashCode( |
| 1681 | win.mClient.asBinder())) |
| 1682 | + ", surface=" + win.mSurface); |
| 1683 | |
| 1684 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1685 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1686 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 1687 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 1688 | + " mExiting=" + win.mExiting |
| 1689 | + " isAnimating=" + win.isAnimating() |
| 1690 | + " app-animation=" |
| 1691 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 1692 | + " inPendingTransaction=" |
| 1693 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 1694 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 1695 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 1696 | boolean wasVisible = false; |
| 1697 | // First, see if we need to run an animation. If we do, we have |
| 1698 | // to hold off on removing the window until the animation is done. |
| 1699 | // If the display is frozen, just remove immediately, since the |
| 1700 | // animation wouldn't be seen. |
| 1701 | if (win.mSurface != null && !mDisplayFrozen) { |
| 1702 | // If we are not currently running the exit animation, we |
| 1703 | // need to see about starting one. |
| 1704 | if (wasVisible=win.isWinVisibleLw()) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1705 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1706 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 1707 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 1708 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 1709 | } |
| 1710 | // Try starting an animation. |
| 1711 | if (applyAnimationLocked(win, transit, false)) { |
| 1712 | win.mExiting = true; |
| 1713 | } |
| 1714 | } |
| 1715 | if (win.mExiting || win.isAnimating()) { |
| 1716 | // The exit animation is running... wait for it! |
| 1717 | //Log.i(TAG, "*** Running exit animation..."); |
| 1718 | win.mExiting = true; |
| 1719 | win.mRemoveOnExit = true; |
| 1720 | mLayoutNeeded = true; |
| 1721 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 1722 | performLayoutAndPlaceSurfacesLocked(); |
| 1723 | if (win.mAppToken != null) { |
| 1724 | win.mAppToken.updateReportedVisibilityLocked(); |
| 1725 | } |
| 1726 | //dump(); |
| 1727 | Binder.restoreCallingIdentity(origId); |
| 1728 | return; |
| 1729 | } |
| 1730 | } |
| 1731 | |
| 1732 | removeWindowInnerLocked(session, win); |
| 1733 | // Removing a visible window will effect the computed orientation |
| 1734 | // So just update orientation if needed. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1735 | if (wasVisible && computeForcedAppOrientationLocked() |
| 1736 | != mForcedAppOrientation) { |
| 1737 | 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] | 1738 | } |
| 1739 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 1740 | Binder.restoreCallingIdentity(origId); |
| 1741 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1742 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1743 | private void removeWindowInnerLocked(Session session, WindowState win) { |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1744 | mKeyWaiter.finishedKey(session, win.mClient, true, |
| 1745 | KeyWaiter.RETURN_NOTHING); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1746 | mKeyWaiter.releasePendingPointerLocked(win.mSession); |
| 1747 | mKeyWaiter.releasePendingTrackballLocked(win.mSession); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1748 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1749 | win.mRemoved = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1750 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1751 | if (mInputMethodTarget == win) { |
| 1752 | moveInputMethodWindowsIfNeededLocked(false); |
| 1753 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1754 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1755 | mPolicy.removeWindowLw(win); |
| 1756 | win.removeLocked(); |
| 1757 | |
| 1758 | mWindowMap.remove(win.mClient.asBinder()); |
| 1759 | mWindows.remove(win); |
| 1760 | |
| 1761 | if (mInputMethodWindow == win) { |
| 1762 | mInputMethodWindow = null; |
| 1763 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 1764 | mInputMethodDialogs.remove(win); |
| 1765 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1766 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1767 | final WindowToken token = win.mToken; |
| 1768 | final AppWindowToken atoken = win.mAppToken; |
| 1769 | token.windows.remove(win); |
| 1770 | if (atoken != null) { |
| 1771 | atoken.allAppWindows.remove(win); |
| 1772 | } |
| 1773 | if (localLOGV) Log.v( |
| 1774 | TAG, "**** Removing window " + win + ": count=" |
| 1775 | + token.windows.size()); |
| 1776 | if (token.windows.size() == 0) { |
| 1777 | if (!token.explicit) { |
| 1778 | mTokenMap.remove(token.token); |
| 1779 | mTokenList.remove(token); |
| 1780 | } else if (atoken != null) { |
| 1781 | atoken.firstWindowDrawn = false; |
| 1782 | } |
| 1783 | } |
| 1784 | |
| 1785 | if (atoken != null) { |
| 1786 | if (atoken.startingWindow == win) { |
| 1787 | atoken.startingWindow = null; |
| 1788 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 1789 | // If this is the last window and we had requested a starting |
| 1790 | // transition window, well there is no point now. |
| 1791 | atoken.startingData = null; |
| 1792 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 1793 | // If this is the last window except for a starting transition |
| 1794 | // window, we need to get rid of the starting transition. |
| 1795 | if (DEBUG_STARTING_WINDOW) { |
| 1796 | Log.v(TAG, "Schedule remove starting " + token |
| 1797 | + ": no more real windows"); |
| 1798 | } |
| 1799 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 1800 | mH.sendMessage(m); |
| 1801 | } |
| 1802 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1803 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame^] | 1804 | if (win.mAttrs.type == TYPE_WALLPAPER || |
| 1805 | (win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 1806 | adjustWallpaperWindowsLocked(); |
| 1807 | } |
| 1808 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1809 | if (!mInLayout) { |
| 1810 | assignLayersLocked(); |
| 1811 | mLayoutNeeded = true; |
| 1812 | performLayoutAndPlaceSurfacesLocked(); |
| 1813 | if (win.mAppToken != null) { |
| 1814 | win.mAppToken.updateReportedVisibilityLocked(); |
| 1815 | } |
| 1816 | } |
| 1817 | } |
| 1818 | |
| 1819 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 1820 | long origId = Binder.clearCallingIdentity(); |
| 1821 | try { |
| 1822 | synchronized (mWindowMap) { |
| 1823 | WindowState w = windowForClientLocked(session, client); |
| 1824 | if ((w != null) && (w.mSurface != null)) { |
| 1825 | Surface.openTransaction(); |
| 1826 | try { |
| 1827 | w.mSurface.setTransparentRegionHint(region); |
| 1828 | } finally { |
| 1829 | Surface.closeTransaction(); |
| 1830 | } |
| 1831 | } |
| 1832 | } |
| 1833 | } finally { |
| 1834 | Binder.restoreCallingIdentity(origId); |
| 1835 | } |
| 1836 | } |
| 1837 | |
| 1838 | void setInsetsWindow(Session session, IWindow client, |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1839 | int touchableInsets, Rect contentInsets, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1840 | Rect visibleInsets) { |
| 1841 | long origId = Binder.clearCallingIdentity(); |
| 1842 | try { |
| 1843 | synchronized (mWindowMap) { |
| 1844 | WindowState w = windowForClientLocked(session, client); |
| 1845 | if (w != null) { |
| 1846 | w.mGivenInsetsPending = false; |
| 1847 | w.mGivenContentInsets.set(contentInsets); |
| 1848 | w.mGivenVisibleInsets.set(visibleInsets); |
| 1849 | w.mTouchableInsets = touchableInsets; |
| 1850 | mLayoutNeeded = true; |
| 1851 | performLayoutAndPlaceSurfacesLocked(); |
| 1852 | } |
| 1853 | } |
| 1854 | } finally { |
| 1855 | Binder.restoreCallingIdentity(origId); |
| 1856 | } |
| 1857 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1858 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1859 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 1860 | Rect outDisplayFrame) { |
| 1861 | synchronized(mWindowMap) { |
| 1862 | WindowState win = windowForClientLocked(session, client); |
| 1863 | if (win == null) { |
| 1864 | outDisplayFrame.setEmpty(); |
| 1865 | return; |
| 1866 | } |
| 1867 | outDisplayFrame.set(win.mDisplayFrame); |
| 1868 | } |
| 1869 | } |
| 1870 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1871 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y) { |
| 1872 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 1873 | window.mWallpaperX = x; |
| 1874 | window.mWallpaperY = y; |
| 1875 | |
| 1876 | if (mWallpaperTarget == window) { |
| 1877 | if (updateWallpaperOffsetLocked()) { |
| 1878 | performLayoutAndPlaceSurfacesLocked(); |
| 1879 | } |
| 1880 | } |
| 1881 | } |
| 1882 | } |
| 1883 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1884 | public int relayoutWindow(Session session, IWindow client, |
| 1885 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 1886 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 1887 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
| 1888 | Surface outSurface) { |
| 1889 | boolean displayed = false; |
| 1890 | boolean inTouchMode; |
| 1891 | Configuration newConfig = null; |
| 1892 | long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1893 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1894 | synchronized(mWindowMap) { |
| 1895 | WindowState win = windowForClientLocked(session, client); |
| 1896 | if (win == null) { |
| 1897 | return 0; |
| 1898 | } |
| 1899 | win.mRequestedWidth = requestedWidth; |
| 1900 | win.mRequestedHeight = requestedHeight; |
| 1901 | |
| 1902 | if (attrs != null) { |
| 1903 | mPolicy.adjustWindowParamsLw(attrs); |
| 1904 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1905 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1906 | int attrChanges = 0; |
| 1907 | int flagChanges = 0; |
| 1908 | if (attrs != null) { |
| 1909 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 1910 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 1911 | } |
| 1912 | |
| 1913 | if (localLOGV) Log.v( |
| 1914 | TAG, "Relayout given client " + client.asBinder() |
| 1915 | + " (" + win.mAttrs.getTitle() + ")"); |
| 1916 | |
| 1917 | |
| 1918 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 1919 | win.mAlpha = attrs.alpha; |
| 1920 | } |
| 1921 | |
| 1922 | final boolean scaledWindow = |
| 1923 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 1924 | |
| 1925 | if (scaledWindow) { |
| 1926 | // requested{Width|Height} Surface's physical size |
| 1927 | // attrs.{width|height} Size on screen |
| 1928 | win.mHScale = (attrs.width != requestedWidth) ? |
| 1929 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 1930 | win.mVScale = (attrs.height != requestedHeight) ? |
| 1931 | (attrs.height / (float)requestedHeight) : 1.0f; |
| 1932 | } |
| 1933 | |
| 1934 | boolean imMayMove = (flagChanges&( |
| 1935 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 1936 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1937 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1938 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 1939 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 1940 | || (!win.mRelayoutCalled); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1941 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1942 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 1943 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
| 1944 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1945 | win.mRelayoutCalled = true; |
| 1946 | final int oldVisibility = win.mViewVisibility; |
| 1947 | win.mViewVisibility = viewVisibility; |
| 1948 | if (viewVisibility == View.VISIBLE && |
| 1949 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 1950 | displayed = !win.isVisibleLw(); |
| 1951 | if (win.mExiting) { |
| 1952 | win.mExiting = false; |
| 1953 | win.mAnimation = null; |
| 1954 | } |
| 1955 | if (win.mDestroying) { |
| 1956 | win.mDestroying = false; |
| 1957 | mDestroySurface.remove(win); |
| 1958 | } |
| 1959 | if (oldVisibility == View.GONE) { |
| 1960 | win.mEnterAnimationPending = true; |
| 1961 | } |
| 1962 | if (displayed && win.mSurface != null && !win.mDrawPending |
| 1963 | && !win.mCommitDrawPending && !mDisplayFrozen) { |
| 1964 | applyEnterAnimationLocked(win); |
| 1965 | } |
| 1966 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 1967 | // To change the format, we need to re-build the surface. |
| 1968 | win.destroySurfaceLocked(); |
| 1969 | displayed = true; |
| 1970 | } |
| 1971 | try { |
| 1972 | Surface surface = win.createSurfaceLocked(); |
| 1973 | if (surface != null) { |
| 1974 | outSurface.copyFrom(surface); |
| 1975 | } else { |
| 1976 | outSurface.clear(); |
| 1977 | } |
| 1978 | } catch (Exception e) { |
| 1979 | Log.w(TAG, "Exception thrown when creating surface for client " |
| 1980 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 1981 | e); |
| 1982 | Binder.restoreCallingIdentity(origId); |
| 1983 | return 0; |
| 1984 | } |
| 1985 | if (displayed) { |
| 1986 | focusMayChange = true; |
| 1987 | } |
| 1988 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 1989 | && mInputMethodWindow == null) { |
| 1990 | mInputMethodWindow = win; |
| 1991 | imMayMove = true; |
| 1992 | } |
| 1993 | } else { |
| 1994 | win.mEnterAnimationPending = false; |
| 1995 | if (win.mSurface != null) { |
| 1996 | // If we are not currently running the exit animation, we |
| 1997 | // need to see about starting one. |
| 1998 | if (!win.mExiting) { |
| 1999 | // Try starting an animation; if there isn't one, we |
| 2000 | // can destroy the surface right away. |
| 2001 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2002 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2003 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2004 | } |
| 2005 | if (win.isWinVisibleLw() && |
| 2006 | applyAnimationLocked(win, transit, false)) { |
| 2007 | win.mExiting = true; |
| 2008 | mKeyWaiter.finishedKey(session, client, true, |
| 2009 | KeyWaiter.RETURN_NOTHING); |
| 2010 | } else if (win.isAnimating()) { |
| 2011 | // Currently in a hide animation... turn this into |
| 2012 | // an exit. |
| 2013 | win.mExiting = true; |
| 2014 | } else { |
| 2015 | if (mInputMethodWindow == win) { |
| 2016 | mInputMethodWindow = null; |
| 2017 | } |
| 2018 | win.destroySurfaceLocked(); |
| 2019 | } |
| 2020 | } |
| 2021 | } |
| 2022 | outSurface.clear(); |
| 2023 | } |
| 2024 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2025 | if (focusMayChange) { |
| 2026 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 2027 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2028 | imMayMove = false; |
| 2029 | } |
| 2030 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2031 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2032 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2033 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2034 | // reassign them at this point if the IM window state gets shuffled |
| 2035 | boolean assignLayers = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2036 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2037 | if (imMayMove) { |
| 2038 | if (moveInputMethodWindowsIfNeededLocked(false)) { |
| 2039 | assignLayers = true; |
| 2040 | } |
| 2041 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2042 | if (wallpaperMayMove) { |
| 2043 | if (adjustWallpaperWindowsLocked()) { |
| 2044 | assignLayers = true; |
| 2045 | } |
| 2046 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2047 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2048 | mLayoutNeeded = true; |
| 2049 | win.mGivenInsetsPending = insetsPending; |
| 2050 | if (assignLayers) { |
| 2051 | assignLayersLocked(); |
| 2052 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2053 | newConfig = updateOrientationFromAppTokensLocked(null, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2054 | performLayoutAndPlaceSurfacesLocked(); |
| 2055 | if (win.mAppToken != null) { |
| 2056 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2057 | } |
| 2058 | outFrame.set(win.mFrame); |
| 2059 | outContentInsets.set(win.mContentInsets); |
| 2060 | outVisibleInsets.set(win.mVisibleInsets); |
| 2061 | if (localLOGV) Log.v( |
| 2062 | TAG, "Relayout given client " + client.asBinder() |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2063 | + ", requestedWidth=" + requestedWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2064 | + ", requestedHeight=" + requestedHeight |
| 2065 | + ", viewVisibility=" + viewVisibility |
| 2066 | + "\nRelayout returning frame=" + outFrame |
| 2067 | + ", surface=" + outSurface); |
| 2068 | |
| 2069 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 2070 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2071 | |
| 2072 | inTouchMode = mInTouchMode; |
| 2073 | } |
| 2074 | |
| 2075 | if (newConfig != null) { |
| 2076 | sendNewConfiguration(); |
| 2077 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2078 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2079 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2080 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2081 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2082 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2083 | } |
| 2084 | |
| 2085 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2086 | final long origId = Binder.clearCallingIdentity(); |
| 2087 | synchronized(mWindowMap) { |
| 2088 | WindowState win = windowForClientLocked(session, client); |
| 2089 | if (win != null && win.finishDrawingLocked()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2090 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2091 | adjustWallpaperWindowsLocked(); |
| 2092 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2093 | mLayoutNeeded = true; |
| 2094 | performLayoutAndPlaceSurfacesLocked(); |
| 2095 | } |
| 2096 | } |
| 2097 | Binder.restoreCallingIdentity(origId); |
| 2098 | } |
| 2099 | |
| 2100 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
| 2101 | if (DEBUG_ANIM) Log.v(TAG, "Loading animations: params package=" |
| 2102 | + (lp != null ? lp.packageName : null) |
| 2103 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2104 | if (lp != null && lp.windowAnimations != 0) { |
| 2105 | // If this is a system resource, don't try to load it from the |
| 2106 | // application resources. It is nice to avoid loading application |
| 2107 | // resources if we can. |
| 2108 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2109 | int resId = lp.windowAnimations; |
| 2110 | if ((resId&0xFF000000) == 0x01000000) { |
| 2111 | packageName = "android"; |
| 2112 | } |
| 2113 | if (DEBUG_ANIM) Log.v(TAG, "Loading animations: picked package=" |
| 2114 | + packageName); |
| 2115 | return AttributeCache.instance().get(packageName, resId, |
| 2116 | com.android.internal.R.styleable.WindowAnimation); |
| 2117 | } |
| 2118 | return null; |
| 2119 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2120 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2121 | private void applyEnterAnimationLocked(WindowState win) { |
| 2122 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 2123 | if (win.mEnterAnimationPending) { |
| 2124 | win.mEnterAnimationPending = false; |
| 2125 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 2126 | } |
| 2127 | |
| 2128 | applyAnimationLocked(win, transit, true); |
| 2129 | } |
| 2130 | |
| 2131 | private boolean applyAnimationLocked(WindowState win, |
| 2132 | int transit, boolean isEntrance) { |
| 2133 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 2134 | // If we are trying to apply an animation, but already running |
| 2135 | // an animation of the same type, then just leave that one alone. |
| 2136 | return true; |
| 2137 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2138 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2139 | // Only apply an animation if the display isn't frozen. If it is |
| 2140 | // frozen, there is no reason to animate and it can cause strange |
| 2141 | // artifacts when we unfreeze the display if some different animation |
| 2142 | // is running. |
| 2143 | if (!mDisplayFrozen) { |
| 2144 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 2145 | int attr = -1; |
| 2146 | Animation a = null; |
| 2147 | if (anim != 0) { |
| 2148 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 2149 | } else { |
| 2150 | switch (transit) { |
| 2151 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 2152 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 2153 | break; |
| 2154 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 2155 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 2156 | break; |
| 2157 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 2158 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 2159 | break; |
| 2160 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 2161 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 2162 | break; |
| 2163 | } |
| 2164 | if (attr >= 0) { |
| 2165 | a = loadAnimation(win.mAttrs, attr); |
| 2166 | } |
| 2167 | } |
| 2168 | if (DEBUG_ANIM) Log.v(TAG, "applyAnimation: win=" + win |
| 2169 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 2170 | + " mAnimation=" + win.mAnimation |
| 2171 | + " isEntrance=" + isEntrance); |
| 2172 | if (a != null) { |
| 2173 | if (DEBUG_ANIM) { |
| 2174 | RuntimeException e = new RuntimeException(); |
| 2175 | e.fillInStackTrace(); |
| 2176 | Log.v(TAG, "Loaded animation " + a + " for " + win, e); |
| 2177 | } |
| 2178 | win.setAnimation(a); |
| 2179 | win.mAnimationIsEntrance = isEntrance; |
| 2180 | } |
| 2181 | } else { |
| 2182 | win.clearAnimation(); |
| 2183 | } |
| 2184 | |
| 2185 | return win.mAnimation != null; |
| 2186 | } |
| 2187 | |
| 2188 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 2189 | int anim = 0; |
| 2190 | Context context = mContext; |
| 2191 | if (animAttr >= 0) { |
| 2192 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 2193 | if (ent != null) { |
| 2194 | context = ent.context; |
| 2195 | anim = ent.array.getResourceId(animAttr, 0); |
| 2196 | } |
| 2197 | } |
| 2198 | if (anim != 0) { |
| 2199 | return AnimationUtils.loadAnimation(context, anim); |
| 2200 | } |
| 2201 | return null; |
| 2202 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2203 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2204 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 2205 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 2206 | // Only apply an animation if the display isn't frozen. If it is |
| 2207 | // frozen, there is no reason to animate and it can cause strange |
| 2208 | // artifacts when we unfreeze the display if some different animation |
| 2209 | // is running. |
| 2210 | if (!mDisplayFrozen) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2211 | Animation a; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 2212 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2213 | a = new FadeInOutAnimation(enter); |
| 2214 | if (DEBUG_ANIM) Log.v(TAG, |
| 2215 | "applying FadeInOutAnimation for a window in compatibility mode"); |
| 2216 | } else { |
| 2217 | int animAttr = 0; |
| 2218 | switch (transit) { |
| 2219 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 2220 | animAttr = enter |
| 2221 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 2222 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 2223 | break; |
| 2224 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 2225 | animAttr = enter |
| 2226 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 2227 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 2228 | break; |
| 2229 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 2230 | animAttr = enter |
| 2231 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 2232 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 2233 | break; |
| 2234 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 2235 | animAttr = enter |
| 2236 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 2237 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 2238 | break; |
| 2239 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 2240 | animAttr = enter |
| 2241 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 2242 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 2243 | break; |
| 2244 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 2245 | animAttr = enter |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 2246 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2247 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 2248 | break; |
| 2249 | } |
| 2250 | a = loadAnimation(lp, animAttr); |
| 2251 | if (DEBUG_ANIM) Log.v(TAG, "applyAnimation: wtoken=" + wtoken |
| 2252 | + " anim=" + a |
| 2253 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 2254 | + " transit=" + transit); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2255 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2256 | if (a != null) { |
| 2257 | if (DEBUG_ANIM) { |
| 2258 | RuntimeException e = new RuntimeException(); |
| 2259 | e.fillInStackTrace(); |
| 2260 | Log.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
| 2261 | } |
| 2262 | wtoken.setAnimation(a); |
| 2263 | } |
| 2264 | } else { |
| 2265 | wtoken.clearAnimation(); |
| 2266 | } |
| 2267 | |
| 2268 | return wtoken.animation != null; |
| 2269 | } |
| 2270 | |
| 2271 | // ------------------------------------------------------------- |
| 2272 | // Application Window Tokens |
| 2273 | // ------------------------------------------------------------- |
| 2274 | |
| 2275 | public void validateAppTokens(List tokens) { |
| 2276 | int v = tokens.size()-1; |
| 2277 | int m = mAppTokens.size()-1; |
| 2278 | while (v >= 0 && m >= 0) { |
| 2279 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2280 | if (wtoken.removed) { |
| 2281 | m--; |
| 2282 | continue; |
| 2283 | } |
| 2284 | if (tokens.get(v) != wtoken.token) { |
| 2285 | Log.w(TAG, "Tokens out of sync: external is " + tokens.get(v) |
| 2286 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 2287 | } |
| 2288 | v--; |
| 2289 | m--; |
| 2290 | } |
| 2291 | while (v >= 0) { |
| 2292 | Log.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v); |
| 2293 | v--; |
| 2294 | } |
| 2295 | while (m >= 0) { |
| 2296 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2297 | if (!wtoken.removed) { |
| 2298 | Log.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
| 2299 | } |
| 2300 | m--; |
| 2301 | } |
| 2302 | } |
| 2303 | |
| 2304 | boolean checkCallingPermission(String permission, String func) { |
| 2305 | // Quick check: if the calling permission is me, it's all okay. |
| 2306 | if (Binder.getCallingPid() == Process.myPid()) { |
| 2307 | return true; |
| 2308 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2309 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2310 | if (mContext.checkCallingPermission(permission) |
| 2311 | == PackageManager.PERMISSION_GRANTED) { |
| 2312 | return true; |
| 2313 | } |
| 2314 | String msg = "Permission Denial: " + func + " from pid=" |
| 2315 | + Binder.getCallingPid() |
| 2316 | + ", uid=" + Binder.getCallingUid() |
| 2317 | + " requires " + permission; |
| 2318 | Log.w(TAG, msg); |
| 2319 | return false; |
| 2320 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2321 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2322 | AppWindowToken findAppWindowToken(IBinder token) { |
| 2323 | WindowToken wtoken = mTokenMap.get(token); |
| 2324 | if (wtoken == null) { |
| 2325 | return null; |
| 2326 | } |
| 2327 | return wtoken.appWindowToken; |
| 2328 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2329 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2330 | public void addWindowToken(IBinder token, int type) { |
| 2331 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2332 | "addWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2333 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2334 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2335 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2336 | synchronized(mWindowMap) { |
| 2337 | WindowToken wtoken = mTokenMap.get(token); |
| 2338 | if (wtoken != null) { |
| 2339 | Log.w(TAG, "Attempted to add existing input method token: " + token); |
| 2340 | return; |
| 2341 | } |
| 2342 | wtoken = new WindowToken(token, type, true); |
| 2343 | mTokenMap.put(token, wtoken); |
| 2344 | mTokenList.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2345 | if (type == TYPE_WALLPAPER) { |
| 2346 | mWallpaperTokens.add(wtoken); |
| 2347 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2348 | } |
| 2349 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2350 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2351 | public void removeWindowToken(IBinder token) { |
| 2352 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2353 | "removeWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2354 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2355 | } |
| 2356 | |
| 2357 | final long origId = Binder.clearCallingIdentity(); |
| 2358 | synchronized(mWindowMap) { |
| 2359 | WindowToken wtoken = mTokenMap.remove(token); |
| 2360 | mTokenList.remove(wtoken); |
| 2361 | if (wtoken != null) { |
| 2362 | boolean delayed = false; |
| 2363 | if (!wtoken.hidden) { |
| 2364 | wtoken.hidden = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2365 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2366 | final int N = wtoken.windows.size(); |
| 2367 | boolean changed = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2368 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2369 | for (int i=0; i<N; i++) { |
| 2370 | WindowState win = wtoken.windows.get(i); |
| 2371 | |
| 2372 | if (win.isAnimating()) { |
| 2373 | delayed = true; |
| 2374 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2375 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2376 | if (win.isVisibleNow()) { |
| 2377 | applyAnimationLocked(win, |
| 2378 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 2379 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 2380 | KeyWaiter.RETURN_NOTHING); |
| 2381 | changed = true; |
| 2382 | } |
| 2383 | } |
| 2384 | |
| 2385 | if (changed) { |
| 2386 | mLayoutNeeded = true; |
| 2387 | performLayoutAndPlaceSurfacesLocked(); |
| 2388 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2389 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2390 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2391 | if (delayed) { |
| 2392 | mExitingTokens.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2393 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 2394 | mWallpaperTokens.remove(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2395 | } |
| 2396 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2397 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2398 | } else { |
| 2399 | Log.w(TAG, "Attempted to remove non-existing token: " + token); |
| 2400 | } |
| 2401 | } |
| 2402 | Binder.restoreCallingIdentity(origId); |
| 2403 | } |
| 2404 | |
| 2405 | public void addAppToken(int addPos, IApplicationToken token, |
| 2406 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 2407 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2408 | "addAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2409 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2410 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2411 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2412 | synchronized(mWindowMap) { |
| 2413 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 2414 | if (wtoken != null) { |
| 2415 | Log.w(TAG, "Attempted to add existing app token: " + token); |
| 2416 | return; |
| 2417 | } |
| 2418 | wtoken = new AppWindowToken(token); |
| 2419 | wtoken.groupId = groupId; |
| 2420 | wtoken.appFullscreen = fullscreen; |
| 2421 | wtoken.requestedOrientation = requestedOrientation; |
| 2422 | mAppTokens.add(addPos, wtoken); |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 2423 | 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] | 2424 | mTokenMap.put(token.asBinder(), wtoken); |
| 2425 | mTokenList.add(wtoken); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2427 | // Application tokens start out hidden. |
| 2428 | wtoken.hidden = true; |
| 2429 | wtoken.hiddenRequested = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2430 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2431 | //dump(); |
| 2432 | } |
| 2433 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2434 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2435 | public void setAppGroupId(IBinder token, int groupId) { |
| 2436 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2437 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2438 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2439 | } |
| 2440 | |
| 2441 | synchronized(mWindowMap) { |
| 2442 | AppWindowToken wtoken = findAppWindowToken(token); |
| 2443 | if (wtoken == null) { |
| 2444 | Log.w(TAG, "Attempted to set group id of non-existing app token: " + token); |
| 2445 | return; |
| 2446 | } |
| 2447 | wtoken.groupId = groupId; |
| 2448 | } |
| 2449 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2451 | public int getOrientationFromWindowsLocked() { |
| 2452 | int pos = mWindows.size() - 1; |
| 2453 | while (pos >= 0) { |
| 2454 | WindowState wtoken = (WindowState) mWindows.get(pos); |
| 2455 | pos--; |
| 2456 | if (wtoken.mAppToken != null) { |
| 2457 | // We hit an application window. so the orientation will be determined by the |
| 2458 | // app window. No point in continuing further. |
| 2459 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2460 | } |
| 2461 | if (!wtoken.isVisibleLw()) { |
| 2462 | continue; |
| 2463 | } |
| 2464 | int req = wtoken.mAttrs.screenOrientation; |
| 2465 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 2466 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 2467 | continue; |
| 2468 | } else { |
| 2469 | return req; |
| 2470 | } |
| 2471 | } |
| 2472 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2473 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2474 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2475 | public int getOrientationFromAppTokensLocked() { |
| 2476 | int pos = mAppTokens.size() - 1; |
| 2477 | int curGroup = 0; |
| 2478 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2479 | boolean findingBehind = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2480 | boolean haveGroup = false; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2481 | boolean lastFullscreen = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2482 | while (pos >= 0) { |
| 2483 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 2484 | pos--; |
Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2485 | // if we're about to tear down this window and not seek for |
| 2486 | // the behind activity, don't use it for orientation |
| 2487 | if (!findingBehind |
| 2488 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2489 | continue; |
| 2490 | } |
| 2491 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2492 | if (!haveGroup) { |
| 2493 | // We ignore any hidden applications on the top. |
| 2494 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
| 2495 | continue; |
| 2496 | } |
| 2497 | haveGroup = true; |
| 2498 | curGroup = wtoken.groupId; |
| 2499 | lastOrientation = wtoken.requestedOrientation; |
| 2500 | } else if (curGroup != wtoken.groupId) { |
| 2501 | // If we have hit a new application group, and the bottom |
| 2502 | // 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] | 2503 | // the orientation behind it, and the last app was |
| 2504 | // full screen, then we'll stick with the |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2505 | // user's orientation. |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2506 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 2507 | && lastFullscreen) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2508 | return lastOrientation; |
| 2509 | } |
| 2510 | } |
| 2511 | int or = wtoken.requestedOrientation; |
Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2512 | // If this application is fullscreen, and didn't explicitly say |
| 2513 | // 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] | 2514 | // orientation it has and ignores whatever is under it. |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2515 | lastFullscreen = wtoken.appFullscreen; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2516 | if (lastFullscreen |
Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2517 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2518 | return or; |
| 2519 | } |
| 2520 | // If this application has requested an explicit orientation, |
| 2521 | // then use it. |
| 2522 | if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || |
| 2523 | or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || |
| 2524 | or == ActivityInfo.SCREEN_ORIENTATION_SENSOR || |
| 2525 | or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR || |
| 2526 | or == ActivityInfo.SCREEN_ORIENTATION_USER) { |
| 2527 | return or; |
| 2528 | } |
Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2529 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2530 | } |
| 2531 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2532 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2533 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2534 | public Configuration updateOrientationFromAppTokens( |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2535 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2536 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2537 | "updateOrientationFromAppTokens()")) { |
| 2538 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 2539 | } |
| 2540 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2541 | Configuration config; |
| 2542 | long ident = Binder.clearCallingIdentity(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2543 | config = updateOrientationFromAppTokensUnchecked(currentConfig, |
| 2544 | freezeThisOneIfNeeded); |
| 2545 | Binder.restoreCallingIdentity(ident); |
| 2546 | return config; |
| 2547 | } |
| 2548 | |
| 2549 | Configuration updateOrientationFromAppTokensUnchecked( |
| 2550 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| 2551 | Configuration config; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2552 | synchronized(mWindowMap) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2553 | config = updateOrientationFromAppTokensLocked(currentConfig, freezeThisOneIfNeeded); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2554 | } |
| 2555 | if (config != null) { |
| 2556 | mLayoutNeeded = true; |
| 2557 | performLayoutAndPlaceSurfacesLocked(); |
| 2558 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2559 | return config; |
| 2560 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2561 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2562 | /* |
| 2563 | * The orientation is computed from non-application windows first. If none of |
| 2564 | * the non-application windows specify orientation, the orientation is computed from |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2565 | * application tokens. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2566 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 2567 | * android.os.IBinder) |
| 2568 | */ |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2569 | Configuration updateOrientationFromAppTokensLocked( |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2570 | Configuration appConfig, IBinder freezeThisOneIfNeeded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2571 | boolean changed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2572 | long ident = Binder.clearCallingIdentity(); |
| 2573 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2574 | int req = computeForcedAppOrientationLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2575 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2576 | if (req != mForcedAppOrientation) { |
| 2577 | changed = true; |
| 2578 | mForcedAppOrientation = req; |
| 2579 | //send a message to Policy indicating orientation change to take |
| 2580 | //action like disabling/enabling sensors etc., |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2581 | mPolicy.setCurrentOrientationLw(req); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2582 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2583 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2584 | if (changed) { |
| 2585 | changed = setRotationUncheckedLocked( |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 2586 | WindowManagerPolicy.USE_LAST_ROTATION, |
| 2587 | mLastRotationFlags & (~Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2588 | if (changed) { |
| 2589 | if (freezeThisOneIfNeeded != null) { |
| 2590 | AppWindowToken wtoken = findAppWindowToken( |
| 2591 | freezeThisOneIfNeeded); |
| 2592 | if (wtoken != null) { |
| 2593 | startAppFreezingScreenLocked(wtoken, |
| 2594 | ActivityInfo.CONFIG_ORIENTATION); |
| 2595 | } |
| 2596 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 2597 | return computeNewConfigurationLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2598 | } |
| 2599 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2600 | |
| 2601 | // No obvious action we need to take, but if our current |
| 2602 | // state mismatches the activity maanager's, update it |
| 2603 | if (appConfig != null) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 2604 | mTempConfiguration.setToDefaults(); |
| 2605 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 2606 | if (appConfig.diff(mTempConfiguration) != 0) { |
| 2607 | Log.i(TAG, "Config changed: " + mTempConfiguration); |
| 2608 | return new Configuration(mTempConfiguration); |
| 2609 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2610 | } |
| 2611 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2612 | } finally { |
| 2613 | Binder.restoreCallingIdentity(ident); |
| 2614 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2615 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2616 | return null; |
| 2617 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2618 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2619 | int computeForcedAppOrientationLocked() { |
| 2620 | int req = getOrientationFromWindowsLocked(); |
| 2621 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 2622 | req = getOrientationFromAppTokensLocked(); |
| 2623 | } |
| 2624 | return req; |
| 2625 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2626 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2627 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 2628 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2629 | "setAppOrientation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2630 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2631 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2632 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2633 | synchronized(mWindowMap) { |
| 2634 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 2635 | if (wtoken == null) { |
| 2636 | Log.w(TAG, "Attempted to set orientation of non-existing app token: " + token); |
| 2637 | return; |
| 2638 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2639 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2640 | wtoken.requestedOrientation = requestedOrientation; |
| 2641 | } |
| 2642 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2643 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2644 | public int getAppOrientation(IApplicationToken token) { |
| 2645 | synchronized(mWindowMap) { |
| 2646 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 2647 | if (wtoken == null) { |
| 2648 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2649 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2650 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2651 | return wtoken.requestedOrientation; |
| 2652 | } |
| 2653 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2654 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2655 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 2656 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2657 | "setFocusedApp()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2658 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2659 | } |
| 2660 | |
| 2661 | synchronized(mWindowMap) { |
| 2662 | boolean changed = false; |
| 2663 | if (token == null) { |
| 2664 | if (DEBUG_FOCUS) Log.v(TAG, "Clearing focused app, was " + mFocusedApp); |
| 2665 | changed = mFocusedApp != null; |
| 2666 | mFocusedApp = null; |
| 2667 | mKeyWaiter.tickle(); |
| 2668 | } else { |
| 2669 | AppWindowToken newFocus = findAppWindowToken(token); |
| 2670 | if (newFocus == null) { |
| 2671 | Log.w(TAG, "Attempted to set focus to non-existing app token: " + token); |
| 2672 | return; |
| 2673 | } |
| 2674 | changed = mFocusedApp != newFocus; |
| 2675 | mFocusedApp = newFocus; |
| 2676 | if (DEBUG_FOCUS) Log.v(TAG, "Set focused app to: " + mFocusedApp); |
| 2677 | mKeyWaiter.tickle(); |
| 2678 | } |
| 2679 | |
| 2680 | if (moveFocusNow && changed) { |
| 2681 | final long origId = Binder.clearCallingIdentity(); |
| 2682 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2683 | Binder.restoreCallingIdentity(origId); |
| 2684 | } |
| 2685 | } |
| 2686 | } |
| 2687 | |
| 2688 | public void prepareAppTransition(int transit) { |
| 2689 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2690 | "prepareAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2691 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2692 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2693 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2694 | synchronized(mWindowMap) { |
| 2695 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 2696 | TAG, "Prepare app transition: transit=" + transit |
| 2697 | + " mNextAppTransition=" + mNextAppTransition); |
| 2698 | if (!mDisplayFrozen) { |
| 2699 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
| 2700 | mNextAppTransition = transit; |
Dianne Hackborn | d7cd29d | 2009-07-01 11:22:45 -0700 | [diff] [blame] | 2701 | } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 2702 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 2703 | // Opening a new task always supersedes a close for the anim. |
| 2704 | mNextAppTransition = transit; |
| 2705 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 2706 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 2707 | // Opening a new activity always supersedes a close for the anim. |
| 2708 | mNextAppTransition = transit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2709 | } |
| 2710 | mAppTransitionReady = false; |
| 2711 | mAppTransitionTimeout = false; |
| 2712 | mStartingIconInTransition = false; |
| 2713 | mSkipAppTransitionAnimation = false; |
| 2714 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 2715 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 2716 | 5000); |
| 2717 | } |
| 2718 | } |
| 2719 | } |
| 2720 | |
| 2721 | public int getPendingAppTransition() { |
| 2722 | return mNextAppTransition; |
| 2723 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2724 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2725 | public void executeAppTransition() { |
| 2726 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2727 | "executeAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2728 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2729 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2730 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2731 | synchronized(mWindowMap) { |
| 2732 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 2733 | TAG, "Execute app transition: mNextAppTransition=" + mNextAppTransition); |
| 2734 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) { |
| 2735 | mAppTransitionReady = true; |
| 2736 | final long origId = Binder.clearCallingIdentity(); |
| 2737 | performLayoutAndPlaceSurfacesLocked(); |
| 2738 | Binder.restoreCallingIdentity(origId); |
| 2739 | } |
| 2740 | } |
| 2741 | } |
| 2742 | |
| 2743 | public void setAppStartingWindow(IBinder token, String pkg, |
| 2744 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| 2745 | IBinder transferFrom, boolean createIfNeeded) { |
| 2746 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2747 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2748 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2749 | } |
| 2750 | |
| 2751 | synchronized(mWindowMap) { |
| 2752 | if (DEBUG_STARTING_WINDOW) Log.v( |
| 2753 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 2754 | + " transferFrom=" + transferFrom); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2755 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2756 | AppWindowToken wtoken = findAppWindowToken(token); |
| 2757 | if (wtoken == null) { |
| 2758 | Log.w(TAG, "Attempted to set icon of non-existing app token: " + token); |
| 2759 | return; |
| 2760 | } |
| 2761 | |
| 2762 | // If the display is frozen, we won't do anything until the |
| 2763 | // actual window is displayed so there is no reason to put in |
| 2764 | // the starting window. |
| 2765 | if (mDisplayFrozen) { |
| 2766 | return; |
| 2767 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2768 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2769 | if (wtoken.startingData != null) { |
| 2770 | return; |
| 2771 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2772 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2773 | if (transferFrom != null) { |
| 2774 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 2775 | if (ttoken != null) { |
| 2776 | WindowState startingWindow = ttoken.startingWindow; |
| 2777 | if (startingWindow != null) { |
| 2778 | if (mStartingIconInTransition) { |
| 2779 | // In this case, the starting icon has already |
| 2780 | // been displayed, so start letting windows get |
| 2781 | // shown immediately without any more transitions. |
| 2782 | mSkipAppTransitionAnimation = true; |
| 2783 | } |
| 2784 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 2785 | "Moving existing starting from " + ttoken |
| 2786 | + " to " + wtoken); |
| 2787 | final long origId = Binder.clearCallingIdentity(); |
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 | // Transfer the starting window over to the new |
| 2790 | // token. |
| 2791 | wtoken.startingData = ttoken.startingData; |
| 2792 | wtoken.startingView = ttoken.startingView; |
| 2793 | wtoken.startingWindow = startingWindow; |
| 2794 | ttoken.startingData = null; |
| 2795 | ttoken.startingView = null; |
| 2796 | ttoken.startingWindow = null; |
| 2797 | ttoken.startingMoved = true; |
| 2798 | startingWindow.mToken = wtoken; |
Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 2799 | startingWindow.mRootToken = wtoken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2800 | startingWindow.mAppToken = wtoken; |
| 2801 | mWindows.remove(startingWindow); |
| 2802 | ttoken.windows.remove(startingWindow); |
| 2803 | ttoken.allAppWindows.remove(startingWindow); |
| 2804 | addWindowToListInOrderLocked(startingWindow, true); |
| 2805 | wtoken.allAppWindows.add(startingWindow); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2806 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2807 | // Propagate other interesting state between the |
| 2808 | // tokens. If the old token is displayed, we should |
| 2809 | // immediately force the new one to be displayed. If |
| 2810 | // it is animating, we need to move that animation to |
| 2811 | // the new one. |
| 2812 | if (ttoken.allDrawn) { |
| 2813 | wtoken.allDrawn = true; |
| 2814 | } |
| 2815 | if (ttoken.firstWindowDrawn) { |
| 2816 | wtoken.firstWindowDrawn = true; |
| 2817 | } |
| 2818 | if (!ttoken.hidden) { |
| 2819 | wtoken.hidden = false; |
| 2820 | wtoken.hiddenRequested = false; |
| 2821 | wtoken.willBeHidden = false; |
| 2822 | } |
| 2823 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 2824 | wtoken.clientHidden = ttoken.clientHidden; |
| 2825 | wtoken.sendAppVisibilityToClients(); |
| 2826 | } |
| 2827 | if (ttoken.animation != null) { |
| 2828 | wtoken.animation = ttoken.animation; |
| 2829 | wtoken.animating = ttoken.animating; |
| 2830 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 2831 | ttoken.animation = null; |
| 2832 | ttoken.animLayerAdjustment = 0; |
| 2833 | wtoken.updateLayers(); |
| 2834 | ttoken.updateLayers(); |
| 2835 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2836 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2837 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2838 | mLayoutNeeded = true; |
| 2839 | performLayoutAndPlaceSurfacesLocked(); |
| 2840 | Binder.restoreCallingIdentity(origId); |
| 2841 | return; |
| 2842 | } else if (ttoken.startingData != null) { |
| 2843 | // The previous app was getting ready to show a |
| 2844 | // starting window, but hasn't yet done so. Steal it! |
| 2845 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 2846 | "Moving pending starting from " + ttoken |
| 2847 | + " to " + wtoken); |
| 2848 | wtoken.startingData = ttoken.startingData; |
| 2849 | ttoken.startingData = null; |
| 2850 | ttoken.startingMoved = true; |
| 2851 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 2852 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 2853 | // want to process the message ASAP, before any other queued |
| 2854 | // messages. |
| 2855 | mH.sendMessageAtFrontOfQueue(m); |
| 2856 | return; |
| 2857 | } |
| 2858 | } |
| 2859 | } |
| 2860 | |
| 2861 | // There is no existing starting window, and the caller doesn't |
| 2862 | // want us to create one, so that's it! |
| 2863 | if (!createIfNeeded) { |
| 2864 | return; |
| 2865 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2866 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2867 | mStartingIconInTransition = true; |
| 2868 | wtoken.startingData = new StartingData( |
| 2869 | pkg, theme, nonLocalizedLabel, |
| 2870 | labelRes, icon); |
| 2871 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 2872 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 2873 | // want to process the message ASAP, before any other queued |
| 2874 | // messages. |
| 2875 | mH.sendMessageAtFrontOfQueue(m); |
| 2876 | } |
| 2877 | } |
| 2878 | |
| 2879 | public void setAppWillBeHidden(IBinder token) { |
| 2880 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2881 | "setAppWillBeHidden()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2882 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2883 | } |
| 2884 | |
| 2885 | AppWindowToken wtoken; |
| 2886 | |
| 2887 | synchronized(mWindowMap) { |
| 2888 | wtoken = findAppWindowToken(token); |
| 2889 | if (wtoken == null) { |
| 2890 | Log.w(TAG, "Attempted to set will be hidden of non-existing app token: " + token); |
| 2891 | return; |
| 2892 | } |
| 2893 | wtoken.willBeHidden = true; |
| 2894 | } |
| 2895 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2896 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2897 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 2898 | boolean visible, int transit, boolean performLayout) { |
| 2899 | boolean delayed = false; |
| 2900 | |
| 2901 | if (wtoken.clientHidden == visible) { |
| 2902 | wtoken.clientHidden = !visible; |
| 2903 | wtoken.sendAppVisibilityToClients(); |
| 2904 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2905 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2906 | wtoken.willBeHidden = false; |
| 2907 | if (wtoken.hidden == visible) { |
| 2908 | final int N = wtoken.allAppWindows.size(); |
| 2909 | boolean changed = false; |
| 2910 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 2911 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 2912 | + " performLayout=" + performLayout); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2913 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2914 | boolean runningAppAnimation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2916 | if (transit != WindowManagerPolicy.TRANSIT_NONE) { |
| 2917 | if (wtoken.animation == sDummyAnimation) { |
| 2918 | wtoken.animation = null; |
| 2919 | } |
| 2920 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 2921 | changed = true; |
| 2922 | if (wtoken.animation != null) { |
| 2923 | delayed = runningAppAnimation = true; |
| 2924 | } |
| 2925 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2926 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2927 | for (int i=0; i<N; i++) { |
| 2928 | WindowState win = wtoken.allAppWindows.get(i); |
| 2929 | if (win == wtoken.startingWindow) { |
| 2930 | continue; |
| 2931 | } |
| 2932 | |
| 2933 | if (win.isAnimating()) { |
| 2934 | delayed = true; |
| 2935 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2936 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2937 | //Log.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
| 2938 | //win.dump(" "); |
| 2939 | if (visible) { |
| 2940 | if (!win.isVisibleNow()) { |
| 2941 | if (!runningAppAnimation) { |
| 2942 | applyAnimationLocked(win, |
| 2943 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 2944 | } |
| 2945 | changed = true; |
| 2946 | } |
| 2947 | } else if (win.isVisibleNow()) { |
| 2948 | if (!runningAppAnimation) { |
| 2949 | applyAnimationLocked(win, |
| 2950 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 2951 | } |
| 2952 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 2953 | KeyWaiter.RETURN_NOTHING); |
| 2954 | changed = true; |
| 2955 | } |
| 2956 | } |
| 2957 | |
| 2958 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 2959 | if (!visible) { |
| 2960 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 2961 | } else { |
| 2962 | // If we are being set visible, and the starting window is |
| 2963 | // not yet displayed, then make sure it doesn't get displayed. |
| 2964 | WindowState swin = wtoken.startingWindow; |
| 2965 | if (swin != null && (swin.mDrawPending |
| 2966 | || swin.mCommitDrawPending)) { |
| 2967 | swin.mPolicyVisibility = false; |
| 2968 | swin.mPolicyVisibilityAfterAnim = false; |
| 2969 | } |
| 2970 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2971 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2972 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "setTokenVisibilityLocked: " + wtoken |
| 2973 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 2974 | + wtoken.hiddenRequested); |
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 | if (changed && performLayout) { |
| 2977 | mLayoutNeeded = true; |
| 2978 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2979 | performLayoutAndPlaceSurfacesLocked(); |
| 2980 | } |
| 2981 | } |
| 2982 | |
| 2983 | if (wtoken.animation != null) { |
| 2984 | delayed = true; |
| 2985 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2986 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2987 | return delayed; |
| 2988 | } |
| 2989 | |
| 2990 | public void setAppVisibility(IBinder token, boolean visible) { |
| 2991 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2992 | "setAppVisibility()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2993 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2994 | } |
| 2995 | |
| 2996 | AppWindowToken wtoken; |
| 2997 | |
| 2998 | synchronized(mWindowMap) { |
| 2999 | wtoken = findAppWindowToken(token); |
| 3000 | if (wtoken == null) { |
| 3001 | Log.w(TAG, "Attempted to set visibility of non-existing app token: " + token); |
| 3002 | return; |
| 3003 | } |
| 3004 | |
| 3005 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
| 3006 | RuntimeException e = new RuntimeException(); |
| 3007 | e.fillInStackTrace(); |
| 3008 | Log.v(TAG, "setAppVisibility(" + token + ", " + visible |
| 3009 | + "): mNextAppTransition=" + mNextAppTransition |
| 3010 | + " hidden=" + wtoken.hidden |
| 3011 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3012 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3013 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3014 | // If we are preparing an app transition, then delay changing |
| 3015 | // the visibility of this token until we execute that transition. |
| 3016 | if (!mDisplayFrozen && mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) { |
| 3017 | // Already in requested state, don't do anything more. |
| 3018 | if (wtoken.hiddenRequested != visible) { |
| 3019 | return; |
| 3020 | } |
| 3021 | wtoken.hiddenRequested = !visible; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3022 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3023 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 3024 | TAG, "Setting dummy animation on: " + wtoken); |
| 3025 | wtoken.setDummyAnimation(); |
| 3026 | mOpeningApps.remove(wtoken); |
| 3027 | mClosingApps.remove(wtoken); |
| 3028 | wtoken.inPendingTransaction = true; |
| 3029 | if (visible) { |
| 3030 | mOpeningApps.add(wtoken); |
| 3031 | wtoken.allDrawn = false; |
| 3032 | wtoken.startingDisplayed = false; |
| 3033 | wtoken.startingMoved = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3034 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3035 | if (wtoken.clientHidden) { |
| 3036 | // In the case where we are making an app visible |
| 3037 | // but holding off for a transition, we still need |
| 3038 | // to tell the client to make its windows visible so |
| 3039 | // they get drawn. Otherwise, we will wait on |
| 3040 | // performing the transition until all windows have |
| 3041 | // been drawn, they never will be, and we are sad. |
| 3042 | wtoken.clientHidden = false; |
| 3043 | wtoken.sendAppVisibilityToClients(); |
| 3044 | } |
| 3045 | } else { |
| 3046 | mClosingApps.add(wtoken); |
| 3047 | } |
| 3048 | return; |
| 3049 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3050 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3051 | final long origId = Binder.clearCallingIdentity(); |
| 3052 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_NONE, true); |
| 3053 | wtoken.updateReportedVisibilityLocked(); |
| 3054 | Binder.restoreCallingIdentity(origId); |
| 3055 | } |
| 3056 | } |
| 3057 | |
| 3058 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3059 | boolean unfreezeSurfaceNow, boolean force) { |
| 3060 | if (wtoken.freezingScreen) { |
| 3061 | if (DEBUG_ORIENTATION) Log.v(TAG, "Clear freezing of " + wtoken |
| 3062 | + " force=" + force); |
| 3063 | final int N = wtoken.allAppWindows.size(); |
| 3064 | boolean unfrozeWindows = false; |
| 3065 | for (int i=0; i<N; i++) { |
| 3066 | WindowState w = wtoken.allAppWindows.get(i); |
| 3067 | if (w.mAppFreezing) { |
| 3068 | w.mAppFreezing = false; |
| 3069 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 3070 | w.mOrientationChanging = true; |
| 3071 | } |
| 3072 | unfrozeWindows = true; |
| 3073 | } |
| 3074 | } |
| 3075 | if (force || unfrozeWindows) { |
| 3076 | if (DEBUG_ORIENTATION) Log.v(TAG, "No longer freezing: " + wtoken); |
| 3077 | wtoken.freezingScreen = false; |
| 3078 | mAppsFreezingScreen--; |
| 3079 | } |
| 3080 | if (unfreezeSurfaceNow) { |
| 3081 | if (unfrozeWindows) { |
| 3082 | mLayoutNeeded = true; |
| 3083 | performLayoutAndPlaceSurfacesLocked(); |
| 3084 | } |
| 3085 | if (mAppsFreezingScreen == 0 && !mWindowsFreezingScreen) { |
| 3086 | stopFreezingDisplayLocked(); |
| 3087 | } |
| 3088 | } |
| 3089 | } |
| 3090 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3091 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3092 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3093 | int configChanges) { |
| 3094 | if (DEBUG_ORIENTATION) { |
| 3095 | RuntimeException e = new RuntimeException(); |
| 3096 | e.fillInStackTrace(); |
| 3097 | Log.i(TAG, "Set freezing of " + wtoken.appToken |
| 3098 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 3099 | + wtoken.freezingScreen, e); |
| 3100 | } |
| 3101 | if (!wtoken.hiddenRequested) { |
| 3102 | if (!wtoken.freezingScreen) { |
| 3103 | wtoken.freezingScreen = true; |
| 3104 | mAppsFreezingScreen++; |
| 3105 | if (mAppsFreezingScreen == 1) { |
| 3106 | startFreezingDisplayLocked(); |
| 3107 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 3108 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 3109 | 5000); |
| 3110 | } |
| 3111 | } |
| 3112 | final int N = wtoken.allAppWindows.size(); |
| 3113 | for (int i=0; i<N; i++) { |
| 3114 | WindowState w = wtoken.allAppWindows.get(i); |
| 3115 | w.mAppFreezing = true; |
| 3116 | } |
| 3117 | } |
| 3118 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3119 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3120 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 3121 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3122 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3123 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3124 | } |
| 3125 | |
| 3126 | synchronized(mWindowMap) { |
| 3127 | if (configChanges == 0 && !mDisplayFrozen) { |
| 3128 | if (DEBUG_ORIENTATION) Log.v(TAG, "Skipping set freeze of " + token); |
| 3129 | return; |
| 3130 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3131 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3132 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3133 | if (wtoken == null || wtoken.appToken == null) { |
| 3134 | Log.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken); |
| 3135 | return; |
| 3136 | } |
| 3137 | final long origId = Binder.clearCallingIdentity(); |
| 3138 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 3139 | Binder.restoreCallingIdentity(origId); |
| 3140 | } |
| 3141 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3142 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3143 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 3144 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3145 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3146 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3147 | } |
| 3148 | |
| 3149 | synchronized(mWindowMap) { |
| 3150 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3151 | if (wtoken == null || wtoken.appToken == null) { |
| 3152 | return; |
| 3153 | } |
| 3154 | final long origId = Binder.clearCallingIdentity(); |
| 3155 | if (DEBUG_ORIENTATION) Log.v(TAG, "Clear freezing of " + token |
| 3156 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 3157 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 3158 | Binder.restoreCallingIdentity(origId); |
| 3159 | } |
| 3160 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3161 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3162 | public void removeAppToken(IBinder token) { |
| 3163 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3164 | "removeAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3165 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3166 | } |
| 3167 | |
| 3168 | AppWindowToken wtoken = null; |
| 3169 | AppWindowToken startingToken = null; |
| 3170 | boolean delayed = false; |
| 3171 | |
| 3172 | final long origId = Binder.clearCallingIdentity(); |
| 3173 | synchronized(mWindowMap) { |
| 3174 | WindowToken basewtoken = mTokenMap.remove(token); |
| 3175 | mTokenList.remove(basewtoken); |
| 3176 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
| 3177 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "Removing app token: " + wtoken); |
| 3178 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_NONE, true); |
| 3179 | wtoken.inPendingTransaction = false; |
| 3180 | mOpeningApps.remove(wtoken); |
| 3181 | if (mClosingApps.contains(wtoken)) { |
| 3182 | delayed = true; |
| 3183 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) { |
| 3184 | mClosingApps.add(wtoken); |
| 3185 | delayed = true; |
| 3186 | } |
| 3187 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 3188 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 3189 | + " animation=" + wtoken.animation |
| 3190 | + " animating=" + wtoken.animating); |
| 3191 | if (delayed) { |
| 3192 | // set the token aside because it has an active animation to be finished |
| 3193 | mExitingAppTokens.add(wtoken); |
| 3194 | } |
| 3195 | mAppTokens.remove(wtoken); |
| 3196 | wtoken.removed = true; |
| 3197 | if (wtoken.startingData != null) { |
| 3198 | startingToken = wtoken; |
| 3199 | } |
| 3200 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3201 | if (mFocusedApp == wtoken) { |
| 3202 | if (DEBUG_FOCUS) Log.v(TAG, "Removing focused app token:" + wtoken); |
| 3203 | mFocusedApp = null; |
| 3204 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3205 | mKeyWaiter.tickle(); |
| 3206 | } |
| 3207 | } else { |
| 3208 | Log.w(TAG, "Attempted to remove non-existing app token: " + token); |
| 3209 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3210 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3211 | if (!delayed && wtoken != null) { |
| 3212 | wtoken.updateReportedVisibilityLocked(); |
| 3213 | } |
| 3214 | } |
| 3215 | Binder.restoreCallingIdentity(origId); |
| 3216 | |
| 3217 | if (startingToken != null) { |
| 3218 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Schedule remove starting " |
| 3219 | + startingToken + ": app token removed"); |
| 3220 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 3221 | mH.sendMessage(m); |
| 3222 | } |
| 3223 | } |
| 3224 | |
| 3225 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 3226 | final int NW = token.windows.size(); |
| 3227 | for (int i=0; i<NW; i++) { |
| 3228 | WindowState win = token.windows.get(i); |
| 3229 | mWindows.remove(win); |
| 3230 | int j = win.mChildWindows.size(); |
| 3231 | while (j > 0) { |
| 3232 | j--; |
| 3233 | mWindows.remove(win.mChildWindows.get(j)); |
| 3234 | } |
| 3235 | } |
| 3236 | return NW > 0; |
| 3237 | } |
| 3238 | |
| 3239 | void dumpAppTokensLocked() { |
| 3240 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| 3241 | Log.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
| 3242 | } |
| 3243 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3244 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3245 | void dumpWindowsLocked() { |
| 3246 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 3247 | Log.v(TAG, " #" + i + ": " + mWindows.get(i)); |
| 3248 | } |
| 3249 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3250 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3251 | private int findWindowOffsetLocked(int tokenPos) { |
| 3252 | final int NW = mWindows.size(); |
| 3253 | |
| 3254 | if (tokenPos >= mAppTokens.size()) { |
| 3255 | int i = NW; |
| 3256 | while (i > 0) { |
| 3257 | i--; |
| 3258 | WindowState win = (WindowState)mWindows.get(i); |
| 3259 | if (win.getAppToken() != null) { |
| 3260 | return i+1; |
| 3261 | } |
| 3262 | } |
| 3263 | } |
| 3264 | |
| 3265 | while (tokenPos > 0) { |
| 3266 | // Find the first app token below the new position that has |
| 3267 | // a window displayed. |
| 3268 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
| 3269 | if (DEBUG_REORDER) Log.v(TAG, "Looking for lower windows @ " |
| 3270 | + tokenPos + " -- " + wtoken.token); |
| 3271 | int i = wtoken.windows.size(); |
| 3272 | while (i > 0) { |
| 3273 | i--; |
| 3274 | WindowState win = wtoken.windows.get(i); |
| 3275 | int j = win.mChildWindows.size(); |
| 3276 | while (j > 0) { |
| 3277 | j--; |
| 3278 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| 3279 | if (cwin.mSubLayer >= 0 ) { |
| 3280 | for (int pos=NW-1; pos>=0; pos--) { |
| 3281 | if (mWindows.get(pos) == cwin) { |
| 3282 | if (DEBUG_REORDER) Log.v(TAG, |
| 3283 | "Found child win @" + (pos+1)); |
| 3284 | return pos+1; |
| 3285 | } |
| 3286 | } |
| 3287 | } |
| 3288 | } |
| 3289 | for (int pos=NW-1; pos>=0; pos--) { |
| 3290 | if (mWindows.get(pos) == win) { |
| 3291 | if (DEBUG_REORDER) Log.v(TAG, "Found win @" + (pos+1)); |
| 3292 | return pos+1; |
| 3293 | } |
| 3294 | } |
| 3295 | } |
| 3296 | tokenPos--; |
| 3297 | } |
| 3298 | |
| 3299 | return 0; |
| 3300 | } |
| 3301 | |
| 3302 | private final int reAddWindowLocked(int index, WindowState win) { |
| 3303 | final int NCW = win.mChildWindows.size(); |
| 3304 | boolean added = false; |
| 3305 | for (int j=0; j<NCW; j++) { |
| 3306 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| 3307 | if (!added && cwin.mSubLayer >= 0) { |
| 3308 | mWindows.add(index, win); |
| 3309 | index++; |
| 3310 | added = true; |
| 3311 | } |
| 3312 | mWindows.add(index, cwin); |
| 3313 | index++; |
| 3314 | } |
| 3315 | if (!added) { |
| 3316 | mWindows.add(index, win); |
| 3317 | index++; |
| 3318 | } |
| 3319 | return index; |
| 3320 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3321 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3322 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 3323 | final int NW = token.windows.size(); |
| 3324 | for (int i=0; i<NW; i++) { |
| 3325 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 3326 | } |
| 3327 | return index; |
| 3328 | } |
| 3329 | |
| 3330 | public void moveAppToken(int index, IBinder token) { |
| 3331 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3332 | "moveAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3333 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3334 | } |
| 3335 | |
| 3336 | synchronized(mWindowMap) { |
| 3337 | if (DEBUG_REORDER) Log.v(TAG, "Initial app tokens:"); |
| 3338 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 3339 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 3340 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
| 3341 | Log.w(TAG, "Attempting to reorder token that doesn't exist: " |
| 3342 | + token + " (" + wtoken + ")"); |
| 3343 | return; |
| 3344 | } |
| 3345 | mAppTokens.add(index, wtoken); |
| 3346 | if (DEBUG_REORDER) Log.v(TAG, "Moved " + token + " to " + index + ":"); |
| 3347 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3348 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3349 | final long origId = Binder.clearCallingIdentity(); |
| 3350 | if (DEBUG_REORDER) Log.v(TAG, "Removing windows in " + token + ":"); |
| 3351 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3352 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
| 3353 | if (DEBUG_REORDER) Log.v(TAG, "Adding windows back in:"); |
| 3354 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3355 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
| 3356 | if (DEBUG_REORDER) Log.v(TAG, "Final window list:"); |
| 3357 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3358 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3359 | mLayoutNeeded = true; |
| 3360 | performLayoutAndPlaceSurfacesLocked(); |
| 3361 | } |
| 3362 | Binder.restoreCallingIdentity(origId); |
| 3363 | } |
| 3364 | } |
| 3365 | |
| 3366 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 3367 | // XXX This should be done more efficiently! |
| 3368 | // (take advantage of the fact that both lists should be |
| 3369 | // ordered in the same way.) |
| 3370 | int N = tokens.size(); |
| 3371 | for (int i=0; i<N; i++) { |
| 3372 | IBinder token = tokens.get(i); |
| 3373 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 3374 | if (!mAppTokens.remove(wtoken)) { |
| 3375 | Log.w(TAG, "Attempting to reorder token that doesn't exist: " |
| 3376 | + token + " (" + wtoken + ")"); |
| 3377 | i--; |
| 3378 | N--; |
| 3379 | } |
| 3380 | } |
| 3381 | } |
| 3382 | |
| 3383 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 3384 | // First remove all of the windows from the list. |
| 3385 | final int N = tokens.size(); |
| 3386 | int i; |
| 3387 | for (i=0; i<N; i++) { |
| 3388 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 3389 | if (token != null) { |
| 3390 | tmpRemoveAppWindowsLocked(token); |
| 3391 | } |
| 3392 | } |
| 3393 | |
| 3394 | // Where to start adding? |
| 3395 | int pos = findWindowOffsetLocked(tokenPos); |
| 3396 | |
| 3397 | // And now add them back at the correct place. |
| 3398 | for (i=0; i<N; i++) { |
| 3399 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 3400 | if (token != null) { |
| 3401 | pos = reAddAppWindowsLocked(pos, token); |
| 3402 | } |
| 3403 | } |
| 3404 | |
| 3405 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3406 | mLayoutNeeded = true; |
| 3407 | performLayoutAndPlaceSurfacesLocked(); |
| 3408 | |
| 3409 | //dump(); |
| 3410 | } |
| 3411 | |
| 3412 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 3413 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3414 | "moveAppTokensToTop()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3415 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3416 | } |
| 3417 | |
| 3418 | final long origId = Binder.clearCallingIdentity(); |
| 3419 | synchronized(mWindowMap) { |
| 3420 | removeAppTokensLocked(tokens); |
| 3421 | final int N = tokens.size(); |
| 3422 | for (int i=0; i<N; i++) { |
| 3423 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 3424 | if (wt != null) { |
| 3425 | mAppTokens.add(wt); |
| 3426 | } |
| 3427 | } |
| 3428 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 3429 | } |
| 3430 | Binder.restoreCallingIdentity(origId); |
| 3431 | } |
| 3432 | |
| 3433 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 3434 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3435 | "moveAppTokensToBottom()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3436 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3437 | } |
| 3438 | |
| 3439 | final long origId = Binder.clearCallingIdentity(); |
| 3440 | synchronized(mWindowMap) { |
| 3441 | removeAppTokensLocked(tokens); |
| 3442 | final int N = tokens.size(); |
| 3443 | int pos = 0; |
| 3444 | for (int i=0; i<N; i++) { |
| 3445 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 3446 | if (wt != null) { |
| 3447 | mAppTokens.add(pos, wt); |
| 3448 | pos++; |
| 3449 | } |
| 3450 | } |
| 3451 | moveAppWindowsLocked(tokens, 0); |
| 3452 | } |
| 3453 | Binder.restoreCallingIdentity(origId); |
| 3454 | } |
| 3455 | |
| 3456 | // ------------------------------------------------------------- |
| 3457 | // Misc IWindowSession methods |
| 3458 | // ------------------------------------------------------------- |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3459 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3460 | public void disableKeyguard(IBinder token, String tag) { |
| 3461 | if (mContext.checkCallingPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| 3462 | != PackageManager.PERMISSION_GRANTED) { |
| 3463 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 3464 | } |
| 3465 | mKeyguardDisabled.acquire(token, tag); |
| 3466 | } |
| 3467 | |
| 3468 | public void reenableKeyguard(IBinder token) { |
| 3469 | if (mContext.checkCallingPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| 3470 | != PackageManager.PERMISSION_GRANTED) { |
| 3471 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 3472 | } |
| 3473 | synchronized (mKeyguardDisabled) { |
| 3474 | mKeyguardDisabled.release(token); |
| 3475 | |
| 3476 | if (!mKeyguardDisabled.isAcquired()) { |
| 3477 | // if we are the last one to reenable the keyguard wait until |
| 3478 | // we have actaully finished reenabling until returning |
| 3479 | mWaitingUntilKeyguardReenabled = true; |
| 3480 | while (mWaitingUntilKeyguardReenabled) { |
| 3481 | try { |
| 3482 | mKeyguardDisabled.wait(); |
| 3483 | } catch (InterruptedException e) { |
| 3484 | Thread.currentThread().interrupt(); |
| 3485 | } |
| 3486 | } |
| 3487 | } |
| 3488 | } |
| 3489 | } |
| 3490 | |
| 3491 | /** |
| 3492 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 3493 | */ |
| 3494 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
| 3495 | if (mContext.checkCallingPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| 3496 | != PackageManager.PERMISSION_GRANTED) { |
| 3497 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 3498 | } |
| 3499 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 3500 | public void onKeyguardExitResult(boolean success) { |
| 3501 | try { |
| 3502 | callback.onKeyguardExitResult(success); |
| 3503 | } catch (RemoteException e) { |
| 3504 | // Client has died, we don't care. |
| 3505 | } |
| 3506 | } |
| 3507 | }); |
| 3508 | } |
| 3509 | |
| 3510 | public boolean inKeyguardRestrictedInputMode() { |
| 3511 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 3512 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3513 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3514 | static float fixScale(float scale) { |
| 3515 | if (scale < 0) scale = 0; |
| 3516 | else if (scale > 20) scale = 20; |
| 3517 | return Math.abs(scale); |
| 3518 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3519 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3520 | public void setAnimationScale(int which, float scale) { |
| 3521 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 3522 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3523 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3524 | } |
| 3525 | |
| 3526 | if (scale < 0) scale = 0; |
| 3527 | else if (scale > 20) scale = 20; |
| 3528 | scale = Math.abs(scale); |
| 3529 | switch (which) { |
| 3530 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 3531 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 3532 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3533 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3534 | // Persist setting |
| 3535 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 3536 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3537 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3538 | public void setAnimationScales(float[] scales) { |
| 3539 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 3540 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3541 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3542 | } |
| 3543 | |
| 3544 | if (scales != null) { |
| 3545 | if (scales.length >= 1) { |
| 3546 | mWindowAnimationScale = fixScale(scales[0]); |
| 3547 | } |
| 3548 | if (scales.length >= 2) { |
| 3549 | mTransitionAnimationScale = fixScale(scales[1]); |
| 3550 | } |
| 3551 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3552 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3553 | // Persist setting |
| 3554 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 3555 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3556 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3557 | public float getAnimationScale(int which) { |
| 3558 | switch (which) { |
| 3559 | case 0: return mWindowAnimationScale; |
| 3560 | case 1: return mTransitionAnimationScale; |
| 3561 | } |
| 3562 | return 0; |
| 3563 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3564 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3565 | public float[] getAnimationScales() { |
| 3566 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 3567 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3568 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3569 | public int getSwitchState(int sw) { |
| 3570 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 3571 | "getSwitchState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3572 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3573 | } |
| 3574 | return KeyInputQueue.getSwitchState(sw); |
| 3575 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3576 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3577 | public int getSwitchStateForDevice(int devid, int sw) { |
| 3578 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 3579 | "getSwitchStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3580 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3581 | } |
| 3582 | return KeyInputQueue.getSwitchState(devid, sw); |
| 3583 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3584 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3585 | public int getScancodeState(int sw) { |
| 3586 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 3587 | "getScancodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3588 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3589 | } |
| 3590 | return KeyInputQueue.getScancodeState(sw); |
| 3591 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3592 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3593 | public int getScancodeStateForDevice(int devid, int sw) { |
| 3594 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 3595 | "getScancodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3596 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3597 | } |
| 3598 | return KeyInputQueue.getScancodeState(devid, sw); |
| 3599 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3600 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3601 | public int getKeycodeState(int sw) { |
| 3602 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 3603 | "getKeycodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3604 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3605 | } |
| 3606 | return KeyInputQueue.getKeycodeState(sw); |
| 3607 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3608 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3609 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 3610 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 3611 | "getKeycodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3612 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3613 | } |
| 3614 | return KeyInputQueue.getKeycodeState(devid, sw); |
| 3615 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3616 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3617 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
| 3618 | return KeyInputQueue.hasKeys(keycodes, keyExists); |
| 3619 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3620 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3621 | public void enableScreenAfterBoot() { |
| 3622 | synchronized(mWindowMap) { |
| 3623 | if (mSystemBooted) { |
| 3624 | return; |
| 3625 | } |
| 3626 | mSystemBooted = true; |
| 3627 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3628 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3629 | performEnableScreen(); |
| 3630 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3631 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3632 | public void enableScreenIfNeededLocked() { |
| 3633 | if (mDisplayEnabled) { |
| 3634 | return; |
| 3635 | } |
| 3636 | if (!mSystemBooted) { |
| 3637 | return; |
| 3638 | } |
| 3639 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 3640 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3641 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3642 | public void performEnableScreen() { |
| 3643 | synchronized(mWindowMap) { |
| 3644 | if (mDisplayEnabled) { |
| 3645 | return; |
| 3646 | } |
| 3647 | if (!mSystemBooted) { |
| 3648 | return; |
| 3649 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3650 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3651 | // Don't enable the screen until all existing windows |
| 3652 | // have been drawn. |
| 3653 | final int N = mWindows.size(); |
| 3654 | for (int i=0; i<N; i++) { |
| 3655 | WindowState w = (WindowState)mWindows.get(i); |
| 3656 | if (w.isVisibleLw() && !w.isDisplayedLw()) { |
| 3657 | return; |
| 3658 | } |
| 3659 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3660 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3661 | mDisplayEnabled = true; |
| 3662 | if (false) { |
| 3663 | Log.i(TAG, "ENABLING SCREEN!"); |
| 3664 | StringWriter sw = new StringWriter(); |
| 3665 | PrintWriter pw = new PrintWriter(sw); |
| 3666 | this.dump(null, pw, null); |
| 3667 | Log.i(TAG, sw.toString()); |
| 3668 | } |
| 3669 | try { |
| 3670 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 3671 | if (surfaceFlinger != null) { |
| 3672 | //Log.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
| 3673 | Parcel data = Parcel.obtain(); |
| 3674 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 3675 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 3676 | data, null, 0); |
| 3677 | data.recycle(); |
| 3678 | } |
| 3679 | } catch (RemoteException ex) { |
| 3680 | Log.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
| 3681 | } |
| 3682 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3683 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3684 | mPolicy.enableScreenAfterBoot(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3685 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3686 | // Make sure the last requested orientation has been applied. |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 3687 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 3688 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3689 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3690 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3691 | public void setInTouchMode(boolean mode) { |
| 3692 | synchronized(mWindowMap) { |
| 3693 | mInTouchMode = mode; |
| 3694 | } |
| 3695 | } |
| 3696 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3697 | public void setRotation(int rotation, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3698 | boolean alwaysSendConfiguration, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3699 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3700 | "setRotation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3701 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3702 | } |
| 3703 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3704 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3705 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3706 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3707 | public void setRotationUnchecked(int rotation, |
| 3708 | boolean alwaysSendConfiguration, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3709 | if(DEBUG_ORIENTATION) Log.v(TAG, |
| 3710 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3711 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3712 | long origId = Binder.clearCallingIdentity(); |
| 3713 | boolean changed; |
| 3714 | synchronized(mWindowMap) { |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3715 | changed = setRotationUncheckedLocked(rotation, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3716 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3717 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3718 | if (changed) { |
| 3719 | sendNewConfiguration(); |
| 3720 | synchronized(mWindowMap) { |
| 3721 | mLayoutNeeded = true; |
| 3722 | performLayoutAndPlaceSurfacesLocked(); |
| 3723 | } |
| 3724 | } else if (alwaysSendConfiguration) { |
| 3725 | //update configuration ignoring orientation change |
| 3726 | sendNewConfiguration(); |
| 3727 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3728 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3729 | Binder.restoreCallingIdentity(origId); |
| 3730 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3731 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3732 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3733 | boolean changed; |
| 3734 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 3735 | rotation = mRequestedRotation; |
| 3736 | } else { |
| 3737 | mRequestedRotation = rotation; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 3738 | mLastRotationFlags = animFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3739 | } |
| 3740 | 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] | 3741 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3742 | mRotation, mDisplayEnabled); |
| 3743 | if (DEBUG_ORIENTATION) Log.v(TAG, "new rotation is set to " + rotation); |
| 3744 | changed = mDisplayEnabled && mRotation != rotation; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3745 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3746 | if (changed) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3747 | if (DEBUG_ORIENTATION) Log.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3748 | "Rotation changed to " + rotation |
| 3749 | + " from " + mRotation |
| 3750 | + " (forceApp=" + mForcedAppOrientation |
| 3751 | + ", req=" + mRequestedRotation + ")"); |
| 3752 | mRotation = rotation; |
| 3753 | mWindowsFreezingScreen = true; |
| 3754 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 3755 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 3756 | 2000); |
| 3757 | startFreezingDisplayLocked(); |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3758 | Log.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3759 | mQueue.setOrientation(rotation); |
| 3760 | if (mDisplayEnabled) { |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 3761 | Surface.setOrientation(0, rotation, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3762 | } |
| 3763 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 3764 | WindowState w = (WindowState)mWindows.get(i); |
| 3765 | if (w.mSurface != null) { |
| 3766 | w.mOrientationChanging = true; |
| 3767 | } |
| 3768 | } |
| 3769 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 3770 | try { |
| 3771 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 3772 | } catch (RemoteException e) { |
| 3773 | } |
| 3774 | } |
| 3775 | } //end if changed |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3776 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3777 | return changed; |
| 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 | public int getRotation() { |
| 3781 | return mRotation; |
| 3782 | } |
| 3783 | |
| 3784 | public int watchRotation(IRotationWatcher watcher) { |
| 3785 | final IBinder watcherBinder = watcher.asBinder(); |
| 3786 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 3787 | public void binderDied() { |
| 3788 | synchronized (mWindowMap) { |
| 3789 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 3790 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 3791 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 3792 | if (removed != null) { |
| 3793 | removed.asBinder().unlinkToDeath(this, 0); |
| 3794 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3795 | i--; |
| 3796 | } |
| 3797 | } |
| 3798 | } |
| 3799 | } |
| 3800 | }; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3801 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3802 | synchronized (mWindowMap) { |
| 3803 | try { |
| 3804 | watcher.asBinder().linkToDeath(dr, 0); |
| 3805 | mRotationWatchers.add(watcher); |
| 3806 | } catch (RemoteException e) { |
| 3807 | // Client died, no cleanup needed. |
| 3808 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3809 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3810 | return mRotation; |
| 3811 | } |
| 3812 | } |
| 3813 | |
| 3814 | /** |
| 3815 | * Starts the view server on the specified port. |
| 3816 | * |
| 3817 | * @param port The port to listener to. |
| 3818 | * |
| 3819 | * @return True if the server was successfully started, false otherwise. |
| 3820 | * |
| 3821 | * @see com.android.server.ViewServer |
| 3822 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 3823 | */ |
| 3824 | public boolean startViewServer(int port) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3825 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3826 | return false; |
| 3827 | } |
| 3828 | |
| 3829 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 3830 | return false; |
| 3831 | } |
| 3832 | |
| 3833 | if (port < 1024) { |
| 3834 | return false; |
| 3835 | } |
| 3836 | |
| 3837 | if (mViewServer != null) { |
| 3838 | if (!mViewServer.isRunning()) { |
| 3839 | try { |
| 3840 | return mViewServer.start(); |
| 3841 | } catch (IOException e) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3842 | Log.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3843 | } |
| 3844 | } |
| 3845 | return false; |
| 3846 | } |
| 3847 | |
| 3848 | try { |
| 3849 | mViewServer = new ViewServer(this, port); |
| 3850 | return mViewServer.start(); |
| 3851 | } catch (IOException e) { |
| 3852 | Log.w(TAG, "View server did not start"); |
| 3853 | } |
| 3854 | return false; |
| 3855 | } |
| 3856 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3857 | private boolean isSystemSecure() { |
| 3858 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 3859 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 3860 | } |
| 3861 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3862 | /** |
| 3863 | * Stops the view server if it exists. |
| 3864 | * |
| 3865 | * @return True if the server stopped, false if it wasn't started or |
| 3866 | * couldn't be stopped. |
| 3867 | * |
| 3868 | * @see com.android.server.ViewServer |
| 3869 | */ |
| 3870 | public boolean stopViewServer() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3871 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3872 | return false; |
| 3873 | } |
| 3874 | |
| 3875 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 3876 | return false; |
| 3877 | } |
| 3878 | |
| 3879 | if (mViewServer != null) { |
| 3880 | return mViewServer.stop(); |
| 3881 | } |
| 3882 | return false; |
| 3883 | } |
| 3884 | |
| 3885 | /** |
| 3886 | * Indicates whether the view server is running. |
| 3887 | * |
| 3888 | * @return True if the server is running, false otherwise. |
| 3889 | * |
| 3890 | * @see com.android.server.ViewServer |
| 3891 | */ |
| 3892 | public boolean isViewServerRunning() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3893 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3894 | return false; |
| 3895 | } |
| 3896 | |
| 3897 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 3898 | return false; |
| 3899 | } |
| 3900 | |
| 3901 | return mViewServer != null && mViewServer.isRunning(); |
| 3902 | } |
| 3903 | |
| 3904 | /** |
| 3905 | * Lists all availble windows in the system. The listing is written in the |
| 3906 | * specified Socket's output stream with the following syntax: |
| 3907 | * windowHashCodeInHexadecimal windowName |
| 3908 | * Each line of the ouput represents a different window. |
| 3909 | * |
| 3910 | * @param client The remote client to send the listing to. |
| 3911 | * @return False if an error occured, true otherwise. |
| 3912 | */ |
| 3913 | boolean viewServerListWindows(Socket client) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3914 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3915 | return false; |
| 3916 | } |
| 3917 | |
| 3918 | boolean result = true; |
| 3919 | |
| 3920 | Object[] windows; |
| 3921 | synchronized (mWindowMap) { |
| 3922 | windows = new Object[mWindows.size()]; |
| 3923 | //noinspection unchecked |
| 3924 | windows = mWindows.toArray(windows); |
| 3925 | } |
| 3926 | |
| 3927 | BufferedWriter out = null; |
| 3928 | |
| 3929 | // Any uncaught exception will crash the system process |
| 3930 | try { |
| 3931 | OutputStream clientStream = client.getOutputStream(); |
| 3932 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 3933 | |
| 3934 | final int count = windows.length; |
| 3935 | for (int i = 0; i < count; i++) { |
| 3936 | final WindowState w = (WindowState) windows[i]; |
| 3937 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 3938 | out.write(' '); |
| 3939 | out.append(w.mAttrs.getTitle()); |
| 3940 | out.write('\n'); |
| 3941 | } |
| 3942 | |
| 3943 | out.write("DONE.\n"); |
| 3944 | out.flush(); |
| 3945 | } catch (Exception e) { |
| 3946 | result = false; |
| 3947 | } finally { |
| 3948 | if (out != null) { |
| 3949 | try { |
| 3950 | out.close(); |
| 3951 | } catch (IOException e) { |
| 3952 | result = false; |
| 3953 | } |
| 3954 | } |
| 3955 | } |
| 3956 | |
| 3957 | return result; |
| 3958 | } |
| 3959 | |
| 3960 | /** |
| 3961 | * Sends a command to a target window. The result of the command, if any, will be |
| 3962 | * written in the output stream of the specified socket. |
| 3963 | * |
| 3964 | * The parameters must follow this syntax: |
| 3965 | * windowHashcode extra |
| 3966 | * |
| 3967 | * Where XX is the length in characeters of the windowTitle. |
| 3968 | * |
| 3969 | * The first parameter is the target window. The window with the specified hashcode |
| 3970 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 3971 | * will be delivered to the target window and as parameters to the command itself. |
| 3972 | * |
| 3973 | * @param client The remote client to sent the result, if any, to. |
| 3974 | * @param command The command to execute. |
| 3975 | * @param parameters The command parameters. |
| 3976 | * |
| 3977 | * @return True if the command was successfully delivered, false otherwise. This does |
| 3978 | * not indicate whether the command itself was successful. |
| 3979 | */ |
| 3980 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3981 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3982 | return false; |
| 3983 | } |
| 3984 | |
| 3985 | boolean success = true; |
| 3986 | Parcel data = null; |
| 3987 | Parcel reply = null; |
| 3988 | |
| 3989 | // Any uncaught exception will crash the system process |
| 3990 | try { |
| 3991 | // Find the hashcode of the window |
| 3992 | int index = parameters.indexOf(' '); |
| 3993 | if (index == -1) { |
| 3994 | index = parameters.length(); |
| 3995 | } |
| 3996 | final String code = parameters.substring(0, index); |
| 3997 | int hashCode = "ffffffff".equals(code) ? -1 : Integer.parseInt(code, 16); |
| 3998 | |
| 3999 | // Extract the command's parameter after the window description |
| 4000 | if (index < parameters.length()) { |
| 4001 | parameters = parameters.substring(index + 1); |
| 4002 | } else { |
| 4003 | parameters = ""; |
| 4004 | } |
| 4005 | |
| 4006 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 4007 | if (window == null) { |
| 4008 | return false; |
| 4009 | } |
| 4010 | |
| 4011 | data = Parcel.obtain(); |
| 4012 | data.writeInterfaceToken("android.view.IWindow"); |
| 4013 | data.writeString(command); |
| 4014 | data.writeString(parameters); |
| 4015 | data.writeInt(1); |
| 4016 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 4017 | |
| 4018 | reply = Parcel.obtain(); |
| 4019 | |
| 4020 | final IBinder binder = window.mClient.asBinder(); |
| 4021 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 4022 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 4023 | |
| 4024 | reply.readException(); |
| 4025 | |
| 4026 | } catch (Exception e) { |
| 4027 | Log.w(TAG, "Could not send command " + command + " with parameters " + parameters, e); |
| 4028 | success = false; |
| 4029 | } finally { |
| 4030 | if (data != null) { |
| 4031 | data.recycle(); |
| 4032 | } |
| 4033 | if (reply != null) { |
| 4034 | reply.recycle(); |
| 4035 | } |
| 4036 | } |
| 4037 | |
| 4038 | return success; |
| 4039 | } |
| 4040 | |
| 4041 | private WindowState findWindow(int hashCode) { |
| 4042 | if (hashCode == -1) { |
| 4043 | return getFocusedWindow(); |
| 4044 | } |
| 4045 | |
| 4046 | synchronized (mWindowMap) { |
| 4047 | final ArrayList windows = mWindows; |
| 4048 | final int count = windows.size(); |
| 4049 | |
| 4050 | for (int i = 0; i < count; i++) { |
| 4051 | WindowState w = (WindowState) windows.get(i); |
| 4052 | if (System.identityHashCode(w) == hashCode) { |
| 4053 | return w; |
| 4054 | } |
| 4055 | } |
| 4056 | } |
| 4057 | |
| 4058 | return null; |
| 4059 | } |
| 4060 | |
| 4061 | /* |
| 4062 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 4063 | * that to config-changed listeners if appropriate. |
| 4064 | */ |
| 4065 | void sendNewConfiguration() { |
| 4066 | try { |
| 4067 | mActivityManager.updateConfiguration(null); |
| 4068 | } catch (RemoteException e) { |
| 4069 | } |
| 4070 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4071 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4072 | public Configuration computeNewConfiguration() { |
| 4073 | synchronized (mWindowMap) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4074 | return computeNewConfigurationLocked(); |
| 4075 | } |
| 4076 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4077 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4078 | Configuration computeNewConfigurationLocked() { |
| 4079 | Configuration config = new Configuration(); |
| 4080 | if (!computeNewConfigurationLocked(config)) { |
| 4081 | return null; |
| 4082 | } |
| 4083 | Log.i(TAG, "Config changed: " + config); |
| 4084 | long now = SystemClock.uptimeMillis(); |
| 4085 | //Log.i(TAG, "Config changing, gc pending: " + mFreezeGcPending + ", now " + now); |
| 4086 | if (mFreezeGcPending != 0) { |
| 4087 | if (now > (mFreezeGcPending+1000)) { |
| 4088 | //Log.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| 4089 | mH.removeMessages(H.FORCE_GC); |
| 4090 | Runtime.getRuntime().gc(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4091 | mFreezeGcPending = now; |
| 4092 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4093 | } else { |
| 4094 | mFreezeGcPending = now; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4095 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4096 | return config; |
| 4097 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4098 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4099 | boolean computeNewConfigurationLocked(Configuration config) { |
| 4100 | if (mDisplay == null) { |
| 4101 | return false; |
| 4102 | } |
| 4103 | mQueue.getInputConfiguration(config); |
| 4104 | final int dw = mDisplay.getWidth(); |
| 4105 | final int dh = mDisplay.getHeight(); |
| 4106 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 4107 | if (dw < dh) { |
| 4108 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 4109 | } else if (dw > dh) { |
| 4110 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 4111 | } |
| 4112 | config.orientation = orientation; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4113 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4114 | DisplayMetrics dm = new DisplayMetrics(); |
| 4115 | mDisplay.getMetrics(dm); |
| 4116 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 4117 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4118 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4119 | // Note we only do this once because at this point we don't |
| 4120 | // expect the screen to change in this way at runtime, and want |
| 4121 | // to avoid all of this computation for every config change. |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4122 | int longSize = dw; |
| 4123 | int shortSize = dh; |
| 4124 | if (longSize < shortSize) { |
| 4125 | int tmp = longSize; |
| 4126 | longSize = shortSize; |
| 4127 | shortSize = tmp; |
| 4128 | } |
| 4129 | longSize = (int)(longSize/dm.density); |
| 4130 | shortSize = (int)(shortSize/dm.density); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4131 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4132 | // These semi-magic numbers define our compatibility modes for |
| 4133 | // applications with different screens. Don't change unless you |
| 4134 | // make sure to test lots and lots of apps! |
| 4135 | if (longSize < 470) { |
| 4136 | // This is shorter than an HVGA normal density screen (which |
| 4137 | // is 480 pixels on its long side). |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4138 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 4139 | | Configuration.SCREENLAYOUT_LONG_NO; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4140 | } else { |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4141 | // Is this a large screen? |
| 4142 | if (longSize > 640 && shortSize >= 480) { |
| 4143 | // VGA or larger screens at medium density are the point |
| 4144 | // at which we consider it to be a large screen. |
| 4145 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 4146 | } else { |
| 4147 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
| 4148 | |
| 4149 | // If this screen is wider than normal HVGA, or taller |
| 4150 | // than FWVGA, then for old apps we want to run in size |
| 4151 | // compatibility mode. |
| 4152 | if (shortSize > 321 || longSize > 570) { |
| 4153 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 4154 | } |
| 4155 | } |
| 4156 | |
| 4157 | // Is this a long screen? |
| 4158 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 4159 | // Anything wider than WVGA (5:3) is considering to be long. |
| 4160 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 4161 | } else { |
| 4162 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 4163 | } |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4164 | } |
| 4165 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4166 | config.screenLayout = mScreenLayout; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4167 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4168 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 4169 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 4170 | mPolicy.adjustConfigurationLw(config); |
| 4171 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4172 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4174 | // ------------------------------------------------------------- |
| 4175 | // Input Events and Focus Management |
| 4176 | // ------------------------------------------------------------- |
| 4177 | |
| 4178 | private final void wakeupIfNeeded(WindowState targetWin, int eventType) { |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4179 | long curTime = SystemClock.uptimeMillis(); |
| 4180 | |
Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 4181 | if (eventType == TOUCH_EVENT || eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) { |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4182 | if (mLastTouchEventType == eventType && |
| 4183 | (curTime - mLastUserActivityCallTime) < MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 4184 | return; |
| 4185 | } |
| 4186 | mLastUserActivityCallTime = curTime; |
| 4187 | mLastTouchEventType = eventType; |
| 4188 | } |
| 4189 | |
| 4190 | if (targetWin == null |
| 4191 | || targetWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) { |
| 4192 | mPowerManager.userActivity(curTime, false, eventType, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4193 | } |
| 4194 | } |
| 4195 | |
| 4196 | // tells if it's a cheek event or not -- this function is stateful |
| 4197 | private static final int EVENT_NONE = 0; |
| 4198 | private static final int EVENT_UNKNOWN = 0; |
| 4199 | private static final int EVENT_CHEEK = 0; |
| 4200 | private static final int EVENT_IGNORE_DURATION = 300; // ms |
| 4201 | private static final float CHEEK_THRESHOLD = 0.6f; |
| 4202 | private int mEventState = EVENT_NONE; |
| 4203 | private float mEventSize; |
Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4204 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4205 | private int eventType(MotionEvent ev) { |
| 4206 | float size = ev.getSize(); |
| 4207 | switch (ev.getAction()) { |
| 4208 | case MotionEvent.ACTION_DOWN: |
| 4209 | mEventSize = size; |
| 4210 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_EVENT; |
| 4211 | case MotionEvent.ACTION_UP: |
| 4212 | if (size > mEventSize) mEventSize = size; |
Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4213 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_UP_EVENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4214 | case MotionEvent.ACTION_MOVE: |
| 4215 | final int N = ev.getHistorySize(); |
| 4216 | if (size > mEventSize) mEventSize = size; |
| 4217 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 4218 | for (int i=0; i<N; i++) { |
| 4219 | size = ev.getHistoricalSize(i); |
| 4220 | if (size > mEventSize) mEventSize = size; |
| 4221 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 4222 | } |
| 4223 | if (ev.getEventTime() < ev.getDownTime() + EVENT_IGNORE_DURATION) { |
| 4224 | return TOUCH_EVENT; |
| 4225 | } else { |
Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4226 | return LONG_TOUCH_EVENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4227 | } |
| 4228 | default: |
| 4229 | // not good |
| 4230 | return OTHER_EVENT; |
| 4231 | } |
| 4232 | } |
| 4233 | |
| 4234 | /** |
| 4235 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4236 | */ |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4237 | 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] | 4238 | if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Log.v(TAG, |
| 4239 | "dispatchPointer " + ev); |
| 4240 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4241 | if (MEASURE_LATENCY) { |
| 4242 | lt.sample("3 Wait for last dispatch ", System.nanoTime() - qev.whenNano); |
| 4243 | } |
| 4244 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4245 | Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4246 | ev, true, false, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4247 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4248 | if (MEASURE_LATENCY) { |
| 4249 | lt.sample("3 Last dispatch finished ", System.nanoTime() - qev.whenNano); |
| 4250 | } |
| 4251 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4252 | int action = ev.getAction(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4253 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4254 | if (action == MotionEvent.ACTION_UP) { |
| 4255 | // let go of our target |
| 4256 | mKeyWaiter.mMotionTarget = null; |
| 4257 | mPowerManager.logPointerUpEvent(); |
| 4258 | } else if (action == MotionEvent.ACTION_DOWN) { |
| 4259 | mPowerManager.logPointerDownEvent(); |
| 4260 | } |
| 4261 | |
| 4262 | if (targetObj == null) { |
| 4263 | // In this case we are either dropping the event, or have received |
| 4264 | // a move or up without a down. It is common to receive move |
| 4265 | // events in such a way, since this means the user is moving the |
| 4266 | // pointer without actually pressing down. All other cases should |
| 4267 | // be atypical, so let's log them. |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4268 | if (action != MotionEvent.ACTION_MOVE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4269 | Log.w(TAG, "No window to dispatch pointer action " + ev.getAction()); |
| 4270 | } |
| 4271 | if (qev != null) { |
| 4272 | mQueue.recycleEvent(qev); |
| 4273 | } |
| 4274 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4275 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4276 | } |
| 4277 | if (targetObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| 4278 | if (qev != null) { |
| 4279 | mQueue.recycleEvent(qev); |
| 4280 | } |
| 4281 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4282 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4283 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4284 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4285 | WindowState target = (WindowState)targetObj; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4286 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4287 | final long eventTime = ev.getEventTime(); |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4288 | final long eventTimeNano = ev.getEventTimeNano(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4289 | |
| 4290 | //Log.i(TAG, "Sending " + ev + " to " + target); |
| 4291 | |
| 4292 | if (uid != 0 && uid != target.mSession.mUid) { |
| 4293 | if (mContext.checkPermission( |
| 4294 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 4295 | != PackageManager.PERMISSION_GRANTED) { |
| 4296 | Log.w(TAG, "Permission denied: injecting pointer event from pid " |
| 4297 | + pid + " uid " + uid + " to window " + target |
| 4298 | + " owned by uid " + target.mSession.mUid); |
| 4299 | if (qev != null) { |
| 4300 | mQueue.recycleEvent(qev); |
| 4301 | } |
| 4302 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4303 | return INJECT_NO_PERMISSION; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4304 | } |
| 4305 | } |
| 4306 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4307 | if (MEASURE_LATENCY) { |
| 4308 | lt.sample("4 in dispatchPointer ", System.nanoTime() - eventTimeNano); |
| 4309 | } |
| 4310 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4311 | if ((target.mAttrs.flags & |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4312 | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES) != 0) { |
| 4313 | //target wants to ignore fat touch events |
| 4314 | boolean cheekPress = mPolicy.isCheekPressedAgainstScreen(ev); |
| 4315 | //explicit flag to return without processing event further |
| 4316 | boolean returnFlag = false; |
| 4317 | if((action == MotionEvent.ACTION_DOWN)) { |
| 4318 | mFatTouch = false; |
| 4319 | if(cheekPress) { |
| 4320 | mFatTouch = true; |
| 4321 | returnFlag = true; |
| 4322 | } |
| 4323 | } else { |
| 4324 | if(action == MotionEvent.ACTION_UP) { |
| 4325 | if(mFatTouch) { |
| 4326 | //earlier even was invalid doesnt matter if current up is cheekpress or not |
| 4327 | mFatTouch = false; |
| 4328 | returnFlag = true; |
| 4329 | } else if(cheekPress) { |
| 4330 | //cancel the earlier event |
| 4331 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 4332 | action = MotionEvent.ACTION_CANCEL; |
| 4333 | } |
| 4334 | } else if(action == MotionEvent.ACTION_MOVE) { |
| 4335 | if(mFatTouch) { |
| 4336 | //two cases here |
| 4337 | //an invalid down followed by 0 or moves(valid or invalid) |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4338 | //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] | 4339 | returnFlag = true; |
| 4340 | } else if(cheekPress) { |
| 4341 | //valid down followed by invalid moves |
| 4342 | //an invalid move have to cancel earlier action |
| 4343 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 4344 | action = MotionEvent.ACTION_CANCEL; |
| 4345 | if (DEBUG_INPUT) Log.v(TAG, "Sending cancel for invalid ACTION_MOVE"); |
| 4346 | //note that the subsequent invalid moves will not get here |
| 4347 | mFatTouch = true; |
| 4348 | } |
| 4349 | } |
| 4350 | } //else if action |
| 4351 | if(returnFlag) { |
| 4352 | //recycle que, ev |
| 4353 | if (qev != null) { |
| 4354 | mQueue.recycleEvent(qev); |
| 4355 | } |
| 4356 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4357 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4358 | } |
| 4359 | } //end if target |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4360 | |
Michael Chan | 9f028e6 | 2009-08-04 17:37:46 -0700 | [diff] [blame] | 4361 | // Enable this for testing the "right" value |
| 4362 | if (false && action == MotionEvent.ACTION_DOWN) { |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4363 | int max_events_per_sec = 35; |
| 4364 | try { |
| 4365 | max_events_per_sec = Integer.parseInt(SystemProperties |
| 4366 | .get("windowsmgr.max_events_per_sec")); |
| 4367 | if (max_events_per_sec < 1) { |
| 4368 | max_events_per_sec = 35; |
| 4369 | } |
| 4370 | } catch (NumberFormatException e) { |
| 4371 | } |
| 4372 | mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec; |
| 4373 | } |
| 4374 | |
| 4375 | /* |
| 4376 | * Throttle events to minimize CPU usage when there's a flood of events |
| 4377 | * e.g. constant contact with the screen |
| 4378 | */ |
| 4379 | if (action == MotionEvent.ACTION_MOVE) { |
| 4380 | long nextEventTime = mLastTouchEventTime + mMinWaitTimeBetweenTouchEvents; |
| 4381 | long now = SystemClock.uptimeMillis(); |
| 4382 | if (now < nextEventTime) { |
| 4383 | try { |
| 4384 | Thread.sleep(nextEventTime - now); |
| 4385 | } catch (InterruptedException e) { |
| 4386 | } |
| 4387 | mLastTouchEventTime = nextEventTime; |
| 4388 | } else { |
| 4389 | mLastTouchEventTime = now; |
| 4390 | } |
| 4391 | } |
| 4392 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4393 | if (MEASURE_LATENCY) { |
| 4394 | lt.sample("5 in dispatchPointer ", System.nanoTime() - eventTimeNano); |
| 4395 | } |
| 4396 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4397 | synchronized(mWindowMap) { |
| 4398 | if (qev != null && action == MotionEvent.ACTION_MOVE) { |
| 4399 | mKeyWaiter.bindTargetWindowLocked(target, |
| 4400 | KeyWaiter.RETURN_PENDING_POINTER, qev); |
| 4401 | ev = null; |
| 4402 | } else { |
| 4403 | if (action == MotionEvent.ACTION_DOWN) { |
| 4404 | WindowState out = mKeyWaiter.mOutsideTouchTargets; |
| 4405 | if (out != null) { |
| 4406 | MotionEvent oev = MotionEvent.obtain(ev); |
| 4407 | oev.setAction(MotionEvent.ACTION_OUTSIDE); |
| 4408 | do { |
| 4409 | final Rect frame = out.mFrame; |
| 4410 | oev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 4411 | try { |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 4412 | out.mClient.dispatchPointer(oev, eventTime, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4413 | } catch (android.os.RemoteException e) { |
| 4414 | Log.i(TAG, "WINDOW DIED during outside motion dispatch: " + out); |
| 4415 | } |
| 4416 | oev.offsetLocation((float)frame.left, (float)frame.top); |
| 4417 | out = out.mNextOutsideTouch; |
| 4418 | } while (out != null); |
| 4419 | mKeyWaiter.mOutsideTouchTargets = null; |
| 4420 | } |
| 4421 | } |
| 4422 | final Rect frame = target.mFrame; |
| 4423 | ev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 4424 | mKeyWaiter.bindTargetWindowLocked(target); |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 4425 | |
| 4426 | // If we are on top of the wallpaper, then the wallpaper also |
| 4427 | // gets to see this movement. |
| 4428 | if (mWallpaperTarget == target) { |
| 4429 | sendPointerToWallpaperLocked(target, ev, eventTime); |
| 4430 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4431 | } |
| 4432 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4433 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4434 | // finally offset the event to the target's coordinate system and |
| 4435 | // dispatch the event. |
| 4436 | try { |
| 4437 | if (DEBUG_INPUT || DEBUG_FOCUS || WindowManagerPolicy.WATCH_POINTER) { |
| 4438 | Log.v(TAG, "Delivering pointer " + qev + " to " + target); |
| 4439 | } |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4440 | |
| 4441 | if (MEASURE_LATENCY) { |
| 4442 | lt.sample("6 before svr->client ipc ", System.nanoTime() - eventTimeNano); |
| 4443 | } |
| 4444 | |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 4445 | target.mClient.dispatchPointer(ev, eventTime, true); |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4446 | |
| 4447 | if (MEASURE_LATENCY) { |
| 4448 | lt.sample("7 after svr->client ipc ", System.nanoTime() - eventTimeNano); |
| 4449 | } |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4450 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4451 | } catch (android.os.RemoteException e) { |
| 4452 | Log.i(TAG, "WINDOW DIED during motion dispatch: " + target); |
| 4453 | mKeyWaiter.mMotionTarget = null; |
| 4454 | try { |
| 4455 | removeWindow(target.mSession, target.mClient); |
| 4456 | } catch (java.util.NoSuchElementException ex) { |
| 4457 | // This will happen if the window has already been |
| 4458 | // removed. |
| 4459 | } |
| 4460 | } |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4461 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4462 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4463 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4464 | /** |
| 4465 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4466 | */ |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4467 | 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] | 4468 | if (DEBUG_INPUT) Log.v( |
| 4469 | TAG, "dispatchTrackball [" + ev.getAction() +"] <" + ev.getX() + ", " + ev.getY() + ">"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4470 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4471 | Object focusObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4472 | ev, false, false, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4473 | if (focusObj == null) { |
| 4474 | Log.w(TAG, "No focus window, dropping trackball: " + ev); |
| 4475 | if (qev != null) { |
| 4476 | mQueue.recycleEvent(qev); |
| 4477 | } |
| 4478 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4479 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4480 | } |
| 4481 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| 4482 | if (qev != null) { |
| 4483 | mQueue.recycleEvent(qev); |
| 4484 | } |
| 4485 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4486 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4487 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4488 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4489 | WindowState focus = (WindowState)focusObj; |
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 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 4492 | if (mContext.checkPermission( |
| 4493 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 4494 | != PackageManager.PERMISSION_GRANTED) { |
| 4495 | Log.w(TAG, "Permission denied: injecting key event from pid " |
| 4496 | + pid + " uid " + uid + " to window " + focus |
| 4497 | + " owned by uid " + focus.mSession.mUid); |
| 4498 | if (qev != null) { |
| 4499 | mQueue.recycleEvent(qev); |
| 4500 | } |
| 4501 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4502 | return INJECT_NO_PERMISSION; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4503 | } |
| 4504 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4505 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4506 | final long eventTime = ev.getEventTime(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4507 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4508 | synchronized(mWindowMap) { |
| 4509 | if (qev != null && ev.getAction() == MotionEvent.ACTION_MOVE) { |
| 4510 | mKeyWaiter.bindTargetWindowLocked(focus, |
| 4511 | KeyWaiter.RETURN_PENDING_TRACKBALL, qev); |
| 4512 | // We don't deliver movement events to the client, we hold |
| 4513 | // them and wait for them to call back. |
| 4514 | ev = null; |
| 4515 | } else { |
| 4516 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 4517 | } |
| 4518 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4519 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4520 | try { |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 4521 | focus.mClient.dispatchTrackball(ev, eventTime, true); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4522 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4523 | } catch (android.os.RemoteException e) { |
| 4524 | Log.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| 4525 | try { |
| 4526 | removeWindow(focus.mSession, focus.mClient); |
| 4527 | } catch (java.util.NoSuchElementException ex) { |
| 4528 | // This will happen if the window has already been |
| 4529 | // removed. |
| 4530 | } |
| 4531 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4532 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4533 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4534 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4535 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4536 | /** |
| 4537 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4538 | */ |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4539 | private int dispatchKey(KeyEvent event, int pid, int uid) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4540 | if (DEBUG_INPUT) Log.v(TAG, "Dispatch key: " + event); |
| 4541 | |
| 4542 | Object focusObj = mKeyWaiter.waitForNextEventTarget(event, null, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4543 | null, false, false, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4544 | if (focusObj == null) { |
| 4545 | Log.w(TAG, "No focus window, dropping: " + event); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4546 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4547 | } |
| 4548 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4549 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4550 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4551 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4552 | WindowState focus = (WindowState)focusObj; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4553 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4554 | if (DEBUG_INPUT) Log.v( |
| 4555 | TAG, "Dispatching to " + focus + ": " + event); |
| 4556 | |
| 4557 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 4558 | if (mContext.checkPermission( |
| 4559 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 4560 | != PackageManager.PERMISSION_GRANTED) { |
| 4561 | Log.w(TAG, "Permission denied: injecting key event from pid " |
| 4562 | + pid + " uid " + uid + " to window " + focus |
| 4563 | + " owned by uid " + focus.mSession.mUid); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4564 | return INJECT_NO_PERMISSION; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4565 | } |
| 4566 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4567 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4568 | synchronized(mWindowMap) { |
| 4569 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 4570 | } |
| 4571 | |
| 4572 | // NOSHIP extra state logging |
| 4573 | mKeyWaiter.recordDispatchState(event, focus); |
| 4574 | // END NOSHIP |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4575 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4576 | try { |
| 4577 | if (DEBUG_INPUT || DEBUG_FOCUS) { |
| 4578 | Log.v(TAG, "Delivering key " + event.getKeyCode() |
| 4579 | + " to " + focus); |
| 4580 | } |
| 4581 | focus.mClient.dispatchKey(event); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4582 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4583 | } catch (android.os.RemoteException e) { |
| 4584 | Log.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| 4585 | try { |
| 4586 | removeWindow(focus.mSession, focus.mClient); |
| 4587 | } catch (java.util.NoSuchElementException ex) { |
| 4588 | // This will happen if the window has already been |
| 4589 | // removed. |
| 4590 | } |
| 4591 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4592 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4593 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4594 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4595 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4596 | public void pauseKeyDispatching(IBinder _token) { |
| 4597 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4598 | "pauseKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4599 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4600 | } |
| 4601 | |
| 4602 | synchronized (mWindowMap) { |
| 4603 | WindowToken token = mTokenMap.get(_token); |
| 4604 | if (token != null) { |
| 4605 | mKeyWaiter.pauseDispatchingLocked(token); |
| 4606 | } |
| 4607 | } |
| 4608 | } |
| 4609 | |
| 4610 | public void resumeKeyDispatching(IBinder _token) { |
| 4611 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4612 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4613 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4614 | } |
| 4615 | |
| 4616 | synchronized (mWindowMap) { |
| 4617 | WindowToken token = mTokenMap.get(_token); |
| 4618 | if (token != null) { |
| 4619 | mKeyWaiter.resumeDispatchingLocked(token); |
| 4620 | } |
| 4621 | } |
| 4622 | } |
| 4623 | |
| 4624 | public void setEventDispatching(boolean enabled) { |
| 4625 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4626 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4627 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4628 | } |
| 4629 | |
| 4630 | synchronized (mWindowMap) { |
| 4631 | mKeyWaiter.setEventDispatchingLocked(enabled); |
| 4632 | } |
| 4633 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4634 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4635 | /** |
| 4636 | * Injects a keystroke event into the UI. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4637 | * |
| 4638 | * @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] | 4639 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 4640 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 4641 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4642 | */ |
| 4643 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 4644 | long downTime = ev.getDownTime(); |
| 4645 | long eventTime = ev.getEventTime(); |
| 4646 | |
| 4647 | int action = ev.getAction(); |
| 4648 | int code = ev.getKeyCode(); |
| 4649 | int repeatCount = ev.getRepeatCount(); |
| 4650 | int metaState = ev.getMetaState(); |
| 4651 | int deviceId = ev.getDeviceId(); |
| 4652 | int scancode = ev.getScanCode(); |
| 4653 | |
| 4654 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 4655 | if (downTime == 0) downTime = eventTime; |
| 4656 | |
| 4657 | 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] | 4658 | deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4659 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4660 | final int pid = Binder.getCallingPid(); |
| 4661 | final int uid = Binder.getCallingUid(); |
| 4662 | final long ident = Binder.clearCallingIdentity(); |
| 4663 | final int result = dispatchKey(newEvent, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4664 | if (sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4665 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4666 | } |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4667 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4668 | switch (result) { |
| 4669 | case INJECT_NO_PERMISSION: |
| 4670 | throw new SecurityException( |
| 4671 | "Injecting to another application requires INJECT_EVENT permission"); |
| 4672 | case INJECT_SUCCEEDED: |
| 4673 | return true; |
| 4674 | } |
| 4675 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4676 | } |
| 4677 | |
| 4678 | /** |
| 4679 | * Inject a pointer (touch) event into the UI. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4680 | * |
| 4681 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 4682 | * {@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] | 4683 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 4684 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 4685 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4686 | */ |
| 4687 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4688 | final int pid = Binder.getCallingPid(); |
| 4689 | final int uid = Binder.getCallingUid(); |
| 4690 | final long ident = Binder.clearCallingIdentity(); |
| 4691 | final int result = dispatchPointer(null, ev, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4692 | if (sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4693 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4694 | } |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4695 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4696 | switch (result) { |
| 4697 | case INJECT_NO_PERMISSION: |
| 4698 | throw new SecurityException( |
| 4699 | "Injecting to another application requires INJECT_EVENT permission"); |
| 4700 | case INJECT_SUCCEEDED: |
| 4701 | return true; |
| 4702 | } |
| 4703 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4704 | } |
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 | /** |
| 4707 | * Inject a trackball (navigation device) event into the UI. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4708 | * |
| 4709 | * @param ev A motion event describing the trackball action. (As noted in |
| 4710 | * {@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] | 4711 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 4712 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 4713 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4714 | */ |
| 4715 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4716 | final int pid = Binder.getCallingPid(); |
| 4717 | final int uid = Binder.getCallingUid(); |
| 4718 | final long ident = Binder.clearCallingIdentity(); |
| 4719 | final int result = dispatchTrackball(null, ev, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4720 | if (sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4721 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4722 | } |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4723 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4724 | switch (result) { |
| 4725 | case INJECT_NO_PERMISSION: |
| 4726 | throw new SecurityException( |
| 4727 | "Injecting to another application requires INJECT_EVENT permission"); |
| 4728 | case INJECT_SUCCEEDED: |
| 4729 | return true; |
| 4730 | } |
| 4731 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4732 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4733 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4734 | private WindowState getFocusedWindow() { |
| 4735 | synchronized (mWindowMap) { |
| 4736 | return getFocusedWindowLocked(); |
| 4737 | } |
| 4738 | } |
| 4739 | |
| 4740 | private WindowState getFocusedWindowLocked() { |
| 4741 | return mCurrentFocus; |
| 4742 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4743 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4744 | /** |
| 4745 | * This class holds the state for dispatching key events. This state |
| 4746 | * is protected by the KeyWaiter instance, NOT by the window lock. You |
| 4747 | * can be holding the main window lock while acquire the KeyWaiter lock, |
| 4748 | * but not the other way around. |
| 4749 | */ |
| 4750 | final class KeyWaiter { |
| 4751 | // NOSHIP debugging |
| 4752 | public class DispatchState { |
| 4753 | private KeyEvent event; |
| 4754 | private WindowState focus; |
| 4755 | private long time; |
| 4756 | private WindowState lastWin; |
| 4757 | private IBinder lastBinder; |
| 4758 | private boolean finished; |
| 4759 | private boolean gotFirstWindow; |
| 4760 | private boolean eventDispatching; |
| 4761 | private long timeToSwitch; |
| 4762 | private boolean wasFrozen; |
| 4763 | private boolean focusPaused; |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 4764 | private WindowState curFocus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4765 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4766 | DispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 4767 | focus = theFocus; |
| 4768 | event = theEvent; |
| 4769 | time = System.currentTimeMillis(); |
| 4770 | // snapshot KeyWaiter state |
| 4771 | lastWin = mLastWin; |
| 4772 | lastBinder = mLastBinder; |
| 4773 | finished = mFinished; |
| 4774 | gotFirstWindow = mGotFirstWindow; |
| 4775 | eventDispatching = mEventDispatching; |
| 4776 | timeToSwitch = mTimeToSwitch; |
| 4777 | wasFrozen = mWasFrozen; |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 4778 | curFocus = mCurrentFocus; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4779 | // cache the paused state at ctor time as well |
| 4780 | if (theFocus == null || theFocus.mToken == null) { |
| 4781 | Log.i(TAG, "focus " + theFocus + " mToken is null at event dispatch!"); |
| 4782 | focusPaused = false; |
| 4783 | } else { |
| 4784 | focusPaused = theFocus.mToken.paused; |
| 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 | public String toString() { |
| 4789 | return "{{" + event + " to " + focus + " @ " + time |
| 4790 | + " lw=" + lastWin + " lb=" + lastBinder |
| 4791 | + " fin=" + finished + " gfw=" + gotFirstWindow |
| 4792 | + " ed=" + eventDispatching + " tts=" + timeToSwitch |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 4793 | + " wf=" + wasFrozen + " fp=" + focusPaused |
| 4794 | + " mcf=" + mCurrentFocus + "}}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4795 | } |
| 4796 | }; |
| 4797 | private DispatchState mDispatchState = null; |
| 4798 | public void recordDispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 4799 | mDispatchState = new DispatchState(theEvent, theFocus); |
| 4800 | } |
| 4801 | // END NOSHIP |
| 4802 | |
| 4803 | public static final int RETURN_NOTHING = 0; |
| 4804 | public static final int RETURN_PENDING_POINTER = 1; |
| 4805 | public static final int RETURN_PENDING_TRACKBALL = 2; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4806 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4807 | final Object SKIP_TARGET_TOKEN = new Object(); |
| 4808 | final Object CONSUMED_EVENT_TOKEN = new Object(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4809 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4810 | private WindowState mLastWin = null; |
| 4811 | private IBinder mLastBinder = null; |
| 4812 | private boolean mFinished = true; |
| 4813 | private boolean mGotFirstWindow = false; |
| 4814 | private boolean mEventDispatching = true; |
| 4815 | private long mTimeToSwitch = 0; |
| 4816 | /* package */ boolean mWasFrozen = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4817 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4818 | // Target of Motion events |
| 4819 | WindowState mMotionTarget; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4820 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4821 | // Windows above the target who would like to receive an "outside" |
| 4822 | // touch event for any down events outside of them. |
| 4823 | WindowState mOutsideTouchTargets; |
| 4824 | |
| 4825 | /** |
| 4826 | * Wait for the last event dispatch to complete, then find the next |
| 4827 | * target that should receive the given event and wait for that one |
| 4828 | * to be ready to receive it. |
| 4829 | */ |
| 4830 | Object waitForNextEventTarget(KeyEvent nextKey, QueuedEvent qev, |
| 4831 | MotionEvent nextMotion, boolean isPointerEvent, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4832 | boolean failIfTimeout, int callingPid, int callingUid) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4833 | long startTime = SystemClock.uptimeMillis(); |
| 4834 | long keyDispatchingTimeout = 5 * 1000; |
| 4835 | long waitedFor = 0; |
| 4836 | |
| 4837 | while (true) { |
| 4838 | // Figure out which window we care about. It is either the |
| 4839 | // last window we are waiting to have process the event or, |
| 4840 | // if none, then the next window we think the event should go |
| 4841 | // to. Note: we retrieve mLastWin outside of the lock, so |
| 4842 | // it may change before we lock. Thus we must check it again. |
| 4843 | WindowState targetWin = mLastWin; |
| 4844 | boolean targetIsNew = targetWin == null; |
| 4845 | if (DEBUG_INPUT) Log.v( |
| 4846 | TAG, "waitForLastKey: mFinished=" + mFinished + |
| 4847 | ", mLastWin=" + mLastWin); |
| 4848 | if (targetIsNew) { |
| 4849 | Object target = findTargetWindow(nextKey, qev, nextMotion, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4850 | isPointerEvent, callingPid, callingUid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4851 | if (target == SKIP_TARGET_TOKEN) { |
| 4852 | // The user has pressed a special key, and we are |
| 4853 | // dropping all pending events before it. |
| 4854 | if (DEBUG_INPUT) Log.v(TAG, "Skipping: " + nextKey |
| 4855 | + " " + nextMotion); |
| 4856 | return null; |
| 4857 | } |
| 4858 | if (target == CONSUMED_EVENT_TOKEN) { |
| 4859 | if (DEBUG_INPUT) Log.v(TAG, "Consumed: " + nextKey |
| 4860 | + " " + nextMotion); |
| 4861 | return target; |
| 4862 | } |
| 4863 | targetWin = (WindowState)target; |
| 4864 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4865 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4866 | AppWindowToken targetApp = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4867 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4868 | // Now: is it okay to send the next event to this window? |
| 4869 | synchronized (this) { |
| 4870 | // First: did we come here based on the last window not |
| 4871 | // being null, but it changed by the time we got here? |
| 4872 | // If so, try again. |
| 4873 | if (!targetIsNew && mLastWin == null) { |
| 4874 | continue; |
| 4875 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4876 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4877 | // We never dispatch events if not finished with the |
| 4878 | // last one, or the display is frozen. |
| 4879 | if (mFinished && !mDisplayFrozen) { |
| 4880 | // If event dispatching is disabled, then we |
| 4881 | // just consume the events. |
| 4882 | if (!mEventDispatching) { |
| 4883 | if (DEBUG_INPUT) Log.v(TAG, |
| 4884 | "Skipping event; dispatching disabled: " |
| 4885 | + nextKey + " " + nextMotion); |
| 4886 | return null; |
| 4887 | } |
| 4888 | if (targetWin != null) { |
| 4889 | // If this is a new target, and that target is not |
| 4890 | // paused or unresponsive, then all looks good to |
| 4891 | // handle the event. |
| 4892 | if (targetIsNew && !targetWin.mToken.paused) { |
| 4893 | return targetWin; |
| 4894 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4895 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4896 | // If we didn't find a target window, and there is no |
| 4897 | // focused app window, then just eat the events. |
| 4898 | } else if (mFocusedApp == null) { |
| 4899 | if (DEBUG_INPUT) Log.v(TAG, |
| 4900 | "Skipping event; no focused app: " |
| 4901 | + nextKey + " " + nextMotion); |
| 4902 | return null; |
| 4903 | } |
| 4904 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4905 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4906 | if (DEBUG_INPUT) Log.v( |
| 4907 | TAG, "Waiting for last key in " + mLastBinder |
| 4908 | + " target=" + targetWin |
| 4909 | + " mFinished=" + mFinished |
| 4910 | + " mDisplayFrozen=" + mDisplayFrozen |
| 4911 | + " targetIsNew=" + targetIsNew |
| 4912 | + " paused=" |
| 4913 | + (targetWin != null ? targetWin.mToken.paused : false) |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 4914 | + " mFocusedApp=" + mFocusedApp |
| 4915 | + " mCurrentFocus=" + mCurrentFocus); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4916 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4917 | targetApp = targetWin != null |
| 4918 | ? targetWin.mAppToken : mFocusedApp; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4919 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4920 | long curTimeout = keyDispatchingTimeout; |
| 4921 | if (mTimeToSwitch != 0) { |
| 4922 | long now = SystemClock.uptimeMillis(); |
| 4923 | if (mTimeToSwitch <= now) { |
| 4924 | // If an app switch key has been pressed, and we have |
| 4925 | // waited too long for the current app to finish |
| 4926 | // processing keys, then wait no more! |
| 4927 | doFinishedKeyLocked(true); |
| 4928 | continue; |
| 4929 | } |
| 4930 | long switchTimeout = mTimeToSwitch - now; |
| 4931 | if (curTimeout > switchTimeout) { |
| 4932 | curTimeout = switchTimeout; |
| 4933 | } |
| 4934 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4935 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4936 | try { |
| 4937 | // after that continue |
| 4938 | // processing keys, so we don't get stuck. |
| 4939 | if (DEBUG_INPUT) Log.v( |
| 4940 | TAG, "Waiting for key dispatch: " + curTimeout); |
| 4941 | wait(curTimeout); |
| 4942 | if (DEBUG_INPUT) Log.v(TAG, "Finished waiting @" |
| 4943 | + SystemClock.uptimeMillis() + " startTime=" |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 4944 | + startTime + " switchTime=" + mTimeToSwitch |
| 4945 | + " target=" + targetWin + " mLW=" + mLastWin |
| 4946 | + " mLB=" + mLastBinder + " fin=" + mFinished |
| 4947 | + " mCurrentFocus=" + mCurrentFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4948 | } catch (InterruptedException e) { |
| 4949 | } |
| 4950 | } |
| 4951 | |
| 4952 | // If we were frozen during configuration change, restart the |
| 4953 | // timeout checks from now; otherwise look at whether we timed |
| 4954 | // out before awakening. |
| 4955 | if (mWasFrozen) { |
| 4956 | waitedFor = 0; |
| 4957 | mWasFrozen = false; |
| 4958 | } else { |
| 4959 | waitedFor = SystemClock.uptimeMillis() - startTime; |
| 4960 | } |
| 4961 | |
| 4962 | if (waitedFor >= keyDispatchingTimeout && mTimeToSwitch == 0) { |
| 4963 | IApplicationToken at = null; |
| 4964 | synchronized (this) { |
| 4965 | Log.w(TAG, "Key dispatching timed out sending to " + |
| 4966 | (targetWin != null ? targetWin.mAttrs.getTitle() |
| 4967 | : "<null>")); |
| 4968 | // NOSHIP debugging |
| 4969 | Log.w(TAG, "Dispatch state: " + mDispatchState); |
| 4970 | Log.w(TAG, "Current state: " + new DispatchState(nextKey, targetWin)); |
| 4971 | // END NOSHIP |
| 4972 | //dump(); |
| 4973 | if (targetWin != null) { |
| 4974 | at = targetWin.getAppToken(); |
| 4975 | } else if (targetApp != null) { |
| 4976 | at = targetApp.appToken; |
| 4977 | } |
| 4978 | } |
| 4979 | |
| 4980 | boolean abort = true; |
| 4981 | if (at != null) { |
| 4982 | try { |
| 4983 | long timeout = at.getKeyDispatchingTimeout(); |
| 4984 | if (timeout > waitedFor) { |
| 4985 | // we did not wait the proper amount of time for this application. |
| 4986 | // set the timeout to be the real timeout and wait again. |
| 4987 | keyDispatchingTimeout = timeout - waitedFor; |
| 4988 | continue; |
| 4989 | } else { |
| 4990 | abort = at.keyDispatchingTimedOut(); |
| 4991 | } |
| 4992 | } catch (RemoteException ex) { |
| 4993 | } |
| 4994 | } |
| 4995 | |
| 4996 | synchronized (this) { |
| 4997 | if (abort && (mLastWin == targetWin || targetWin == null)) { |
| 4998 | mFinished = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4999 | if (mLastWin != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5000 | if (DEBUG_INPUT) Log.v(TAG, |
| 5001 | "Window " + mLastWin + |
| 5002 | " timed out on key input"); |
| 5003 | if (mLastWin.mToken.paused) { |
| 5004 | Log.w(TAG, "Un-pausing dispatching to this window"); |
| 5005 | mLastWin.mToken.paused = false; |
| 5006 | } |
| 5007 | } |
| 5008 | if (mMotionTarget == targetWin) { |
| 5009 | mMotionTarget = null; |
| 5010 | } |
| 5011 | mLastWin = null; |
| 5012 | mLastBinder = null; |
| 5013 | if (failIfTimeout || targetWin == null) { |
| 5014 | return null; |
| 5015 | } |
| 5016 | } else { |
| 5017 | Log.w(TAG, "Continuing to wait for key to be dispatched"); |
| 5018 | startTime = SystemClock.uptimeMillis(); |
| 5019 | } |
| 5020 | } |
| 5021 | } |
| 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 | Object findTargetWindow(KeyEvent nextKey, QueuedEvent qev, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5026 | MotionEvent nextMotion, boolean isPointerEvent, |
| 5027 | int callingPid, int callingUid) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5028 | mOutsideTouchTargets = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5029 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5030 | if (nextKey != null) { |
| 5031 | // Find the target window for a normal key event. |
| 5032 | final int keycode = nextKey.getKeyCode(); |
| 5033 | final int repeatCount = nextKey.getRepeatCount(); |
| 5034 | final boolean down = nextKey.getAction() != KeyEvent.ACTION_UP; |
| 5035 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(keycode); |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5036 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5037 | if (!dispatch) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5038 | if (callingUid == 0 || |
| 5039 | mContext.checkPermission( |
| 5040 | android.Manifest.permission.INJECT_EVENTS, |
| 5041 | callingPid, callingUid) |
| 5042 | == PackageManager.PERMISSION_GRANTED) { |
| 5043 | mPolicy.interceptKeyTi(null, keycode, |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 5044 | nextKey.getMetaState(), down, repeatCount, |
| 5045 | nextKey.getFlags()); |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5046 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5047 | Log.w(TAG, "Event timeout during app switch: dropping " |
| 5048 | + nextKey); |
| 5049 | return SKIP_TARGET_TOKEN; |
| 5050 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5051 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5052 | // System.out.println("##### [" + SystemClock.uptimeMillis() + "] WindowManagerService.dispatchKey(" + keycode + ", " + down + ", " + repeatCount + ")"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5053 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5054 | WindowState focus = null; |
| 5055 | synchronized(mWindowMap) { |
| 5056 | focus = getFocusedWindowLocked(); |
| 5057 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5058 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5059 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5060 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5061 | if (callingUid == 0 || |
| 5062 | (focus != null && callingUid == focus.mSession.mUid) || |
| 5063 | mContext.checkPermission( |
| 5064 | android.Manifest.permission.INJECT_EVENTS, |
| 5065 | callingPid, callingUid) |
| 5066 | == PackageManager.PERMISSION_GRANTED) { |
| 5067 | if (mPolicy.interceptKeyTi(focus, |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 5068 | keycode, nextKey.getMetaState(), down, repeatCount, |
| 5069 | nextKey.getFlags())) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5070 | return CONSUMED_EVENT_TOKEN; |
| 5071 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | return focus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5075 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5076 | } else if (!isPointerEvent) { |
| 5077 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(-1); |
| 5078 | if (!dispatch) { |
| 5079 | Log.w(TAG, "Event timeout during app switch: dropping trackball " |
| 5080 | + nextMotion); |
| 5081 | return SKIP_TARGET_TOKEN; |
| 5082 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5083 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5084 | WindowState focus = null; |
| 5085 | synchronized(mWindowMap) { |
| 5086 | focus = getFocusedWindowLocked(); |
| 5087 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5088 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5089 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
| 5090 | return focus; |
| 5091 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5092 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5093 | if (nextMotion == null) { |
| 5094 | return SKIP_TARGET_TOKEN; |
| 5095 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5096 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5097 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey( |
| 5098 | KeyEvent.KEYCODE_UNKNOWN); |
| 5099 | if (!dispatch) { |
| 5100 | Log.w(TAG, "Event timeout during app switch: dropping pointer " |
| 5101 | + nextMotion); |
| 5102 | return SKIP_TARGET_TOKEN; |
| 5103 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5104 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5105 | // Find the target window for a pointer event. |
| 5106 | int action = nextMotion.getAction(); |
| 5107 | final float xf = nextMotion.getX(); |
| 5108 | final float yf = nextMotion.getY(); |
| 5109 | final long eventTime = nextMotion.getEventTime(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5110 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5111 | final boolean screenWasOff = qev != null |
| 5112 | && (qev.flags&WindowManagerPolicy.FLAG_BRIGHT_HERE) != 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5113 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5114 | WindowState target = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5115 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5116 | synchronized(mWindowMap) { |
| 5117 | synchronized (this) { |
| 5118 | if (action == MotionEvent.ACTION_DOWN) { |
| 5119 | if (mMotionTarget != null) { |
| 5120 | // this is weird, we got a pen down, but we thought it was |
| 5121 | // already down! |
| 5122 | // XXX: We should probably send an ACTION_UP to the current |
| 5123 | // target. |
| 5124 | Log.w(TAG, "Pointer down received while already down in: " |
| 5125 | + mMotionTarget); |
| 5126 | mMotionTarget = null; |
| 5127 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5128 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5129 | // ACTION_DOWN is special, because we need to lock next events to |
| 5130 | // the window we'll land onto. |
| 5131 | final int x = (int)xf; |
| 5132 | final int y = (int)yf; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5133 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5134 | final ArrayList windows = mWindows; |
| 5135 | final int N = windows.size(); |
| 5136 | WindowState topErrWindow = null; |
| 5137 | final Rect tmpRect = mTempRect; |
| 5138 | for (int i=N-1; i>=0; i--) { |
| 5139 | WindowState child = (WindowState)windows.get(i); |
| 5140 | //Log.i(TAG, "Checking dispatch to: " + child); |
| 5141 | final int flags = child.mAttrs.flags; |
| 5142 | if ((flags & WindowManager.LayoutParams.FLAG_SYSTEM_ERROR) != 0) { |
| 5143 | if (topErrWindow == null) { |
| 5144 | topErrWindow = child; |
| 5145 | } |
| 5146 | } |
| 5147 | if (!child.isVisibleLw()) { |
| 5148 | //Log.i(TAG, "Not visible!"); |
| 5149 | continue; |
| 5150 | } |
| 5151 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 5152 | //Log.i(TAG, "Not touchable!"); |
| 5153 | if ((flags & WindowManager.LayoutParams |
| 5154 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 5155 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 5156 | mOutsideTouchTargets = child; |
| 5157 | } |
| 5158 | continue; |
| 5159 | } |
| 5160 | tmpRect.set(child.mFrame); |
| 5161 | if (child.mTouchableInsets == ViewTreeObserver |
| 5162 | .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) { |
| 5163 | // The touch is inside of the window if it is |
| 5164 | // inside the frame, AND the content part of that |
| 5165 | // frame that was given by the application. |
| 5166 | tmpRect.left += child.mGivenContentInsets.left; |
| 5167 | tmpRect.top += child.mGivenContentInsets.top; |
| 5168 | tmpRect.right -= child.mGivenContentInsets.right; |
| 5169 | tmpRect.bottom -= child.mGivenContentInsets.bottom; |
| 5170 | } else if (child.mTouchableInsets == ViewTreeObserver |
| 5171 | .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) { |
| 5172 | // The touch is inside of the window if it is |
| 5173 | // inside the frame, AND the visible part of that |
| 5174 | // frame that was given by the application. |
| 5175 | tmpRect.left += child.mGivenVisibleInsets.left; |
| 5176 | tmpRect.top += child.mGivenVisibleInsets.top; |
| 5177 | tmpRect.right -= child.mGivenVisibleInsets.right; |
| 5178 | tmpRect.bottom -= child.mGivenVisibleInsets.bottom; |
| 5179 | } |
| 5180 | final int touchFlags = flags & |
| 5181 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 5182 | |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 5183 | if (tmpRect.contains(x, y) || touchFlags == 0) { |
| 5184 | //Log.i(TAG, "Using this target!"); |
| 5185 | if (!screenWasOff || (flags & |
| 5186 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING) != 0) { |
| 5187 | mMotionTarget = child; |
| 5188 | } else { |
| 5189 | //Log.i(TAG, "Waking, skip!"); |
| 5190 | mMotionTarget = null; |
| 5191 | } |
| 5192 | break; |
| 5193 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5194 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5195 | if ((flags & WindowManager.LayoutParams |
| 5196 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 5197 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 5198 | mOutsideTouchTargets = child; |
| 5199 | //Log.i(TAG, "Adding to outside target list: " + child); |
| 5200 | } |
| 5201 | } |
| 5202 | |
| 5203 | // if there's an error window but it's not accepting |
| 5204 | // focus (typically because it is not yet visible) just |
| 5205 | // wait for it -- any other focused window may in fact |
| 5206 | // be in ANR state. |
| 5207 | if (topErrWindow != null && mMotionTarget != topErrWindow) { |
| 5208 | mMotionTarget = null; |
| 5209 | } |
| 5210 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5211 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5212 | target = mMotionTarget; |
| 5213 | } |
| 5214 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5215 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5216 | wakeupIfNeeded(target, eventType(nextMotion)); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5217 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5218 | // Pointer events are a little different -- if there isn't a |
| 5219 | // target found for any event, then just drop it. |
| 5220 | return target != null ? target : SKIP_TARGET_TOKEN; |
| 5221 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5222 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5223 | boolean checkShouldDispatchKey(int keycode) { |
| 5224 | synchronized (this) { |
| 5225 | if (mPolicy.isAppSwitchKeyTqTiLwLi(keycode)) { |
| 5226 | mTimeToSwitch = 0; |
| 5227 | return true; |
| 5228 | } |
| 5229 | if (mTimeToSwitch != 0 |
| 5230 | && mTimeToSwitch < SystemClock.uptimeMillis()) { |
| 5231 | return false; |
| 5232 | } |
| 5233 | return true; |
| 5234 | } |
| 5235 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5236 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5237 | void bindTargetWindowLocked(WindowState win, |
| 5238 | int pendingWhat, QueuedEvent pendingMotion) { |
| 5239 | synchronized (this) { |
| 5240 | bindTargetWindowLockedLocked(win, pendingWhat, pendingMotion); |
| 5241 | } |
| 5242 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5243 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5244 | void bindTargetWindowLocked(WindowState win) { |
| 5245 | synchronized (this) { |
| 5246 | bindTargetWindowLockedLocked(win, RETURN_NOTHING, null); |
| 5247 | } |
| 5248 | } |
| 5249 | |
| 5250 | void bindTargetWindowLockedLocked(WindowState win, |
| 5251 | int pendingWhat, QueuedEvent pendingMotion) { |
| 5252 | mLastWin = win; |
| 5253 | mLastBinder = win.mClient.asBinder(); |
| 5254 | mFinished = false; |
| 5255 | if (pendingMotion != null) { |
| 5256 | final Session s = win.mSession; |
| 5257 | if (pendingWhat == RETURN_PENDING_POINTER) { |
| 5258 | releasePendingPointerLocked(s); |
| 5259 | s.mPendingPointerMove = pendingMotion; |
| 5260 | s.mPendingPointerWindow = win; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5261 | if (DEBUG_INPUT) Log.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5262 | "bindTargetToWindow " + s.mPendingPointerMove); |
| 5263 | } else if (pendingWhat == RETURN_PENDING_TRACKBALL) { |
| 5264 | releasePendingTrackballLocked(s); |
| 5265 | s.mPendingTrackballMove = pendingMotion; |
| 5266 | s.mPendingTrackballWindow = win; |
| 5267 | } |
| 5268 | } |
| 5269 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5270 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5271 | void releasePendingPointerLocked(Session s) { |
| 5272 | if (DEBUG_INPUT) Log.v(TAG, |
| 5273 | "releasePendingPointer " + s.mPendingPointerMove); |
| 5274 | if (s.mPendingPointerMove != null) { |
| 5275 | mQueue.recycleEvent(s.mPendingPointerMove); |
| 5276 | s.mPendingPointerMove = null; |
| 5277 | } |
| 5278 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5279 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5280 | void releasePendingTrackballLocked(Session s) { |
| 5281 | if (s.mPendingTrackballMove != null) { |
| 5282 | mQueue.recycleEvent(s.mPendingTrackballMove); |
| 5283 | s.mPendingTrackballMove = null; |
| 5284 | } |
| 5285 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5286 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5287 | MotionEvent finishedKey(Session session, IWindow client, boolean force, |
| 5288 | int returnWhat) { |
| 5289 | if (DEBUG_INPUT) Log.v( |
| 5290 | TAG, "finishedKey: client=" + client + ", force=" + force); |
| 5291 | |
| 5292 | if (client == null) { |
| 5293 | return null; |
| 5294 | } |
| 5295 | |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5296 | MotionEvent res = null; |
| 5297 | QueuedEvent qev = null; |
| 5298 | WindowState win = null; |
| 5299 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5300 | synchronized (this) { |
| 5301 | if (DEBUG_INPUT) Log.v( |
| 5302 | TAG, "finishedKey: client=" + client.asBinder() |
| 5303 | + ", force=" + force + ", last=" + mLastBinder |
| 5304 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) + ")"); |
| 5305 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5306 | if (returnWhat == RETURN_PENDING_POINTER) { |
| 5307 | qev = session.mPendingPointerMove; |
| 5308 | win = session.mPendingPointerWindow; |
| 5309 | session.mPendingPointerMove = null; |
| 5310 | session.mPendingPointerWindow = null; |
| 5311 | } else if (returnWhat == RETURN_PENDING_TRACKBALL) { |
| 5312 | qev = session.mPendingTrackballMove; |
| 5313 | win = session.mPendingTrackballWindow; |
| 5314 | session.mPendingTrackballMove = null; |
| 5315 | session.mPendingTrackballWindow = null; |
| 5316 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5317 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5318 | if (mLastBinder == client.asBinder()) { |
| 5319 | if (DEBUG_INPUT) Log.v( |
| 5320 | TAG, "finishedKey: last paused=" |
| 5321 | + ((mLastWin != null) ? mLastWin.mToken.paused : "null")); |
| 5322 | if (mLastWin != null && (!mLastWin.mToken.paused || force |
| 5323 | || !mEventDispatching)) { |
| 5324 | doFinishedKeyLocked(false); |
| 5325 | } else { |
| 5326 | // Make sure to wake up anyone currently waiting to |
| 5327 | // dispatch a key, so they can re-evaluate their |
| 5328 | // current situation. |
| 5329 | mFinished = true; |
| 5330 | notifyAll(); |
| 5331 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5332 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5333 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5334 | if (qev != null) { |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5335 | res = (MotionEvent)qev.event; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5336 | if (DEBUG_INPUT) Log.v(TAG, |
| 5337 | "Returning pending motion: " + res); |
| 5338 | mQueue.recycleEvent(qev); |
| 5339 | if (win != null && returnWhat == RETURN_PENDING_POINTER) { |
| 5340 | res.offsetLocation(-win.mFrame.left, -win.mFrame.top); |
| 5341 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5342 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5343 | } |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5344 | |
| 5345 | if (res != null && returnWhat == RETURN_PENDING_POINTER) { |
| 5346 | synchronized (mWindowMap) { |
| 5347 | if (mWallpaperTarget == win) { |
| 5348 | sendPointerToWallpaperLocked(win, res, res.getEventTime()); |
| 5349 | } |
| 5350 | } |
| 5351 | } |
| 5352 | |
| 5353 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5354 | } |
| 5355 | |
| 5356 | void tickle() { |
| 5357 | synchronized (this) { |
| 5358 | notifyAll(); |
| 5359 | } |
| 5360 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5361 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5362 | void handleNewWindowLocked(WindowState newWindow) { |
| 5363 | if (!newWindow.canReceiveKeys()) { |
| 5364 | return; |
| 5365 | } |
| 5366 | synchronized (this) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5367 | if (DEBUG_INPUT) Log.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5368 | TAG, "New key dispatch window: win=" |
| 5369 | + newWindow.mClient.asBinder() |
| 5370 | + ", last=" + mLastBinder |
| 5371 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 5372 | + "), finished=" + mFinished + ", paused=" |
| 5373 | + newWindow.mToken.paused); |
| 5374 | |
| 5375 | // Displaying a window implicitly causes dispatching to |
| 5376 | // be unpaused. (This is to protect against bugs if someone |
| 5377 | // pauses dispatching but forgets to resume.) |
| 5378 | newWindow.mToken.paused = false; |
| 5379 | |
| 5380 | mGotFirstWindow = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5381 | |
| 5382 | if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) { |
| 5383 | if (DEBUG_INPUT) Log.v(TAG, |
| 5384 | "New SYSTEM_ERROR window; resetting state"); |
| 5385 | mLastWin = null; |
| 5386 | mLastBinder = null; |
| 5387 | mMotionTarget = null; |
| 5388 | mFinished = true; |
| 5389 | } else if (mLastWin != null) { |
| 5390 | // If the new window is above the window we are |
| 5391 | // waiting on, then stop waiting and let key dispatching |
| 5392 | // start on the new guy. |
| 5393 | if (DEBUG_INPUT) Log.v( |
| 5394 | TAG, "Last win layer=" + mLastWin.mLayer |
| 5395 | + ", new win layer=" + newWindow.mLayer); |
| 5396 | if (newWindow.mLayer >= mLastWin.mLayer) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5397 | // The new window is above the old; finish pending input to the last |
| 5398 | // window and start directing it to the new one. |
| 5399 | mLastWin.mToken.paused = false; |
| 5400 | doFinishedKeyLocked(true); // does a notifyAll() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5401 | } |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5402 | // Either the new window is lower, so there is no need to wake key waiters, |
| 5403 | // or we just finished key input to the previous window, which implicitly |
| 5404 | // notified the key waiters. In both cases, we don't need to issue the |
| 5405 | // notification here. |
| 5406 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5407 | } |
| 5408 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5409 | // Now that we've put a new window state in place, make the event waiter |
| 5410 | // take notice and retarget its attentions. |
| 5411 | notifyAll(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5412 | } |
| 5413 | } |
| 5414 | |
| 5415 | void pauseDispatchingLocked(WindowToken token) { |
| 5416 | synchronized (this) |
| 5417 | { |
| 5418 | if (DEBUG_INPUT) Log.v(TAG, "Pausing WindowToken " + token); |
| 5419 | token.paused = true; |
| 5420 | |
| 5421 | /* |
| 5422 | if (mLastWin != null && !mFinished && mLastWin.mBaseLayer <= layer) { |
| 5423 | mPaused = true; |
| 5424 | } else { |
| 5425 | if (mLastWin == null) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 5426 | 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] | 5427 | } else if (mFinished) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 5428 | 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] | 5429 | } else { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 5430 | 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] | 5431 | } |
| 5432 | } |
| 5433 | */ |
| 5434 | } |
| 5435 | } |
| 5436 | |
| 5437 | void resumeDispatchingLocked(WindowToken token) { |
| 5438 | synchronized (this) { |
| 5439 | if (token.paused) { |
| 5440 | if (DEBUG_INPUT) Log.v( |
| 5441 | TAG, "Resuming WindowToken " + token |
| 5442 | + ", last=" + mLastBinder |
| 5443 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 5444 | + "), finished=" + mFinished + ", paused=" |
| 5445 | + token.paused); |
| 5446 | token.paused = false; |
| 5447 | if (mLastWin != null && mLastWin.mToken == token && mFinished) { |
| 5448 | doFinishedKeyLocked(true); |
| 5449 | } else { |
| 5450 | notifyAll(); |
| 5451 | } |
| 5452 | } |
| 5453 | } |
| 5454 | } |
| 5455 | |
| 5456 | void setEventDispatchingLocked(boolean enabled) { |
| 5457 | synchronized (this) { |
| 5458 | mEventDispatching = enabled; |
| 5459 | notifyAll(); |
| 5460 | } |
| 5461 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5462 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5463 | void appSwitchComing() { |
| 5464 | synchronized (this) { |
| 5465 | // Don't wait for more than .5 seconds for app to finish |
| 5466 | // processing the pending events. |
| 5467 | long now = SystemClock.uptimeMillis() + 500; |
| 5468 | if (DEBUG_INPUT) Log.v(TAG, "appSwitchComing: " + now); |
| 5469 | if (mTimeToSwitch == 0 || now < mTimeToSwitch) { |
| 5470 | mTimeToSwitch = now; |
| 5471 | } |
| 5472 | notifyAll(); |
| 5473 | } |
| 5474 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5475 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5476 | private final void doFinishedKeyLocked(boolean doRecycle) { |
| 5477 | if (mLastWin != null) { |
| 5478 | releasePendingPointerLocked(mLastWin.mSession); |
| 5479 | releasePendingTrackballLocked(mLastWin.mSession); |
| 5480 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5481 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5482 | if (mLastWin == null || !mLastWin.mToken.paused |
| 5483 | || !mLastWin.isVisibleLw()) { |
| 5484 | // If the current window has been paused, we aren't -really- |
| 5485 | // finished... so let the waiters still wait. |
| 5486 | mLastWin = null; |
| 5487 | mLastBinder = null; |
| 5488 | } |
| 5489 | mFinished = true; |
| 5490 | notifyAll(); |
| 5491 | } |
| 5492 | } |
| 5493 | |
| 5494 | private class KeyQ extends KeyInputQueue |
| 5495 | implements KeyInputQueue.FilterCallback { |
| 5496 | PowerManager.WakeLock mHoldingScreen; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5497 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5498 | KeyQ() { |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 5499 | super(mContext, WindowManagerService.this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5500 | PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE); |
| 5501 | mHoldingScreen = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 5502 | "KEEP_SCREEN_ON_FLAG"); |
| 5503 | mHoldingScreen.setReferenceCounted(false); |
| 5504 | } |
| 5505 | |
| 5506 | @Override |
| 5507 | boolean preprocessEvent(InputDevice device, RawInputEvent event) { |
| 5508 | if (mPolicy.preprocessInputEventTq(event)) { |
| 5509 | return true; |
| 5510 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5511 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5512 | switch (event.type) { |
| 5513 | case RawInputEvent.EV_KEY: { |
| 5514 | // XXX begin hack |
| 5515 | if (DEBUG) { |
| 5516 | if (event.keycode == KeyEvent.KEYCODE_G) { |
| 5517 | if (event.value != 0) { |
| 5518 | // G down |
| 5519 | mPolicy.screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 5520 | } |
| 5521 | return false; |
| 5522 | } |
| 5523 | if (event.keycode == KeyEvent.KEYCODE_D) { |
| 5524 | if (event.value != 0) { |
| 5525 | //dump(); |
| 5526 | } |
| 5527 | return false; |
| 5528 | } |
| 5529 | } |
| 5530 | // XXX end hack |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5531 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5532 | boolean screenIsOff = !mPowerManager.screenIsOn(); |
| 5533 | boolean screenIsDim = !mPowerManager.screenIsBright(); |
| 5534 | int actions = mPolicy.interceptKeyTq(event, !screenIsOff); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5535 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5536 | if ((actions & WindowManagerPolicy.ACTION_GO_TO_SLEEP) != 0) { |
| 5537 | mPowerManager.goToSleep(event.when); |
| 5538 | } |
| 5539 | |
| 5540 | if (screenIsOff) { |
| 5541 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 5542 | } |
| 5543 | if (screenIsDim) { |
| 5544 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 5545 | } |
| 5546 | if ((actions & WindowManagerPolicy.ACTION_POKE_USER_ACTIVITY) != 0) { |
| 5547 | mPowerManager.userActivity(event.when, false, |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5548 | LocalPowerManager.BUTTON_EVENT, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5549 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5550 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5551 | if ((actions & WindowManagerPolicy.ACTION_PASS_TO_USER) != 0) { |
| 5552 | if (event.value != 0 && mPolicy.isAppSwitchKeyTqTiLwLi(event.keycode)) { |
| 5553 | filterQueue(this); |
| 5554 | mKeyWaiter.appSwitchComing(); |
| 5555 | } |
| 5556 | return true; |
| 5557 | } else { |
| 5558 | return false; |
| 5559 | } |
| 5560 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5561 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5562 | case RawInputEvent.EV_REL: { |
| 5563 | boolean screenIsOff = !mPowerManager.screenIsOn(); |
| 5564 | boolean screenIsDim = !mPowerManager.screenIsBright(); |
| 5565 | if (screenIsOff) { |
| 5566 | if (!mPolicy.isWakeRelMovementTq(event.deviceId, |
| 5567 | device.classes, event)) { |
| 5568 | //Log.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| 5569 | return false; |
| 5570 | } |
| 5571 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 5572 | } |
| 5573 | if (screenIsDim) { |
| 5574 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 5575 | } |
| 5576 | return true; |
| 5577 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5578 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5579 | case RawInputEvent.EV_ABS: { |
| 5580 | boolean screenIsOff = !mPowerManager.screenIsOn(); |
| 5581 | boolean screenIsDim = !mPowerManager.screenIsBright(); |
| 5582 | if (screenIsOff) { |
| 5583 | if (!mPolicy.isWakeAbsMovementTq(event.deviceId, |
| 5584 | device.classes, event)) { |
| 5585 | //Log.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| 5586 | return false; |
| 5587 | } |
| 5588 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 5589 | } |
| 5590 | if (screenIsDim) { |
| 5591 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 5592 | } |
| 5593 | return true; |
| 5594 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5595 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5596 | default: |
| 5597 | return true; |
| 5598 | } |
| 5599 | } |
| 5600 | |
| 5601 | public int filterEvent(QueuedEvent ev) { |
| 5602 | switch (ev.classType) { |
| 5603 | case RawInputEvent.CLASS_KEYBOARD: |
| 5604 | KeyEvent ke = (KeyEvent)ev.event; |
| 5605 | if (mPolicy.isMovementKeyTi(ke.getKeyCode())) { |
| 5606 | Log.w(TAG, "Dropping movement key during app switch: " |
| 5607 | + ke.getKeyCode() + ", action=" + ke.getAction()); |
| 5608 | return FILTER_REMOVE; |
| 5609 | } |
| 5610 | return FILTER_ABORT; |
| 5611 | default: |
| 5612 | return FILTER_KEEP; |
| 5613 | } |
| 5614 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5615 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5616 | /** |
| 5617 | * Must be called with the main window manager lock held. |
| 5618 | */ |
| 5619 | void setHoldScreenLocked(boolean holding) { |
| 5620 | boolean state = mHoldingScreen.isHeld(); |
| 5621 | if (holding != state) { |
| 5622 | if (holding) { |
| 5623 | mHoldingScreen.acquire(); |
| 5624 | } else { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 5625 | mPolicy.screenOnStoppedLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5626 | mHoldingScreen.release(); |
| 5627 | } |
| 5628 | } |
| 5629 | } |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5630 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5631 | |
| 5632 | public boolean detectSafeMode() { |
| 5633 | mSafeMode = mPolicy.detectSafeMode(); |
| 5634 | return mSafeMode; |
| 5635 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5636 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5637 | public void systemReady() { |
| 5638 | mPolicy.systemReady(); |
| 5639 | } |
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 | private final class InputDispatcherThread extends Thread { |
| 5642 | // Time to wait when there is nothing to do: 9999 seconds. |
| 5643 | static final int LONG_WAIT=9999*1000; |
| 5644 | |
| 5645 | public InputDispatcherThread() { |
| 5646 | super("InputDispatcher"); |
| 5647 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5648 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5649 | @Override |
| 5650 | public void run() { |
| 5651 | while (true) { |
| 5652 | try { |
| 5653 | process(); |
| 5654 | } catch (Exception e) { |
| 5655 | Log.e(TAG, "Exception in input dispatcher", e); |
| 5656 | } |
| 5657 | } |
| 5658 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5659 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5660 | private void process() { |
| 5661 | android.os.Process.setThreadPriority( |
| 5662 | android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5663 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5664 | // The last key event we saw |
| 5665 | KeyEvent lastKey = null; |
| 5666 | |
| 5667 | // Last keydown time for auto-repeating keys |
| 5668 | long lastKeyTime = SystemClock.uptimeMillis(); |
| 5669 | long nextKeyTime = lastKeyTime+LONG_WAIT; |
| 5670 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5671 | // How many successive repeats we generated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5672 | int keyRepeatCount = 0; |
| 5673 | |
| 5674 | // Need to report that configuration has changed? |
| 5675 | boolean configChanged = false; |
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 | while (true) { |
| 5678 | long curTime = SystemClock.uptimeMillis(); |
| 5679 | |
| 5680 | if (DEBUG_INPUT) Log.v( |
| 5681 | TAG, "Waiting for next key: now=" + curTime |
| 5682 | + ", repeat @ " + nextKeyTime); |
| 5683 | |
| 5684 | // Retrieve next event, waiting only as long as the next |
| 5685 | // repeat timeout. If the configuration has changed, then |
| 5686 | // don't wait at all -- we'll report the change as soon as |
| 5687 | // we have processed all events. |
| 5688 | QueuedEvent ev = mQueue.getEvent( |
| 5689 | (int)((!configChanged && curTime < nextKeyTime) |
| 5690 | ? (nextKeyTime-curTime) : 0)); |
| 5691 | |
| 5692 | if (DEBUG_INPUT && ev != null) Log.v( |
| 5693 | TAG, "Event: type=" + ev.classType + " data=" + ev.event); |
| 5694 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5695 | if (MEASURE_LATENCY) { |
| 5696 | lt.sample("2 got event ", System.nanoTime() - ev.whenNano); |
| 5697 | } |
| 5698 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5699 | try { |
| 5700 | if (ev != null) { |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5701 | curTime = SystemClock.uptimeMillis(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5702 | int eventType; |
| 5703 | if (ev.classType == RawInputEvent.CLASS_TOUCHSCREEN) { |
| 5704 | eventType = eventType((MotionEvent)ev.event); |
| 5705 | } else if (ev.classType == RawInputEvent.CLASS_KEYBOARD || |
| 5706 | ev.classType == RawInputEvent.CLASS_TRACKBALL) { |
| 5707 | eventType = LocalPowerManager.BUTTON_EVENT; |
| 5708 | } else { |
| 5709 | eventType = LocalPowerManager.OTHER_EVENT; |
| 5710 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5711 | try { |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5712 | if ((curTime - mLastBatteryStatsCallTime) |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5713 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5714 | mLastBatteryStatsCallTime = curTime; |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5715 | mBatteryStats.noteInputEvent(); |
| 5716 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5717 | } catch (RemoteException e) { |
| 5718 | // Ignore |
| 5719 | } |
Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 5720 | |
| 5721 | if (eventType != TOUCH_EVENT |
| 5722 | && eventType != LONG_TOUCH_EVENT |
| 5723 | && eventType != CHEEK_EVENT) { |
| 5724 | mPowerManager.userActivity(curTime, false, |
| 5725 | eventType, false); |
| 5726 | } else if (mLastTouchEventType != eventType |
| 5727 | || (curTime - mLastUserActivityCallTime) |
| 5728 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 5729 | mLastUserActivityCallTime = curTime; |
| 5730 | mLastTouchEventType = eventType; |
| 5731 | mPowerManager.userActivity(curTime, false, |
| 5732 | eventType, false); |
| 5733 | } |
| 5734 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5735 | switch (ev.classType) { |
| 5736 | case RawInputEvent.CLASS_KEYBOARD: |
| 5737 | KeyEvent ke = (KeyEvent)ev.event; |
| 5738 | if (ke.isDown()) { |
| 5739 | lastKey = ke; |
| 5740 | keyRepeatCount = 0; |
| 5741 | lastKeyTime = curTime; |
| 5742 | nextKeyTime = lastKeyTime |
| 5743 | + KEY_REPEAT_FIRST_DELAY; |
| 5744 | if (DEBUG_INPUT) Log.v( |
| 5745 | TAG, "Received key down: first repeat @ " |
| 5746 | + nextKeyTime); |
| 5747 | } else { |
| 5748 | lastKey = null; |
| 5749 | // Arbitrary long timeout. |
| 5750 | lastKeyTime = curTime; |
| 5751 | nextKeyTime = curTime + LONG_WAIT; |
| 5752 | if (DEBUG_INPUT) Log.v( |
| 5753 | TAG, "Received key up: ignore repeat @ " |
| 5754 | + nextKeyTime); |
| 5755 | } |
| 5756 | dispatchKey((KeyEvent)ev.event, 0, 0); |
| 5757 | mQueue.recycleEvent(ev); |
| 5758 | break; |
| 5759 | case RawInputEvent.CLASS_TOUCHSCREEN: |
| 5760 | //Log.i(TAG, "Read next event " + ev); |
| 5761 | dispatchPointer(ev, (MotionEvent)ev.event, 0, 0); |
| 5762 | break; |
| 5763 | case RawInputEvent.CLASS_TRACKBALL: |
| 5764 | dispatchTrackball(ev, (MotionEvent)ev.event, 0, 0); |
| 5765 | break; |
| 5766 | case RawInputEvent.CLASS_CONFIGURATION_CHANGED: |
| 5767 | configChanged = true; |
| 5768 | break; |
| 5769 | default: |
| 5770 | mQueue.recycleEvent(ev); |
| 5771 | break; |
| 5772 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5773 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5774 | } else if (configChanged) { |
| 5775 | configChanged = false; |
| 5776 | sendNewConfiguration(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5777 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5778 | } else if (lastKey != null) { |
| 5779 | curTime = SystemClock.uptimeMillis(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5780 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5781 | // Timeout occurred while key was down. If it is at or |
| 5782 | // past the key repeat time, dispatch the repeat. |
| 5783 | if (DEBUG_INPUT) Log.v( |
| 5784 | TAG, "Key timeout: repeat=" + nextKeyTime |
| 5785 | + ", now=" + curTime); |
| 5786 | if (curTime < nextKeyTime) { |
| 5787 | continue; |
| 5788 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5789 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5790 | lastKeyTime = nextKeyTime; |
| 5791 | nextKeyTime = nextKeyTime + KEY_REPEAT_DELAY; |
| 5792 | keyRepeatCount++; |
| 5793 | if (DEBUG_INPUT) Log.v( |
| 5794 | TAG, "Key repeat: count=" + keyRepeatCount |
| 5795 | + ", next @ " + nextKeyTime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5796 | dispatchKey(KeyEvent.changeTimeRepeat(lastKey, curTime, keyRepeatCount), 0, 0); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5797 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5798 | } else { |
| 5799 | curTime = SystemClock.uptimeMillis(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5800 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5801 | lastKeyTime = curTime; |
| 5802 | nextKeyTime = curTime + LONG_WAIT; |
| 5803 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5804 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5805 | } catch (Exception e) { |
| 5806 | Log.e(TAG, |
| 5807 | "Input thread received uncaught exception: " + e, e); |
| 5808 | } |
| 5809 | } |
| 5810 | } |
| 5811 | } |
| 5812 | |
| 5813 | // ------------------------------------------------------------- |
| 5814 | // Client Session State |
| 5815 | // ------------------------------------------------------------- |
| 5816 | |
| 5817 | private final class Session extends IWindowSession.Stub |
| 5818 | implements IBinder.DeathRecipient { |
| 5819 | final IInputMethodClient mClient; |
| 5820 | final IInputContext mInputContext; |
| 5821 | final int mUid; |
| 5822 | final int mPid; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5823 | final String mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5824 | SurfaceSession mSurfaceSession; |
| 5825 | int mNumWindow = 0; |
| 5826 | boolean mClientDead = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5827 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5828 | /** |
| 5829 | * Current pointer move event being dispatched to client window... must |
| 5830 | * hold key lock to access. |
| 5831 | */ |
| 5832 | QueuedEvent mPendingPointerMove; |
| 5833 | WindowState mPendingPointerWindow; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5834 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5835 | /** |
| 5836 | * Current trackball move event being dispatched to client window... must |
| 5837 | * hold key lock to access. |
| 5838 | */ |
| 5839 | QueuedEvent mPendingTrackballMove; |
| 5840 | WindowState mPendingTrackballWindow; |
| 5841 | |
| 5842 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 5843 | mClient = client; |
| 5844 | mInputContext = inputContext; |
| 5845 | mUid = Binder.getCallingUid(); |
| 5846 | mPid = Binder.getCallingPid(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5847 | StringBuilder sb = new StringBuilder(); |
| 5848 | sb.append("Session{"); |
| 5849 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 5850 | sb.append(" uid "); |
| 5851 | sb.append(mUid); |
| 5852 | sb.append("}"); |
| 5853 | mStringName = sb.toString(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5854 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5855 | synchronized (mWindowMap) { |
| 5856 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 5857 | IBinder b = ServiceManager.getService( |
| 5858 | Context.INPUT_METHOD_SERVICE); |
| 5859 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 5860 | } |
| 5861 | } |
| 5862 | long ident = Binder.clearCallingIdentity(); |
| 5863 | try { |
| 5864 | // Note: it is safe to call in to the input method manager |
| 5865 | // here because we are not holding our lock. |
| 5866 | if (mInputMethodManager != null) { |
| 5867 | mInputMethodManager.addClient(client, inputContext, |
| 5868 | mUid, mPid); |
| 5869 | } else { |
| 5870 | client.setUsingInputMethod(false); |
| 5871 | } |
| 5872 | client.asBinder().linkToDeath(this, 0); |
| 5873 | } catch (RemoteException e) { |
| 5874 | // The caller has died, so we can just forget about this. |
| 5875 | try { |
| 5876 | if (mInputMethodManager != null) { |
| 5877 | mInputMethodManager.removeClient(client); |
| 5878 | } |
| 5879 | } catch (RemoteException ee) { |
| 5880 | } |
| 5881 | } finally { |
| 5882 | Binder.restoreCallingIdentity(ident); |
| 5883 | } |
| 5884 | } |
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 | @Override |
| 5887 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 5888 | throws RemoteException { |
| 5889 | try { |
| 5890 | return super.onTransact(code, data, reply, flags); |
| 5891 | } catch (RuntimeException e) { |
| 5892 | // Log all 'real' exceptions thrown to the caller |
| 5893 | if (!(e instanceof SecurityException)) { |
| 5894 | Log.e(TAG, "Window Session Crash", e); |
| 5895 | } |
| 5896 | throw e; |
| 5897 | } |
| 5898 | } |
| 5899 | |
| 5900 | public void binderDied() { |
| 5901 | // Note: it is safe to call in to the input method manager |
| 5902 | // here because we are not holding our lock. |
| 5903 | try { |
| 5904 | if (mInputMethodManager != null) { |
| 5905 | mInputMethodManager.removeClient(mClient); |
| 5906 | } |
| 5907 | } catch (RemoteException e) { |
| 5908 | } |
| 5909 | synchronized(mWindowMap) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 5910 | mClient.asBinder().unlinkToDeath(this, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5911 | mClientDead = true; |
| 5912 | killSessionLocked(); |
| 5913 | } |
| 5914 | } |
| 5915 | |
| 5916 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
| 5917 | int viewVisibility, Rect outContentInsets) { |
| 5918 | return addWindow(this, window, attrs, viewVisibility, outContentInsets); |
| 5919 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5920 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5921 | public void remove(IWindow window) { |
| 5922 | removeWindow(this, window); |
| 5923 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5924 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5925 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 5926 | int requestedWidth, int requestedHeight, int viewFlags, |
| 5927 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
| 5928 | Rect outVisibleInsets, Surface outSurface) { |
| 5929 | return relayoutWindow(this, window, attrs, |
| 5930 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
| 5931 | outFrame, outContentInsets, outVisibleInsets, outSurface); |
| 5932 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5933 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5934 | public void setTransparentRegion(IWindow window, Region region) { |
| 5935 | setTransparentRegionWindow(this, window, region); |
| 5936 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5937 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5938 | public void setInsets(IWindow window, int touchableInsets, |
| 5939 | Rect contentInsets, Rect visibleInsets) { |
| 5940 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 5941 | visibleInsets); |
| 5942 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5943 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5944 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 5945 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 5946 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5947 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5948 | public void finishDrawing(IWindow window) { |
| 5949 | if (localLOGV) Log.v( |
| 5950 | TAG, "IWindow finishDrawing called for " + window); |
| 5951 | finishDrawingWindow(this, window); |
| 5952 | } |
| 5953 | |
| 5954 | public void finishKey(IWindow window) { |
| 5955 | if (localLOGV) Log.v( |
| 5956 | TAG, "IWindow finishKey called for " + window); |
| 5957 | mKeyWaiter.finishedKey(this, window, false, |
| 5958 | KeyWaiter.RETURN_NOTHING); |
| 5959 | } |
| 5960 | |
| 5961 | public MotionEvent getPendingPointerMove(IWindow window) { |
| 5962 | if (localLOGV) Log.v( |
| 5963 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 5964 | return mKeyWaiter.finishedKey(this, window, false, |
| 5965 | KeyWaiter.RETURN_PENDING_POINTER); |
| 5966 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5967 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5968 | public MotionEvent getPendingTrackballMove(IWindow window) { |
| 5969 | if (localLOGV) Log.v( |
| 5970 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 5971 | return mKeyWaiter.finishedKey(this, window, false, |
| 5972 | KeyWaiter.RETURN_PENDING_TRACKBALL); |
| 5973 | } |
| 5974 | |
| 5975 | public void setInTouchMode(boolean mode) { |
| 5976 | synchronized(mWindowMap) { |
| 5977 | mInTouchMode = mode; |
| 5978 | } |
| 5979 | } |
| 5980 | |
| 5981 | public boolean getInTouchMode() { |
| 5982 | synchronized(mWindowMap) { |
| 5983 | return mInTouchMode; |
| 5984 | } |
| 5985 | } |
| 5986 | |
| 5987 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 5988 | boolean always) { |
| 5989 | synchronized(mWindowMap) { |
| 5990 | long ident = Binder.clearCallingIdentity(); |
| 5991 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 5992 | return mPolicy.performHapticFeedbackLw( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5993 | windowForClientLocked(this, window), effectId, always); |
| 5994 | } finally { |
| 5995 | Binder.restoreCallingIdentity(ident); |
| 5996 | } |
| 5997 | } |
| 5998 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5999 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6000 | public void setWallpaperPosition(IBinder window, float x, float y) { |
| 6001 | synchronized(mWindowMap) { |
| 6002 | long ident = Binder.clearCallingIdentity(); |
| 6003 | try { |
| 6004 | setWindowWallpaperPositionLocked(windowForClientLocked(this, window), |
| 6005 | x, y); |
| 6006 | } finally { |
| 6007 | Binder.restoreCallingIdentity(ident); |
| 6008 | } |
| 6009 | } |
| 6010 | } |
| 6011 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6012 | void windowAddedLocked() { |
| 6013 | if (mSurfaceSession == null) { |
| 6014 | if (localLOGV) Log.v( |
| 6015 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 6016 | mSurfaceSession = new SurfaceSession(); |
| 6017 | mSessions.add(this); |
| 6018 | } |
| 6019 | mNumWindow++; |
| 6020 | } |
| 6021 | |
| 6022 | void windowRemovedLocked() { |
| 6023 | mNumWindow--; |
| 6024 | killSessionLocked(); |
| 6025 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6026 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6027 | void killSessionLocked() { |
| 6028 | if (mNumWindow <= 0 && mClientDead) { |
| 6029 | mSessions.remove(this); |
| 6030 | if (mSurfaceSession != null) { |
| 6031 | if (localLOGV) Log.v( |
| 6032 | TAG, "Last window removed from " + this |
| 6033 | + ", destroying " + mSurfaceSession); |
| 6034 | try { |
| 6035 | mSurfaceSession.kill(); |
| 6036 | } catch (Exception e) { |
| 6037 | Log.w(TAG, "Exception thrown when killing surface session " |
| 6038 | + mSurfaceSession + " in session " + this |
| 6039 | + ": " + e.toString()); |
| 6040 | } |
| 6041 | mSurfaceSession = null; |
| 6042 | } |
| 6043 | } |
| 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 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6047 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 6048 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 6049 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
| 6050 | if (mPendingPointerWindow != null || mPendingPointerMove != null) { |
| 6051 | pw.print(prefix); |
| 6052 | pw.print("mPendingPointerWindow="); pw.print(mPendingPointerWindow); |
| 6053 | pw.print(" mPendingPointerMove="); pw.println(mPendingPointerMove); |
| 6054 | } |
| 6055 | if (mPendingTrackballWindow != null || mPendingTrackballMove != null) { |
| 6056 | pw.print(prefix); |
| 6057 | pw.print("mPendingTrackballWindow="); pw.print(mPendingTrackballWindow); |
| 6058 | pw.print(" mPendingTrackballMove="); pw.println(mPendingTrackballMove); |
| 6059 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6060 | } |
| 6061 | |
| 6062 | @Override |
| 6063 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6064 | return mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6065 | } |
| 6066 | } |
| 6067 | |
| 6068 | // ------------------------------------------------------------- |
| 6069 | // Client Window State |
| 6070 | // ------------------------------------------------------------- |
| 6071 | |
| 6072 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 6073 | final Session mSession; |
| 6074 | final IWindow mClient; |
| 6075 | WindowToken mToken; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6076 | WindowToken mRootToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6077 | AppWindowToken mAppToken; |
| 6078 | AppWindowToken mTargetAppToken; |
| 6079 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 6080 | final DeathRecipient mDeathRecipient; |
| 6081 | final WindowState mAttachedWindow; |
| 6082 | final ArrayList mChildWindows = new ArrayList(); |
| 6083 | final int mBaseLayer; |
| 6084 | final int mSubLayer; |
| 6085 | final boolean mLayoutAttached; |
| 6086 | final boolean mIsImWindow; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6087 | final boolean mIsWallpaper; |
| 6088 | final boolean mIsFloatingLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6089 | int mViewVisibility; |
| 6090 | boolean mPolicyVisibility = true; |
| 6091 | boolean mPolicyVisibilityAfterAnim = true; |
| 6092 | boolean mAppFreezing; |
| 6093 | Surface mSurface; |
| 6094 | boolean mAttachedHidden; // is our parent window hidden? |
| 6095 | boolean mLastHidden; // was this window last hidden? |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6096 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6097 | int mRequestedWidth; |
| 6098 | int mRequestedHeight; |
| 6099 | int mLastRequestedWidth; |
| 6100 | int mLastRequestedHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6101 | int mLayer; |
| 6102 | int mAnimLayer; |
| 6103 | int mLastLayer; |
| 6104 | boolean mHaveFrame; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6105 | boolean mObscured; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6106 | |
| 6107 | WindowState mNextOutsideTouch; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6108 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6109 | // Actual frame shown on-screen (may be modified by animation) |
| 6110 | final Rect mShownFrame = new Rect(); |
| 6111 | final Rect mLastShownFrame = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6112 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6113 | /** |
| 6114 | * Insets that determine the actually visible area |
| 6115 | */ |
| 6116 | final Rect mVisibleInsets = new Rect(); |
| 6117 | final Rect mLastVisibleInsets = new Rect(); |
| 6118 | boolean mVisibleInsetsChanged; |
| 6119 | |
| 6120 | /** |
| 6121 | * Insets that are covered by system windows |
| 6122 | */ |
| 6123 | final Rect mContentInsets = new Rect(); |
| 6124 | final Rect mLastContentInsets = new Rect(); |
| 6125 | boolean mContentInsetsChanged; |
| 6126 | |
| 6127 | /** |
| 6128 | * Set to true if we are waiting for this window to receive its |
| 6129 | * given internal insets before laying out other windows based on it. |
| 6130 | */ |
| 6131 | boolean mGivenInsetsPending; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6132 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6133 | /** |
| 6134 | * These are the content insets that were given during layout for |
| 6135 | * this window, to be applied to windows behind it. |
| 6136 | */ |
| 6137 | final Rect mGivenContentInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6138 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6139 | /** |
| 6140 | * These are the visible insets that were given during layout for |
| 6141 | * this window, to be applied to windows behind it. |
| 6142 | */ |
| 6143 | final Rect mGivenVisibleInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6144 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6145 | /** |
| 6146 | * Flag indicating whether the touchable region should be adjusted by |
| 6147 | * the visible insets; if false the area outside the visible insets is |
| 6148 | * NOT touchable, so we must use those to adjust the frame during hit |
| 6149 | * tests. |
| 6150 | */ |
| 6151 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6152 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6153 | // Current transformation being applied. |
| 6154 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 6155 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 6156 | float mHScale=1, mVScale=1; |
| 6157 | float mLastHScale=1, mLastVScale=1; |
| 6158 | final Matrix mTmpMatrix = new Matrix(); |
| 6159 | |
| 6160 | // "Real" frame that the application sees. |
| 6161 | final Rect mFrame = new Rect(); |
| 6162 | final Rect mLastFrame = new Rect(); |
| 6163 | |
| 6164 | final Rect mContainingFrame = new Rect(); |
| 6165 | final Rect mDisplayFrame = new Rect(); |
| 6166 | final Rect mContentFrame = new Rect(); |
| 6167 | final Rect mVisibleFrame = new Rect(); |
| 6168 | |
| 6169 | float mShownAlpha = 1; |
| 6170 | float mAlpha = 1; |
| 6171 | float mLastAlpha = 1; |
| 6172 | |
| 6173 | // Set to true if, when the window gets displayed, it should perform |
| 6174 | // an enter animation. |
| 6175 | boolean mEnterAnimationPending; |
| 6176 | |
| 6177 | // Currently running animation. |
| 6178 | boolean mAnimating; |
| 6179 | boolean mLocalAnimating; |
| 6180 | Animation mAnimation; |
| 6181 | boolean mAnimationIsEntrance; |
| 6182 | boolean mHasTransformation; |
| 6183 | boolean mHasLocalTransformation; |
| 6184 | final Transformation mTransformation = new Transformation(); |
| 6185 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6186 | // If a window showing a wallpaper: the requested offset for the |
| 6187 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 6188 | float mWallpaperX = -1; |
| 6189 | float mWallpaperY = -1; |
| 6190 | |
| 6191 | // Wallpaper windows: pixels offset based on above variables. |
| 6192 | int mXOffset; |
| 6193 | int mYOffset; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6194 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6195 | // This is set after IWindowSession.relayout() has been called at |
| 6196 | // least once for the window. It allows us to detect the situation |
| 6197 | // where we don't yet have a surface, but should have one soon, so |
| 6198 | // we can give the window focus before waiting for the relayout. |
| 6199 | boolean mRelayoutCalled; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6200 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6201 | // This is set after the Surface has been created but before the |
| 6202 | // window has been drawn. During this time the surface is hidden. |
| 6203 | boolean mDrawPending; |
| 6204 | |
| 6205 | // This is set after the window has finished drawing for the first |
| 6206 | // time but before its surface is shown. The surface will be |
| 6207 | // displayed when the next layout is run. |
| 6208 | boolean mCommitDrawPending; |
| 6209 | |
| 6210 | // This is set during the time after the window's drawing has been |
| 6211 | // committed, and before its surface is actually shown. It is used |
| 6212 | // to delay showing the surface until all windows in a token are ready |
| 6213 | // to be shown. |
| 6214 | boolean mReadyToShow; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6215 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6216 | // Set when the window has been shown in the screen the first time. |
| 6217 | boolean mHasDrawn; |
| 6218 | |
| 6219 | // Currently running an exit animation? |
| 6220 | boolean mExiting; |
| 6221 | |
| 6222 | // Currently on the mDestroySurface list? |
| 6223 | boolean mDestroying; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6224 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6225 | // Completely remove from window manager after exit animation? |
| 6226 | boolean mRemoveOnExit; |
| 6227 | |
| 6228 | // Set when the orientation is changing and this window has not yet |
| 6229 | // been updated for the new orientation. |
| 6230 | boolean mOrientationChanging; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6231 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6232 | // Is this window now (or just being) removed? |
| 6233 | boolean mRemoved; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6234 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6235 | WindowState(Session s, IWindow c, WindowToken token, |
| 6236 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 6237 | int viewVisibility) { |
| 6238 | mSession = s; |
| 6239 | mClient = c; |
| 6240 | mToken = token; |
| 6241 | mAttrs.copyFrom(a); |
| 6242 | mViewVisibility = viewVisibility; |
| 6243 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 6244 | mAlpha = a.alpha; |
| 6245 | if (localLOGV) Log.v( |
| 6246 | TAG, "Window " + this + " client=" + c.asBinder() |
| 6247 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 6248 | try { |
| 6249 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 6250 | } catch (RemoteException e) { |
| 6251 | mDeathRecipient = null; |
| 6252 | mAttachedWindow = null; |
| 6253 | mLayoutAttached = false; |
| 6254 | mIsImWindow = false; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6255 | mIsWallpaper = false; |
| 6256 | mIsFloatingLayer = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6257 | mBaseLayer = 0; |
| 6258 | mSubLayer = 0; |
| 6259 | return; |
| 6260 | } |
| 6261 | mDeathRecipient = deathRecipient; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6262 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6263 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 6264 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 6265 | // The multiplier here is to reserve space for multiple |
| 6266 | // windows in the same type layer. |
| 6267 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 6268 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 6269 | + TYPE_LAYER_OFFSET; |
| 6270 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 6271 | mAttachedWindow = attachedWindow; |
| 6272 | mAttachedWindow.mChildWindows.add(this); |
| 6273 | mLayoutAttached = mAttrs.type != |
| 6274 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 6275 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 6276 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6277 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 6278 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6279 | } else { |
| 6280 | // The multiplier here is to reserve space for multiple |
| 6281 | // windows in the same type layer. |
| 6282 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 6283 | * TYPE_LAYER_MULTIPLIER |
| 6284 | + TYPE_LAYER_OFFSET; |
| 6285 | mSubLayer = 0; |
| 6286 | mAttachedWindow = null; |
| 6287 | mLayoutAttached = false; |
| 6288 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 6289 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6290 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 6291 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6292 | } |
| 6293 | |
| 6294 | WindowState appWin = this; |
| 6295 | while (appWin.mAttachedWindow != null) { |
| 6296 | appWin = mAttachedWindow; |
| 6297 | } |
| 6298 | WindowToken appToken = appWin.mToken; |
| 6299 | while (appToken.appWindowToken == null) { |
| 6300 | WindowToken parent = mTokenMap.get(appToken.token); |
| 6301 | if (parent == null || appToken == parent) { |
| 6302 | break; |
| 6303 | } |
| 6304 | appToken = parent; |
| 6305 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6306 | mRootToken = appToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6307 | mAppToken = appToken.appWindowToken; |
| 6308 | |
| 6309 | mSurface = null; |
| 6310 | mRequestedWidth = 0; |
| 6311 | mRequestedHeight = 0; |
| 6312 | mLastRequestedWidth = 0; |
| 6313 | mLastRequestedHeight = 0; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6314 | mXOffset = 0; |
| 6315 | mYOffset = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6316 | mLayer = 0; |
| 6317 | mAnimLayer = 0; |
| 6318 | mLastLayer = 0; |
| 6319 | } |
| 6320 | |
| 6321 | void attach() { |
| 6322 | if (localLOGV) Log.v( |
| 6323 | TAG, "Attaching " + this + " token=" + mToken |
| 6324 | + ", list=" + mToken.windows); |
| 6325 | mSession.windowAddedLocked(); |
| 6326 | } |
| 6327 | |
| 6328 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 6329 | mHaveFrame = true; |
| 6330 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6331 | final Rect container = mContainingFrame; |
| 6332 | container.set(pf); |
| 6333 | |
| 6334 | final Rect display = mDisplayFrame; |
| 6335 | display.set(df); |
| 6336 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6337 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6338 | container.intersect(mCompatibleScreenFrame); |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6339 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 6340 | display.intersect(mCompatibleScreenFrame); |
| 6341 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6342 | } |
| 6343 | |
| 6344 | final int pw = container.right - container.left; |
| 6345 | final int ph = container.bottom - container.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6346 | |
| 6347 | int w,h; |
| 6348 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 6349 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 6350 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 6351 | } else { |
| 6352 | w = mAttrs.width == mAttrs.FILL_PARENT ? pw : mRequestedWidth; |
| 6353 | h = mAttrs.height== mAttrs.FILL_PARENT ? ph : mRequestedHeight; |
| 6354 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6355 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6356 | final Rect content = mContentFrame; |
| 6357 | content.set(cf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6358 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6359 | final Rect visible = mVisibleFrame; |
| 6360 | visible.set(vf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6361 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6362 | final Rect frame = mFrame; |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame^] | 6363 | final int fw = frame.width(); |
| 6364 | final int fh = frame.height(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6365 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6366 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 6367 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 6368 | |
| 6369 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 6370 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 6371 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 6372 | |
| 6373 | //System.out.println("Out: " + mFrame); |
| 6374 | |
| 6375 | // Now make sure the window fits in the overall display. |
| 6376 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6377 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6378 | // Make sure the content and visible frames are inside of the |
| 6379 | // final window frame. |
| 6380 | if (content.left < frame.left) content.left = frame.left; |
| 6381 | if (content.top < frame.top) content.top = frame.top; |
| 6382 | if (content.right > frame.right) content.right = frame.right; |
| 6383 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 6384 | if (visible.left < frame.left) visible.left = frame.left; |
| 6385 | if (visible.top < frame.top) visible.top = frame.top; |
| 6386 | if (visible.right > frame.right) visible.right = frame.right; |
| 6387 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6388 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6389 | final Rect contentInsets = mContentInsets; |
| 6390 | contentInsets.left = content.left-frame.left; |
| 6391 | contentInsets.top = content.top-frame.top; |
| 6392 | contentInsets.right = frame.right-content.right; |
| 6393 | contentInsets.bottom = frame.bottom-content.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6394 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6395 | final Rect visibleInsets = mVisibleInsets; |
| 6396 | visibleInsets.left = visible.left-frame.left; |
| 6397 | visibleInsets.top = visible.top-frame.top; |
| 6398 | visibleInsets.right = frame.right-visible.right; |
| 6399 | visibleInsets.bottom = frame.bottom-visible.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6400 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame^] | 6401 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height()) |
| 6402 | && mWallpaperTarget != null) { |
| 6403 | updateWallpaperOffsetLocked(mWallpaperTarget, this, |
| 6404 | mDisplay.getWidth(), mDisplay.getHeight()); |
| 6405 | } |
| 6406 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6407 | if (localLOGV) { |
| 6408 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 6409 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
| 6410 | Log.v(TAG, "Resolving (mRequestedWidth=" |
| 6411 | + mRequestedWidth + ", mRequestedheight=" |
| 6412 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 6413 | + "): frame=" + mFrame.toShortString() |
| 6414 | + " ci=" + contentInsets.toShortString() |
| 6415 | + " vi=" + visibleInsets.toShortString()); |
| 6416 | //} |
| 6417 | } |
| 6418 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6419 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6420 | public Rect getFrameLw() { |
| 6421 | return mFrame; |
| 6422 | } |
| 6423 | |
| 6424 | public Rect getShownFrameLw() { |
| 6425 | return mShownFrame; |
| 6426 | } |
| 6427 | |
| 6428 | public Rect getDisplayFrameLw() { |
| 6429 | return mDisplayFrame; |
| 6430 | } |
| 6431 | |
| 6432 | public Rect getContentFrameLw() { |
| 6433 | return mContentFrame; |
| 6434 | } |
| 6435 | |
| 6436 | public Rect getVisibleFrameLw() { |
| 6437 | return mVisibleFrame; |
| 6438 | } |
| 6439 | |
| 6440 | public boolean getGivenInsetsPendingLw() { |
| 6441 | return mGivenInsetsPending; |
| 6442 | } |
| 6443 | |
| 6444 | public Rect getGivenContentInsetsLw() { |
| 6445 | return mGivenContentInsets; |
| 6446 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6447 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6448 | public Rect getGivenVisibleInsetsLw() { |
| 6449 | return mGivenVisibleInsets; |
| 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 | public WindowManager.LayoutParams getAttrs() { |
| 6453 | return mAttrs; |
| 6454 | } |
| 6455 | |
| 6456 | public int getSurfaceLayer() { |
| 6457 | return mLayer; |
| 6458 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6459 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6460 | public IApplicationToken getAppToken() { |
| 6461 | return mAppToken != null ? mAppToken.appToken : null; |
| 6462 | } |
| 6463 | |
| 6464 | public boolean hasAppShownWindows() { |
| 6465 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 6466 | } |
| 6467 | |
| 6468 | public boolean hasAppStartingIcon() { |
| 6469 | return mAppToken != null ? (mAppToken.startingData != null) : false; |
| 6470 | } |
| 6471 | |
| 6472 | public WindowManagerPolicy.WindowState getAppStartingWindow() { |
| 6473 | return mAppToken != null ? mAppToken.startingWindow : null; |
| 6474 | } |
| 6475 | |
| 6476 | public void setAnimation(Animation anim) { |
| 6477 | if (localLOGV) Log.v( |
| 6478 | TAG, "Setting animation in " + this + ": " + anim); |
| 6479 | mAnimating = false; |
| 6480 | mLocalAnimating = false; |
| 6481 | mAnimation = anim; |
| 6482 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 6483 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 6484 | } |
| 6485 | |
| 6486 | public void clearAnimation() { |
| 6487 | if (mAnimation != null) { |
| 6488 | mAnimating = true; |
| 6489 | mLocalAnimating = false; |
| 6490 | mAnimation = null; |
| 6491 | } |
| 6492 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6493 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6494 | Surface createSurfaceLocked() { |
| 6495 | if (mSurface == null) { |
| 6496 | mDrawPending = true; |
| 6497 | mCommitDrawPending = false; |
| 6498 | mReadyToShow = false; |
| 6499 | if (mAppToken != null) { |
| 6500 | mAppToken.allDrawn = false; |
| 6501 | } |
| 6502 | |
| 6503 | int flags = 0; |
Mathias Agopian | 317a628 | 2009-08-13 17:29:02 -0700 | [diff] [blame] | 6504 | if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6505 | flags |= Surface.PUSH_BUFFERS; |
| 6506 | } |
| 6507 | |
| 6508 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 6509 | flags |= Surface.SECURE; |
| 6510 | } |
| 6511 | if (DEBUG_VISIBILITY) Log.v( |
| 6512 | TAG, "Creating surface in session " |
| 6513 | + mSession.mSurfaceSession + " window " + this |
| 6514 | + " w=" + mFrame.width() |
| 6515 | + " h=" + mFrame.height() + " format=" |
| 6516 | + mAttrs.format + " flags=" + flags); |
| 6517 | |
| 6518 | int w = mFrame.width(); |
| 6519 | int h = mFrame.height(); |
| 6520 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 6521 | // for a scaled surface, we always want the requested |
| 6522 | // size. |
| 6523 | w = mRequestedWidth; |
| 6524 | h = mRequestedHeight; |
| 6525 | } |
| 6526 | |
| 6527 | try { |
| 6528 | mSurface = new Surface( |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6529 | mSession.mSurfaceSession, mSession.mPid, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6530 | 0, w, h, mAttrs.format, flags); |
| 6531 | } catch (Surface.OutOfResourcesException e) { |
| 6532 | Log.w(TAG, "OutOfResourcesException creating surface"); |
| 6533 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 6534 | return null; |
| 6535 | } catch (Exception e) { |
| 6536 | Log.e(TAG, "Exception creating surface", e); |
| 6537 | return null; |
| 6538 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6539 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6540 | if (localLOGV) Log.v( |
| 6541 | TAG, "Got surface: " + mSurface |
| 6542 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 6543 | + ", animLayer=" + mAnimLayer); |
| 6544 | if (SHOW_TRANSACTIONS) { |
| 6545 | Log.i(TAG, ">>> OPEN TRANSACTION"); |
| 6546 | Log.i(TAG, " SURFACE " + mSurface + ": CREATE (" |
| 6547 | + mAttrs.getTitle() + ") pos=(" + |
| 6548 | mFrame.left + "," + mFrame.top + ") (" + |
| 6549 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 6550 | mAnimLayer + " HIDE"); |
| 6551 | } |
| 6552 | Surface.openTransaction(); |
| 6553 | try { |
| 6554 | try { |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame^] | 6555 | mSurface.setPosition(mFrame.left + mXOffset, |
| 6556 | mFrame.top + mYOffset); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6557 | mSurface.setLayer(mAnimLayer); |
| 6558 | mSurface.hide(); |
| 6559 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
| 6560 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 6561 | Surface.SURFACE_DITHER); |
| 6562 | } |
| 6563 | } catch (RuntimeException e) { |
| 6564 | Log.w(TAG, "Error creating surface in " + w, e); |
| 6565 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 6566 | } |
| 6567 | mLastHidden = true; |
| 6568 | } finally { |
| 6569 | if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION"); |
| 6570 | Surface.closeTransaction(); |
| 6571 | } |
| 6572 | if (localLOGV) Log.v( |
| 6573 | TAG, "Created surface " + this); |
| 6574 | } |
| 6575 | return mSurface; |
| 6576 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6577 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6578 | void destroySurfaceLocked() { |
| 6579 | // Window is no longer on-screen, so can no longer receive |
| 6580 | // key events... if we were waiting for it to finish |
| 6581 | // handling a key event, the wait is over! |
| 6582 | mKeyWaiter.finishedKey(mSession, mClient, true, |
| 6583 | KeyWaiter.RETURN_NOTHING); |
| 6584 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 6585 | mKeyWaiter.releasePendingTrackballLocked(mSession); |
| 6586 | |
| 6587 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 6588 | mAppToken.startingDisplayed = false; |
| 6589 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6590 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6591 | if (localLOGV) Log.v( |
| 6592 | TAG, "Window " + this |
| 6593 | + " destroying surface " + mSurface + ", session " + mSession); |
| 6594 | if (mSurface != null) { |
| 6595 | try { |
| 6596 | if (SHOW_TRANSACTIONS) { |
| 6597 | RuntimeException ex = new RuntimeException(); |
| 6598 | ex.fillInStackTrace(); |
| 6599 | Log.i(TAG, " SURFACE " + mSurface + ": DESTROY (" |
| 6600 | + mAttrs.getTitle() + ")", ex); |
| 6601 | } |
| 6602 | mSurface.clear(); |
| 6603 | } catch (RuntimeException e) { |
| 6604 | Log.w(TAG, "Exception thrown when destroying Window " + this |
| 6605 | + " surface " + mSurface + " session " + mSession |
| 6606 | + ": " + e.toString()); |
| 6607 | } |
| 6608 | mSurface = null; |
| 6609 | mDrawPending = false; |
| 6610 | mCommitDrawPending = false; |
| 6611 | mReadyToShow = false; |
| 6612 | |
| 6613 | int i = mChildWindows.size(); |
| 6614 | while (i > 0) { |
| 6615 | i--; |
| 6616 | WindowState c = (WindowState)mChildWindows.get(i); |
| 6617 | c.mAttachedHidden = true; |
| 6618 | } |
| 6619 | } |
| 6620 | } |
| 6621 | |
| 6622 | boolean finishDrawingLocked() { |
| 6623 | if (mDrawPending) { |
| 6624 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Log.v( |
| 6625 | TAG, "finishDrawingLocked: " + mSurface); |
| 6626 | mCommitDrawPending = true; |
| 6627 | mDrawPending = false; |
| 6628 | return true; |
| 6629 | } |
| 6630 | return false; |
| 6631 | } |
| 6632 | |
| 6633 | // This must be called while inside a transaction. |
| 6634 | void commitFinishDrawingLocked(long currentTime) { |
| 6635 | //Log.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
| 6636 | if (!mCommitDrawPending) { |
| 6637 | return; |
| 6638 | } |
| 6639 | mCommitDrawPending = false; |
| 6640 | mReadyToShow = true; |
| 6641 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 6642 | final AppWindowToken atoken = mAppToken; |
| 6643 | if (atoken == null || atoken.allDrawn || starting) { |
| 6644 | performShowLocked(); |
| 6645 | } |
| 6646 | } |
| 6647 | |
| 6648 | // This must be called while inside a transaction. |
| 6649 | boolean performShowLocked() { |
| 6650 | if (DEBUG_VISIBILITY) { |
| 6651 | RuntimeException e = new RuntimeException(); |
| 6652 | e.fillInStackTrace(); |
| 6653 | Log.v(TAG, "performShow on " + this |
| 6654 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 6655 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 6656 | } |
| 6657 | if (mReadyToShow && isReadyForDisplay()) { |
| 6658 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Log.i( |
| 6659 | TAG, " SURFACE " + mSurface + ": SHOW (performShowLocked)"); |
| 6660 | if (DEBUG_VISIBILITY) Log.v(TAG, "Showing " + this |
| 6661 | + " during animation: policyVis=" + mPolicyVisibility |
| 6662 | + " attHidden=" + mAttachedHidden |
| 6663 | + " tok.hiddenRequested=" |
| 6664 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
| 6665 | + " tok.idden=" |
| 6666 | + (mAppToken != null ? mAppToken.hidden : false) |
| 6667 | + " animating=" + mAnimating |
| 6668 | + " tok animating=" |
| 6669 | + (mAppToken != null ? mAppToken.animating : false)); |
| 6670 | if (!showSurfaceRobustlyLocked(this)) { |
| 6671 | return false; |
| 6672 | } |
| 6673 | mLastAlpha = -1; |
| 6674 | mHasDrawn = true; |
| 6675 | mLastHidden = false; |
| 6676 | mReadyToShow = false; |
| 6677 | enableScreenIfNeededLocked(); |
| 6678 | |
| 6679 | applyEnterAnimationLocked(this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6680 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6681 | int i = mChildWindows.size(); |
| 6682 | while (i > 0) { |
| 6683 | i--; |
| 6684 | WindowState c = (WindowState)mChildWindows.get(i); |
| 6685 | if (c.mSurface != null && c.mAttachedHidden) { |
| 6686 | c.mAttachedHidden = false; |
| 6687 | c.performShowLocked(); |
| 6688 | } |
| 6689 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6690 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6691 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 6692 | && mAppToken != null) { |
| 6693 | mAppToken.firstWindowDrawn = true; |
| 6694 | if (mAnimation == null && mAppToken.startingData != null) { |
| 6695 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Finish starting " |
| 6696 | + mToken |
| 6697 | + ": first real window is shown, no animation"); |
| 6698 | mFinishedStarting.add(mAppToken); |
| 6699 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 6700 | } |
| 6701 | mAppToken.updateReportedVisibilityLocked(); |
| 6702 | } |
| 6703 | } |
| 6704 | return true; |
| 6705 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6706 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6707 | // This must be called while inside a transaction. Returns true if |
| 6708 | // there is more animation to run. |
| 6709 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| 6710 | if (!mDisplayFrozen) { |
| 6711 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6712 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6713 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 6714 | mHasTransformation = true; |
| 6715 | mHasLocalTransformation = true; |
| 6716 | if (!mLocalAnimating) { |
| 6717 | if (DEBUG_ANIM) Log.v( |
| 6718 | TAG, "Starting animation in " + this + |
| 6719 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 6720 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 6721 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 6722 | mAnimation.setStartTime(currentTime); |
| 6723 | mLocalAnimating = true; |
| 6724 | mAnimating = true; |
| 6725 | } |
| 6726 | mTransformation.clear(); |
| 6727 | final boolean more = mAnimation.getTransformation( |
| 6728 | currentTime, mTransformation); |
| 6729 | if (DEBUG_ANIM) Log.v( |
| 6730 | TAG, "Stepped animation in " + this + |
| 6731 | ": more=" + more + ", xform=" + mTransformation); |
| 6732 | if (more) { |
| 6733 | // we're not done! |
| 6734 | return true; |
| 6735 | } |
| 6736 | if (DEBUG_ANIM) Log.v( |
| 6737 | TAG, "Finished animation in " + this + |
| 6738 | " @ " + currentTime); |
| 6739 | mAnimation = null; |
| 6740 | //WindowManagerService.this.dump(); |
| 6741 | } |
| 6742 | mHasLocalTransformation = false; |
| 6743 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
| 6744 | && mAppToken.hasTransformation) { |
| 6745 | // When our app token is animating, we kind-of pretend like |
| 6746 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 6747 | // part of this check means that we will only do this if |
| 6748 | // our window is not currently exiting, or it is not |
| 6749 | // locally animating itself. The idea being that one that |
| 6750 | // is exiting and doing a local animation should be removed |
| 6751 | // once that animation is done. |
| 6752 | mAnimating = true; |
| 6753 | mHasTransformation = true; |
| 6754 | mTransformation.clear(); |
| 6755 | return false; |
| 6756 | } else if (mHasTransformation) { |
| 6757 | // Little trick to get through the path below to act like |
| 6758 | // we have finished an animation. |
| 6759 | mAnimating = true; |
| 6760 | } else if (isAnimating()) { |
| 6761 | mAnimating = true; |
| 6762 | } |
| 6763 | } else if (mAnimation != null) { |
| 6764 | // If the display is frozen, and there is a pending animation, |
| 6765 | // clear it and make sure we run the cleanup code. |
| 6766 | mAnimating = true; |
| 6767 | mLocalAnimating = true; |
| 6768 | mAnimation = null; |
| 6769 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6770 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6771 | if (!mAnimating && !mLocalAnimating) { |
| 6772 | return false; |
| 6773 | } |
| 6774 | |
| 6775 | if (DEBUG_ANIM) Log.v( |
| 6776 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 6777 | + ", reportedVisible=" |
| 6778 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6779 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6780 | mAnimating = false; |
| 6781 | mLocalAnimating = false; |
| 6782 | mAnimation = null; |
| 6783 | mAnimLayer = mLayer; |
| 6784 | if (mIsImWindow) { |
| 6785 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6786 | } else if (mIsWallpaper) { |
| 6787 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6788 | } |
| 6789 | if (DEBUG_LAYERS) Log.v(TAG, "Stepping win " + this |
| 6790 | + " anim layer: " + mAnimLayer); |
| 6791 | mHasTransformation = false; |
| 6792 | mHasLocalTransformation = false; |
| 6793 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 6794 | mTransformation.clear(); |
| 6795 | if (mHasDrawn |
| 6796 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 6797 | && mAppToken != null |
| 6798 | && mAppToken.firstWindowDrawn |
| 6799 | && mAppToken.startingData != null) { |
| 6800 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Finish starting " |
| 6801 | + mToken + ": first real window done animating"); |
| 6802 | mFinishedStarting.add(mAppToken); |
| 6803 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 6804 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6805 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6806 | finishExit(); |
| 6807 | |
| 6808 | if (mAppToken != null) { |
| 6809 | mAppToken.updateReportedVisibilityLocked(); |
| 6810 | } |
| 6811 | |
| 6812 | return false; |
| 6813 | } |
| 6814 | |
| 6815 | void finishExit() { |
| 6816 | if (DEBUG_ANIM) Log.v( |
| 6817 | TAG, "finishExit in " + this |
| 6818 | + ": exiting=" + mExiting |
| 6819 | + " remove=" + mRemoveOnExit |
| 6820 | + " windowAnimating=" + isWindowAnimating()); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6821 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6822 | final int N = mChildWindows.size(); |
| 6823 | for (int i=0; i<N; i++) { |
| 6824 | ((WindowState)mChildWindows.get(i)).finishExit(); |
| 6825 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6826 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6827 | if (!mExiting) { |
| 6828 | return; |
| 6829 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6830 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6831 | if (isWindowAnimating()) { |
| 6832 | return; |
| 6833 | } |
| 6834 | |
| 6835 | if (localLOGV) Log.v( |
| 6836 | TAG, "Exit animation finished in " + this |
| 6837 | + ": remove=" + mRemoveOnExit); |
| 6838 | if (mSurface != null) { |
| 6839 | mDestroySurface.add(this); |
| 6840 | mDestroying = true; |
| 6841 | if (SHOW_TRANSACTIONS) Log.i( |
| 6842 | TAG, " SURFACE " + mSurface + ": HIDE (finishExit)"); |
| 6843 | try { |
| 6844 | mSurface.hide(); |
| 6845 | } catch (RuntimeException e) { |
| 6846 | Log.w(TAG, "Error hiding surface in " + this, e); |
| 6847 | } |
| 6848 | mLastHidden = true; |
| 6849 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 6850 | } |
| 6851 | mExiting = false; |
| 6852 | if (mRemoveOnExit) { |
| 6853 | mPendingRemove.add(this); |
| 6854 | mRemoveOnExit = false; |
| 6855 | } |
| 6856 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6857 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6858 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 6859 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 6860 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 6861 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 6862 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 6863 | return true; |
| 6864 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6865 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6866 | void computeShownFrameLocked() { |
| 6867 | final boolean selfTransformation = mHasLocalTransformation; |
| 6868 | Transformation attachedTransformation = |
| 6869 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 6870 | ? mAttachedWindow.mTransformation : null; |
| 6871 | Transformation appTransformation = |
| 6872 | (mAppToken != null && mAppToken.hasTransformation) |
| 6873 | ? mAppToken.transformation : null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6874 | |
| 6875 | // Wallpapers are animated based on the "real" window they |
| 6876 | // are currently targeting. |
| 6877 | if (mAttrs.type == TYPE_WALLPAPER && mWallpaperTarget != null) { |
| 6878 | if (mWallpaperTarget.mHasLocalTransformation) { |
| 6879 | attachedTransformation = mWallpaperTarget.mTransformation; |
| 6880 | } |
| 6881 | if (mWallpaperTarget.mAppToken != null && |
| 6882 | mWallpaperTarget.mAppToken.hasTransformation) { |
| 6883 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
| 6884 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6885 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
| 6886 | Log.v(TAG, "WP target attached xform: " + attachedTransformation); |
| 6887 | } |
| 6888 | if (DEBUG_WALLPAPER && appTransformation != null) { |
| 6889 | Log.v(TAG, "WP target app xform: " + appTransformation); |
| 6890 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6891 | } |
| 6892 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6893 | if (selfTransformation || attachedTransformation != null |
| 6894 | || appTransformation != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6895 | // cache often used attributes locally |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6896 | final Rect frame = mFrame; |
| 6897 | final float tmpFloats[] = mTmpFloats; |
| 6898 | final Matrix tmpMatrix = mTmpMatrix; |
| 6899 | |
| 6900 | // Compute the desired transformation. |
| 6901 | tmpMatrix.setTranslate(frame.left, frame.top); |
| 6902 | if (selfTransformation) { |
| 6903 | tmpMatrix.preConcat(mTransformation.getMatrix()); |
| 6904 | } |
| 6905 | if (attachedTransformation != null) { |
| 6906 | tmpMatrix.preConcat(attachedTransformation.getMatrix()); |
| 6907 | } |
| 6908 | if (appTransformation != null) { |
| 6909 | tmpMatrix.preConcat(appTransformation.getMatrix()); |
| 6910 | } |
| 6911 | |
| 6912 | // "convert" it into SurfaceFlinger's format |
| 6913 | // (a 2x2 matrix + an offset) |
| 6914 | // Here we must not transform the position of the surface |
| 6915 | // since it is already included in the transformation. |
| 6916 | //Log.i(TAG, "Transform: " + matrix); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6917 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6918 | tmpMatrix.getValues(tmpFloats); |
| 6919 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 6920 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 6921 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 6922 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6923 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 6924 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6925 | int w = frame.width(); |
| 6926 | int h = frame.height(); |
| 6927 | mShownFrame.set(x, y, x+w, y+h); |
| 6928 | |
| 6929 | // Now set the alpha... but because our current hardware |
| 6930 | // can't do alpha transformation on a non-opaque surface, |
| 6931 | // turn it off if we are running an animation that is also |
| 6932 | // transforming since it is more important to have that |
| 6933 | // animation be smooth. |
| 6934 | mShownAlpha = mAlpha; |
| 6935 | if (!mLimitedAlphaCompositing |
| 6936 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 6937 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 6938 | && x == frame.left && y == frame.top))) { |
| 6939 | //Log.i(TAG, "Applying alpha transform"); |
| 6940 | if (selfTransformation) { |
| 6941 | mShownAlpha *= mTransformation.getAlpha(); |
| 6942 | } |
| 6943 | if (attachedTransformation != null) { |
| 6944 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 6945 | } |
| 6946 | if (appTransformation != null) { |
| 6947 | mShownAlpha *= appTransformation.getAlpha(); |
| 6948 | } |
| 6949 | } else { |
| 6950 | //Log.i(TAG, "Not applying alpha transform"); |
| 6951 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6952 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6953 | if (localLOGV) Log.v( |
| 6954 | TAG, "Continuing animation in " + this + |
| 6955 | ": " + mShownFrame + |
| 6956 | ", alpha=" + mTransformation.getAlpha()); |
| 6957 | return; |
| 6958 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6959 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6960 | mShownFrame.set(mFrame); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6961 | if (mXOffset != 0 || mYOffset != 0) { |
| 6962 | mShownFrame.offset(mXOffset, mYOffset); |
| 6963 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6964 | mShownAlpha = mAlpha; |
| 6965 | mDsDx = 1; |
| 6966 | mDtDx = 0; |
| 6967 | mDsDy = 0; |
| 6968 | mDtDy = 1; |
| 6969 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6970 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6971 | /** |
| 6972 | * Is this window visible? It is not visible if there is no |
| 6973 | * surface, or we are in the process of running an exit animation |
| 6974 | * that will remove the surface, or its app token has been hidden. |
| 6975 | */ |
| 6976 | public boolean isVisibleLw() { |
| 6977 | final AppWindowToken atoken = mAppToken; |
| 6978 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 6979 | && (atoken == null || !atoken.hiddenRequested) |
| 6980 | && !mExiting && !mDestroying; |
| 6981 | } |
| 6982 | |
| 6983 | /** |
| 6984 | * Is this window visible, ignoring its app token? It is not visible |
| 6985 | * if there is no surface, or we are in the process of running an exit animation |
| 6986 | * that will remove the surface. |
| 6987 | */ |
| 6988 | public boolean isWinVisibleLw() { |
| 6989 | final AppWindowToken atoken = mAppToken; |
| 6990 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 6991 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 6992 | && !mExiting && !mDestroying; |
| 6993 | } |
| 6994 | |
| 6995 | /** |
| 6996 | * The same as isVisible(), but follows the current hidden state of |
| 6997 | * the associated app token, not the pending requested hidden state. |
| 6998 | */ |
| 6999 | boolean isVisibleNow() { |
| 7000 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7001 | && !mRootToken.hidden && !mExiting && !mDestroying; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7002 | } |
| 7003 | |
| 7004 | /** |
| 7005 | * Same as isVisible(), but we also count it as visible between the |
| 7006 | * call to IWindowSession.add() and the first relayout(). |
| 7007 | */ |
| 7008 | boolean isVisibleOrAdding() { |
| 7009 | final AppWindowToken atoken = mAppToken; |
| 7010 | return (mSurface != null |
| 7011 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 7012 | && mPolicyVisibility && !mAttachedHidden |
| 7013 | && (atoken == null || !atoken.hiddenRequested) |
| 7014 | && !mExiting && !mDestroying; |
| 7015 | } |
| 7016 | |
| 7017 | /** |
| 7018 | * Is this window currently on-screen? It is on-screen either if it |
| 7019 | * is visible or it is currently running an animation before no longer |
| 7020 | * being visible. |
| 7021 | */ |
| 7022 | boolean isOnScreen() { |
| 7023 | final AppWindowToken atoken = mAppToken; |
| 7024 | if (atoken != null) { |
| 7025 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7026 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7027 | || mAnimation != null || atoken.animation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7028 | } else { |
| 7029 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7030 | && (!mAttachedHidden || mAnimation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7031 | } |
| 7032 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7033 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7034 | /** |
| 7035 | * Like isOnScreen(), but we don't return true if the window is part |
| 7036 | * of a transition that has not yet been started. |
| 7037 | */ |
| 7038 | boolean isReadyForDisplay() { |
| 7039 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7040 | final boolean animating = atoken != null |
| 7041 | ? (atoken.animation != null) : false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7042 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7043 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 7044 | && !mRootToken.hidden) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7045 | || mAnimation != null || animating); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7046 | } |
| 7047 | |
| 7048 | /** Is the window or its container currently animating? */ |
| 7049 | boolean isAnimating() { |
| 7050 | final WindowState attached = mAttachedWindow; |
| 7051 | final AppWindowToken atoken = mAppToken; |
| 7052 | return mAnimation != null |
| 7053 | || (attached != null && attached.mAnimation != null) |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7054 | || (atoken != null && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7055 | (atoken.animation != null |
| 7056 | || atoken.inPendingTransaction)); |
| 7057 | } |
| 7058 | |
| 7059 | /** Is this window currently animating? */ |
| 7060 | boolean isWindowAnimating() { |
| 7061 | return mAnimation != null; |
| 7062 | } |
| 7063 | |
| 7064 | /** |
| 7065 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 7066 | * been drawn. |
| 7067 | */ |
| 7068 | public boolean isDisplayedLw() { |
| 7069 | final AppWindowToken atoken = mAppToken; |
| 7070 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7071 | && !mDrawPending && !mCommitDrawPending |
| 7072 | && ((!mAttachedHidden && |
| 7073 | (atoken == null || !atoken.hiddenRequested)) |
| 7074 | || mAnimating); |
| 7075 | } |
| 7076 | |
| 7077 | public boolean fillsScreenLw(int screenWidth, int screenHeight, |
| 7078 | boolean shownFrame, boolean onlyOpaque) { |
| 7079 | if (mSurface == null) { |
| 7080 | return false; |
| 7081 | } |
| 7082 | if (mAppToken != null && !mAppToken.appFullscreen) { |
| 7083 | return false; |
| 7084 | } |
| 7085 | if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) { |
| 7086 | return false; |
| 7087 | } |
| 7088 | final Rect frame = shownFrame ? mShownFrame : mFrame; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7089 | |
| 7090 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| 7091 | return frame.left <= mCompatibleScreenFrame.left && |
| 7092 | frame.top <= mCompatibleScreenFrame.top && |
| 7093 | frame.right >= mCompatibleScreenFrame.right && |
| 7094 | frame.bottom >= mCompatibleScreenFrame.bottom; |
| 7095 | } else { |
| 7096 | return frame.left <= 0 && frame.top <= 0 |
| 7097 | && frame.right >= screenWidth |
| 7098 | && frame.bottom >= screenHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7099 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7100 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7101 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7102 | /** |
| 7103 | * Return true if the window is opaque and fully drawn. |
| 7104 | */ |
| 7105 | boolean isOpaqueDrawn() { |
| 7106 | return mAttrs.format == PixelFormat.OPAQUE && mSurface != null |
| 7107 | && mAnimation == null && !mDrawPending && !mCommitDrawPending; |
| 7108 | } |
| 7109 | |
| 7110 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 7111 | return |
| 7112 | // only if the application is requesting compatible window |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7113 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 7114 | // only if it's visible |
| 7115 | mHasDrawn && mViewVisibility == View.VISIBLE && |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7116 | // and only if the application fills the compatible screen |
| 7117 | mFrame.left <= mCompatibleScreenFrame.left && |
| 7118 | mFrame.top <= mCompatibleScreenFrame.top && |
| 7119 | mFrame.right >= mCompatibleScreenFrame.right && |
| 7120 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7121 | // and starting window do not need background filler |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7122 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7123 | } |
| 7124 | |
| 7125 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 7126 | return mFrame.left <= 0 && mFrame.top <= 0 && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7127 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7128 | } |
| 7129 | |
| 7130 | void removeLocked() { |
| 7131 | if (mAttachedWindow != null) { |
| 7132 | mAttachedWindow.mChildWindows.remove(this); |
| 7133 | } |
| 7134 | destroySurfaceLocked(); |
| 7135 | mSession.windowRemovedLocked(); |
| 7136 | try { |
| 7137 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 7138 | } catch (RuntimeException e) { |
| 7139 | // Ignore if it has already been removed (usually because |
| 7140 | // we are doing this as part of processing a death note.) |
| 7141 | } |
| 7142 | } |
| 7143 | |
| 7144 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 7145 | public void binderDied() { |
| 7146 | try { |
| 7147 | synchronized(mWindowMap) { |
| 7148 | WindowState win = windowForClientLocked(mSession, mClient); |
| 7149 | Log.i(TAG, "WIN DEATH: " + win); |
| 7150 | if (win != null) { |
| 7151 | removeWindowLocked(mSession, win); |
| 7152 | } |
| 7153 | } |
| 7154 | } catch (IllegalArgumentException ex) { |
| 7155 | // This will happen if the window has already been |
| 7156 | // removed. |
| 7157 | } |
| 7158 | } |
| 7159 | } |
| 7160 | |
| 7161 | /** Returns true if this window desires key events. */ |
| 7162 | public final boolean canReceiveKeys() { |
| 7163 | return isVisibleOrAdding() |
| 7164 | && (mViewVisibility == View.VISIBLE) |
| 7165 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 7166 | } |
| 7167 | |
| 7168 | public boolean hasDrawnLw() { |
| 7169 | return mHasDrawn; |
| 7170 | } |
| 7171 | |
| 7172 | public boolean showLw(boolean doAnimation) { |
| 7173 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim) { |
| 7174 | mPolicyVisibility = true; |
| 7175 | mPolicyVisibilityAfterAnim = true; |
| 7176 | if (doAnimation) { |
| 7177 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 7178 | } |
| 7179 | requestAnimationLocked(0); |
| 7180 | return true; |
| 7181 | } |
| 7182 | return false; |
| 7183 | } |
| 7184 | |
| 7185 | public boolean hideLw(boolean doAnimation) { |
| 7186 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 7187 | : mPolicyVisibility; |
| 7188 | if (current) { |
| 7189 | if (doAnimation) { |
| 7190 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 7191 | if (mAnimation == null) { |
| 7192 | doAnimation = false; |
| 7193 | } |
| 7194 | } |
| 7195 | if (doAnimation) { |
| 7196 | mPolicyVisibilityAfterAnim = false; |
| 7197 | } else { |
| 7198 | mPolicyVisibilityAfterAnim = false; |
| 7199 | mPolicyVisibility = false; |
| 7200 | } |
| 7201 | requestAnimationLocked(0); |
| 7202 | return true; |
| 7203 | } |
| 7204 | return false; |
| 7205 | } |
| 7206 | |
| 7207 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7208 | StringBuilder sb = new StringBuilder(64); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7209 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7210 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 7211 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 7212 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 7213 | if (mAttachedWindow != null || mLayoutAttached) { |
| 7214 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 7215 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 7216 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7217 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 7218 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 7219 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7220 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 7221 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7222 | } |
| 7223 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 7224 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 7225 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 7226 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 7227 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 7228 | pw.print("="); pw.print(mAnimLayer); |
| 7229 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 7230 | if (mSurface != null) { |
| 7231 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
| 7232 | } |
| 7233 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 7234 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 7235 | if (mAppToken != null) { |
| 7236 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 7237 | } |
| 7238 | if (mTargetAppToken != null) { |
| 7239 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 7240 | } |
| 7241 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 7242 | pw.print(Integer.toHexString(mViewVisibility)); |
| 7243 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7244 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 7245 | pw.print(" mObscured="); pw.println(mObscured); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7246 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 7247 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 7248 | pw.print(mPolicyVisibility); |
| 7249 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 7250 | pw.print(mPolicyVisibilityAfterAnim); |
| 7251 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 7252 | } |
| 7253 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7254 | pw.print(" h="); pw.println(mRequestedHeight); |
| 7255 | if (mXOffset != 0 || mYOffset != 0) { |
| 7256 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 7257 | pw.print(" y="); pw.println(mYOffset); |
| 7258 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7259 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 7260 | mGivenContentInsets.printShortString(pw); |
| 7261 | pw.print(" mGivenVisibleInsets="); |
| 7262 | mGivenVisibleInsets.printShortString(pw); |
| 7263 | pw.println(); |
| 7264 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 7265 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 7266 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 7267 | } |
| 7268 | pw.print(prefix); pw.print("mShownFrame="); |
| 7269 | mShownFrame.printShortString(pw); |
| 7270 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 7271 | pw.println(); |
| 7272 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 7273 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 7274 | pw.println(); |
| 7275 | pw.print(prefix); pw.print("mContainingFrame="); |
| 7276 | mContainingFrame.printShortString(pw); |
| 7277 | pw.print(" mDisplayFrame="); |
| 7278 | mDisplayFrame.printShortString(pw); |
| 7279 | pw.println(); |
| 7280 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 7281 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 7282 | pw.println(); |
| 7283 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 7284 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 7285 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 7286 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 7287 | pw.println(); |
| 7288 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 7289 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 7290 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 7291 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 7292 | } |
| 7293 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 7294 | || mAnimation != null) { |
| 7295 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 7296 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 7297 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 7298 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 7299 | } |
| 7300 | if (mHasTransformation || mHasLocalTransformation) { |
| 7301 | pw.print(prefix); pw.print("XForm: has="); |
| 7302 | pw.print(mHasTransformation); |
| 7303 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 7304 | pw.print(" "); mTransformation.printShortString(pw); |
| 7305 | pw.println(); |
| 7306 | } |
| 7307 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 7308 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 7309 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 7310 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 7311 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 7312 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 7313 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 7314 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 7315 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 7316 | } |
| 7317 | if (mOrientationChanging || mAppFreezing) { |
| 7318 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 7319 | pw.print(mOrientationChanging); |
| 7320 | pw.print(" mAppFreezing="); pw.println(mAppFreezing); |
| 7321 | } |
Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 7322 | if (mHScale != 1 || mVScale != 1) { |
| 7323 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 7324 | pw.print(" mVScale="); pw.println(mVScale); |
| 7325 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7326 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7327 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 7328 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 7329 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7330 | } |
| 7331 | |
| 7332 | @Override |
| 7333 | public String toString() { |
| 7334 | return "Window{" |
| 7335 | + Integer.toHexString(System.identityHashCode(this)) |
| 7336 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 7337 | } |
| 7338 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7339 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7340 | // ------------------------------------------------------------- |
| 7341 | // Window Token State |
| 7342 | // ------------------------------------------------------------- |
| 7343 | |
| 7344 | class WindowToken { |
| 7345 | // The actual token. |
| 7346 | final IBinder token; |
| 7347 | |
| 7348 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 7349 | final int windowType; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7350 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7351 | // Set if this token was explicitly added by a client, so should |
| 7352 | // not be removed when all windows are removed. |
| 7353 | final boolean explicit; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7354 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7355 | // For printing. |
| 7356 | String stringName; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7357 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7358 | // If this is an AppWindowToken, this is non-null. |
| 7359 | AppWindowToken appWindowToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7360 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7361 | // All of the windows associated with this token. |
| 7362 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 7363 | |
| 7364 | // Is key dispatching paused for this token? |
| 7365 | boolean paused = false; |
| 7366 | |
| 7367 | // Should this token's windows be hidden? |
| 7368 | boolean hidden; |
| 7369 | |
| 7370 | // Temporary for finding which tokens no longer have visible windows. |
| 7371 | boolean hasVisible; |
| 7372 | |
| 7373 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 7374 | token = _token; |
| 7375 | windowType = type; |
| 7376 | explicit = _explicit; |
| 7377 | } |
| 7378 | |
| 7379 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7380 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 7381 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 7382 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 7383 | pw.print(" hidden="); pw.print(hidden); |
| 7384 | pw.print(" hasVisible="); pw.println(hasVisible); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7385 | } |
| 7386 | |
| 7387 | @Override |
| 7388 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7389 | if (stringName == null) { |
| 7390 | StringBuilder sb = new StringBuilder(); |
| 7391 | sb.append("WindowToken{"); |
| 7392 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7393 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 7394 | stringName = sb.toString(); |
| 7395 | } |
| 7396 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7397 | } |
| 7398 | }; |
| 7399 | |
| 7400 | class AppWindowToken extends WindowToken { |
| 7401 | // Non-null only for application tokens. |
| 7402 | final IApplicationToken appToken; |
| 7403 | |
| 7404 | // All of the windows and child windows that are included in this |
| 7405 | // application token. Note this list is NOT sorted! |
| 7406 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 7407 | |
| 7408 | int groupId = -1; |
| 7409 | boolean appFullscreen; |
| 7410 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7411 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7412 | // These are used for determining when all windows associated with |
| 7413 | // an activity have been drawn, so they can be made visible together |
| 7414 | // at the same time. |
| 7415 | int lastTransactionSequence = mTransactionSequence-1; |
| 7416 | int numInterestingWindows; |
| 7417 | int numDrawnWindows; |
| 7418 | boolean inPendingTransaction; |
| 7419 | boolean allDrawn; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7420 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7421 | // Is this token going to be hidden in a little while? If so, it |
| 7422 | // won't be taken into account for setting the screen orientation. |
| 7423 | boolean willBeHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7424 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7425 | // Is this window's surface needed? This is almost like hidden, except |
| 7426 | // it will sometimes be true a little earlier: when the token has |
| 7427 | // been shown, but is still waiting for its app transition to execute |
| 7428 | // before making its windows shown. |
| 7429 | boolean hiddenRequested; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7430 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7431 | // Have we told the window clients to hide themselves? |
| 7432 | boolean clientHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7433 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7434 | // Last visibility state we reported to the app token. |
| 7435 | boolean reportedVisible; |
| 7436 | |
| 7437 | // Set to true when the token has been removed from the window mgr. |
| 7438 | boolean removed; |
| 7439 | |
| 7440 | // Have we been asked to have this token keep the screen frozen? |
| 7441 | boolean freezingScreen; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7442 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7443 | boolean animating; |
| 7444 | Animation animation; |
| 7445 | boolean hasTransformation; |
| 7446 | final Transformation transformation = new Transformation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7447 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7448 | // Offset to the window of all layers in the token, for use by |
| 7449 | // AppWindowToken animations. |
| 7450 | int animLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7451 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7452 | // Information about an application starting window if displayed. |
| 7453 | StartingData startingData; |
| 7454 | WindowState startingWindow; |
| 7455 | View startingView; |
| 7456 | boolean startingDisplayed; |
| 7457 | boolean startingMoved; |
| 7458 | boolean firstWindowDrawn; |
| 7459 | |
| 7460 | AppWindowToken(IApplicationToken _token) { |
| 7461 | super(_token.asBinder(), |
| 7462 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 7463 | appWindowToken = this; |
| 7464 | appToken = _token; |
| 7465 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7466 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7467 | public void setAnimation(Animation anim) { |
| 7468 | if (localLOGV) Log.v( |
| 7469 | TAG, "Setting animation in " + this + ": " + anim); |
| 7470 | animation = anim; |
| 7471 | animating = false; |
| 7472 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 7473 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 7474 | int zorder = anim.getZAdjustment(); |
| 7475 | int adj = 0; |
| 7476 | if (zorder == Animation.ZORDER_TOP) { |
| 7477 | adj = TYPE_LAYER_OFFSET; |
| 7478 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 7479 | adj = -TYPE_LAYER_OFFSET; |
| 7480 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7481 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7482 | if (animLayerAdjustment != adj) { |
| 7483 | animLayerAdjustment = adj; |
| 7484 | updateLayers(); |
| 7485 | } |
| 7486 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7487 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7488 | public void setDummyAnimation() { |
| 7489 | if (animation == null) { |
| 7490 | if (localLOGV) Log.v( |
| 7491 | TAG, "Setting dummy animation in " + this); |
| 7492 | animation = sDummyAnimation; |
| 7493 | } |
| 7494 | } |
| 7495 | |
| 7496 | public void clearAnimation() { |
| 7497 | if (animation != null) { |
| 7498 | animation = null; |
| 7499 | animating = true; |
| 7500 | } |
| 7501 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7502 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7503 | void updateLayers() { |
| 7504 | final int N = allAppWindows.size(); |
| 7505 | final int adj = animLayerAdjustment; |
| 7506 | for (int i=0; i<N; i++) { |
| 7507 | WindowState w = allAppWindows.get(i); |
| 7508 | w.mAnimLayer = w.mLayer + adj; |
| 7509 | if (DEBUG_LAYERS) Log.v(TAG, "Updating layer " + w + ": " |
| 7510 | + w.mAnimLayer); |
| 7511 | if (w == mInputMethodTarget) { |
| 7512 | setInputMethodAnimLayerAdjustment(adj); |
| 7513 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7514 | if (w == mWallpaperTarget) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7515 | setWallpaperAnimLayerAdjustmentLocked(adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7516 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7517 | } |
| 7518 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7519 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7520 | void sendAppVisibilityToClients() { |
| 7521 | final int N = allAppWindows.size(); |
| 7522 | for (int i=0; i<N; i++) { |
| 7523 | WindowState win = allAppWindows.get(i); |
| 7524 | if (win == startingWindow && clientHidden) { |
| 7525 | // Don't hide the starting window. |
| 7526 | continue; |
| 7527 | } |
| 7528 | try { |
| 7529 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 7530 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 7531 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 7532 | } catch (RemoteException e) { |
| 7533 | } |
| 7534 | } |
| 7535 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7536 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7537 | void showAllWindowsLocked() { |
| 7538 | final int NW = allAppWindows.size(); |
| 7539 | for (int i=0; i<NW; i++) { |
| 7540 | WindowState w = allAppWindows.get(i); |
| 7541 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 7542 | "performing show on: " + w); |
| 7543 | w.performShowLocked(); |
| 7544 | } |
| 7545 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7546 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7547 | // This must be called while inside a transaction. |
| 7548 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| 7549 | if (!mDisplayFrozen) { |
| 7550 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7551 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7552 | if (animation == sDummyAnimation) { |
| 7553 | // This guy is going to animate, but not yet. For now count |
| 7554 | // it is not animating for purposes of scheduling transactions; |
| 7555 | // when it is really time to animate, this will be set to |
| 7556 | // a real animation and the next call will execute normally. |
| 7557 | return false; |
| 7558 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7559 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7560 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 7561 | if (!animating) { |
| 7562 | if (DEBUG_ANIM) Log.v( |
| 7563 | TAG, "Starting animation in " + this + |
| 7564 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 7565 | + " scale=" + mTransitionAnimationScale |
| 7566 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 7567 | animation.initialize(dw, dh, dw, dh); |
| 7568 | animation.setStartTime(currentTime); |
| 7569 | animating = true; |
| 7570 | } |
| 7571 | transformation.clear(); |
| 7572 | final boolean more = animation.getTransformation( |
| 7573 | currentTime, transformation); |
| 7574 | if (DEBUG_ANIM) Log.v( |
| 7575 | TAG, "Stepped animation in " + this + |
| 7576 | ": more=" + more + ", xform=" + transformation); |
| 7577 | if (more) { |
| 7578 | // we're done! |
| 7579 | hasTransformation = true; |
| 7580 | return true; |
| 7581 | } |
| 7582 | if (DEBUG_ANIM) Log.v( |
| 7583 | TAG, "Finished animation in " + this + |
| 7584 | " @ " + currentTime); |
| 7585 | animation = null; |
| 7586 | } |
| 7587 | } else if (animation != null) { |
| 7588 | // If the display is frozen, and there is a pending animation, |
| 7589 | // clear it and make sure we run the cleanup code. |
| 7590 | animating = true; |
| 7591 | animation = null; |
| 7592 | } |
| 7593 | |
| 7594 | hasTransformation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7595 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7596 | if (!animating) { |
| 7597 | return false; |
| 7598 | } |
| 7599 | |
| 7600 | clearAnimation(); |
| 7601 | animating = false; |
| 7602 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 7603 | moveInputMethodWindowsIfNeededLocked(true); |
| 7604 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7605 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7606 | if (DEBUG_ANIM) Log.v( |
| 7607 | TAG, "Animation done in " + this |
| 7608 | + ": reportedVisible=" + reportedVisible); |
| 7609 | |
| 7610 | transformation.clear(); |
| 7611 | if (animLayerAdjustment != 0) { |
| 7612 | animLayerAdjustment = 0; |
| 7613 | updateLayers(); |
| 7614 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7615 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7616 | final int N = windows.size(); |
| 7617 | for (int i=0; i<N; i++) { |
| 7618 | ((WindowState)windows.get(i)).finishExit(); |
| 7619 | } |
| 7620 | updateReportedVisibilityLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7621 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7622 | return false; |
| 7623 | } |
| 7624 | |
| 7625 | void updateReportedVisibilityLocked() { |
| 7626 | if (appToken == null) { |
| 7627 | return; |
| 7628 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7629 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7630 | int numInteresting = 0; |
| 7631 | int numVisible = 0; |
| 7632 | boolean nowGone = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7633 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7634 | if (DEBUG_VISIBILITY) Log.v(TAG, "Update reported visibility: " + this); |
| 7635 | final int N = allAppWindows.size(); |
| 7636 | for (int i=0; i<N; i++) { |
| 7637 | WindowState win = allAppWindows.get(i); |
| 7638 | if (win == startingWindow || win.mAppFreezing) { |
| 7639 | continue; |
| 7640 | } |
| 7641 | if (DEBUG_VISIBILITY) { |
| 7642 | Log.v(TAG, "Win " + win + ": isDisplayed=" |
| 7643 | + win.isDisplayedLw() |
| 7644 | + ", isAnimating=" + win.isAnimating()); |
| 7645 | if (!win.isDisplayedLw()) { |
| 7646 | Log.v(TAG, "Not displayed: s=" + win.mSurface |
| 7647 | + " pv=" + win.mPolicyVisibility |
| 7648 | + " dp=" + win.mDrawPending |
| 7649 | + " cdp=" + win.mCommitDrawPending |
| 7650 | + " ah=" + win.mAttachedHidden |
| 7651 | + " th=" |
| 7652 | + (win.mAppToken != null |
| 7653 | ? win.mAppToken.hiddenRequested : false) |
| 7654 | + " a=" + win.mAnimating); |
| 7655 | } |
| 7656 | } |
| 7657 | numInteresting++; |
| 7658 | if (win.isDisplayedLw()) { |
| 7659 | if (!win.isAnimating()) { |
| 7660 | numVisible++; |
| 7661 | } |
| 7662 | nowGone = false; |
| 7663 | } else if (win.isAnimating()) { |
| 7664 | nowGone = false; |
| 7665 | } |
| 7666 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7667 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7668 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
| 7669 | if (DEBUG_VISIBILITY) Log.v(TAG, "VIS " + this + ": interesting=" |
| 7670 | + numInteresting + " visible=" + numVisible); |
| 7671 | if (nowVisible != reportedVisible) { |
| 7672 | if (DEBUG_VISIBILITY) Log.v( |
| 7673 | TAG, "Visibility changed in " + this |
| 7674 | + ": vis=" + nowVisible); |
| 7675 | reportedVisible = nowVisible; |
| 7676 | Message m = mH.obtainMessage( |
| 7677 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 7678 | nowVisible ? 1 : 0, |
| 7679 | nowGone ? 1 : 0, |
| 7680 | this); |
| 7681 | mH.sendMessage(m); |
| 7682 | } |
| 7683 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7684 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7685 | void dump(PrintWriter pw, String prefix) { |
| 7686 | super.dump(pw, prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7687 | if (appToken != null) { |
| 7688 | pw.print(prefix); pw.println("app=true"); |
| 7689 | } |
| 7690 | if (allAppWindows.size() > 0) { |
| 7691 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 7692 | } |
| 7693 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
| 7694 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 7695 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 7696 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 7697 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 7698 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 7699 | if (paused || freezingScreen) { |
| 7700 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 7701 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 7702 | } |
| 7703 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 7704 | || inPendingTransaction || allDrawn) { |
| 7705 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 7706 | pw.print(numInterestingWindows); |
| 7707 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 7708 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 7709 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 7710 | } |
| 7711 | if (animating || animation != null) { |
| 7712 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 7713 | pw.print(" animation="); pw.println(animation); |
| 7714 | } |
| 7715 | if (animLayerAdjustment != 0) { |
| 7716 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 7717 | } |
| 7718 | if (hasTransformation) { |
| 7719 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 7720 | pw.print(" transformation="); transformation.printShortString(pw); |
| 7721 | pw.println(); |
| 7722 | } |
| 7723 | if (startingData != null || removed || firstWindowDrawn) { |
| 7724 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 7725 | pw.print(" removed="); pw.print(removed); |
| 7726 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 7727 | } |
| 7728 | if (startingWindow != null || startingView != null |
| 7729 | || startingDisplayed || startingMoved) { |
| 7730 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 7731 | pw.print(" startingView="); pw.print(startingView); |
| 7732 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 7733 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 7734 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7735 | } |
| 7736 | |
| 7737 | @Override |
| 7738 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7739 | if (stringName == null) { |
| 7740 | StringBuilder sb = new StringBuilder(); |
| 7741 | sb.append("AppWindowToken{"); |
| 7742 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7743 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 7744 | stringName = sb.toString(); |
| 7745 | } |
| 7746 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7747 | } |
| 7748 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7749 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7750 | public static WindowManager.LayoutParams findAnimations( |
| 7751 | ArrayList<AppWindowToken> order, |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 7752 | ArrayList<AppWindowToken> openingTokenList1, |
| 7753 | ArrayList<AppWindowToken> closingTokenList2) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7754 | // We need to figure out which animation to use... |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 7755 | |
| 7756 | // First, check if there is a compatible window in opening/closing |
| 7757 | // apps, and use it if exists. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7758 | WindowManager.LayoutParams animParams = null; |
| 7759 | int animSrc = 0; |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 7760 | animParams = findCompatibleWindowParams(openingTokenList1); |
| 7761 | if (animParams == null) { |
| 7762 | animParams = findCompatibleWindowParams(closingTokenList2); |
| 7763 | } |
| 7764 | if (animParams != null) { |
| 7765 | return animParams; |
| 7766 | } |
| 7767 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7768 | //Log.i(TAG, "Looking for animations..."); |
| 7769 | for (int i=order.size()-1; i>=0; i--) { |
| 7770 | AppWindowToken wtoken = order.get(i); |
| 7771 | //Log.i(TAG, "Token " + wtoken + " with " + wtoken.windows.size() + " windows"); |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 7772 | if (openingTokenList1.contains(wtoken) || closingTokenList2.contains(wtoken)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7773 | int j = wtoken.windows.size(); |
| 7774 | while (j > 0) { |
| 7775 | j--; |
| 7776 | WindowState win = wtoken.windows.get(j); |
| 7777 | //Log.i(TAG, "Window " + win + ": type=" + win.mAttrs.type); |
| 7778 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 7779 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 7780 | //Log.i(TAG, "Found base or application window, done!"); |
| 7781 | if (wtoken.appFullscreen) { |
| 7782 | return win.mAttrs; |
| 7783 | } |
| 7784 | if (animSrc < 2) { |
| 7785 | animParams = win.mAttrs; |
| 7786 | animSrc = 2; |
| 7787 | } |
| 7788 | } else if (animSrc < 1 && win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION) { |
| 7789 | //Log.i(TAG, "Found normal window, we may use this..."); |
| 7790 | animParams = win.mAttrs; |
| 7791 | animSrc = 1; |
| 7792 | } |
| 7793 | } |
| 7794 | } |
| 7795 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7796 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7797 | return animParams; |
| 7798 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7799 | |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 7800 | private static LayoutParams findCompatibleWindowParams(ArrayList<AppWindowToken> tokenList) { |
| 7801 | for (int appCount = tokenList.size() - 1; appCount >= 0; appCount--) { |
| 7802 | AppWindowToken wtoken = tokenList.get(appCount); |
| 7803 | // Just checking one window is sufficient as all windows have the compatible flag |
| 7804 | // if the application is in compatibility mode. |
| 7805 | if (wtoken.windows.size() > 0) { |
| 7806 | WindowManager.LayoutParams params = wtoken.windows.get(0).mAttrs; |
| 7807 | if ((params.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| 7808 | return params; |
| 7809 | } |
| 7810 | } |
| 7811 | } |
| 7812 | return null; |
| 7813 | } |
| 7814 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7815 | // ------------------------------------------------------------- |
| 7816 | // DummyAnimation |
| 7817 | // ------------------------------------------------------------- |
| 7818 | |
| 7819 | // This is an animation that does nothing: it just immediately finishes |
| 7820 | // itself every time it is called. It is used as a stub animation in cases |
| 7821 | // where we want to synchronize multiple things that may be animating. |
| 7822 | static final class DummyAnimation extends Animation { |
| 7823 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 7824 | return false; |
| 7825 | } |
| 7826 | } |
| 7827 | static final Animation sDummyAnimation = new DummyAnimation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7828 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7829 | // ------------------------------------------------------------- |
| 7830 | // Async Handler |
| 7831 | // ------------------------------------------------------------- |
| 7832 | |
| 7833 | static final class StartingData { |
| 7834 | final String pkg; |
| 7835 | final int theme; |
| 7836 | final CharSequence nonLocalizedLabel; |
| 7837 | final int labelRes; |
| 7838 | final int icon; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7839 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7840 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 7841 | int _labelRes, int _icon) { |
| 7842 | pkg = _pkg; |
| 7843 | theme = _theme; |
| 7844 | nonLocalizedLabel = _nonLocalizedLabel; |
| 7845 | labelRes = _labelRes; |
| 7846 | icon = _icon; |
| 7847 | } |
| 7848 | } |
| 7849 | |
| 7850 | private final class H extends Handler { |
| 7851 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 7852 | public static final int REPORT_LOSING_FOCUS = 3; |
| 7853 | public static final int ANIMATE = 4; |
| 7854 | public static final int ADD_STARTING = 5; |
| 7855 | public static final int REMOVE_STARTING = 6; |
| 7856 | public static final int FINISHED_STARTING = 7; |
| 7857 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7858 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 7859 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 7860 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 7861 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 7862 | public static final int FORCE_GC = 15; |
| 7863 | public static final int ENABLE_SCREEN = 16; |
| 7864 | public static final int APP_FREEZE_TIMEOUT = 17; |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 7865 | public static final int COMPUTE_AND_SEND_NEW_CONFIGURATION = 18; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7866 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7867 | private Session mLastReportedHold; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7868 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7869 | public H() { |
| 7870 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7871 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7872 | @Override |
| 7873 | public void handleMessage(Message msg) { |
| 7874 | switch (msg.what) { |
| 7875 | case REPORT_FOCUS_CHANGE: { |
| 7876 | WindowState lastFocus; |
| 7877 | WindowState newFocus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7878 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7879 | synchronized(mWindowMap) { |
| 7880 | lastFocus = mLastFocus; |
| 7881 | newFocus = mCurrentFocus; |
| 7882 | if (lastFocus == newFocus) { |
| 7883 | // Focus is not changing, so nothing to do. |
| 7884 | return; |
| 7885 | } |
| 7886 | mLastFocus = newFocus; |
| 7887 | //Log.i(TAG, "Focus moving from " + lastFocus |
| 7888 | // + " to " + newFocus); |
| 7889 | if (newFocus != null && lastFocus != null |
| 7890 | && !newFocus.isDisplayedLw()) { |
| 7891 | //Log.i(TAG, "Delaying loss of focus..."); |
| 7892 | mLosingFocus.add(lastFocus); |
| 7893 | lastFocus = null; |
| 7894 | } |
| 7895 | } |
| 7896 | |
| 7897 | if (lastFocus != newFocus) { |
| 7898 | //System.out.println("Changing focus from " + lastFocus |
| 7899 | // + " to " + newFocus); |
| 7900 | if (newFocus != null) { |
| 7901 | try { |
| 7902 | //Log.i(TAG, "Gaining focus: " + newFocus); |
| 7903 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 7904 | } catch (RemoteException e) { |
| 7905 | // Ignore if process has died. |
| 7906 | } |
| 7907 | } |
| 7908 | |
| 7909 | if (lastFocus != null) { |
| 7910 | try { |
| 7911 | //Log.i(TAG, "Losing focus: " + lastFocus); |
| 7912 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 7913 | } catch (RemoteException e) { |
| 7914 | // Ignore if process has died. |
| 7915 | } |
| 7916 | } |
| 7917 | } |
| 7918 | } break; |
| 7919 | |
| 7920 | case REPORT_LOSING_FOCUS: { |
| 7921 | ArrayList<WindowState> losers; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7922 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7923 | synchronized(mWindowMap) { |
| 7924 | losers = mLosingFocus; |
| 7925 | mLosingFocus = new ArrayList<WindowState>(); |
| 7926 | } |
| 7927 | |
| 7928 | final int N = losers.size(); |
| 7929 | for (int i=0; i<N; i++) { |
| 7930 | try { |
| 7931 | //Log.i(TAG, "Losing delayed focus: " + losers.get(i)); |
| 7932 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 7933 | } catch (RemoteException e) { |
| 7934 | // Ignore if process has died. |
| 7935 | } |
| 7936 | } |
| 7937 | } break; |
| 7938 | |
| 7939 | case ANIMATE: { |
| 7940 | synchronized(mWindowMap) { |
| 7941 | mAnimationPending = false; |
| 7942 | performLayoutAndPlaceSurfacesLocked(); |
| 7943 | } |
| 7944 | } break; |
| 7945 | |
| 7946 | case ADD_STARTING: { |
| 7947 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7948 | final StartingData sd = wtoken.startingData; |
| 7949 | |
| 7950 | if (sd == null) { |
| 7951 | // Animation has been canceled... do nothing. |
| 7952 | return; |
| 7953 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7954 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7955 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Add starting " |
| 7956 | + wtoken + ": pkg=" + sd.pkg); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7957 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7958 | View view = null; |
| 7959 | try { |
| 7960 | view = mPolicy.addStartingWindow( |
| 7961 | wtoken.token, sd.pkg, |
| 7962 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 7963 | sd.icon); |
| 7964 | } catch (Exception e) { |
| 7965 | Log.w(TAG, "Exception when adding starting window", e); |
| 7966 | } |
| 7967 | |
| 7968 | if (view != null) { |
| 7969 | boolean abort = false; |
| 7970 | |
| 7971 | synchronized(mWindowMap) { |
| 7972 | if (wtoken.removed || wtoken.startingData == null) { |
| 7973 | // If the window was successfully added, then |
| 7974 | // we need to remove it. |
| 7975 | if (wtoken.startingWindow != null) { |
| 7976 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 7977 | "Aborted starting " + wtoken |
| 7978 | + ": removed=" + wtoken.removed |
| 7979 | + " startingData=" + wtoken.startingData); |
| 7980 | wtoken.startingWindow = null; |
| 7981 | wtoken.startingData = null; |
| 7982 | abort = true; |
| 7983 | } |
| 7984 | } else { |
| 7985 | wtoken.startingView = view; |
| 7986 | } |
| 7987 | if (DEBUG_STARTING_WINDOW && !abort) Log.v(TAG, |
| 7988 | "Added starting " + wtoken |
| 7989 | + ": startingWindow=" |
| 7990 | + wtoken.startingWindow + " startingView=" |
| 7991 | + wtoken.startingView); |
| 7992 | } |
| 7993 | |
| 7994 | if (abort) { |
| 7995 | try { |
| 7996 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 7997 | } catch (Exception e) { |
| 7998 | Log.w(TAG, "Exception when removing starting window", e); |
| 7999 | } |
| 8000 | } |
| 8001 | } |
| 8002 | } break; |
| 8003 | |
| 8004 | case REMOVE_STARTING: { |
| 8005 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8006 | IBinder token = null; |
| 8007 | View view = null; |
| 8008 | synchronized (mWindowMap) { |
| 8009 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Remove starting " |
| 8010 | + wtoken + ": startingWindow=" |
| 8011 | + wtoken.startingWindow + " startingView=" |
| 8012 | + wtoken.startingView); |
| 8013 | if (wtoken.startingWindow != null) { |
| 8014 | view = wtoken.startingView; |
| 8015 | token = wtoken.token; |
| 8016 | wtoken.startingData = null; |
| 8017 | wtoken.startingView = null; |
| 8018 | wtoken.startingWindow = null; |
| 8019 | } |
| 8020 | } |
| 8021 | if (view != null) { |
| 8022 | try { |
| 8023 | mPolicy.removeStartingWindow(token, view); |
| 8024 | } catch (Exception e) { |
| 8025 | Log.w(TAG, "Exception when removing starting window", e); |
| 8026 | } |
| 8027 | } |
| 8028 | } break; |
| 8029 | |
| 8030 | case FINISHED_STARTING: { |
| 8031 | IBinder token = null; |
| 8032 | View view = null; |
| 8033 | while (true) { |
| 8034 | synchronized (mWindowMap) { |
| 8035 | final int N = mFinishedStarting.size(); |
| 8036 | if (N <= 0) { |
| 8037 | break; |
| 8038 | } |
| 8039 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 8040 | |
| 8041 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 8042 | "Finished starting " + wtoken |
| 8043 | + ": startingWindow=" + wtoken.startingWindow |
| 8044 | + " startingView=" + wtoken.startingView); |
| 8045 | |
| 8046 | if (wtoken.startingWindow == null) { |
| 8047 | continue; |
| 8048 | } |
| 8049 | |
| 8050 | view = wtoken.startingView; |
| 8051 | token = wtoken.token; |
| 8052 | wtoken.startingData = null; |
| 8053 | wtoken.startingView = null; |
| 8054 | wtoken.startingWindow = null; |
| 8055 | } |
| 8056 | |
| 8057 | try { |
| 8058 | mPolicy.removeStartingWindow(token, view); |
| 8059 | } catch (Exception e) { |
| 8060 | Log.w(TAG, "Exception when removing starting window", e); |
| 8061 | } |
| 8062 | } |
| 8063 | } break; |
| 8064 | |
| 8065 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 8066 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8067 | |
| 8068 | boolean nowVisible = msg.arg1 != 0; |
| 8069 | boolean nowGone = msg.arg2 != 0; |
| 8070 | |
| 8071 | try { |
| 8072 | if (DEBUG_VISIBILITY) Log.v( |
| 8073 | TAG, "Reporting visible in " + wtoken |
| 8074 | + " visible=" + nowVisible |
| 8075 | + " gone=" + nowGone); |
| 8076 | if (nowVisible) { |
| 8077 | wtoken.appToken.windowsVisible(); |
| 8078 | } else { |
| 8079 | wtoken.appToken.windowsGone(); |
| 8080 | } |
| 8081 | } catch (RemoteException ex) { |
| 8082 | } |
| 8083 | } break; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8084 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8085 | case WINDOW_FREEZE_TIMEOUT: { |
| 8086 | synchronized (mWindowMap) { |
| 8087 | Log.w(TAG, "Window freeze timeout expired."); |
| 8088 | int i = mWindows.size(); |
| 8089 | while (i > 0) { |
| 8090 | i--; |
| 8091 | WindowState w = (WindowState)mWindows.get(i); |
| 8092 | if (w.mOrientationChanging) { |
| 8093 | w.mOrientationChanging = false; |
| 8094 | Log.w(TAG, "Force clearing orientation change: " + w); |
| 8095 | } |
| 8096 | } |
| 8097 | performLayoutAndPlaceSurfacesLocked(); |
| 8098 | } |
| 8099 | break; |
| 8100 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8101 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8102 | case HOLD_SCREEN_CHANGED: { |
| 8103 | Session oldHold; |
| 8104 | Session newHold; |
| 8105 | synchronized (mWindowMap) { |
| 8106 | oldHold = mLastReportedHold; |
| 8107 | newHold = (Session)msg.obj; |
| 8108 | mLastReportedHold = newHold; |
| 8109 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8110 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8111 | if (oldHold != newHold) { |
| 8112 | try { |
| 8113 | if (oldHold != null) { |
| 8114 | mBatteryStats.noteStopWakelock(oldHold.mUid, |
| 8115 | "window", |
| 8116 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8117 | } |
| 8118 | if (newHold != null) { |
| 8119 | mBatteryStats.noteStartWakelock(newHold.mUid, |
| 8120 | "window", |
| 8121 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8122 | } |
| 8123 | } catch (RemoteException e) { |
| 8124 | } |
| 8125 | } |
| 8126 | break; |
| 8127 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8128 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8129 | case APP_TRANSITION_TIMEOUT: { |
| 8130 | synchronized (mWindowMap) { |
| 8131 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) { |
| 8132 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 8133 | "*** APP TRANSITION TIMEOUT"); |
| 8134 | mAppTransitionReady = true; |
| 8135 | mAppTransitionTimeout = true; |
| 8136 | performLayoutAndPlaceSurfacesLocked(); |
| 8137 | } |
| 8138 | } |
| 8139 | break; |
| 8140 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8141 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8142 | case PERSIST_ANIMATION_SCALE: { |
| 8143 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8144 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 8145 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8146 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 8147 | break; |
| 8148 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8149 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8150 | case FORCE_GC: { |
| 8151 | synchronized(mWindowMap) { |
| 8152 | if (mAnimationPending) { |
| 8153 | // If we are animating, don't do the gc now but |
| 8154 | // delay a bit so we don't interrupt the animation. |
| 8155 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 8156 | 2000); |
| 8157 | return; |
| 8158 | } |
| 8159 | // If we are currently rotating the display, it will |
| 8160 | // schedule a new message when done. |
| 8161 | if (mDisplayFrozen) { |
| 8162 | return; |
| 8163 | } |
| 8164 | mFreezeGcPending = 0; |
| 8165 | } |
| 8166 | Runtime.getRuntime().gc(); |
| 8167 | break; |
| 8168 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8169 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8170 | case ENABLE_SCREEN: { |
| 8171 | performEnableScreen(); |
| 8172 | break; |
| 8173 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8174 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8175 | case APP_FREEZE_TIMEOUT: { |
| 8176 | synchronized (mWindowMap) { |
| 8177 | Log.w(TAG, "App freeze timeout expired."); |
| 8178 | int i = mAppTokens.size(); |
| 8179 | while (i > 0) { |
| 8180 | i--; |
| 8181 | AppWindowToken tok = mAppTokens.get(i); |
| 8182 | if (tok.freezingScreen) { |
| 8183 | Log.w(TAG, "Force clearing freeze: " + tok); |
| 8184 | unsetAppFreezingScreenLocked(tok, true, true); |
| 8185 | } |
| 8186 | } |
| 8187 | } |
| 8188 | break; |
| 8189 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8190 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8191 | case COMPUTE_AND_SEND_NEW_CONFIGURATION: { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 8192 | if (updateOrientationFromAppTokensUnchecked(null, null) != null) { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8193 | sendNewConfiguration(); |
| 8194 | } |
| 8195 | break; |
| 8196 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8197 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8198 | } |
| 8199 | } |
| 8200 | } |
| 8201 | |
| 8202 | // ------------------------------------------------------------- |
| 8203 | // IWindowManager API |
| 8204 | // ------------------------------------------------------------- |
| 8205 | |
| 8206 | public IWindowSession openSession(IInputMethodClient client, |
| 8207 | IInputContext inputContext) { |
| 8208 | if (client == null) throw new IllegalArgumentException("null client"); |
| 8209 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
| 8210 | return new Session(client, inputContext); |
| 8211 | } |
| 8212 | |
| 8213 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 8214 | synchronized (mWindowMap) { |
| 8215 | // The focus for the client is the window immediately below |
| 8216 | // where we would place the input method window. |
| 8217 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 8218 | WindowState imFocus; |
| 8219 | if (idx > 0) { |
| 8220 | imFocus = (WindowState)mWindows.get(idx-1); |
| 8221 | if (imFocus != null) { |
| 8222 | if (imFocus.mSession.mClient != null && |
| 8223 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 8224 | return true; |
| 8225 | } |
| 8226 | } |
| 8227 | } |
| 8228 | } |
| 8229 | return false; |
| 8230 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8231 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8232 | // ------------------------------------------------------------- |
| 8233 | // Internals |
| 8234 | // ------------------------------------------------------------- |
| 8235 | |
| 8236 | final WindowState windowForClientLocked(Session session, IWindow client) { |
| 8237 | return windowForClientLocked(session, client.asBinder()); |
| 8238 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8239 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8240 | final WindowState windowForClientLocked(Session session, IBinder client) { |
| 8241 | WindowState win = mWindowMap.get(client); |
| 8242 | if (localLOGV) Log.v( |
| 8243 | TAG, "Looking up client " + client + ": " + win); |
| 8244 | if (win == null) { |
| 8245 | RuntimeException ex = new RuntimeException(); |
| 8246 | Log.w(TAG, "Requested window " + client + " does not exist", ex); |
| 8247 | return null; |
| 8248 | } |
| 8249 | if (session != null && win.mSession != session) { |
| 8250 | RuntimeException ex = new RuntimeException(); |
| 8251 | Log.w(TAG, "Requested window " + client + " is in session " + |
| 8252 | win.mSession + ", not " + session, ex); |
| 8253 | return null; |
| 8254 | } |
| 8255 | |
| 8256 | return win; |
| 8257 | } |
| 8258 | |
| 8259 | private final void assignLayersLocked() { |
| 8260 | int N = mWindows.size(); |
| 8261 | int curBaseLayer = 0; |
| 8262 | int curLayer = 0; |
| 8263 | int i; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8264 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8265 | for (i=0; i<N; i++) { |
| 8266 | WindowState w = (WindowState)mWindows.get(i); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8267 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 8268 | || (i > 0 && w.mIsWallpaper)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8269 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 8270 | w.mLayer = curLayer; |
| 8271 | } else { |
| 8272 | curBaseLayer = curLayer = w.mBaseLayer; |
| 8273 | w.mLayer = curLayer; |
| 8274 | } |
| 8275 | if (w.mTargetAppToken != null) { |
| 8276 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 8277 | } else if (w.mAppToken != null) { |
| 8278 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 8279 | } else { |
| 8280 | w.mAnimLayer = w.mLayer; |
| 8281 | } |
| 8282 | if (w.mIsImWindow) { |
| 8283 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8284 | } else if (w.mIsWallpaper) { |
| 8285 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8286 | } |
| 8287 | if (DEBUG_LAYERS) Log.v(TAG, "Assign layer " + w + ": " |
| 8288 | + w.mAnimLayer); |
| 8289 | //System.out.println( |
| 8290 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 8291 | } |
| 8292 | } |
| 8293 | |
| 8294 | private boolean mInLayout = false; |
| 8295 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 8296 | if (mInLayout) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 8297 | if (DEBUG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8298 | throw new RuntimeException("Recursive call!"); |
| 8299 | } |
| 8300 | Log.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
| 8301 | return; |
| 8302 | } |
| 8303 | |
| 8304 | boolean recoveringMemory = false; |
| 8305 | if (mForceRemoves != null) { |
| 8306 | recoveringMemory = true; |
| 8307 | // Wait a little it for things to settle down, and off we go. |
| 8308 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 8309 | WindowState ws = mForceRemoves.get(i); |
| 8310 | Log.i(TAG, "Force removing: " + ws); |
| 8311 | removeWindowInnerLocked(ws.mSession, ws); |
| 8312 | } |
| 8313 | mForceRemoves = null; |
| 8314 | Log.w(TAG, "Due to memory failure, waiting a bit for next layout"); |
| 8315 | Object tmp = new Object(); |
| 8316 | synchronized (tmp) { |
| 8317 | try { |
| 8318 | tmp.wait(250); |
| 8319 | } catch (InterruptedException e) { |
| 8320 | } |
| 8321 | } |
| 8322 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8323 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8324 | mInLayout = true; |
| 8325 | try { |
| 8326 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8327 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8328 | int i = mPendingRemove.size()-1; |
| 8329 | if (i >= 0) { |
| 8330 | while (i >= 0) { |
| 8331 | WindowState w = mPendingRemove.get(i); |
| 8332 | removeWindowInnerLocked(w.mSession, w); |
| 8333 | i--; |
| 8334 | } |
| 8335 | mPendingRemove.clear(); |
| 8336 | |
| 8337 | mInLayout = false; |
| 8338 | assignLayersLocked(); |
| 8339 | mLayoutNeeded = true; |
| 8340 | performLayoutAndPlaceSurfacesLocked(); |
| 8341 | |
| 8342 | } else { |
| 8343 | mInLayout = false; |
| 8344 | if (mLayoutNeeded) { |
| 8345 | requestAnimationLocked(0); |
| 8346 | } |
| 8347 | } |
| 8348 | } catch (RuntimeException e) { |
| 8349 | mInLayout = false; |
| 8350 | Log.e(TAG, "Unhandled exception while layout out windows", e); |
| 8351 | } |
| 8352 | } |
| 8353 | |
| 8354 | private final void performLayoutLockedInner() { |
| 8355 | final int dw = mDisplay.getWidth(); |
| 8356 | final int dh = mDisplay.getHeight(); |
| 8357 | |
| 8358 | final int N = mWindows.size(); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 8359 | int repeats = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8360 | int i; |
| 8361 | |
| 8362 | // FIRST LOOP: Perform a layout, if needed. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8363 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 8364 | while (mLayoutNeeded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8365 | mPolicy.beginLayoutLw(dw, dh); |
| 8366 | |
| 8367 | // First perform layout of any root windows (not attached |
| 8368 | // to another window). |
| 8369 | int topAttached = -1; |
| 8370 | for (i = N-1; i >= 0; i--) { |
| 8371 | WindowState win = (WindowState) mWindows.get(i); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 8372 | |
| 8373 | // Don't do layout of a window if it is not visible, or |
| 8374 | // soon won't be visible, to avoid wasting time and funky |
| 8375 | // changes while a window is animating away. |
| 8376 | final AppWindowToken atoken = win.mAppToken; |
| 8377 | final boolean gone = win.mViewVisibility == View.GONE |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8378 | || !win.mRelayoutCalled |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 8379 | || win.mRootToken.hidden |
| 8380 | || (atoken != null && atoken.hiddenRequested) |
| 8381 | || !win.mPolicyVisibility |
| 8382 | || win.mAttachedHidden |
| 8383 | || win.mExiting || win.mDestroying; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8384 | |
| 8385 | // If this view is GONE, then skip it -- keep the current |
| 8386 | // frame, and let the caller know so they can ignore it |
| 8387 | // if they want. (We do the normal layout for INVISIBLE |
| 8388 | // windows, since that means "perform layout as normal, |
| 8389 | // just don't display"). |
| 8390 | if (!gone || !win.mHaveFrame) { |
| 8391 | if (!win.mLayoutAttached) { |
| 8392 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 8393 | } else { |
| 8394 | if (topAttached < 0) topAttached = i; |
| 8395 | } |
| 8396 | } |
| 8397 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8398 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8399 | // Now perform layout of attached windows, which usually |
| 8400 | // depend on the position of the window they are attached to. |
| 8401 | // XXX does not deal with windows that are attached to windows |
| 8402 | // that are themselves attached. |
| 8403 | for (i = topAttached; i >= 0; i--) { |
| 8404 | WindowState win = (WindowState) mWindows.get(i); |
| 8405 | |
| 8406 | // If this view is GONE, then skip it -- keep the current |
| 8407 | // frame, and let the caller know so they can ignore it |
| 8408 | // if they want. (We do the normal layout for INVISIBLE |
| 8409 | // windows, since that means "perform layout as normal, |
| 8410 | // just don't display"). |
| 8411 | if (win.mLayoutAttached) { |
| 8412 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 8413 | || !win.mHaveFrame) { |
| 8414 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 8415 | } |
| 8416 | } |
| 8417 | } |
| 8418 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 8419 | if (!mPolicy.finishLayoutLw()) { |
| 8420 | mLayoutNeeded = false; |
| 8421 | } else if (repeats > 2) { |
| 8422 | Log.w(TAG, "Layout repeat aborted after too many iterations"); |
| 8423 | mLayoutNeeded = false; |
| 8424 | } else { |
| 8425 | repeats++; |
| 8426 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8427 | } |
| 8428 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8429 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8430 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 8431 | boolean recoveringMemory) { |
| 8432 | final long currentTime = SystemClock.uptimeMillis(); |
| 8433 | final int dw = mDisplay.getWidth(); |
| 8434 | final int dh = mDisplay.getHeight(); |
| 8435 | |
| 8436 | final int N = mWindows.size(); |
| 8437 | int i; |
| 8438 | |
| 8439 | // FIRST LOOP: Perform a layout, if needed. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8440 | performLayoutLockedInner(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8441 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8442 | if (mFxSession == null) { |
| 8443 | mFxSession = new SurfaceSession(); |
| 8444 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8445 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8446 | if (SHOW_TRANSACTIONS) Log.i(TAG, ">>> OPEN TRANSACTION"); |
| 8447 | |
| 8448 | // Initialize state of exiting tokens. |
| 8449 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 8450 | mExitingTokens.get(i).hasVisible = false; |
| 8451 | } |
| 8452 | |
| 8453 | // Initialize state of exiting applications. |
| 8454 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 8455 | mExitingAppTokens.get(i).hasVisible = false; |
| 8456 | } |
| 8457 | |
| 8458 | // SECOND LOOP: Execute animations and update visibility of windows. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8459 | boolean orientationChangeComplete = true; |
| 8460 | Session holdScreen = null; |
| 8461 | float screenBrightness = -1; |
| 8462 | boolean focusDisplayed = false; |
| 8463 | boolean animating = false; |
| 8464 | |
| 8465 | Surface.openTransaction(); |
| 8466 | try { |
| 8467 | boolean restart; |
| 8468 | |
| 8469 | do { |
| 8470 | final int transactionSequence = ++mTransactionSequence; |
| 8471 | |
| 8472 | // Update animations of all applications, including those |
| 8473 | // associated with exiting/removed apps |
| 8474 | boolean tokensAnimating = false; |
| 8475 | final int NAT = mAppTokens.size(); |
| 8476 | for (i=0; i<NAT; i++) { |
| 8477 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 8478 | tokensAnimating = true; |
| 8479 | } |
| 8480 | } |
| 8481 | final int NEAT = mExitingAppTokens.size(); |
| 8482 | for (i=0; i<NEAT; i++) { |
| 8483 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 8484 | tokensAnimating = true; |
| 8485 | } |
| 8486 | } |
| 8487 | |
| 8488 | animating = tokensAnimating; |
| 8489 | restart = false; |
| 8490 | |
| 8491 | boolean tokenMayBeDrawn = false; |
| 8492 | |
| 8493 | mPolicy.beginAnimationLw(dw, dh); |
| 8494 | |
| 8495 | for (i=N-1; i>=0; i--) { |
| 8496 | WindowState w = (WindowState)mWindows.get(i); |
| 8497 | |
| 8498 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 8499 | |
| 8500 | if (w.mSurface != null) { |
| 8501 | // Execute animation. |
| 8502 | w.commitFinishDrawingLocked(currentTime); |
| 8503 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 8504 | animating = true; |
| 8505 | //w.dump(" "); |
| 8506 | } |
| 8507 | |
| 8508 | mPolicy.animatingWindowLw(w, attrs); |
| 8509 | } |
| 8510 | |
| 8511 | final AppWindowToken atoken = w.mAppToken; |
| 8512 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 8513 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 8514 | atoken.lastTransactionSequence = transactionSequence; |
| 8515 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 8516 | atoken.startingDisplayed = false; |
| 8517 | } |
| 8518 | if ((w.isOnScreen() || w.mAttrs.type |
| 8519 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 8520 | && !w.mExiting && !w.mDestroying) { |
| 8521 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
| 8522 | Log.v(TAG, "Eval win " + w + ": isDisplayed=" |
| 8523 | + w.isDisplayedLw() |
| 8524 | + ", isAnimating=" + w.isAnimating()); |
| 8525 | if (!w.isDisplayedLw()) { |
| 8526 | Log.v(TAG, "Not displayed: s=" + w.mSurface |
| 8527 | + " pv=" + w.mPolicyVisibility |
| 8528 | + " dp=" + w.mDrawPending |
| 8529 | + " cdp=" + w.mCommitDrawPending |
| 8530 | + " ah=" + w.mAttachedHidden |
| 8531 | + " th=" + atoken.hiddenRequested |
| 8532 | + " a=" + w.mAnimating); |
| 8533 | } |
| 8534 | } |
| 8535 | if (w != atoken.startingWindow) { |
| 8536 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 8537 | atoken.numInterestingWindows++; |
| 8538 | if (w.isDisplayedLw()) { |
| 8539 | atoken.numDrawnWindows++; |
| 8540 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Log.v(TAG, |
| 8541 | "tokenMayBeDrawn: " + atoken |
| 8542 | + " freezingScreen=" + atoken.freezingScreen |
| 8543 | + " mAppFreezing=" + w.mAppFreezing); |
| 8544 | tokenMayBeDrawn = true; |
| 8545 | } |
| 8546 | } |
| 8547 | } else if (w.isDisplayedLw()) { |
| 8548 | atoken.startingDisplayed = true; |
| 8549 | } |
| 8550 | } |
| 8551 | } else if (w.mReadyToShow) { |
| 8552 | w.performShowLocked(); |
| 8553 | } |
| 8554 | } |
| 8555 | |
| 8556 | if (mPolicy.finishAnimationLw()) { |
| 8557 | restart = true; |
| 8558 | } |
| 8559 | |
| 8560 | if (tokenMayBeDrawn) { |
| 8561 | // See if any windows have been drawn, so they (and others |
| 8562 | // associated with them) can now be shown. |
| 8563 | final int NT = mTokenList.size(); |
| 8564 | for (i=0; i<NT; i++) { |
| 8565 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 8566 | if (wtoken == null) { |
| 8567 | continue; |
| 8568 | } |
| 8569 | if (wtoken.freezingScreen) { |
| 8570 | int numInteresting = wtoken.numInterestingWindows; |
| 8571 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| 8572 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 8573 | "allDrawn: " + wtoken |
| 8574 | + " interesting=" + numInteresting |
| 8575 | + " drawn=" + wtoken.numDrawnWindows); |
| 8576 | wtoken.showAllWindowsLocked(); |
| 8577 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 8578 | orientationChangeComplete = true; |
| 8579 | } |
| 8580 | } else if (!wtoken.allDrawn) { |
| 8581 | int numInteresting = wtoken.numInterestingWindows; |
| 8582 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| 8583 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 8584 | "allDrawn: " + wtoken |
| 8585 | + " interesting=" + numInteresting |
| 8586 | + " drawn=" + wtoken.numDrawnWindows); |
| 8587 | wtoken.allDrawn = true; |
| 8588 | restart = true; |
| 8589 | |
| 8590 | // We can now show all of the drawn windows! |
| 8591 | if (!mOpeningApps.contains(wtoken)) { |
| 8592 | wtoken.showAllWindowsLocked(); |
| 8593 | } |
| 8594 | } |
| 8595 | } |
| 8596 | } |
| 8597 | } |
| 8598 | |
| 8599 | // If we are ready to perform an app transition, check through |
| 8600 | // all of the app tokens to be shown and see if they are ready |
| 8601 | // to go. |
| 8602 | if (mAppTransitionReady) { |
| 8603 | int NN = mOpeningApps.size(); |
| 8604 | boolean goodToGo = true; |
| 8605 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 8606 | "Checking " + NN + " opening apps (frozen=" |
| 8607 | + mDisplayFrozen + " timeout=" |
| 8608 | + mAppTransitionTimeout + ")..."); |
| 8609 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 8610 | // If the display isn't frozen, wait to do anything until |
| 8611 | // all of the apps are ready. Otherwise just go because |
| 8612 | // we'll unfreeze the display when everyone is ready. |
| 8613 | for (i=0; i<NN && goodToGo; i++) { |
| 8614 | AppWindowToken wtoken = mOpeningApps.get(i); |
| 8615 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 8616 | "Check opening app" + wtoken + ": allDrawn=" |
| 8617 | + wtoken.allDrawn + " startingDisplayed=" |
| 8618 | + wtoken.startingDisplayed); |
| 8619 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 8620 | && !wtoken.startingMoved) { |
| 8621 | goodToGo = false; |
| 8622 | } |
| 8623 | } |
| 8624 | } |
| 8625 | if (goodToGo) { |
| 8626 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "**** GOOD TO GO"); |
| 8627 | int transit = mNextAppTransition; |
| 8628 | if (mSkipAppTransitionAnimation) { |
| 8629 | transit = WindowManagerPolicy.TRANSIT_NONE; |
| 8630 | } |
| 8631 | mNextAppTransition = WindowManagerPolicy.TRANSIT_NONE; |
| 8632 | mAppTransitionReady = false; |
| 8633 | mAppTransitionTimeout = false; |
| 8634 | mStartingIconInTransition = false; |
| 8635 | mSkipAppTransitionAnimation = false; |
| 8636 | |
| 8637 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 8638 | |
| 8639 | // We need to figure out which animation to use... |
| 8640 | WindowManager.LayoutParams lp = findAnimations(mAppTokens, |
| 8641 | mOpeningApps, mClosingApps); |
| 8642 | |
| 8643 | NN = mOpeningApps.size(); |
| 8644 | for (i=0; i<NN; i++) { |
| 8645 | AppWindowToken wtoken = mOpeningApps.get(i); |
| 8646 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 8647 | "Now opening app" + wtoken); |
| 8648 | wtoken.reportedVisible = false; |
| 8649 | wtoken.inPendingTransaction = false; |
| 8650 | setTokenVisibilityLocked(wtoken, lp, true, transit, false); |
| 8651 | wtoken.updateReportedVisibilityLocked(); |
| 8652 | wtoken.showAllWindowsLocked(); |
| 8653 | } |
| 8654 | NN = mClosingApps.size(); |
| 8655 | for (i=0; i<NN; i++) { |
| 8656 | AppWindowToken wtoken = mClosingApps.get(i); |
| 8657 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 8658 | "Now closing app" + wtoken); |
| 8659 | wtoken.inPendingTransaction = false; |
| 8660 | setTokenVisibilityLocked(wtoken, lp, false, transit, false); |
| 8661 | wtoken.updateReportedVisibilityLocked(); |
| 8662 | // Force the allDrawn flag, because we want to start |
| 8663 | // this guy's animations regardless of whether it's |
| 8664 | // gotten drawn. |
| 8665 | wtoken.allDrawn = true; |
| 8666 | } |
| 8667 | |
| 8668 | mOpeningApps.clear(); |
| 8669 | mClosingApps.clear(); |
| 8670 | |
| 8671 | // This has changed the visibility of windows, so perform |
| 8672 | // a new layout to get them all up-to-date. |
| 8673 | mLayoutNeeded = true; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8674 | adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 8675 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 8676 | assignLayersLocked(); |
| 8677 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8678 | performLayoutLockedInner(); |
| 8679 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
| 8680 | |
| 8681 | restart = true; |
| 8682 | } |
| 8683 | } |
| 8684 | } while (restart); |
| 8685 | |
| 8686 | // THIRD LOOP: Update the surfaces of all windows. |
| 8687 | |
| 8688 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 8689 | |
| 8690 | boolean obscured = false; |
| 8691 | boolean blurring = false; |
| 8692 | boolean dimming = false; |
| 8693 | boolean covered = false; |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 8694 | boolean syswin = false; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8695 | boolean backgroundFillerShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8696 | |
| 8697 | for (i=N-1; i>=0; i--) { |
| 8698 | WindowState w = (WindowState)mWindows.get(i); |
| 8699 | |
| 8700 | boolean displayed = false; |
| 8701 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 8702 | final int attrFlags = attrs.flags; |
| 8703 | |
| 8704 | if (w.mSurface != null) { |
| 8705 | w.computeShownFrameLocked(); |
| 8706 | if (localLOGV) Log.v( |
| 8707 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 8708 | + ": new=" + w.mShownFrame + ", old=" |
| 8709 | + w.mLastShownFrame); |
| 8710 | |
| 8711 | boolean resize; |
| 8712 | int width, height; |
| 8713 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 8714 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 8715 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 8716 | // for a scaled surface, we just want to use |
| 8717 | // the requested size. |
| 8718 | width = w.mRequestedWidth; |
| 8719 | height = w.mRequestedHeight; |
| 8720 | w.mLastRequestedWidth = width; |
| 8721 | w.mLastRequestedHeight = height; |
| 8722 | w.mLastShownFrame.set(w.mShownFrame); |
| 8723 | try { |
| 8724 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 8725 | } catch (RuntimeException e) { |
| 8726 | Log.w(TAG, "Error positioning surface in " + w, e); |
| 8727 | if (!recoveringMemory) { |
| 8728 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 8729 | } |
| 8730 | } |
| 8731 | } else { |
| 8732 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 8733 | width = w.mShownFrame.width(); |
| 8734 | height = w.mShownFrame.height(); |
| 8735 | w.mLastShownFrame.set(w.mShownFrame); |
| 8736 | if (resize) { |
| 8737 | if (SHOW_TRANSACTIONS) Log.i( |
| 8738 | TAG, " SURFACE " + w.mSurface + ": (" |
| 8739 | + w.mShownFrame.left + "," |
| 8740 | + w.mShownFrame.top + ") (" |
| 8741 | + w.mShownFrame.width() + "x" |
| 8742 | + w.mShownFrame.height() + ")"); |
| 8743 | } |
| 8744 | } |
| 8745 | |
| 8746 | if (resize) { |
| 8747 | if (width < 1) width = 1; |
| 8748 | if (height < 1) height = 1; |
| 8749 | if (w.mSurface != null) { |
| 8750 | try { |
| 8751 | w.mSurface.setSize(width, height); |
| 8752 | w.mSurface.setPosition(w.mShownFrame.left, |
| 8753 | w.mShownFrame.top); |
| 8754 | } catch (RuntimeException e) { |
| 8755 | // If something goes wrong with the surface (such |
| 8756 | // as running out of memory), don't take down the |
| 8757 | // entire system. |
| 8758 | Log.e(TAG, "Failure updating surface of " + w |
| 8759 | + "size=(" + width + "x" + height |
| 8760 | + "), pos=(" + w.mShownFrame.left |
| 8761 | + "," + w.mShownFrame.top + ")", e); |
| 8762 | if (!recoveringMemory) { |
| 8763 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 8764 | } |
| 8765 | } |
| 8766 | } |
| 8767 | } |
| 8768 | if (!w.mAppFreezing) { |
| 8769 | w.mContentInsetsChanged = |
| 8770 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 8771 | w.mVisibleInsetsChanged = |
| 8772 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8773 | if (!w.mLastFrame.equals(w.mFrame) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8774 | || w.mContentInsetsChanged |
| 8775 | || w.mVisibleInsetsChanged) { |
| 8776 | w.mLastFrame.set(w.mFrame); |
| 8777 | w.mLastContentInsets.set(w.mContentInsets); |
| 8778 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
| 8779 | // If the orientation is changing, then we need to |
| 8780 | // hold off on unfreezing the display until this |
| 8781 | // window has been redrawn; to do that, we need |
| 8782 | // to go through the process of getting informed |
| 8783 | // by the application when it has finished drawing. |
| 8784 | if (w.mOrientationChanging) { |
| 8785 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 8786 | "Orientation start waiting for draw in " |
| 8787 | + w + ", surface " + w.mSurface); |
| 8788 | w.mDrawPending = true; |
| 8789 | w.mCommitDrawPending = false; |
| 8790 | w.mReadyToShow = false; |
| 8791 | if (w.mAppToken != null) { |
| 8792 | w.mAppToken.allDrawn = false; |
| 8793 | } |
| 8794 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8795 | if (DEBUG_ORIENTATION) Log.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8796 | "Resizing window " + w + " to " + w.mFrame); |
| 8797 | mResizingWindows.add(w); |
| 8798 | } else if (w.mOrientationChanging) { |
| 8799 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
| 8800 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 8801 | "Orientation not waiting for draw in " |
| 8802 | + w + ", surface " + w.mSurface); |
| 8803 | w.mOrientationChanging = false; |
| 8804 | } |
| 8805 | } |
| 8806 | } |
| 8807 | |
| 8808 | if (w.mAttachedHidden) { |
| 8809 | if (!w.mLastHidden) { |
| 8810 | //dump(); |
| 8811 | w.mLastHidden = true; |
| 8812 | if (SHOW_TRANSACTIONS) Log.i( |
| 8813 | TAG, " SURFACE " + w.mSurface + ": HIDE (performLayout-attached)"); |
| 8814 | if (w.mSurface != null) { |
| 8815 | try { |
| 8816 | w.mSurface.hide(); |
| 8817 | } catch (RuntimeException e) { |
| 8818 | Log.w(TAG, "Exception hiding surface in " + w); |
| 8819 | } |
| 8820 | } |
| 8821 | mKeyWaiter.releasePendingPointerLocked(w.mSession); |
| 8822 | } |
| 8823 | // If we are waiting for this window to handle an |
| 8824 | // orientation change, well, it is hidden, so |
| 8825 | // doesn't really matter. Note that this does |
| 8826 | // introduce a potential glitch if the window |
| 8827 | // becomes unhidden before it has drawn for the |
| 8828 | // new orientation. |
| 8829 | if (w.mOrientationChanging) { |
| 8830 | w.mOrientationChanging = false; |
| 8831 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 8832 | "Orientation change skips hidden " + w); |
| 8833 | } |
| 8834 | } else if (!w.isReadyForDisplay()) { |
| 8835 | if (!w.mLastHidden) { |
| 8836 | //dump(); |
| 8837 | w.mLastHidden = true; |
| 8838 | if (SHOW_TRANSACTIONS) Log.i( |
| 8839 | TAG, " SURFACE " + w.mSurface + ": HIDE (performLayout-ready)"); |
| 8840 | if (w.mSurface != null) { |
| 8841 | try { |
| 8842 | w.mSurface.hide(); |
| 8843 | } catch (RuntimeException e) { |
| 8844 | Log.w(TAG, "Exception exception hiding surface in " + w); |
| 8845 | } |
| 8846 | } |
| 8847 | mKeyWaiter.releasePendingPointerLocked(w.mSession); |
| 8848 | } |
| 8849 | // If we are waiting for this window to handle an |
| 8850 | // orientation change, well, it is hidden, so |
| 8851 | // doesn't really matter. Note that this does |
| 8852 | // introduce a potential glitch if the window |
| 8853 | // becomes unhidden before it has drawn for the |
| 8854 | // new orientation. |
| 8855 | if (w.mOrientationChanging) { |
| 8856 | w.mOrientationChanging = false; |
| 8857 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 8858 | "Orientation change skips hidden " + w); |
| 8859 | } |
| 8860 | } else if (w.mLastLayer != w.mAnimLayer |
| 8861 | || w.mLastAlpha != w.mShownAlpha |
| 8862 | || w.mLastDsDx != w.mDsDx |
| 8863 | || w.mLastDtDx != w.mDtDx |
| 8864 | || w.mLastDsDy != w.mDsDy |
| 8865 | || w.mLastDtDy != w.mDtDy |
| 8866 | || w.mLastHScale != w.mHScale |
| 8867 | || w.mLastVScale != w.mVScale |
| 8868 | || w.mLastHidden) { |
| 8869 | displayed = true; |
| 8870 | w.mLastAlpha = w.mShownAlpha; |
| 8871 | w.mLastLayer = w.mAnimLayer; |
| 8872 | w.mLastDsDx = w.mDsDx; |
| 8873 | w.mLastDtDx = w.mDtDx; |
| 8874 | w.mLastDsDy = w.mDsDy; |
| 8875 | w.mLastDtDy = w.mDtDy; |
| 8876 | w.mLastHScale = w.mHScale; |
| 8877 | w.mLastVScale = w.mVScale; |
| 8878 | if (SHOW_TRANSACTIONS) Log.i( |
| 8879 | TAG, " SURFACE " + w.mSurface + ": alpha=" |
| 8880 | + w.mShownAlpha + " layer=" + w.mAnimLayer); |
| 8881 | if (w.mSurface != null) { |
| 8882 | try { |
| 8883 | w.mSurface.setAlpha(w.mShownAlpha); |
| 8884 | w.mSurface.setLayer(w.mAnimLayer); |
| 8885 | w.mSurface.setMatrix( |
| 8886 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 8887 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 8888 | } catch (RuntimeException e) { |
| 8889 | Log.w(TAG, "Error updating surface in " + w, e); |
| 8890 | if (!recoveringMemory) { |
| 8891 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 8892 | } |
| 8893 | } |
| 8894 | } |
| 8895 | |
| 8896 | if (w.mLastHidden && !w.mDrawPending |
| 8897 | && !w.mCommitDrawPending |
| 8898 | && !w.mReadyToShow) { |
| 8899 | if (SHOW_TRANSACTIONS) Log.i( |
| 8900 | TAG, " SURFACE " + w.mSurface + ": SHOW (performLayout)"); |
| 8901 | if (DEBUG_VISIBILITY) Log.v(TAG, "Showing " + w |
| 8902 | + " during relayout"); |
| 8903 | if (showSurfaceRobustlyLocked(w)) { |
| 8904 | w.mHasDrawn = true; |
| 8905 | w.mLastHidden = false; |
| 8906 | } else { |
| 8907 | w.mOrientationChanging = false; |
| 8908 | } |
| 8909 | } |
| 8910 | if (w.mSurface != null) { |
| 8911 | w.mToken.hasVisible = true; |
| 8912 | } |
| 8913 | } else { |
| 8914 | displayed = true; |
| 8915 | } |
| 8916 | |
| 8917 | if (displayed) { |
| 8918 | if (!covered) { |
| 8919 | if (attrs.width == LayoutParams.FILL_PARENT |
| 8920 | && attrs.height == LayoutParams.FILL_PARENT) { |
| 8921 | covered = true; |
| 8922 | } |
| 8923 | } |
| 8924 | if (w.mOrientationChanging) { |
| 8925 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 8926 | orientationChangeComplete = false; |
| 8927 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 8928 | "Orientation continue waiting for draw in " + w); |
| 8929 | } else { |
| 8930 | w.mOrientationChanging = false; |
| 8931 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 8932 | "Orientation change complete in " + w); |
| 8933 | } |
| 8934 | } |
| 8935 | w.mToken.hasVisible = true; |
| 8936 | } |
| 8937 | } else if (w.mOrientationChanging) { |
| 8938 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 8939 | "Orientation change skips hidden " + w); |
| 8940 | w.mOrientationChanging = false; |
| 8941 | } |
| 8942 | |
| 8943 | final boolean canBeSeen = w.isDisplayedLw(); |
| 8944 | |
| 8945 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 8946 | focusDisplayed = true; |
| 8947 | } |
| 8948 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame^] | 8949 | final boolean obscuredChanged = w.mObscured != obscured; |
| 8950 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8951 | // Update effect. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8952 | if (!(w.mObscured=obscured)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8953 | if (w.mSurface != null) { |
| 8954 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 8955 | holdScreen = w.mSession; |
| 8956 | } |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 8957 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 8958 | && screenBrightness < 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8959 | screenBrightness = w.mAttrs.screenBrightness; |
| 8960 | } |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 8961 | if (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 8962 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 8963 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR) { |
| 8964 | syswin = true; |
| 8965 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8966 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8967 | |
| 8968 | boolean opaqueDrawn = w.isOpaqueDrawn(); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8969 | if ((opaqueDrawn && w.isFullscreen(dw, dh)) |
| 8970 | || attrs.type == TYPE_WALLPAPER) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8971 | // This window completely covers everything behind it, |
| 8972 | // so we want to leave all of them as unblurred (for |
| 8973 | // performance reasons). |
| 8974 | obscured = true; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8975 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
| 8976 | if (SHOW_TRANSACTIONS) Log.d(TAG, "showing background filler"); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8977 | // This window is in compatibility mode, and needs background filler. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8978 | obscured = true; |
| 8979 | if (mBackgroundFillerSurface == null) { |
| 8980 | try { |
| 8981 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
| 8982 | 0, dw, dh, |
| 8983 | PixelFormat.OPAQUE, |
| 8984 | Surface.FX_SURFACE_NORMAL); |
| 8985 | } catch (Exception e) { |
| 8986 | Log.e(TAG, "Exception creating filler surface", e); |
| 8987 | } |
| 8988 | } |
| 8989 | try { |
| 8990 | mBackgroundFillerSurface.setPosition(0, 0); |
| 8991 | mBackgroundFillerSurface.setSize(dw, dh); |
| 8992 | // Using the same layer as Dim because they will never be shown at the |
| 8993 | // same time. |
| 8994 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 8995 | mBackgroundFillerSurface.show(); |
| 8996 | } catch (RuntimeException e) { |
| 8997 | Log.e(TAG, "Exception showing filler surface"); |
| 8998 | } |
| 8999 | backgroundFillerShown = true; |
| 9000 | mBackgroundFillerShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9001 | } else if (canBeSeen && !obscured && |
| 9002 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
| 9003 | if (localLOGV) Log.v(TAG, "Win " + w |
| 9004 | + ": blurring=" + blurring |
| 9005 | + " obscured=" + obscured |
| 9006 | + " displayed=" + displayed); |
| 9007 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 9008 | if (!dimming) { |
| 9009 | //Log.i(TAG, "DIM BEHIND: " + w); |
| 9010 | dimming = true; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9011 | if (mDimAnimator == null) { |
| 9012 | mDimAnimator = new DimAnimator(mFxSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9013 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9014 | mDimAnimator.show(dw, dh); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9015 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9016 | mDimAnimator.updateParameters(w, currentTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9017 | } |
| 9018 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 9019 | if (!blurring) { |
| 9020 | //Log.i(TAG, "BLUR BEHIND: " + w); |
| 9021 | blurring = true; |
| 9022 | mBlurShown = true; |
| 9023 | if (mBlurSurface == null) { |
| 9024 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " |
| 9025 | + mBlurSurface + ": CREATE"); |
| 9026 | try { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9027 | mBlurSurface = new Surface(mFxSession, 0, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9028 | -1, 16, 16, |
| 9029 | PixelFormat.OPAQUE, |
| 9030 | Surface.FX_SURFACE_BLUR); |
| 9031 | } catch (Exception e) { |
| 9032 | Log.e(TAG, "Exception creating Blur surface", e); |
| 9033 | } |
| 9034 | } |
| 9035 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " |
| 9036 | + mBlurSurface + ": SHOW pos=(0,0) (" + |
| 9037 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
| 9038 | if (mBlurSurface != null) { |
| 9039 | mBlurSurface.setPosition(0, 0); |
| 9040 | mBlurSurface.setSize(dw, dh); |
| 9041 | try { |
| 9042 | mBlurSurface.show(); |
| 9043 | } catch (RuntimeException e) { |
| 9044 | Log.w(TAG, "Failure showing blur surface", e); |
| 9045 | } |
| 9046 | } |
| 9047 | } |
| 9048 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 9049 | } |
| 9050 | } |
| 9051 | } |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame^] | 9052 | |
| 9053 | if (obscuredChanged && mWallpaperTarget == w) { |
| 9054 | // This is the wallpaper target and its obscured state |
| 9055 | // changed... make sure the current wallaper's visibility |
| 9056 | // has been updated accordingly. |
| 9057 | updateWallpaperVisibilityLocked(); |
| 9058 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9059 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9060 | |
| 9061 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 9062 | mBackgroundFillerShown = false; |
| 9063 | if (SHOW_TRANSACTIONS) Log.d(TAG, "hiding background filler"); |
| 9064 | try { |
| 9065 | mBackgroundFillerSurface.hide(); |
| 9066 | } catch (RuntimeException e) { |
| 9067 | Log.e(TAG, "Exception hiding filler surface", e); |
| 9068 | } |
| 9069 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9070 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9071 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
| 9072 | animating |= mDimAnimator.updateSurface(dimming, currentTime, mDisplayFrozen); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9073 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9074 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9075 | if (!blurring && mBlurShown) { |
| 9076 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " + mBlurSurface |
| 9077 | + ": HIDE"); |
| 9078 | try { |
| 9079 | mBlurSurface.hide(); |
| 9080 | } catch (IllegalArgumentException e) { |
| 9081 | Log.w(TAG, "Illegal argument exception hiding blur surface"); |
| 9082 | } |
| 9083 | mBlurShown = false; |
| 9084 | } |
| 9085 | |
| 9086 | if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION"); |
| 9087 | } catch (RuntimeException e) { |
| 9088 | Log.e(TAG, "Unhandled exception in Window Manager", e); |
| 9089 | } |
| 9090 | |
| 9091 | Surface.closeTransaction(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9092 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9093 | if (DEBUG_ORIENTATION && mDisplayFrozen) Log.v(TAG, |
| 9094 | "With display frozen, orientationChangeComplete=" |
| 9095 | + orientationChangeComplete); |
| 9096 | if (orientationChangeComplete) { |
| 9097 | if (mWindowsFreezingScreen) { |
| 9098 | mWindowsFreezingScreen = false; |
| 9099 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 9100 | } |
| 9101 | if (mAppsFreezingScreen == 0) { |
| 9102 | stopFreezingDisplayLocked(); |
| 9103 | } |
| 9104 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9105 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9106 | i = mResizingWindows.size(); |
| 9107 | if (i > 0) { |
| 9108 | do { |
| 9109 | i--; |
| 9110 | WindowState win = mResizingWindows.get(i); |
| 9111 | try { |
| 9112 | win.mClient.resized(win.mFrame.width(), |
| 9113 | win.mFrame.height(), win.mLastContentInsets, |
| 9114 | win.mLastVisibleInsets, win.mDrawPending); |
| 9115 | win.mContentInsetsChanged = false; |
| 9116 | win.mVisibleInsetsChanged = false; |
| 9117 | } catch (RemoteException e) { |
| 9118 | win.mOrientationChanging = false; |
| 9119 | } |
| 9120 | } while (i > 0); |
| 9121 | mResizingWindows.clear(); |
| 9122 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9123 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9124 | // Destroy the surface of any windows that are no longer visible. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9125 | boolean wallpaperDestroyed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9126 | i = mDestroySurface.size(); |
| 9127 | if (i > 0) { |
| 9128 | do { |
| 9129 | i--; |
| 9130 | WindowState win = mDestroySurface.get(i); |
| 9131 | win.mDestroying = false; |
| 9132 | if (mInputMethodWindow == win) { |
| 9133 | mInputMethodWindow = null; |
| 9134 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9135 | if (win == mWallpaperTarget) { |
| 9136 | wallpaperDestroyed = true; |
| 9137 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9138 | win.destroySurfaceLocked(); |
| 9139 | } while (i > 0); |
| 9140 | mDestroySurface.clear(); |
| 9141 | } |
| 9142 | |
| 9143 | // Time to remove any exiting tokens? |
| 9144 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9145 | WindowToken token = mExitingTokens.get(i); |
| 9146 | if (!token.hasVisible) { |
| 9147 | mExitingTokens.remove(i); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 9148 | if (token.windowType == TYPE_WALLPAPER) { |
| 9149 | mWallpaperTokens.remove(token); |
| 9150 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9151 | } |
| 9152 | } |
| 9153 | |
| 9154 | // Time to remove any exiting applications? |
| 9155 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9156 | AppWindowToken token = mExitingAppTokens.get(i); |
| 9157 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
| 9158 | mAppTokens.remove(token); |
| 9159 | mExitingAppTokens.remove(i); |
| 9160 | } |
| 9161 | } |
| 9162 | |
| 9163 | if (focusDisplayed) { |
| 9164 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 9165 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9166 | if (wallpaperDestroyed) { |
| 9167 | wallpaperDestroyed = adjustWallpaperWindowsLocked(); |
| 9168 | } |
| 9169 | if (wallpaperDestroyed) { |
| 9170 | requestAnimationLocked(0); |
| 9171 | } else if (animating) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9172 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 9173 | } |
| 9174 | mQueue.setHoldScreenLocked(holdScreen != null); |
| 9175 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 9176 | mPowerManager.setScreenBrightnessOverride(-1); |
| 9177 | } else { |
| 9178 | mPowerManager.setScreenBrightnessOverride((int) |
| 9179 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 9180 | } |
| 9181 | if (holdScreen != mHoldingScreenOn) { |
| 9182 | mHoldingScreenOn = holdScreen; |
| 9183 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 9184 | mH.sendMessage(m); |
| 9185 | } |
| 9186 | } |
| 9187 | |
| 9188 | void requestAnimationLocked(long delay) { |
| 9189 | if (!mAnimationPending) { |
| 9190 | mAnimationPending = true; |
| 9191 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 9192 | } |
| 9193 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9194 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9195 | /** |
| 9196 | * Have the surface flinger show a surface, robustly dealing with |
| 9197 | * error conditions. In particular, if there is not enough memory |
| 9198 | * to show the surface, then we will try to get rid of other surfaces |
| 9199 | * in order to succeed. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9200 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9201 | * @return Returns true if the surface was successfully shown. |
| 9202 | */ |
| 9203 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 9204 | try { |
| 9205 | if (win.mSurface != null) { |
| 9206 | win.mSurface.show(); |
| 9207 | } |
| 9208 | return true; |
| 9209 | } catch (RuntimeException e) { |
| 9210 | Log.w(TAG, "Failure showing surface " + win.mSurface + " in " + win); |
| 9211 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9212 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9213 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9214 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9215 | return false; |
| 9216 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9217 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9218 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 9219 | final Surface surface = win.mSurface; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9220 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9221 | EventLog.writeEvent(LOG_WM_NO_SURFACE_MEMORY, win.toString(), |
| 9222 | win.mSession.mPid, operation); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9223 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9224 | if (mForceRemoves == null) { |
| 9225 | mForceRemoves = new ArrayList<WindowState>(); |
| 9226 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9227 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9228 | long callingIdentity = Binder.clearCallingIdentity(); |
| 9229 | try { |
| 9230 | // There was some problem... first, do a sanity check of the |
| 9231 | // window list to make sure we haven't left any dangling surfaces |
| 9232 | // around. |
| 9233 | int N = mWindows.size(); |
| 9234 | boolean leakedSurface = false; |
| 9235 | Log.i(TAG, "Out of memory for surface! Looking for leaks..."); |
| 9236 | for (int i=0; i<N; i++) { |
| 9237 | WindowState ws = (WindowState)mWindows.get(i); |
| 9238 | if (ws.mSurface != null) { |
| 9239 | if (!mSessions.contains(ws.mSession)) { |
| 9240 | Log.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
| 9241 | + ws + " surface=" + ws.mSurface |
| 9242 | + " token=" + win.mToken |
| 9243 | + " pid=" + ws.mSession.mPid |
| 9244 | + " uid=" + ws.mSession.mUid); |
| 9245 | ws.mSurface.clear(); |
| 9246 | ws.mSurface = null; |
| 9247 | mForceRemoves.add(ws); |
| 9248 | i--; |
| 9249 | N--; |
| 9250 | leakedSurface = true; |
| 9251 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
| 9252 | Log.w(TAG, "LEAKED SURFACE (app token hidden): " |
| 9253 | + ws + " surface=" + ws.mSurface |
| 9254 | + " token=" + win.mAppToken); |
| 9255 | ws.mSurface.clear(); |
| 9256 | ws.mSurface = null; |
| 9257 | leakedSurface = true; |
| 9258 | } |
| 9259 | } |
| 9260 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9261 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9262 | boolean killedApps = false; |
| 9263 | if (!leakedSurface) { |
| 9264 | Log.w(TAG, "No leaked surfaces; killing applicatons!"); |
| 9265 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 9266 | for (int i=0; i<N; i++) { |
| 9267 | WindowState ws = (WindowState)mWindows.get(i); |
| 9268 | if (ws.mSurface != null) { |
| 9269 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 9270 | } |
| 9271 | } |
| 9272 | if (pidCandidates.size() > 0) { |
| 9273 | int[] pids = new int[pidCandidates.size()]; |
| 9274 | for (int i=0; i<pids.length; i++) { |
| 9275 | pids[i] = pidCandidates.keyAt(i); |
| 9276 | } |
| 9277 | try { |
| 9278 | if (mActivityManager.killPidsForMemory(pids)) { |
| 9279 | killedApps = true; |
| 9280 | } |
| 9281 | } catch (RemoteException e) { |
| 9282 | } |
| 9283 | } |
| 9284 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9285 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9286 | if (leakedSurface || killedApps) { |
| 9287 | // We managed to reclaim some memory, so get rid of the trouble |
| 9288 | // surface and ask the app to request another one. |
| 9289 | Log.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry."); |
| 9290 | if (surface != null) { |
| 9291 | surface.clear(); |
| 9292 | win.mSurface = null; |
| 9293 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9294 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9295 | try { |
| 9296 | win.mClient.dispatchGetNewSurface(); |
| 9297 | } catch (RemoteException e) { |
| 9298 | } |
| 9299 | } |
| 9300 | } finally { |
| 9301 | Binder.restoreCallingIdentity(callingIdentity); |
| 9302 | } |
| 9303 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9304 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9305 | private boolean updateFocusedWindowLocked(int mode) { |
| 9306 | WindowState newFocus = computeFocusedWindowLocked(); |
| 9307 | if (mCurrentFocus != newFocus) { |
| 9308 | // This check makes sure that we don't already have the focus |
| 9309 | // change message pending. |
| 9310 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 9311 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
| 9312 | if (localLOGV) Log.v( |
| 9313 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 9314 | final WindowState oldFocus = mCurrentFocus; |
| 9315 | mCurrentFocus = newFocus; |
| 9316 | mLosingFocus.remove(newFocus); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9317 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9318 | final WindowState imWindow = mInputMethodWindow; |
| 9319 | if (newFocus != imWindow && oldFocus != imWindow) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9320 | if (moveInputMethodWindowsIfNeededLocked( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9321 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9322 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 9323 | mLayoutNeeded = true; |
| 9324 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9325 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 9326 | performLayoutLockedInner(); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9327 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 9328 | // Client will do the layout, but we need to assign layers |
| 9329 | // for handleNewWindowLocked() below. |
| 9330 | assignLayersLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9331 | } |
| 9332 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9333 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9334 | if (newFocus != null && mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 9335 | mKeyWaiter.handleNewWindowLocked(newFocus); |
| 9336 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9337 | return true; |
| 9338 | } |
| 9339 | return false; |
| 9340 | } |
| 9341 | |
| 9342 | private WindowState computeFocusedWindowLocked() { |
| 9343 | WindowState result = null; |
| 9344 | WindowState win; |
| 9345 | |
| 9346 | int i = mWindows.size() - 1; |
| 9347 | int nextAppIndex = mAppTokens.size()-1; |
| 9348 | WindowToken nextApp = nextAppIndex >= 0 |
| 9349 | ? mAppTokens.get(nextAppIndex) : null; |
| 9350 | |
| 9351 | while (i >= 0) { |
| 9352 | win = (WindowState)mWindows.get(i); |
| 9353 | |
| 9354 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 9355 | TAG, "Looking for focus: " + i |
| 9356 | + " = " + win |
| 9357 | + ", flags=" + win.mAttrs.flags |
| 9358 | + ", canReceive=" + win.canReceiveKeys()); |
| 9359 | |
| 9360 | AppWindowToken thisApp = win.mAppToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9361 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9362 | // If this window's application has been removed, just skip it. |
| 9363 | if (thisApp != null && thisApp.removed) { |
| 9364 | i--; |
| 9365 | continue; |
| 9366 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9367 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9368 | // If there is a focused app, don't allow focus to go to any |
| 9369 | // windows below it. If this is an application window, step |
| 9370 | // through the app tokens until we find its app. |
| 9371 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 9372 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 9373 | int origAppIndex = nextAppIndex; |
| 9374 | while (nextAppIndex > 0) { |
| 9375 | if (nextApp == mFocusedApp) { |
| 9376 | // Whoops, we are below the focused app... no focus |
| 9377 | // for you! |
| 9378 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 9379 | TAG, "Reached focused app: " + mFocusedApp); |
| 9380 | return null; |
| 9381 | } |
| 9382 | nextAppIndex--; |
| 9383 | nextApp = mAppTokens.get(nextAppIndex); |
| 9384 | if (nextApp == thisApp) { |
| 9385 | break; |
| 9386 | } |
| 9387 | } |
| 9388 | if (thisApp != nextApp) { |
| 9389 | // Uh oh, the app token doesn't exist! This shouldn't |
| 9390 | // happen, but if it does we can get totally hosed... |
| 9391 | // so restart at the original app. |
| 9392 | nextAppIndex = origAppIndex; |
| 9393 | nextApp = mAppTokens.get(nextAppIndex); |
| 9394 | } |
| 9395 | } |
| 9396 | |
| 9397 | // Dispatch to this window if it is wants key events. |
| 9398 | if (win.canReceiveKeys()) { |
| 9399 | if (DEBUG_FOCUS) Log.v( |
| 9400 | TAG, "Found focus @ " + i + " = " + win); |
| 9401 | result = win; |
| 9402 | break; |
| 9403 | } |
| 9404 | |
| 9405 | i--; |
| 9406 | } |
| 9407 | |
| 9408 | return result; |
| 9409 | } |
| 9410 | |
| 9411 | private void startFreezingDisplayLocked() { |
| 9412 | if (mDisplayFrozen) { |
Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 9413 | // Freezing the display also suspends key event delivery, to |
| 9414 | // keep events from going astray while the display is reconfigured. |
| 9415 | // If someone has changed orientation again while the screen is |
| 9416 | // still frozen, the events will continue to be blocked while the |
| 9417 | // successive orientation change is processed. To prevent spurious |
| 9418 | // ANRs, we reset the event dispatch timeout in this case. |
| 9419 | synchronized (mKeyWaiter) { |
| 9420 | mKeyWaiter.mWasFrozen = true; |
| 9421 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9422 | return; |
| 9423 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9424 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9425 | mScreenFrozenLock.acquire(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9427 | long now = SystemClock.uptimeMillis(); |
| 9428 | //Log.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
| 9429 | if (mFreezeGcPending != 0) { |
| 9430 | if (now > (mFreezeGcPending+1000)) { |
| 9431 | //Log.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| 9432 | mH.removeMessages(H.FORCE_GC); |
| 9433 | Runtime.getRuntime().gc(); |
| 9434 | mFreezeGcPending = now; |
| 9435 | } |
| 9436 | } else { |
| 9437 | mFreezeGcPending = now; |
| 9438 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9439 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9440 | mDisplayFrozen = true; |
| 9441 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) { |
| 9442 | mNextAppTransition = WindowManagerPolicy.TRANSIT_NONE; |
| 9443 | mAppTransitionReady = true; |
| 9444 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9445 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9446 | if (PROFILE_ORIENTATION) { |
| 9447 | File file = new File("/data/system/frozen"); |
| 9448 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 9449 | } |
| 9450 | Surface.freezeDisplay(0); |
| 9451 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9452 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9453 | private void stopFreezingDisplayLocked() { |
| 9454 | if (!mDisplayFrozen) { |
| 9455 | return; |
| 9456 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9457 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9458 | mDisplayFrozen = false; |
| 9459 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 9460 | if (PROFILE_ORIENTATION) { |
| 9461 | Debug.stopMethodTracing(); |
| 9462 | } |
| 9463 | Surface.unfreezeDisplay(0); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9464 | |
Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 9465 | // Reset the key delivery timeout on unfreeze, too. We force a wakeup here |
| 9466 | // too because regular key delivery processing should resume immediately. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9467 | synchronized (mKeyWaiter) { |
| 9468 | mKeyWaiter.mWasFrozen = true; |
| 9469 | mKeyWaiter.notifyAll(); |
| 9470 | } |
| 9471 | |
| 9472 | // A little kludge: a lot could have happened while the |
| 9473 | // display was frozen, so now that we are coming back we |
| 9474 | // do a gc so that any remote references the system |
| 9475 | // processes holds on others can be released if they are |
| 9476 | // no longer needed. |
| 9477 | mH.removeMessages(H.FORCE_GC); |
| 9478 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 9479 | 2000); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9480 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9481 | mScreenFrozenLock.release(); |
| 9482 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9483 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9484 | @Override |
| 9485 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 9486 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 9487 | != PackageManager.PERMISSION_GRANTED) { |
| 9488 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 9489 | + Binder.getCallingPid() |
| 9490 | + ", uid=" + Binder.getCallingUid()); |
| 9491 | return; |
| 9492 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9493 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9494 | synchronized(mWindowMap) { |
| 9495 | pw.println("Current Window Manager state:"); |
| 9496 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 9497 | WindowState w = (WindowState)mWindows.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9498 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 9499 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9500 | w.dump(pw, " "); |
| 9501 | } |
| 9502 | if (mInputMethodDialogs.size() > 0) { |
| 9503 | pw.println(" "); |
| 9504 | pw.println(" Input method dialogs:"); |
| 9505 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 9506 | WindowState w = mInputMethodDialogs.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9507 | 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] | 9508 | } |
| 9509 | } |
| 9510 | if (mPendingRemove.size() > 0) { |
| 9511 | pw.println(" "); |
| 9512 | pw.println(" Remove pending for:"); |
| 9513 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 9514 | WindowState w = mPendingRemove.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9515 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 9516 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9517 | w.dump(pw, " "); |
| 9518 | } |
| 9519 | } |
| 9520 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 9521 | pw.println(" "); |
| 9522 | pw.println(" Windows force removing:"); |
| 9523 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 9524 | WindowState w = mForceRemoves.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9525 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 9526 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9527 | w.dump(pw, " "); |
| 9528 | } |
| 9529 | } |
| 9530 | if (mDestroySurface.size() > 0) { |
| 9531 | pw.println(" "); |
| 9532 | pw.println(" Windows waiting to destroy their surface:"); |
| 9533 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 9534 | WindowState w = mDestroySurface.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9535 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 9536 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9537 | w.dump(pw, " "); |
| 9538 | } |
| 9539 | } |
| 9540 | if (mLosingFocus.size() > 0) { |
| 9541 | pw.println(" "); |
| 9542 | pw.println(" Windows losing focus:"); |
| 9543 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 9544 | WindowState w = mLosingFocus.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9545 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 9546 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9547 | w.dump(pw, " "); |
| 9548 | } |
| 9549 | } |
| 9550 | if (mSessions.size() > 0) { |
| 9551 | pw.println(" "); |
| 9552 | pw.println(" All active sessions:"); |
| 9553 | Iterator<Session> it = mSessions.iterator(); |
| 9554 | while (it.hasNext()) { |
| 9555 | Session s = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9556 | pw.print(" Session "); pw.print(s); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9557 | s.dump(pw, " "); |
| 9558 | } |
| 9559 | } |
| 9560 | if (mTokenMap.size() > 0) { |
| 9561 | pw.println(" "); |
| 9562 | pw.println(" All tokens:"); |
| 9563 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 9564 | while (it.hasNext()) { |
| 9565 | WindowToken token = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9566 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9567 | token.dump(pw, " "); |
| 9568 | } |
| 9569 | } |
| 9570 | if (mTokenList.size() > 0) { |
| 9571 | pw.println(" "); |
| 9572 | pw.println(" Window token list:"); |
| 9573 | for (int i=0; i<mTokenList.size(); i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9574 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 9575 | pw.println(mTokenList.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9576 | } |
| 9577 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 9578 | if (mWallpaperTokens.size() > 0) { |
| 9579 | pw.println(" "); |
| 9580 | pw.println(" Wallpaper tokens:"); |
| 9581 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 9582 | WindowToken token = mWallpaperTokens.get(i); |
| 9583 | pw.print(" Wallpaper #"); pw.print(i); |
| 9584 | pw.print(' '); pw.print(token); pw.println(':'); |
| 9585 | token.dump(pw, " "); |
| 9586 | } |
| 9587 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9588 | if (mAppTokens.size() > 0) { |
| 9589 | pw.println(" "); |
| 9590 | pw.println(" Application tokens in Z order:"); |
| 9591 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9592 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 9593 | pw.println(mAppTokens.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9594 | } |
| 9595 | } |
| 9596 | if (mFinishedStarting.size() > 0) { |
| 9597 | pw.println(" "); |
| 9598 | pw.println(" Finishing start of application tokens:"); |
| 9599 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 9600 | WindowToken token = mFinishedStarting.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9601 | pw.print(" Finished Starting #"); pw.print(i); |
| 9602 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9603 | token.dump(pw, " "); |
| 9604 | } |
| 9605 | } |
| 9606 | if (mExitingTokens.size() > 0) { |
| 9607 | pw.println(" "); |
| 9608 | pw.println(" Exiting tokens:"); |
| 9609 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 9610 | WindowToken token = mExitingTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9611 | pw.print(" Exiting #"); pw.print(i); |
| 9612 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9613 | token.dump(pw, " "); |
| 9614 | } |
| 9615 | } |
| 9616 | if (mExitingAppTokens.size() > 0) { |
| 9617 | pw.println(" "); |
| 9618 | pw.println(" Exiting application tokens:"); |
| 9619 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9620 | WindowToken token = mExitingAppTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9621 | pw.print(" Exiting App #"); pw.print(i); |
| 9622 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9623 | token.dump(pw, " "); |
| 9624 | } |
| 9625 | } |
| 9626 | pw.println(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9627 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 9628 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 9629 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 9630 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 9631 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 9632 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9633 | pw.print(" mInTouchMode="); pw.println(mInTouchMode); |
| 9634 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 9635 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 9636 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 9637 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9638 | if (mDimAnimator != null) { |
| 9639 | mDimAnimator.printTo(pw); |
| 9640 | } else { |
| 9641 | pw.print( " no DimAnimator "); |
| 9642 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9643 | pw.print(" mInputMethodAnimLayerAdjustment="); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 9644 | pw.print(mInputMethodAnimLayerAdjustment); |
| 9645 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 9646 | pw.println(mWallpaperAnimLayerAdjustment); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9647 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 9648 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
| 9649 | pw.print(" mAppsFreezingScreen="); pw.println(mAppsFreezingScreen); |
| 9650 | pw.print(" mRotation="); pw.print(mRotation); |
| 9651 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 9652 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 9653 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 9654 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 9655 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 9656 | pw.print(" mNextAppTransition=0x"); |
| 9657 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 9658 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
| 9659 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
| 9660 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 9661 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| 9662 | if (mOpeningApps.size() > 0) { |
| 9663 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 9664 | } |
| 9665 | if (mClosingApps.size() > 0) { |
| 9666 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 9667 | } |
| 9668 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 9669 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9670 | pw.println(" KeyWaiter state:"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9671 | pw.print(" mLastWin="); pw.print(mKeyWaiter.mLastWin); |
| 9672 | pw.print(" mLastBinder="); pw.println(mKeyWaiter.mLastBinder); |
| 9673 | pw.print(" mFinished="); pw.print(mKeyWaiter.mFinished); |
| 9674 | pw.print(" mGotFirstWindow="); pw.print(mKeyWaiter.mGotFirstWindow); |
| 9675 | pw.print(" mEventDispatching="); pw.print(mKeyWaiter.mEventDispatching); |
| 9676 | pw.print(" mTimeToSwitch="); pw.println(mKeyWaiter.mTimeToSwitch); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9677 | } |
| 9678 | } |
| 9679 | |
| 9680 | public void monitor() { |
| 9681 | synchronized (mWindowMap) { } |
| 9682 | synchronized (mKeyguardDisabled) { } |
| 9683 | synchronized (mKeyWaiter) { } |
| 9684 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9685 | |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 9686 | public void virtualKeyFeedback(KeyEvent event) { |
| 9687 | mPolicy.keyFeedbackFromInput(event); |
| 9688 | } |
| 9689 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9690 | /** |
| 9691 | * DimAnimator class that controls the dim animation. This holds the surface and |
| 9692 | * all state used for dim animation. |
| 9693 | */ |
| 9694 | private static class DimAnimator { |
| 9695 | Surface mDimSurface; |
| 9696 | boolean mDimShown = false; |
| 9697 | float mDimCurrentAlpha; |
| 9698 | float mDimTargetAlpha; |
| 9699 | float mDimDeltaPerMs; |
| 9700 | long mLastDimAnimTime; |
| 9701 | |
| 9702 | DimAnimator (SurfaceSession session) { |
| 9703 | if (mDimSurface == null) { |
| 9704 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 9705 | + mDimSurface + ": CREATE"); |
| 9706 | try { |
| 9707 | mDimSurface = new Surface(session, 0, -1, 16, 16, PixelFormat.OPAQUE, |
| 9708 | Surface.FX_SURFACE_DIM); |
| 9709 | } catch (Exception e) { |
| 9710 | Log.e(TAG, "Exception creating Dim surface", e); |
| 9711 | } |
| 9712 | } |
| 9713 | } |
| 9714 | |
| 9715 | /** |
| 9716 | * Show the dim surface. |
| 9717 | */ |
| 9718 | void show(int dw, int dh) { |
| 9719 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 9720 | dw + "x" + dh + ")"); |
| 9721 | mDimShown = true; |
| 9722 | try { |
| 9723 | mDimSurface.setPosition(0, 0); |
| 9724 | mDimSurface.setSize(dw, dh); |
| 9725 | mDimSurface.show(); |
| 9726 | } catch (RuntimeException e) { |
| 9727 | Log.w(TAG, "Failure showing dim surface", e); |
| 9728 | } |
| 9729 | } |
| 9730 | |
| 9731 | /** |
| 9732 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 9733 | * {@link updateSurface} after all windows are examined. |
| 9734 | */ |
| 9735 | void updateParameters(WindowState w, long currentTime) { |
| 9736 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 9737 | |
| 9738 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
| 9739 | if (SHOW_TRANSACTIONS) Log.i(TAG, "layer=" + (w.mAnimLayer-1) + ", target=" + target); |
| 9740 | if (mDimTargetAlpha != target) { |
| 9741 | // If the desired dim level has changed, then |
| 9742 | // start an animation to it. |
| 9743 | mLastDimAnimTime = currentTime; |
| 9744 | long duration = (w.mAnimating && w.mAnimation != null) |
| 9745 | ? w.mAnimation.computeDurationHint() |
| 9746 | : DEFAULT_DIM_DURATION; |
| 9747 | if (target > mDimTargetAlpha) { |
| 9748 | // This is happening behind the activity UI, |
| 9749 | // so we can make it run a little longer to |
| 9750 | // give a stronger impression without disrupting |
| 9751 | // the user. |
| 9752 | duration *= DIM_DURATION_MULTIPLIER; |
| 9753 | } |
| 9754 | if (duration < 1) { |
| 9755 | // Don't divide by zero |
| 9756 | duration = 1; |
| 9757 | } |
| 9758 | mDimTargetAlpha = target; |
| 9759 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 9760 | } |
| 9761 | } |
| 9762 | |
| 9763 | /** |
| 9764 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 9765 | * false when the animation is finished and the dim surface is hidden. |
| 9766 | */ |
| 9767 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 9768 | if (!dimming) { |
| 9769 | if (mDimTargetAlpha != 0) { |
| 9770 | mLastDimAnimTime = currentTime; |
| 9771 | mDimTargetAlpha = 0; |
| 9772 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 9773 | } |
| 9774 | } |
| 9775 | |
| 9776 | boolean animating = false; |
| 9777 | if (mLastDimAnimTime != 0) { |
| 9778 | mDimCurrentAlpha += mDimDeltaPerMs |
| 9779 | * (currentTime-mLastDimAnimTime); |
| 9780 | boolean more = true; |
| 9781 | if (displayFrozen) { |
| 9782 | // If the display is frozen, there is no reason to animate. |
| 9783 | more = false; |
| 9784 | } else if (mDimDeltaPerMs > 0) { |
| 9785 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 9786 | more = false; |
| 9787 | } |
| 9788 | } else if (mDimDeltaPerMs < 0) { |
| 9789 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 9790 | more = false; |
| 9791 | } |
| 9792 | } else { |
| 9793 | more = false; |
| 9794 | } |
| 9795 | |
| 9796 | // Do we need to continue animating? |
| 9797 | if (more) { |
| 9798 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 9799 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 9800 | mLastDimAnimTime = currentTime; |
| 9801 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 9802 | animating = true; |
| 9803 | } else { |
| 9804 | mDimCurrentAlpha = mDimTargetAlpha; |
| 9805 | mLastDimAnimTime = 0; |
| 9806 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 9807 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 9808 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 9809 | if (!dimming) { |
| 9810 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface |
| 9811 | + ": HIDE"); |
| 9812 | try { |
| 9813 | mDimSurface.hide(); |
| 9814 | } catch (RuntimeException e) { |
| 9815 | Log.w(TAG, "Illegal argument exception hiding dim surface"); |
| 9816 | } |
| 9817 | mDimShown = false; |
| 9818 | } |
| 9819 | } |
| 9820 | } |
| 9821 | return animating; |
| 9822 | } |
| 9823 | |
| 9824 | public void printTo(PrintWriter pw) { |
| 9825 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 9826 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 9827 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 9828 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 9829 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 9830 | } |
| 9831 | } |
| 9832 | |
| 9833 | /** |
| 9834 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 9835 | * This is used for opening/closing transition for apps in compatible mode. |
| 9836 | */ |
| 9837 | private static class FadeInOutAnimation extends Animation { |
| 9838 | int mWidth; |
| 9839 | boolean mFadeIn; |
| 9840 | |
| 9841 | public FadeInOutAnimation(boolean fadeIn) { |
| 9842 | setInterpolator(new AccelerateInterpolator()); |
| 9843 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 9844 | mFadeIn = fadeIn; |
| 9845 | } |
| 9846 | |
| 9847 | @Override |
| 9848 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 9849 | float x = interpolatedTime; |
| 9850 | if (!mFadeIn) { |
| 9851 | x = 1.0f - x; // reverse the interpolation for fade out |
| 9852 | } |
| 9853 | if (x < 0.5) { |
| 9854 | // move the window out of the screen. |
| 9855 | t.getMatrix().setTranslate(mWidth, 0); |
| 9856 | } else { |
| 9857 | t.getMatrix().setTranslate(0, 0);// show |
| 9858 | t.setAlpha((x - 0.5f) * 2); |
| 9859 | } |
| 9860 | } |
| 9861 | |
| 9862 | @Override |
| 9863 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 9864 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 9865 | mWidth = width; |
| 9866 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9867 | |
| 9868 | @Override |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 9869 | public int getZAdjustment() { |
| 9870 | return Animation.ZORDER_TOP; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9871 | } |
| 9872 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9873 | } |