| 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; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 408 | // If non-null, we are in the middle of animating from one wallpaper target |
| 409 | // to another, and this is the lower one in Z-order. |
| 410 | WindowState mLowerWallpaperTarget = null; |
| 411 | // If non-null, we are in the middle of animating from one wallpaper target |
| 412 | // to another, and this is the higher one in Z-order. |
| 413 | WindowState mUpperWallpaperTarget = null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 414 | int mWallpaperAnimLayerAdjustment; |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 415 | float mLastWallpaperX; |
| 416 | float mLastWallpaperY; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 417 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | AppWindowToken mFocusedApp = null; |
| 419 | |
| 420 | PowerManagerService mPowerManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 421 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 422 | float mWindowAnimationScale = 1.0f; |
| 423 | float mTransitionAnimationScale = 1.0f; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 424 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 425 | final KeyWaiter mKeyWaiter = new KeyWaiter(); |
| 426 | final KeyQ mQueue; |
| 427 | final InputDispatcherThread mInputThread; |
| 428 | |
| 429 | // Who is holding the screen on. |
| 430 | Session mHoldingScreenOn; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 431 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 432 | /** |
| 433 | * Whether the UI is currently running in touch mode (not showing |
| 434 | * navigational focus because the user is directly pressing the screen). |
| 435 | */ |
| 436 | boolean mInTouchMode = false; |
| 437 | |
| 438 | private ViewServer mViewServer; |
| 439 | |
| 440 | final Rect mTempRect = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 441 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 442 | final Configuration mTempConfiguration = new Configuration(); |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 443 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 444 | |
| 445 | // The frame use to limit the size of the app running in compatibility mode. |
| 446 | Rect mCompatibleScreenFrame = new Rect(); |
| 447 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 448 | Surface mBackgroundFillerSurface = null; |
| 449 | boolean mBackgroundFillerShown = false; |
| 450 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | public static WindowManagerService main(Context context, |
| 452 | PowerManagerService pm, boolean haveInputMethods) { |
| 453 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 454 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 455 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 456 | synchronized (thr) { |
| 457 | while (thr.mService == null) { |
| 458 | try { |
| 459 | thr.wait(); |
| 460 | } catch (InterruptedException e) { |
| 461 | } |
| 462 | } |
| 463 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 464 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 465 | return thr.mService; |
| 466 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 467 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 468 | static class WMThread extends Thread { |
| 469 | WindowManagerService mService; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 470 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | private final Context mContext; |
| 472 | private final PowerManagerService mPM; |
| 473 | private final boolean mHaveInputMethods; |
| 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 WMThread(Context context, PowerManagerService pm, |
| 476 | boolean haveInputMethods) { |
| 477 | super("WindowManager"); |
| 478 | mContext = context; |
| 479 | mPM = pm; |
| 480 | mHaveInputMethods = haveInputMethods; |
| 481 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 482 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 483 | public void run() { |
| 484 | Looper.prepare(); |
| 485 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 486 | mHaveInputMethods); |
| 487 | android.os.Process.setThreadPriority( |
| 488 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 489 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 490 | synchronized (this) { |
| 491 | mService = s; |
| 492 | notifyAll(); |
| 493 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 494 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 495 | Looper.loop(); |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | static class PolicyThread extends Thread { |
| 500 | private final WindowManagerPolicy mPolicy; |
| 501 | private final WindowManagerService mService; |
| 502 | private final Context mContext; |
| 503 | private final PowerManagerService mPM; |
| 504 | boolean mRunning = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 505 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 506 | public PolicyThread(WindowManagerPolicy policy, |
| 507 | WindowManagerService service, Context context, |
| 508 | PowerManagerService pm) { |
| 509 | super("WindowManagerPolicy"); |
| 510 | mPolicy = policy; |
| 511 | mService = service; |
| 512 | mContext = context; |
| 513 | mPM = pm; |
| 514 | } |
| 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 | public void run() { |
| 517 | Looper.prepare(); |
| 518 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
| 519 | // Log.VERBOSE, "WindowManagerPolicy")); |
| 520 | android.os.Process.setThreadPriority( |
| 521 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
| 522 | mPolicy.init(mContext, mService, mPM); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 523 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 524 | synchronized (this) { |
| 525 | mRunning = true; |
| 526 | notifyAll(); |
| 527 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 528 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 529 | Looper.loop(); |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | private WindowManagerService(Context context, PowerManagerService pm, |
| 534 | boolean haveInputMethods) { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 535 | if (MEASURE_LATENCY) { |
| 536 | lt = new LatencyTimer(100, 1000); |
| 537 | } |
| 538 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 539 | mContext = context; |
| 540 | mHaveInputMethods = haveInputMethods; |
| 541 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 542 | com.android.internal.R.bool.config_sf_limitedAlpha); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 543 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 544 | mPowerManager = pm; |
| 545 | mPowerManager.setPolicy(mPolicy); |
| 546 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 547 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 548 | "SCREEN_FROZEN"); |
| 549 | mScreenFrozenLock.setReferenceCounted(false); |
| 550 | |
| 551 | mActivityManager = ActivityManagerNative.getDefault(); |
| 552 | mBatteryStats = BatteryStatsService.getService(); |
| 553 | |
| 554 | // Get persisted window scale setting |
| 555 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 556 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 557 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 558 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 559 | |
| Michael Chan | 9f028e6 | 2009-08-04 17:37:46 -0700 | [diff] [blame] | 560 | int max_events_per_sec = 35; |
| 561 | try { |
| 562 | max_events_per_sec = Integer.parseInt(SystemProperties |
| 563 | .get("windowsmgr.max_events_per_sec")); |
| 564 | if (max_events_per_sec < 1) { |
| 565 | max_events_per_sec = 35; |
| 566 | } |
| 567 | } catch (NumberFormatException e) { |
| 568 | } |
| 569 | mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec; |
| 570 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 571 | mQueue = new KeyQ(); |
| 572 | |
| 573 | mInputThread = new InputDispatcherThread(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 574 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 575 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 576 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 577 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 578 | synchronized (thr) { |
| 579 | while (!thr.mRunning) { |
| 580 | try { |
| 581 | thr.wait(); |
| 582 | } catch (InterruptedException e) { |
| 583 | } |
| 584 | } |
| 585 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 586 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 587 | mInputThread.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 588 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 589 | // Add ourself to the Watchdog monitors. |
| 590 | Watchdog.getInstance().addMonitor(this); |
| 591 | } |
| 592 | |
| 593 | @Override |
| 594 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 595 | throws RemoteException { |
| 596 | try { |
| 597 | return super.onTransact(code, data, reply, flags); |
| 598 | } catch (RuntimeException e) { |
| 599 | // The window manager only throws security exceptions, so let's |
| 600 | // log all others. |
| 601 | if (!(e instanceof SecurityException)) { |
| 602 | Log.e(TAG, "Window Manager Crash", e); |
| 603 | } |
| 604 | throw e; |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | private void placeWindowAfter(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+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 613 | mWindows.add(i+1, window); |
| 614 | } |
| 615 | |
| 616 | private void placeWindowBefore(Object pos, WindowState window) { |
| 617 | final int i = mWindows.indexOf(pos); |
| 618 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 619 | TAG, "Adding window " + window + " at " |
| 620 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 621 | mWindows.add(i, window); |
| 622 | } |
| 623 | |
| 624 | //This method finds out the index of a window that has the same app token as |
| 625 | //win. used for z ordering the windows in mWindows |
| 626 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 627 | //use a local variable to cache mWindows |
| 628 | ArrayList localmWindows = mWindows; |
| 629 | int jmax = localmWindows.size(); |
| 630 | if(jmax == 0) { |
| 631 | return -1; |
| 632 | } |
| 633 | for(int j = (jmax-1); j >= 0; j--) { |
| 634 | WindowState wentry = (WindowState)localmWindows.get(j); |
| 635 | if(wentry.mAppToken == win.mAppToken) { |
| 636 | return j; |
| 637 | } |
| 638 | } |
| 639 | return -1; |
| 640 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 641 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 642 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 643 | final IWindow client = win.mClient; |
| 644 | final WindowToken token = win.mToken; |
| 645 | final ArrayList localmWindows = mWindows; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 646 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 647 | final int N = localmWindows.size(); |
| 648 | final WindowState attached = win.mAttachedWindow; |
| 649 | int i; |
| 650 | if (attached == null) { |
| 651 | int tokenWindowsPos = token.windows.size(); |
| 652 | if (token.appWindowToken != null) { |
| 653 | int index = tokenWindowsPos-1; |
| 654 | if (index >= 0) { |
| 655 | // If this application has existing windows, we |
| 656 | // simply place the new window on top of them... but |
| 657 | // keep the starting window on top. |
| 658 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 659 | // Base windows go behind everything else. |
| 660 | placeWindowBefore(token.windows.get(0), win); |
| 661 | tokenWindowsPos = 0; |
| 662 | } else { |
| 663 | AppWindowToken atoken = win.mAppToken; |
| 664 | if (atoken != null && |
| 665 | token.windows.get(index) == atoken.startingWindow) { |
| 666 | placeWindowBefore(token.windows.get(index), win); |
| 667 | tokenWindowsPos--; |
| 668 | } else { |
| 669 | int newIdx = findIdxBasedOnAppTokens(win); |
| 670 | if(newIdx != -1) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 671 | //there is a window above this one associated with the same |
| 672 | //apptoken note that the window could be a floating window |
| 673 | //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] | 674 | //windows associated with this token. |
| 675 | localmWindows.add(newIdx+1, win); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 676 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 677 | } |
| 678 | } |
| 679 | } else { |
| 680 | if (localLOGV) Log.v( |
| 681 | TAG, "Figuring out where to add app window " |
| 682 | + client.asBinder() + " (token=" + token + ")"); |
| 683 | // Figure out where the window should go, based on the |
| 684 | // order of applications. |
| 685 | final int NA = mAppTokens.size(); |
| 686 | Object pos = null; |
| 687 | for (i=NA-1; i>=0; i--) { |
| 688 | AppWindowToken t = mAppTokens.get(i); |
| 689 | if (t == token) { |
| 690 | i--; |
| 691 | break; |
| 692 | } |
| 693 | if (t.windows.size() > 0) { |
| 694 | pos = t.windows.get(0); |
| 695 | } |
| 696 | } |
| 697 | // We now know the index into the apps. If we found |
| 698 | // an app window above, that gives us the position; else |
| 699 | // we need to look some more. |
| 700 | if (pos != null) { |
| 701 | // Move behind any windows attached to this one. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 702 | WindowToken atoken = |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 703 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 704 | if (atoken != null) { |
| 705 | final int NC = atoken.windows.size(); |
| 706 | if (NC > 0) { |
| 707 | WindowState bottom = atoken.windows.get(0); |
| 708 | if (bottom.mSubLayer < 0) { |
| 709 | pos = bottom; |
| 710 | } |
| 711 | } |
| 712 | } |
| 713 | placeWindowBefore(pos, win); |
| 714 | } else { |
| 715 | while (i >= 0) { |
| 716 | AppWindowToken t = mAppTokens.get(i); |
| 717 | final int NW = t.windows.size(); |
| 718 | if (NW > 0) { |
| 719 | pos = t.windows.get(NW-1); |
| 720 | break; |
| 721 | } |
| 722 | i--; |
| 723 | } |
| 724 | if (pos != null) { |
| 725 | // Move in front of any windows attached to this |
| 726 | // one. |
| 727 | WindowToken atoken = |
| 728 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 729 | if (atoken != null) { |
| 730 | final int NC = atoken.windows.size(); |
| 731 | if (NC > 0) { |
| 732 | WindowState top = atoken.windows.get(NC-1); |
| 733 | if (top.mSubLayer >= 0) { |
| 734 | pos = top; |
| 735 | } |
| 736 | } |
| 737 | } |
| 738 | placeWindowAfter(pos, win); |
| 739 | } else { |
| 740 | // Just search for the start of this layer. |
| 741 | final int myLayer = win.mBaseLayer; |
| 742 | for (i=0; i<N; i++) { |
| 743 | WindowState w = (WindowState)localmWindows.get(i); |
| 744 | if (w.mBaseLayer > myLayer) { |
| 745 | break; |
| 746 | } |
| 747 | } |
| 748 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 749 | TAG, "Adding window " + win + " at " |
| 750 | + i + " of " + N); |
| 751 | localmWindows.add(i, win); |
| 752 | } |
| 753 | } |
| 754 | } |
| 755 | } else { |
| 756 | // Figure out where window should go, based on layer. |
| 757 | final int myLayer = win.mBaseLayer; |
| 758 | for (i=N-1; i>=0; i--) { |
| 759 | if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) { |
| 760 | i++; |
| 761 | break; |
| 762 | } |
| 763 | } |
| 764 | if (i < 0) i = 0; |
| 765 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 766 | TAG, "Adding window " + win + " at " |
| 767 | + i + " of " + N); |
| 768 | localmWindows.add(i, win); |
| 769 | } |
| 770 | if (addToToken) { |
| 771 | token.windows.add(tokenWindowsPos, win); |
| 772 | } |
| 773 | |
| 774 | } else { |
| 775 | // Figure out this window's ordering relative to the window |
| 776 | // it is attached to. |
| 777 | final int NA = token.windows.size(); |
| 778 | final int sublayer = win.mSubLayer; |
| 779 | int largestSublayer = Integer.MIN_VALUE; |
| 780 | WindowState windowWithLargestSublayer = null; |
| 781 | for (i=0; i<NA; i++) { |
| 782 | WindowState w = token.windows.get(i); |
| 783 | final int wSublayer = w.mSubLayer; |
| 784 | if (wSublayer >= largestSublayer) { |
| 785 | largestSublayer = wSublayer; |
| 786 | windowWithLargestSublayer = w; |
| 787 | } |
| 788 | if (sublayer < 0) { |
| 789 | // For negative sublayers, we go below all windows |
| 790 | // in the same sublayer. |
| 791 | if (wSublayer >= sublayer) { |
| 792 | if (addToToken) { |
| 793 | token.windows.add(i, win); |
| 794 | } |
| 795 | placeWindowBefore( |
| 796 | wSublayer >= 0 ? attached : w, win); |
| 797 | break; |
| 798 | } |
| 799 | } else { |
| 800 | // For positive sublayers, we go above all windows |
| 801 | // in the same sublayer. |
| 802 | if (wSublayer > sublayer) { |
| 803 | if (addToToken) { |
| 804 | token.windows.add(i, win); |
| 805 | } |
| 806 | placeWindowBefore(w, win); |
| 807 | break; |
| 808 | } |
| 809 | } |
| 810 | } |
| 811 | if (i >= NA) { |
| 812 | if (addToToken) { |
| 813 | token.windows.add(win); |
| 814 | } |
| 815 | if (sublayer < 0) { |
| 816 | placeWindowBefore(attached, win); |
| 817 | } else { |
| 818 | placeWindowAfter(largestSublayer >= 0 |
| 819 | ? windowWithLargestSublayer |
| 820 | : attached, |
| 821 | win); |
| 822 | } |
| 823 | } |
| 824 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 825 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 826 | if (win.mAppToken != null && addToToken) { |
| 827 | win.mAppToken.allAppWindows.add(win); |
| 828 | } |
| 829 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 830 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 831 | static boolean canBeImeTarget(WindowState w) { |
| 832 | final int fl = w.mAttrs.flags |
| 833 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 834 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 835 | return w.isVisibleOrAdding(); |
| 836 | } |
| 837 | return false; |
| 838 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 839 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 840 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
| 841 | final ArrayList localmWindows = mWindows; |
| 842 | final int N = localmWindows.size(); |
| 843 | WindowState w = null; |
| 844 | int i = N; |
| 845 | while (i > 0) { |
| 846 | i--; |
| 847 | w = (WindowState)localmWindows.get(i); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 848 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 849 | //Log.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
| 850 | // + Integer.toHexString(w.mAttrs.flags)); |
| 851 | if (canBeImeTarget(w)) { |
| 852 | //Log.i(TAG, "Putting input method here!"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 853 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 854 | // Yet more tricksyness! If this window is a "starting" |
| 855 | // window, we do actually want to be on top of it, but |
| 856 | // it is not -really- where input will go. So if the caller |
| 857 | // is not actually looking to move the IME, look down below |
| 858 | // for a real window to target... |
| 859 | if (!willMove |
| 860 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 861 | && i > 0) { |
| 862 | WindowState wb = (WindowState)localmWindows.get(i-1); |
| 863 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 864 | i--; |
| 865 | w = wb; |
| 866 | } |
| 867 | } |
| 868 | break; |
| 869 | } |
| 870 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 871 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 872 | mUpcomingInputMethodTarget = w; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 873 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 874 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Desired input method target=" |
| 875 | + w + " willMove=" + willMove); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 876 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 877 | if (willMove && w != null) { |
| 878 | final WindowState curTarget = mInputMethodTarget; |
| 879 | if (curTarget != null && curTarget.mAppToken != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 880 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 881 | // Now some fun for dealing with window animations that |
| 882 | // modify the Z order. We need to look at all windows below |
| 883 | // the current target that are in this app, finding the highest |
| 884 | // visible one in layering. |
| 885 | AppWindowToken token = curTarget.mAppToken; |
| 886 | WindowState highestTarget = null; |
| 887 | int highestPos = 0; |
| 888 | if (token.animating || token.animation != null) { |
| 889 | int pos = 0; |
| 890 | pos = localmWindows.indexOf(curTarget); |
| 891 | while (pos >= 0) { |
| 892 | WindowState win = (WindowState)localmWindows.get(pos); |
| 893 | if (win.mAppToken != token) { |
| 894 | break; |
| 895 | } |
| 896 | if (!win.mRemoved) { |
| 897 | if (highestTarget == null || win.mAnimLayer > |
| 898 | highestTarget.mAnimLayer) { |
| 899 | highestTarget = win; |
| 900 | highestPos = pos; |
| 901 | } |
| 902 | } |
| 903 | pos--; |
| 904 | } |
| 905 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 906 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 907 | if (highestTarget != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 908 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "mNextAppTransition=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 909 | + mNextAppTransition + " " + highestTarget |
| 910 | + " animating=" + highestTarget.isAnimating() |
| 911 | + " layer=" + highestTarget.mAnimLayer |
| 912 | + " new layer=" + w.mAnimLayer); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 913 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 914 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) { |
| 915 | // If we are currently setting up for an animation, |
| 916 | // hold everything until we can find out what will happen. |
| 917 | mInputMethodTargetWaitingAnim = true; |
| 918 | mInputMethodTarget = highestTarget; |
| 919 | return highestPos + 1; |
| 920 | } else if (highestTarget.isAnimating() && |
| 921 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 922 | // If the window we are currently targeting is involved |
| 923 | // with an animation, and it is on top of the next target |
| 924 | // we will be over, then hold off on moving until |
| 925 | // that is done. |
| 926 | mInputMethodTarget = highestTarget; |
| 927 | return highestPos + 1; |
| 928 | } |
| 929 | } |
| 930 | } |
| 931 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 932 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 933 | //Log.i(TAG, "Placing input method @" + (i+1)); |
| 934 | if (w != null) { |
| 935 | if (willMove) { |
| 936 | RuntimeException e = new RuntimeException(); |
| 937 | e.fillInStackTrace(); |
| 938 | if (DEBUG_INPUT_METHOD) Log.w(TAG, "Moving IM target from " |
| 939 | + mInputMethodTarget + " to " + w, e); |
| 940 | mInputMethodTarget = w; |
| 941 | if (w.mAppToken != null) { |
| 942 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 943 | } else { |
| 944 | setInputMethodAnimLayerAdjustment(0); |
| 945 | } |
| 946 | } |
| 947 | return i+1; |
| 948 | } |
| 949 | if (willMove) { |
| 950 | RuntimeException e = new RuntimeException(); |
| 951 | e.fillInStackTrace(); |
| 952 | if (DEBUG_INPUT_METHOD) Log.w(TAG, "Moving IM target from " |
| 953 | + mInputMethodTarget + " to null", e); |
| 954 | mInputMethodTarget = null; |
| 955 | setInputMethodAnimLayerAdjustment(0); |
| 956 | } |
| 957 | return -1; |
| 958 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 959 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 960 | void addInputMethodWindowToListLocked(WindowState win) { |
| 961 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 962 | if (pos >= 0) { |
| 963 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 964 | mWindows.add(pos, win); |
| 965 | moveInputMethodDialogsLocked(pos+1); |
| 966 | return; |
| 967 | } |
| 968 | win.mTargetAppToken = null; |
| 969 | addWindowToListInOrderLocked(win, true); |
| 970 | moveInputMethodDialogsLocked(pos); |
| 971 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 972 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 973 | void setInputMethodAnimLayerAdjustment(int adj) { |
| 974 | if (DEBUG_LAYERS) Log.v(TAG, "Setting im layer adj to " + adj); |
| 975 | mInputMethodAnimLayerAdjustment = adj; |
| 976 | WindowState imw = mInputMethodWindow; |
| 977 | if (imw != null) { |
| 978 | imw.mAnimLayer = imw.mLayer + adj; |
| 979 | if (DEBUG_LAYERS) Log.v(TAG, "IM win " + imw |
| 980 | + " anim layer: " + imw.mAnimLayer); |
| 981 | int wi = imw.mChildWindows.size(); |
| 982 | while (wi > 0) { |
| 983 | wi--; |
| 984 | WindowState cw = (WindowState)imw.mChildWindows.get(wi); |
| 985 | cw.mAnimLayer = cw.mLayer + adj; |
| 986 | if (DEBUG_LAYERS) Log.v(TAG, "IM win " + cw |
| 987 | + " anim layer: " + cw.mAnimLayer); |
| 988 | } |
| 989 | } |
| 990 | int di = mInputMethodDialogs.size(); |
| 991 | while (di > 0) { |
| 992 | di --; |
| 993 | imw = mInputMethodDialogs.get(di); |
| 994 | imw.mAnimLayer = imw.mLayer + adj; |
| 995 | if (DEBUG_LAYERS) Log.v(TAG, "IM win " + imw |
| 996 | + " anim layer: " + imw.mAnimLayer); |
| 997 | } |
| 998 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 999 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1000 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1001 | int wpos = mWindows.indexOf(win); |
| 1002 | if (wpos >= 0) { |
| 1003 | if (wpos < interestingPos) interestingPos--; |
| 1004 | mWindows.remove(wpos); |
| 1005 | int NC = win.mChildWindows.size(); |
| 1006 | while (NC > 0) { |
| 1007 | NC--; |
| 1008 | WindowState cw = (WindowState)win.mChildWindows.get(NC); |
| 1009 | int cpos = mWindows.indexOf(cw); |
| 1010 | if (cpos >= 0) { |
| 1011 | if (cpos < interestingPos) interestingPos--; |
| 1012 | mWindows.remove(cpos); |
| 1013 | } |
| 1014 | } |
| 1015 | } |
| 1016 | return interestingPos; |
| 1017 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1018 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1019 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1020 | addWindowToListInOrderLocked(win, false); |
| 1021 | // This is a hack to get all of the child windows added as well |
| 1022 | // at the right position. Child windows should be rare and |
| 1023 | // this case should be rare, so it shouldn't be that big a deal. |
| 1024 | int wpos = mWindows.indexOf(win); |
| 1025 | if (wpos >= 0) { |
| 1026 | mWindows.remove(wpos); |
| 1027 | reAddWindowLocked(wpos, win); |
| 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 logWindowList(String prefix) { |
| 1032 | int N = mWindows.size(); |
| 1033 | while (N > 0) { |
| 1034 | N--; |
| 1035 | Log.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
| 1036 | } |
| 1037 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1038 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1039 | void moveInputMethodDialogsLocked(int pos) { |
| 1040 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1041 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1042 | final int N = dialogs.size(); |
| 1043 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Removing " + N + " dialogs w/pos=" + pos); |
| 1044 | for (int i=0; i<N; i++) { |
| 1045 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1046 | } |
| 1047 | if (DEBUG_INPUT_METHOD) { |
| 1048 | Log.v(TAG, "Window list w/pos=" + pos); |
| 1049 | logWindowList(" "); |
| 1050 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1051 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1052 | if (pos >= 0) { |
| 1053 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1054 | if (pos < mWindows.size()) { |
| 1055 | WindowState wp = (WindowState)mWindows.get(pos); |
| 1056 | if (wp == mInputMethodWindow) { |
| 1057 | pos++; |
| 1058 | } |
| 1059 | } |
| 1060 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Adding " + N + " dialogs at pos=" + pos); |
| 1061 | for (int i=0; i<N; i++) { |
| 1062 | WindowState win = dialogs.get(i); |
| 1063 | win.mTargetAppToken = targetAppToken; |
| 1064 | pos = reAddWindowLocked(pos, win); |
| 1065 | } |
| 1066 | if (DEBUG_INPUT_METHOD) { |
| 1067 | Log.v(TAG, "Final window list:"); |
| 1068 | logWindowList(" "); |
| 1069 | } |
| 1070 | return; |
| 1071 | } |
| 1072 | for (int i=0; i<N; i++) { |
| 1073 | WindowState win = dialogs.get(i); |
| 1074 | win.mTargetAppToken = null; |
| 1075 | reAddWindowToListInOrderLocked(win); |
| 1076 | if (DEBUG_INPUT_METHOD) { |
| 1077 | Log.v(TAG, "No IM target, final list:"); |
| 1078 | logWindowList(" "); |
| 1079 | } |
| 1080 | } |
| 1081 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1082 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1083 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1084 | final WindowState imWin = mInputMethodWindow; |
| 1085 | final int DN = mInputMethodDialogs.size(); |
| 1086 | if (imWin == null && DN == 0) { |
| 1087 | return false; |
| 1088 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1089 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1090 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1091 | if (imPos >= 0) { |
| 1092 | // In this case, the input method windows are to be placed |
| 1093 | // immediately above the window they are targeting. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1094 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1095 | // First check to see if the input method windows are already |
| 1096 | // located here, and contiguous. |
| 1097 | final int N = mWindows.size(); |
| 1098 | WindowState firstImWin = imPos < N |
| 1099 | ? (WindowState)mWindows.get(imPos) : null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1100 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1101 | // Figure out the actual input method window that should be |
| 1102 | // at the bottom of their stack. |
| 1103 | WindowState baseImWin = imWin != null |
| 1104 | ? imWin : mInputMethodDialogs.get(0); |
| 1105 | if (baseImWin.mChildWindows.size() > 0) { |
| 1106 | WindowState cw = (WindowState)baseImWin.mChildWindows.get(0); |
| 1107 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1108 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1109 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1110 | if (firstImWin == baseImWin) { |
| 1111 | // The windows haven't moved... but are they still contiguous? |
| 1112 | // First find the top IM window. |
| 1113 | int pos = imPos+1; |
| 1114 | while (pos < N) { |
| 1115 | if (!((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1116 | break; |
| 1117 | } |
| 1118 | pos++; |
| 1119 | } |
| 1120 | pos++; |
| 1121 | // Now there should be no more input method windows above. |
| 1122 | while (pos < N) { |
| 1123 | if (((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1124 | break; |
| 1125 | } |
| 1126 | pos++; |
| 1127 | } |
| 1128 | if (pos >= N) { |
| 1129 | // All is good! |
| 1130 | return false; |
| 1131 | } |
| 1132 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1133 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1134 | if (imWin != null) { |
| 1135 | if (DEBUG_INPUT_METHOD) { |
| 1136 | Log.v(TAG, "Moving IM from " + imPos); |
| 1137 | logWindowList(" "); |
| 1138 | } |
| 1139 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1140 | if (DEBUG_INPUT_METHOD) { |
| 1141 | Log.v(TAG, "List after moving with new pos " + imPos + ":"); |
| 1142 | logWindowList(" "); |
| 1143 | } |
| 1144 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1145 | reAddWindowLocked(imPos, imWin); |
| 1146 | if (DEBUG_INPUT_METHOD) { |
| 1147 | Log.v(TAG, "List after moving IM to " + imPos + ":"); |
| 1148 | logWindowList(" "); |
| 1149 | } |
| 1150 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1151 | } else { |
| 1152 | moveInputMethodDialogsLocked(imPos); |
| 1153 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1154 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1155 | } else { |
| 1156 | // In this case, the input method windows go in a fixed layer, |
| 1157 | // because they aren't currently associated with a focus window. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1158 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1159 | if (imWin != null) { |
| 1160 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Moving IM from " + imPos); |
| 1161 | tmpRemoveWindowLocked(0, imWin); |
| 1162 | imWin.mTargetAppToken = null; |
| 1163 | reAddWindowToListInOrderLocked(imWin); |
| 1164 | if (DEBUG_INPUT_METHOD) { |
| 1165 | Log.v(TAG, "List with no IM target:"); |
| 1166 | logWindowList(" "); |
| 1167 | } |
| 1168 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1169 | } else { |
| 1170 | moveInputMethodDialogsLocked(-1);; |
| 1171 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1172 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1173 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1174 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1175 | if (needAssignLayers) { |
| 1176 | assignLayersLocked(); |
| 1177 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1178 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1179 | return true; |
| 1180 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1181 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1182 | void adjustInputMethodDialogsLocked() { |
| 1183 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1184 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1185 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1186 | boolean adjustWallpaperWindowsLocked() { |
| 1187 | boolean changed = false; |
| 1188 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1189 | final int dw = mDisplay.getWidth(); |
| 1190 | final int dh = mDisplay.getHeight(); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1191 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1192 | // First find top-most window that has asked to be on top of the |
| 1193 | // wallpaper; all wallpapers go behind it. |
| 1194 | final ArrayList localmWindows = mWindows; |
| 1195 | int N = localmWindows.size(); |
| 1196 | WindowState w = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1197 | WindowState foundW = null; |
| 1198 | int foundI = 0; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1199 | int i = N; |
| 1200 | while (i > 0) { |
| 1201 | i--; |
| 1202 | w = (WindowState)localmWindows.get(i); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1203 | if (w.mAppToken != null) { |
| 1204 | // If this window's app token is hidden and not animating, |
| 1205 | // it is of no interest to us. |
| 1206 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
| 1207 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 1208 | "Skipping hidden or animating token: " + w); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1209 | continue; |
| 1210 | } |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1211 | // If this window's app token is ot fullscreen, also irrelevant. |
| 1212 | if (!w.mAppToken.appFullscreen) { |
| 1213 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 1214 | "Skipping non-fullscreen token: " + w); |
| 1215 | continue; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1216 | } |
| 1217 | } |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1218 | if (DEBUG_WALLPAPER) Log.v(TAG, "Win " + w + ": readyfordisplay=" |
| 1219 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1220 | + " commitdrawpending=" + w.mCommitDrawPending); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1221 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1222 | && (mWallpaperTarget == w |
| 1223 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1224 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 1225 | "Found wallpaper activity: #" + i + "=" + w); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1226 | foundW = w; |
| 1227 | foundI = i; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1228 | if (w == mWallpaperTarget && w.mAppToken != null |
| 1229 | && w.mAppToken.animation != null) { |
| 1230 | // The current wallpaper target is animating, so we'll |
| 1231 | // look behind it for another possible target and figure |
| 1232 | // out what is going on below. |
| 1233 | if (DEBUG_WALLPAPER) Log.v(TAG, "Win " + w |
| 1234 | + ": token animating, looking behind."); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1235 | continue; |
| 1236 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1237 | break; |
| 1238 | } |
| 1239 | } |
| 1240 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1241 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) { |
| 1242 | // If we are currently waiting for an app transition, and either |
| 1243 | // the current target or the next target are involved with it, |
| 1244 | // then hold off on doing anything with the wallpaper. |
| 1245 | // Note that we are checking here for just whether the target |
| 1246 | // is part of an app token... which is potentially overly aggressive |
| 1247 | // (the app token may not be involved in the transition), but good |
| 1248 | // enough (we'll just wait until whatever transition is pending |
| 1249 | // executes). |
| 1250 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1251 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 1252 | "Wallpaper not changing: waiting for app anim in current target"); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1253 | return false; |
| 1254 | } |
| 1255 | if (foundW != null && foundW.mAppToken != null) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1256 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 1257 | "Wallpaper not changing: waiting for app anim in found target"); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1258 | return false; |
| 1259 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1260 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1261 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1262 | if (mWallpaperTarget != foundW) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1263 | if (DEBUG_WALLPAPER) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1264 | Log.v(TAG, "New wallpaper target: " + foundW |
| 1265 | + " oldTarget: " + mWallpaperTarget); |
| 1266 | } |
| 1267 | |
| 1268 | mLowerWallpaperTarget = null; |
| 1269 | mUpperWallpaperTarget = null; |
| 1270 | |
| 1271 | WindowState oldW = mWallpaperTarget; |
| 1272 | mWallpaperTarget = foundW; |
| 1273 | |
| 1274 | // Now what is happening... if the current and new targets are |
| 1275 | // animating, then we are in our super special mode! |
| 1276 | if (foundW != null && foundW.mAppToken != null && oldW != null |
| 1277 | && oldW.mAppToken != null) { |
| 1278 | if (DEBUG_WALLPAPER) { |
| 1279 | Log.v(TAG, "New animation: " + foundW.mAppToken.animation |
| 1280 | + " old animation: " + oldW.mAppToken.animation); |
| 1281 | } |
| 1282 | if (foundW.mAppToken.animation != null |
| 1283 | && oldW.mAppToken.animation != null) { |
| 1284 | int oldI = localmWindows.indexOf(oldW); |
| 1285 | if (DEBUG_WALLPAPER) { |
| 1286 | Log.v(TAG, "New i: " + foundI + " old i: " + oldI); |
| 1287 | } |
| 1288 | if (oldI >= 0) { |
| 1289 | if (DEBUG_WALLPAPER) { |
| 1290 | Log.v(TAG, "Animating wallpapers: old#" + oldI |
| 1291 | + "=" + oldW + "; new#" + foundI |
| 1292 | + "=" + foundW); |
| 1293 | } |
| 1294 | |
| 1295 | // Set the new target correctly. |
| 1296 | if (foundW.mAppToken.hiddenRequested) { |
| 1297 | if (DEBUG_WALLPAPER) { |
| 1298 | Log.v(TAG, "Old wallpaper still the target."); |
| 1299 | } |
| 1300 | mWallpaperTarget = oldW; |
| 1301 | } |
| 1302 | |
| 1303 | // Now set the upper and lower wallpaper targets |
| 1304 | // correctly, and make sure that we are positioning |
| 1305 | // the wallpaper below the lower. |
| 1306 | if (foundI > oldI) { |
| 1307 | // The new target is on top of the old one. |
| 1308 | if (DEBUG_WALLPAPER) { |
| 1309 | Log.v(TAG, "Found target above old target."); |
| 1310 | } |
| 1311 | mUpperWallpaperTarget = foundW; |
| 1312 | mLowerWallpaperTarget = oldW; |
| 1313 | foundW = oldW; |
| 1314 | foundI = oldI; |
| 1315 | } else { |
| 1316 | // The new target is below the old one. |
| 1317 | if (DEBUG_WALLPAPER) { |
| 1318 | Log.v(TAG, "Found target below old target."); |
| 1319 | } |
| 1320 | mUpperWallpaperTarget = oldW; |
| 1321 | mLowerWallpaperTarget = foundW; |
| 1322 | } |
| 1323 | } |
| 1324 | } |
| 1325 | } |
| 1326 | |
| 1327 | } else { |
| 1328 | // Is it time to stop animating? |
| 1329 | if (mLowerWallpaperTarget == null |
| 1330 | || mLowerWallpaperTarget.mAppToken.animation == null |
| 1331 | || mUpperWallpaperTarget == null |
| 1332 | || mUpperWallpaperTarget.mAppToken.animation == null) { |
| 1333 | if (DEBUG_WALLPAPER) { |
| 1334 | Log.v(TAG, "No longer animating wallpaper targets!"); |
| 1335 | } |
| 1336 | mLowerWallpaperTarget = null; |
| 1337 | mUpperWallpaperTarget = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1338 | } |
| 1339 | } |
| 1340 | |
| 1341 | boolean visible = foundW != null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1342 | if (visible) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1343 | // The window is visible to the compositor... but is it visible |
| 1344 | // to the user? That is what the wallpaper cares about. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1345 | visible = !foundW.mObscured; |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1346 | if (DEBUG_WALLPAPER) Log.v(TAG, "Wallpaper visibility: " + visible); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1347 | |
| 1348 | // If the wallpaper target is animating, we may need to copy |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1349 | // its layer adjustment. Only do this if we are not transfering |
| 1350 | // between two wallpaper targets. |
| 1351 | mWallpaperAnimLayerAdjustment = |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1352 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1353 | ? foundW.mAppToken.animLayerAdjustment : 0; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1354 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1355 | // Now w is the window we are supposed to be behind... but we |
| 1356 | // need to be sure to also be behind any of its attached windows, |
| 1357 | // AND any starting window associated with it. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1358 | while (foundI > 0) { |
| 1359 | WindowState wb = (WindowState)localmWindows.get(foundI-1); |
| 1360 | if (wb.mAttachedWindow != foundW && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1361 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1362 | wb.mToken != foundW.mToken)) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1363 | // This window is not related to the previous one in any |
| 1364 | // interesting way, so stop here. |
| 1365 | break; |
| 1366 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1367 | foundW = wb; |
| 1368 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1369 | } |
| 1370 | } |
| 1371 | |
| 1372 | // Okay i is the position immediately above the wallpaper. Look at |
| 1373 | // what is below it for later. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1374 | foundW = foundI > 0 ? (WindowState)localmWindows.get(foundI-1) : null; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1375 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1376 | if (visible) { |
| 1377 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
| 1378 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
| 1379 | } |
| 1380 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1381 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1382 | // are correctly placed. |
| 1383 | int curTokenIndex = mWallpaperTokens.size(); |
| 1384 | while (curTokenIndex > 0) { |
| 1385 | curTokenIndex--; |
| 1386 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1387 | int curWallpaperIndex = token.windows.size(); |
| 1388 | while (curWallpaperIndex > 0) { |
| 1389 | curWallpaperIndex--; |
| 1390 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1391 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1392 | if (visible) { |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1393 | updateWallpaperOffsetLocked(wallpaper, dw, dh); |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1394 | } |
| 1395 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1396 | // First, make sure the client has the current visibility |
| 1397 | // state. |
| 1398 | if (wallpaper.mWallpaperVisible != visible) { |
| 1399 | wallpaper.mWallpaperVisible = visible; |
| 1400 | try { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1401 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Log.v(TAG, |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1402 | "Setting visibility of wallpaper " + wallpaper |
| 1403 | + ": " + visible); |
| 1404 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1405 | } catch (RemoteException e) { |
| 1406 | } |
| 1407 | } |
| 1408 | |
| 1409 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1410 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Log.v(TAG, "Wallpaper win " |
| 1411 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1412 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1413 | // First, if this window is at the current index, then all |
| 1414 | // is well. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1415 | if (wallpaper == foundW) { |
| 1416 | foundI--; |
| 1417 | foundW = foundI > 0 |
| 1418 | ? (WindowState)localmWindows.get(foundI-1) : null; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1419 | continue; |
| 1420 | } |
| 1421 | |
| 1422 | // The window didn't match... the current wallpaper window, |
| 1423 | // wherever it is, is in the wrong place, so make sure it is |
| 1424 | // not in the list. |
| 1425 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1426 | if (oldIndex >= 0) { |
| 1427 | localmWindows.remove(oldIndex); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1428 | if (oldIndex < foundI) { |
| 1429 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1430 | } |
| 1431 | } |
| 1432 | |
| 1433 | // Now stick it in. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1434 | if (DEBUG_WALLPAPER) Log.v(TAG, "Moving wallpaper " + wallpaper |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1435 | + " from " + oldIndex + " to " + foundI); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1436 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1437 | localmWindows.add(foundI, wallpaper); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1438 | changed = true; |
| 1439 | } |
| 1440 | } |
| 1441 | |
| 1442 | return changed; |
| 1443 | } |
| 1444 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1445 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1446 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Log.v(TAG, |
| 1447 | "Setting wallpaper layer adj to " + adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1448 | mWallpaperAnimLayerAdjustment = adj; |
| 1449 | int curTokenIndex = mWallpaperTokens.size(); |
| 1450 | while (curTokenIndex > 0) { |
| 1451 | curTokenIndex--; |
| 1452 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1453 | int curWallpaperIndex = token.windows.size(); |
| 1454 | while (curWallpaperIndex > 0) { |
| 1455 | curWallpaperIndex--; |
| 1456 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1457 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1458 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Log.v(TAG, "Wallpaper win " |
| 1459 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1460 | } |
| 1461 | } |
| 1462 | } |
| 1463 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1464 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1465 | boolean changed = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1466 | boolean rawChanged = false; |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1467 | if (mLastWallpaperX >= 0) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1468 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1469 | int offset = availw > 0 ? -(int)(availw*mLastWallpaperX+.5f) : 0; |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1470 | changed = wallpaperWin.mXOffset != offset; |
| 1471 | if (changed) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1472 | if (DEBUG_WALLPAPER) Log.v(TAG, "Update wallpaper " |
| 1473 | + wallpaperWin + " x: " + offset); |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1474 | wallpaperWin.mXOffset = offset; |
| 1475 | } |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1476 | if (wallpaperWin.mWallpaperX != mLastWallpaperX) { |
| 1477 | wallpaperWin.mWallpaperX = mLastWallpaperX; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1478 | rawChanged = true; |
| 1479 | } |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1480 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1481 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1482 | if (mLastWallpaperY >= 0) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1483 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1484 | int offset = availh > 0 ? -(int)(availh*mLastWallpaperY+.5f) : 0; |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1485 | if (wallpaperWin.mYOffset != offset) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1486 | if (DEBUG_WALLPAPER) Log.v(TAG, "Update wallpaper " |
| 1487 | + wallpaperWin + " y: " + offset); |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1488 | changed = true; |
| 1489 | wallpaperWin.mYOffset = offset; |
| 1490 | } |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1491 | if (wallpaperWin.mWallpaperY != mLastWallpaperY) { |
| 1492 | wallpaperWin.mWallpaperY = mLastWallpaperY; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1493 | rawChanged = true; |
| 1494 | } |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1495 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1496 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1497 | if (rawChanged) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1498 | try { |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1499 | if (DEBUG_WALLPAPER) Log.v(TAG, "Report new wp offset " |
| 1500 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 1501 | + " y=" + wallpaperWin.mWallpaperY); |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1502 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
| 1503 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY); |
| 1504 | } catch (RemoteException e) { |
| 1505 | } |
| 1506 | } |
| 1507 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1508 | return changed; |
| 1509 | } |
| 1510 | |
| 1511 | boolean updateWallpaperOffsetLocked() { |
| 1512 | final int dw = mDisplay.getWidth(); |
| 1513 | final int dh = mDisplay.getHeight(); |
| 1514 | |
| 1515 | boolean changed = false; |
| 1516 | |
| 1517 | WindowState target = mWallpaperTarget; |
| 1518 | if (target != null) { |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1519 | mLastWallpaperX = target.mWallpaperX; |
| 1520 | mLastWallpaperY = target.mWallpaperY; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1521 | int curTokenIndex = mWallpaperTokens.size(); |
| 1522 | while (curTokenIndex > 0) { |
| 1523 | curTokenIndex--; |
| 1524 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1525 | int curWallpaperIndex = token.windows.size(); |
| 1526 | while (curWallpaperIndex > 0) { |
| 1527 | curWallpaperIndex--; |
| 1528 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1529 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh)) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1530 | wallpaper.computeShownFrameLocked(); |
| 1531 | changed = true; |
| 1532 | } |
| 1533 | } |
| 1534 | } |
| 1535 | } |
| 1536 | |
| 1537 | return changed; |
| 1538 | } |
| 1539 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1540 | void updateWallpaperVisibilityLocked() { |
| 1541 | final boolean visible = mWallpaperTarget != null |
| 1542 | && !mWallpaperTarget.mObscured; |
| 1543 | final int dw = mDisplay.getWidth(); |
| 1544 | final int dh = mDisplay.getHeight(); |
| 1545 | |
| 1546 | int curTokenIndex = mWallpaperTokens.size(); |
| 1547 | while (curTokenIndex > 0) { |
| 1548 | curTokenIndex--; |
| 1549 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1550 | int curWallpaperIndex = token.windows.size(); |
| 1551 | while (curWallpaperIndex > 0) { |
| 1552 | curWallpaperIndex--; |
| 1553 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1554 | if (visible) { |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1555 | updateWallpaperOffsetLocked(wallpaper, dw, dh); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1556 | } |
| 1557 | |
| 1558 | if (wallpaper.mWallpaperVisible != visible) { |
| 1559 | wallpaper.mWallpaperVisible = visible; |
| 1560 | try { |
| 1561 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Log.v(TAG, |
| 1562 | "Setting visibility of wallpaper " + wallpaper |
| 1563 | + ": " + visible); |
| 1564 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1565 | } catch (RemoteException e) { |
| 1566 | } |
| 1567 | } |
| 1568 | } |
| 1569 | } |
| 1570 | } |
| 1571 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1572 | void sendPointerToWallpaperLocked(WindowState srcWin, |
| 1573 | MotionEvent pointer, long eventTime) { |
| 1574 | int curTokenIndex = mWallpaperTokens.size(); |
| 1575 | while (curTokenIndex > 0) { |
| 1576 | curTokenIndex--; |
| 1577 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1578 | int curWallpaperIndex = token.windows.size(); |
| 1579 | while (curWallpaperIndex > 0) { |
| 1580 | curWallpaperIndex--; |
| 1581 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1582 | if ((wallpaper.mAttrs.flags & |
| 1583 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 1584 | continue; |
| 1585 | } |
| 1586 | try { |
| 1587 | MotionEvent ev = MotionEvent.obtainNoHistory(pointer); |
| 1588 | ev.offsetLocation(srcWin.mFrame.left-wallpaper.mFrame.left, |
| 1589 | srcWin.mFrame.top-wallpaper.mFrame.top); |
| 1590 | wallpaper.mClient.dispatchPointer(ev, eventTime, false); |
| 1591 | } catch (RemoteException e) { |
| 1592 | Log.w(TAG, "Failure sending pointer to wallpaper", e); |
| 1593 | } |
| 1594 | } |
| 1595 | } |
| 1596 | } |
| 1597 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1598 | public int addWindow(Session session, IWindow client, |
| 1599 | WindowManager.LayoutParams attrs, int viewVisibility, |
| 1600 | Rect outContentInsets) { |
| 1601 | int res = mPolicy.checkAddPermission(attrs); |
| 1602 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1603 | return res; |
| 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 | boolean reportNewConfig = false; |
| 1607 | WindowState attachedWindow = null; |
| 1608 | WindowState win = null; |
| 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 | synchronized(mWindowMap) { |
| 1611 | // Instantiating a Display requires talking with the simulator, |
| 1612 | // so don't do it until we know the system is mostly up and |
| 1613 | // running. |
| 1614 | if (mDisplay == null) { |
| 1615 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 1616 | mDisplay = wm.getDefaultDisplay(); |
| 1617 | mQueue.setDisplay(mDisplay); |
| 1618 | reportNewConfig = true; |
| 1619 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1620 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1621 | if (mWindowMap.containsKey(client.asBinder())) { |
| 1622 | Log.w(TAG, "Window " + client + " is already added"); |
| 1623 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 1624 | } |
| 1625 | |
| 1626 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1627 | attachedWindow = windowForClientLocked(null, attrs.token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1628 | if (attachedWindow == null) { |
| 1629 | Log.w(TAG, "Attempted to add window with token that is not a window: " |
| 1630 | + attrs.token + ". Aborting."); |
| 1631 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1632 | } |
| 1633 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 1634 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
| 1635 | Log.w(TAG, "Attempted to add window with token that is a sub-window: " |
| 1636 | + attrs.token + ". Aborting."); |
| 1637 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1638 | } |
| 1639 | } |
| 1640 | |
| 1641 | boolean addToken = false; |
| 1642 | WindowToken token = mTokenMap.get(attrs.token); |
| 1643 | if (token == null) { |
| 1644 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1645 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1646 | Log.w(TAG, "Attempted to add application window with unknown token " |
| 1647 | + attrs.token + ". Aborting."); |
| 1648 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1649 | } |
| 1650 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 1651 | Log.w(TAG, "Attempted to add input method window with unknown token " |
| 1652 | + attrs.token + ". Aborting."); |
| 1653 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1654 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1655 | if (attrs.type == TYPE_WALLPAPER) { |
| 1656 | Log.w(TAG, "Attempted to add wallpaper window with unknown token " |
| 1657 | + attrs.token + ". Aborting."); |
| 1658 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1659 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1660 | token = new WindowToken(attrs.token, -1, false); |
| 1661 | addToken = true; |
| 1662 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1663 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1664 | AppWindowToken atoken = token.appWindowToken; |
| 1665 | if (atoken == null) { |
| 1666 | Log.w(TAG, "Attempted to add window with non-application token " |
| 1667 | + token + ". Aborting."); |
| 1668 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 1669 | } else if (atoken.removed) { |
| 1670 | Log.w(TAG, "Attempted to add window with exiting application token " |
| 1671 | + token + ". Aborting."); |
| 1672 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1673 | } |
| 1674 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 1675 | // No need for this guy! |
| 1676 | if (localLOGV) Log.v( |
| 1677 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 1678 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 1679 | } |
| 1680 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 1681 | if (token.windowType != TYPE_INPUT_METHOD) { |
| 1682 | Log.w(TAG, "Attempted to add input method window with bad token " |
| 1683 | + attrs.token + ". Aborting."); |
| 1684 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1685 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1686 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 1687 | if (token.windowType != TYPE_WALLPAPER) { |
| 1688 | Log.w(TAG, "Attempted to add wallpaper window with bad token " |
| 1689 | + attrs.token + ". Aborting."); |
| 1690 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1691 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1692 | } |
| 1693 | |
| 1694 | win = new WindowState(session, client, token, |
| 1695 | attachedWindow, attrs, viewVisibility); |
| 1696 | if (win.mDeathRecipient == null) { |
| 1697 | // Client has apparently died, so there is no reason to |
| 1698 | // continue. |
| 1699 | Log.w(TAG, "Adding window client " + client.asBinder() |
| 1700 | + " that is dead, aborting."); |
| 1701 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1702 | } |
| 1703 | |
| 1704 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
| 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 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 1707 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1708 | return res; |
| 1709 | } |
| 1710 | |
| 1711 | // From now on, no exceptions or errors allowed! |
| 1712 | |
| 1713 | res = WindowManagerImpl.ADD_OKAY; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1714 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1715 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1716 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1717 | if (addToken) { |
| 1718 | mTokenMap.put(attrs.token, token); |
| 1719 | mTokenList.add(token); |
| 1720 | } |
| 1721 | win.attach(); |
| 1722 | mWindowMap.put(client.asBinder(), win); |
| 1723 | |
| 1724 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 1725 | token.appWindowToken != null) { |
| 1726 | token.appWindowToken.startingWindow = win; |
| 1727 | } |
| 1728 | |
| 1729 | boolean imMayMove = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1730 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1731 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 1732 | mInputMethodWindow = win; |
| 1733 | addInputMethodWindowToListLocked(win); |
| 1734 | imMayMove = false; |
| 1735 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 1736 | mInputMethodDialogs.add(win); |
| 1737 | addWindowToListInOrderLocked(win, true); |
| 1738 | adjustInputMethodDialogsLocked(); |
| 1739 | imMayMove = false; |
| 1740 | } else { |
| 1741 | addWindowToListInOrderLocked(win, true); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1742 | if (attrs.type == TYPE_WALLPAPER || |
| 1743 | (attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 1744 | adjustWallpaperWindowsLocked(); |
| 1745 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1746 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1747 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1748 | win.mEnterAnimationPending = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1749 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1750 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1751 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1752 | if (mInTouchMode) { |
| 1753 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 1754 | } |
| 1755 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 1756 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 1757 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1758 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1759 | boolean focusChanged = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1760 | if (win.canReceiveKeys()) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1761 | if ((focusChanged=updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS)) |
| 1762 | == true) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1763 | imMayMove = false; |
| 1764 | } |
| 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 | if (imMayMove) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1768 | moveInputMethodWindowsIfNeededLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1769 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1770 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1771 | assignLayersLocked(); |
| 1772 | // Don't do layout here, the window must call |
| 1773 | // relayout to be displayed, so we'll do it there. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1774 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1775 | //dump(); |
| 1776 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1777 | if (focusChanged) { |
| 1778 | if (mCurrentFocus != null) { |
| 1779 | mKeyWaiter.handleNewWindowLocked(mCurrentFocus); |
| 1780 | } |
| 1781 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1782 | if (localLOGV) Log.v( |
| 1783 | TAG, "New client " + client.asBinder() |
| 1784 | + ": window=" + win); |
| 1785 | } |
| 1786 | |
| 1787 | // sendNewConfiguration() checks caller permissions so we must call it with |
| 1788 | // privilege. updateOrientationFromAppTokens() clears and resets the caller |
| 1789 | // identity anyway, so it's safe to just clear & restore around this whole |
| 1790 | // block. |
| 1791 | final long origId = Binder.clearCallingIdentity(); |
| 1792 | if (reportNewConfig) { |
| 1793 | sendNewConfiguration(); |
| 1794 | } else { |
| 1795 | // Update Orientation after adding a window, only if the window needs to be |
| 1796 | // displayed right away |
| 1797 | if (win.isVisibleOrAdding()) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 1798 | if (updateOrientationFromAppTokensUnchecked(null, null) != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1799 | sendNewConfiguration(); |
| 1800 | } |
| 1801 | } |
| 1802 | } |
| 1803 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1804 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1805 | return res; |
| 1806 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1807 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1808 | public void removeWindow(Session session, IWindow client) { |
| 1809 | synchronized(mWindowMap) { |
| 1810 | WindowState win = windowForClientLocked(session, client); |
| 1811 | if (win == null) { |
| 1812 | return; |
| 1813 | } |
| 1814 | removeWindowLocked(session, win); |
| 1815 | } |
| 1816 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1817 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1818 | public void removeWindowLocked(Session session, WindowState win) { |
| 1819 | |
| 1820 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 1821 | TAG, "Remove " + win + " client=" |
| 1822 | + Integer.toHexString(System.identityHashCode( |
| 1823 | win.mClient.asBinder())) |
| 1824 | + ", surface=" + win.mSurface); |
| 1825 | |
| 1826 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1827 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1828 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 1829 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 1830 | + " mExiting=" + win.mExiting |
| 1831 | + " isAnimating=" + win.isAnimating() |
| 1832 | + " app-animation=" |
| 1833 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 1834 | + " inPendingTransaction=" |
| 1835 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 1836 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 1837 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 1838 | boolean wasVisible = false; |
| 1839 | // First, see if we need to run an animation. If we do, we have |
| 1840 | // to hold off on removing the window until the animation is done. |
| 1841 | // If the display is frozen, just remove immediately, since the |
| 1842 | // animation wouldn't be seen. |
| 1843 | if (win.mSurface != null && !mDisplayFrozen) { |
| 1844 | // If we are not currently running the exit animation, we |
| 1845 | // need to see about starting one. |
| 1846 | if (wasVisible=win.isWinVisibleLw()) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1847 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1848 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 1849 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 1850 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 1851 | } |
| 1852 | // Try starting an animation. |
| 1853 | if (applyAnimationLocked(win, transit, false)) { |
| 1854 | win.mExiting = true; |
| 1855 | } |
| 1856 | } |
| 1857 | if (win.mExiting || win.isAnimating()) { |
| 1858 | // The exit animation is running... wait for it! |
| 1859 | //Log.i(TAG, "*** Running exit animation..."); |
| 1860 | win.mExiting = true; |
| 1861 | win.mRemoveOnExit = true; |
| 1862 | mLayoutNeeded = true; |
| 1863 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 1864 | performLayoutAndPlaceSurfacesLocked(); |
| 1865 | if (win.mAppToken != null) { |
| 1866 | win.mAppToken.updateReportedVisibilityLocked(); |
| 1867 | } |
| 1868 | //dump(); |
| 1869 | Binder.restoreCallingIdentity(origId); |
| 1870 | return; |
| 1871 | } |
| 1872 | } |
| 1873 | |
| 1874 | removeWindowInnerLocked(session, win); |
| 1875 | // Removing a visible window will effect the computed orientation |
| 1876 | // So just update orientation if needed. |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1877 | if (wasVisible && computeForcedAppOrientationLocked() |
| 1878 | != mForcedAppOrientation) { |
| 1879 | 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] | 1880 | } |
| 1881 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 1882 | Binder.restoreCallingIdentity(origId); |
| 1883 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1884 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1885 | private void removeWindowInnerLocked(Session session, WindowState win) { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1886 | mKeyWaiter.finishedKey(session, win.mClient, true, |
| 1887 | KeyWaiter.RETURN_NOTHING); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1888 | mKeyWaiter.releasePendingPointerLocked(win.mSession); |
| 1889 | mKeyWaiter.releasePendingTrackballLocked(win.mSession); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1890 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1891 | win.mRemoved = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1892 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1893 | if (mInputMethodTarget == win) { |
| 1894 | moveInputMethodWindowsIfNeededLocked(false); |
| 1895 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1896 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1897 | mPolicy.removeWindowLw(win); |
| 1898 | win.removeLocked(); |
| 1899 | |
| 1900 | mWindowMap.remove(win.mClient.asBinder()); |
| 1901 | mWindows.remove(win); |
| 1902 | |
| 1903 | if (mInputMethodWindow == win) { |
| 1904 | mInputMethodWindow = null; |
| 1905 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 1906 | mInputMethodDialogs.remove(win); |
| 1907 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1908 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1909 | final WindowToken token = win.mToken; |
| 1910 | final AppWindowToken atoken = win.mAppToken; |
| 1911 | token.windows.remove(win); |
| 1912 | if (atoken != null) { |
| 1913 | atoken.allAppWindows.remove(win); |
| 1914 | } |
| 1915 | if (localLOGV) Log.v( |
| 1916 | TAG, "**** Removing window " + win + ": count=" |
| 1917 | + token.windows.size()); |
| 1918 | if (token.windows.size() == 0) { |
| 1919 | if (!token.explicit) { |
| 1920 | mTokenMap.remove(token.token); |
| 1921 | mTokenList.remove(token); |
| 1922 | } else if (atoken != null) { |
| 1923 | atoken.firstWindowDrawn = false; |
| 1924 | } |
| 1925 | } |
| 1926 | |
| 1927 | if (atoken != null) { |
| 1928 | if (atoken.startingWindow == win) { |
| 1929 | atoken.startingWindow = null; |
| 1930 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 1931 | // If this is the last window and we had requested a starting |
| 1932 | // transition window, well there is no point now. |
| 1933 | atoken.startingData = null; |
| 1934 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 1935 | // If this is the last window except for a starting transition |
| 1936 | // window, we need to get rid of the starting transition. |
| 1937 | if (DEBUG_STARTING_WINDOW) { |
| 1938 | Log.v(TAG, "Schedule remove starting " + token |
| 1939 | + ": no more real windows"); |
| 1940 | } |
| 1941 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 1942 | mH.sendMessage(m); |
| 1943 | } |
| 1944 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1945 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1946 | if (win.mAttrs.type == TYPE_WALLPAPER || |
| 1947 | (win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 1948 | adjustWallpaperWindowsLocked(); |
| 1949 | } |
| 1950 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1951 | if (!mInLayout) { |
| 1952 | assignLayersLocked(); |
| 1953 | mLayoutNeeded = true; |
| 1954 | performLayoutAndPlaceSurfacesLocked(); |
| 1955 | if (win.mAppToken != null) { |
| 1956 | win.mAppToken.updateReportedVisibilityLocked(); |
| 1957 | } |
| 1958 | } |
| 1959 | } |
| 1960 | |
| 1961 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 1962 | long origId = Binder.clearCallingIdentity(); |
| 1963 | try { |
| 1964 | synchronized (mWindowMap) { |
| 1965 | WindowState w = windowForClientLocked(session, client); |
| 1966 | if ((w != null) && (w.mSurface != null)) { |
| 1967 | Surface.openTransaction(); |
| 1968 | try { |
| 1969 | w.mSurface.setTransparentRegionHint(region); |
| 1970 | } finally { |
| 1971 | Surface.closeTransaction(); |
| 1972 | } |
| 1973 | } |
| 1974 | } |
| 1975 | } finally { |
| 1976 | Binder.restoreCallingIdentity(origId); |
| 1977 | } |
| 1978 | } |
| 1979 | |
| 1980 | void setInsetsWindow(Session session, IWindow client, |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1981 | int touchableInsets, Rect contentInsets, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1982 | Rect visibleInsets) { |
| 1983 | long origId = Binder.clearCallingIdentity(); |
| 1984 | try { |
| 1985 | synchronized (mWindowMap) { |
| 1986 | WindowState w = windowForClientLocked(session, client); |
| 1987 | if (w != null) { |
| 1988 | w.mGivenInsetsPending = false; |
| 1989 | w.mGivenContentInsets.set(contentInsets); |
| 1990 | w.mGivenVisibleInsets.set(visibleInsets); |
| 1991 | w.mTouchableInsets = touchableInsets; |
| 1992 | mLayoutNeeded = true; |
| 1993 | performLayoutAndPlaceSurfacesLocked(); |
| 1994 | } |
| 1995 | } |
| 1996 | } finally { |
| 1997 | Binder.restoreCallingIdentity(origId); |
| 1998 | } |
| 1999 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2000 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2001 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2002 | Rect outDisplayFrame) { |
| 2003 | synchronized(mWindowMap) { |
| 2004 | WindowState win = windowForClientLocked(session, client); |
| 2005 | if (win == null) { |
| 2006 | outDisplayFrame.setEmpty(); |
| 2007 | return; |
| 2008 | } |
| 2009 | outDisplayFrame.set(win.mDisplayFrame); |
| 2010 | } |
| 2011 | } |
| 2012 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2013 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y) { |
| 2014 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2015 | window.mWallpaperX = x; |
| 2016 | window.mWallpaperY = y; |
| 2017 | |
| 2018 | if (mWallpaperTarget == window) { |
| 2019 | if (updateWallpaperOffsetLocked()) { |
| 2020 | performLayoutAndPlaceSurfacesLocked(); |
| 2021 | } |
| 2022 | } |
| 2023 | } |
| 2024 | } |
| 2025 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2026 | public int relayoutWindow(Session session, IWindow client, |
| 2027 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2028 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2029 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
| 2030 | Surface outSurface) { |
| 2031 | boolean displayed = false; |
| 2032 | boolean inTouchMode; |
| 2033 | Configuration newConfig = null; |
| 2034 | long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2035 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2036 | synchronized(mWindowMap) { |
| 2037 | WindowState win = windowForClientLocked(session, client); |
| 2038 | if (win == null) { |
| 2039 | return 0; |
| 2040 | } |
| 2041 | win.mRequestedWidth = requestedWidth; |
| 2042 | win.mRequestedHeight = requestedHeight; |
| 2043 | |
| 2044 | if (attrs != null) { |
| 2045 | mPolicy.adjustWindowParamsLw(attrs); |
| 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 | int attrChanges = 0; |
| 2049 | int flagChanges = 0; |
| 2050 | if (attrs != null) { |
| 2051 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2052 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2053 | } |
| 2054 | |
| 2055 | if (localLOGV) Log.v( |
| 2056 | TAG, "Relayout given client " + client.asBinder() |
| 2057 | + " (" + win.mAttrs.getTitle() + ")"); |
| 2058 | |
| 2059 | |
| 2060 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2061 | win.mAlpha = attrs.alpha; |
| 2062 | } |
| 2063 | |
| 2064 | final boolean scaledWindow = |
| 2065 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2066 | |
| 2067 | if (scaledWindow) { |
| 2068 | // requested{Width|Height} Surface's physical size |
| 2069 | // attrs.{width|height} Size on screen |
| 2070 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2071 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2072 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2073 | (attrs.height / (float)requestedHeight) : 1.0f; |
| 2074 | } |
| 2075 | |
| 2076 | boolean imMayMove = (flagChanges&( |
| 2077 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2078 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2079 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2080 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2081 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2082 | || (!win.mRelayoutCalled); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2083 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2084 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2085 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
| 2086 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2087 | win.mRelayoutCalled = true; |
| 2088 | final int oldVisibility = win.mViewVisibility; |
| 2089 | win.mViewVisibility = viewVisibility; |
| 2090 | if (viewVisibility == View.VISIBLE && |
| 2091 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2092 | displayed = !win.isVisibleLw(); |
| 2093 | if (win.mExiting) { |
| 2094 | win.mExiting = false; |
| 2095 | win.mAnimation = null; |
| 2096 | } |
| 2097 | if (win.mDestroying) { |
| 2098 | win.mDestroying = false; |
| 2099 | mDestroySurface.remove(win); |
| 2100 | } |
| 2101 | if (oldVisibility == View.GONE) { |
| 2102 | win.mEnterAnimationPending = true; |
| 2103 | } |
| 2104 | if (displayed && win.mSurface != null && !win.mDrawPending |
| 2105 | && !win.mCommitDrawPending && !mDisplayFrozen) { |
| 2106 | applyEnterAnimationLocked(win); |
| 2107 | } |
| 2108 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2109 | // To change the format, we need to re-build the surface. |
| 2110 | win.destroySurfaceLocked(); |
| 2111 | displayed = true; |
| 2112 | } |
| 2113 | try { |
| 2114 | Surface surface = win.createSurfaceLocked(); |
| 2115 | if (surface != null) { |
| 2116 | outSurface.copyFrom(surface); |
| 2117 | } else { |
| 2118 | outSurface.clear(); |
| 2119 | } |
| 2120 | } catch (Exception e) { |
| 2121 | Log.w(TAG, "Exception thrown when creating surface for client " |
| 2122 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2123 | e); |
| 2124 | Binder.restoreCallingIdentity(origId); |
| 2125 | return 0; |
| 2126 | } |
| 2127 | if (displayed) { |
| 2128 | focusMayChange = true; |
| 2129 | } |
| 2130 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2131 | && mInputMethodWindow == null) { |
| 2132 | mInputMethodWindow = win; |
| 2133 | imMayMove = true; |
| 2134 | } |
| 2135 | } else { |
| 2136 | win.mEnterAnimationPending = false; |
| 2137 | if (win.mSurface != null) { |
| 2138 | // If we are not currently running the exit animation, we |
| 2139 | // need to see about starting one. |
| 2140 | if (!win.mExiting) { |
| 2141 | // Try starting an animation; if there isn't one, we |
| 2142 | // can destroy the surface right away. |
| 2143 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2144 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2145 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2146 | } |
| 2147 | if (win.isWinVisibleLw() && |
| 2148 | applyAnimationLocked(win, transit, false)) { |
| 2149 | win.mExiting = true; |
| 2150 | mKeyWaiter.finishedKey(session, client, true, |
| 2151 | KeyWaiter.RETURN_NOTHING); |
| 2152 | } else if (win.isAnimating()) { |
| 2153 | // Currently in a hide animation... turn this into |
| 2154 | // an exit. |
| 2155 | win.mExiting = true; |
| 2156 | } else { |
| 2157 | if (mInputMethodWindow == win) { |
| 2158 | mInputMethodWindow = null; |
| 2159 | } |
| 2160 | win.destroySurfaceLocked(); |
| 2161 | } |
| 2162 | } |
| 2163 | } |
| 2164 | outSurface.clear(); |
| 2165 | } |
| 2166 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2167 | if (focusMayChange) { |
| 2168 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 2169 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2170 | imMayMove = false; |
| 2171 | } |
| 2172 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2173 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2174 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2175 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2176 | // reassign them at this point if the IM window state gets shuffled |
| 2177 | boolean assignLayers = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2178 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2179 | if (imMayMove) { |
| 2180 | if (moveInputMethodWindowsIfNeededLocked(false)) { |
| 2181 | assignLayers = true; |
| 2182 | } |
| 2183 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2184 | if (wallpaperMayMove) { |
| 2185 | if (adjustWallpaperWindowsLocked()) { |
| 2186 | assignLayers = true; |
| 2187 | } |
| 2188 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2189 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2190 | mLayoutNeeded = true; |
| 2191 | win.mGivenInsetsPending = insetsPending; |
| 2192 | if (assignLayers) { |
| 2193 | assignLayersLocked(); |
| 2194 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2195 | newConfig = updateOrientationFromAppTokensLocked(null, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2196 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2197 | if (displayed && win.mIsWallpaper) { |
| 2198 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
| 2199 | mDisplay.getHeight()); |
| 2200 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2201 | if (win.mAppToken != null) { |
| 2202 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2203 | } |
| 2204 | outFrame.set(win.mFrame); |
| 2205 | outContentInsets.set(win.mContentInsets); |
| 2206 | outVisibleInsets.set(win.mVisibleInsets); |
| 2207 | if (localLOGV) Log.v( |
| 2208 | TAG, "Relayout given client " + client.asBinder() |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2209 | + ", requestedWidth=" + requestedWidth |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2210 | + ", requestedHeight=" + requestedHeight |
| 2211 | + ", viewVisibility=" + viewVisibility |
| 2212 | + "\nRelayout returning frame=" + outFrame |
| 2213 | + ", surface=" + outSurface); |
| 2214 | |
| 2215 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 2216 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2217 | |
| 2218 | inTouchMode = mInTouchMode; |
| 2219 | } |
| 2220 | |
| 2221 | if (newConfig != null) { |
| 2222 | sendNewConfiguration(); |
| 2223 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2224 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2225 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2226 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2227 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2228 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2229 | } |
| 2230 | |
| 2231 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2232 | final long origId = Binder.clearCallingIdentity(); |
| 2233 | synchronized(mWindowMap) { |
| 2234 | WindowState win = windowForClientLocked(session, client); |
| 2235 | if (win != null && win.finishDrawingLocked()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2236 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2237 | adjustWallpaperWindowsLocked(); |
| 2238 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2239 | mLayoutNeeded = true; |
| 2240 | performLayoutAndPlaceSurfacesLocked(); |
| 2241 | } |
| 2242 | } |
| 2243 | Binder.restoreCallingIdentity(origId); |
| 2244 | } |
| 2245 | |
| 2246 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
| 2247 | if (DEBUG_ANIM) Log.v(TAG, "Loading animations: params package=" |
| 2248 | + (lp != null ? lp.packageName : null) |
| 2249 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2250 | if (lp != null && lp.windowAnimations != 0) { |
| 2251 | // If this is a system resource, don't try to load it from the |
| 2252 | // application resources. It is nice to avoid loading application |
| 2253 | // resources if we can. |
| 2254 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2255 | int resId = lp.windowAnimations; |
| 2256 | if ((resId&0xFF000000) == 0x01000000) { |
| 2257 | packageName = "android"; |
| 2258 | } |
| 2259 | if (DEBUG_ANIM) Log.v(TAG, "Loading animations: picked package=" |
| 2260 | + packageName); |
| 2261 | return AttributeCache.instance().get(packageName, resId, |
| 2262 | com.android.internal.R.styleable.WindowAnimation); |
| 2263 | } |
| 2264 | return null; |
| 2265 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2266 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2267 | private void applyEnterAnimationLocked(WindowState win) { |
| 2268 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 2269 | if (win.mEnterAnimationPending) { |
| 2270 | win.mEnterAnimationPending = false; |
| 2271 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 2272 | } |
| 2273 | |
| 2274 | applyAnimationLocked(win, transit, true); |
| 2275 | } |
| 2276 | |
| 2277 | private boolean applyAnimationLocked(WindowState win, |
| 2278 | int transit, boolean isEntrance) { |
| 2279 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 2280 | // If we are trying to apply an animation, but already running |
| 2281 | // an animation of the same type, then just leave that one alone. |
| 2282 | return true; |
| 2283 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2284 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2285 | // Only apply an animation if the display isn't frozen. If it is |
| 2286 | // frozen, there is no reason to animate and it can cause strange |
| 2287 | // artifacts when we unfreeze the display if some different animation |
| 2288 | // is running. |
| 2289 | if (!mDisplayFrozen) { |
| 2290 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 2291 | int attr = -1; |
| 2292 | Animation a = null; |
| 2293 | if (anim != 0) { |
| 2294 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 2295 | } else { |
| 2296 | switch (transit) { |
| 2297 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 2298 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 2299 | break; |
| 2300 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 2301 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 2302 | break; |
| 2303 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 2304 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 2305 | break; |
| 2306 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 2307 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 2308 | break; |
| 2309 | } |
| 2310 | if (attr >= 0) { |
| 2311 | a = loadAnimation(win.mAttrs, attr); |
| 2312 | } |
| 2313 | } |
| 2314 | if (DEBUG_ANIM) Log.v(TAG, "applyAnimation: win=" + win |
| 2315 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 2316 | + " mAnimation=" + win.mAnimation |
| 2317 | + " isEntrance=" + isEntrance); |
| 2318 | if (a != null) { |
| 2319 | if (DEBUG_ANIM) { |
| 2320 | RuntimeException e = new RuntimeException(); |
| 2321 | e.fillInStackTrace(); |
| 2322 | Log.v(TAG, "Loaded animation " + a + " for " + win, e); |
| 2323 | } |
| 2324 | win.setAnimation(a); |
| 2325 | win.mAnimationIsEntrance = isEntrance; |
| 2326 | } |
| 2327 | } else { |
| 2328 | win.clearAnimation(); |
| 2329 | } |
| 2330 | |
| 2331 | return win.mAnimation != null; |
| 2332 | } |
| 2333 | |
| 2334 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 2335 | int anim = 0; |
| 2336 | Context context = mContext; |
| 2337 | if (animAttr >= 0) { |
| 2338 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 2339 | if (ent != null) { |
| 2340 | context = ent.context; |
| 2341 | anim = ent.array.getResourceId(animAttr, 0); |
| 2342 | } |
| 2343 | } |
| 2344 | if (anim != 0) { |
| 2345 | return AnimationUtils.loadAnimation(context, anim); |
| 2346 | } |
| 2347 | return null; |
| 2348 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2349 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2350 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 2351 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 2352 | // Only apply an animation if the display isn't frozen. If it is |
| 2353 | // frozen, there is no reason to animate and it can cause strange |
| 2354 | // artifacts when we unfreeze the display if some different animation |
| 2355 | // is running. |
| 2356 | if (!mDisplayFrozen) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2357 | Animation a; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 2358 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2359 | a = new FadeInOutAnimation(enter); |
| 2360 | if (DEBUG_ANIM) Log.v(TAG, |
| 2361 | "applying FadeInOutAnimation for a window in compatibility mode"); |
| 2362 | } else { |
| 2363 | int animAttr = 0; |
| 2364 | switch (transit) { |
| 2365 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 2366 | animAttr = enter |
| 2367 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 2368 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 2369 | break; |
| 2370 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 2371 | animAttr = enter |
| 2372 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 2373 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 2374 | break; |
| 2375 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 2376 | animAttr = enter |
| 2377 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 2378 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 2379 | break; |
| 2380 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 2381 | animAttr = enter |
| 2382 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 2383 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 2384 | break; |
| 2385 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 2386 | animAttr = enter |
| 2387 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 2388 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 2389 | break; |
| 2390 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 2391 | animAttr = enter |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 2392 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2393 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 2394 | break; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2395 | case WindowManagerPolicy.TRANSIT_WALLPAPER_ACTIVITY_OPEN: |
| 2396 | animAttr = enter |
| 2397 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperActivityOpenEnterAnimation |
| 2398 | : com.android.internal.R.styleable.WindowAnimation_wallpaperActivityOpenExitAnimation; |
| 2399 | break; |
| 2400 | case WindowManagerPolicy.TRANSIT_WALLPAPER_ACTIVITY_CLOSE: |
| 2401 | animAttr = enter |
| 2402 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperActivityCloseEnterAnimation |
| 2403 | : com.android.internal.R.styleable.WindowAnimation_wallpaperActivityCloseExitAnimation; |
| 2404 | break; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2405 | } |
| 2406 | a = loadAnimation(lp, animAttr); |
| 2407 | if (DEBUG_ANIM) Log.v(TAG, "applyAnimation: wtoken=" + wtoken |
| 2408 | + " anim=" + a |
| 2409 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 2410 | + " transit=" + transit); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2411 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2412 | if (a != null) { |
| 2413 | if (DEBUG_ANIM) { |
| 2414 | RuntimeException e = new RuntimeException(); |
| 2415 | e.fillInStackTrace(); |
| 2416 | Log.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
| 2417 | } |
| 2418 | wtoken.setAnimation(a); |
| 2419 | } |
| 2420 | } else { |
| 2421 | wtoken.clearAnimation(); |
| 2422 | } |
| 2423 | |
| 2424 | return wtoken.animation != null; |
| 2425 | } |
| 2426 | |
| 2427 | // ------------------------------------------------------------- |
| 2428 | // Application Window Tokens |
| 2429 | // ------------------------------------------------------------- |
| 2430 | |
| 2431 | public void validateAppTokens(List tokens) { |
| 2432 | int v = tokens.size()-1; |
| 2433 | int m = mAppTokens.size()-1; |
| 2434 | while (v >= 0 && m >= 0) { |
| 2435 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2436 | if (wtoken.removed) { |
| 2437 | m--; |
| 2438 | continue; |
| 2439 | } |
| 2440 | if (tokens.get(v) != wtoken.token) { |
| 2441 | Log.w(TAG, "Tokens out of sync: external is " + tokens.get(v) |
| 2442 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 2443 | } |
| 2444 | v--; |
| 2445 | m--; |
| 2446 | } |
| 2447 | while (v >= 0) { |
| 2448 | Log.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v); |
| 2449 | v--; |
| 2450 | } |
| 2451 | while (m >= 0) { |
| 2452 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2453 | if (!wtoken.removed) { |
| 2454 | Log.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
| 2455 | } |
| 2456 | m--; |
| 2457 | } |
| 2458 | } |
| 2459 | |
| 2460 | boolean checkCallingPermission(String permission, String func) { |
| 2461 | // Quick check: if the calling permission is me, it's all okay. |
| 2462 | if (Binder.getCallingPid() == Process.myPid()) { |
| 2463 | return true; |
| 2464 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2465 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2466 | if (mContext.checkCallingPermission(permission) |
| 2467 | == PackageManager.PERMISSION_GRANTED) { |
| 2468 | return true; |
| 2469 | } |
| 2470 | String msg = "Permission Denial: " + func + " from pid=" |
| 2471 | + Binder.getCallingPid() |
| 2472 | + ", uid=" + Binder.getCallingUid() |
| 2473 | + " requires " + permission; |
| 2474 | Log.w(TAG, msg); |
| 2475 | return false; |
| 2476 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2477 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2478 | AppWindowToken findAppWindowToken(IBinder token) { |
| 2479 | WindowToken wtoken = mTokenMap.get(token); |
| 2480 | if (wtoken == null) { |
| 2481 | return null; |
| 2482 | } |
| 2483 | return wtoken.appWindowToken; |
| 2484 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2485 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2486 | public void addWindowToken(IBinder token, int type) { |
| 2487 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2488 | "addWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2489 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2490 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2491 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2492 | synchronized(mWindowMap) { |
| 2493 | WindowToken wtoken = mTokenMap.get(token); |
| 2494 | if (wtoken != null) { |
| 2495 | Log.w(TAG, "Attempted to add existing input method token: " + token); |
| 2496 | return; |
| 2497 | } |
| 2498 | wtoken = new WindowToken(token, type, true); |
| 2499 | mTokenMap.put(token, wtoken); |
| 2500 | mTokenList.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2501 | if (type == TYPE_WALLPAPER) { |
| 2502 | mWallpaperTokens.add(wtoken); |
| 2503 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2504 | } |
| 2505 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2506 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2507 | public void removeWindowToken(IBinder token) { |
| 2508 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2509 | "removeWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2510 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | final long origId = Binder.clearCallingIdentity(); |
| 2514 | synchronized(mWindowMap) { |
| 2515 | WindowToken wtoken = mTokenMap.remove(token); |
| 2516 | mTokenList.remove(wtoken); |
| 2517 | if (wtoken != null) { |
| 2518 | boolean delayed = false; |
| 2519 | if (!wtoken.hidden) { |
| 2520 | wtoken.hidden = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2521 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2522 | final int N = wtoken.windows.size(); |
| 2523 | boolean changed = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2524 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2525 | for (int i=0; i<N; i++) { |
| 2526 | WindowState win = wtoken.windows.get(i); |
| 2527 | |
| 2528 | if (win.isAnimating()) { |
| 2529 | delayed = true; |
| 2530 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2531 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2532 | if (win.isVisibleNow()) { |
| 2533 | applyAnimationLocked(win, |
| 2534 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 2535 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 2536 | KeyWaiter.RETURN_NOTHING); |
| 2537 | changed = true; |
| 2538 | } |
| 2539 | } |
| 2540 | |
| 2541 | if (changed) { |
| 2542 | mLayoutNeeded = true; |
| 2543 | performLayoutAndPlaceSurfacesLocked(); |
| 2544 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2545 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2546 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2547 | if (delayed) { |
| 2548 | mExitingTokens.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2549 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 2550 | mWallpaperTokens.remove(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2551 | } |
| 2552 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2553 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2554 | } else { |
| 2555 | Log.w(TAG, "Attempted to remove non-existing token: " + token); |
| 2556 | } |
| 2557 | } |
| 2558 | Binder.restoreCallingIdentity(origId); |
| 2559 | } |
| 2560 | |
| 2561 | public void addAppToken(int addPos, IApplicationToken token, |
| 2562 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 2563 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2564 | "addAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2565 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2566 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2567 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2568 | synchronized(mWindowMap) { |
| 2569 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 2570 | if (wtoken != null) { |
| 2571 | Log.w(TAG, "Attempted to add existing app token: " + token); |
| 2572 | return; |
| 2573 | } |
| 2574 | wtoken = new AppWindowToken(token); |
| 2575 | wtoken.groupId = groupId; |
| 2576 | wtoken.appFullscreen = fullscreen; |
| 2577 | wtoken.requestedOrientation = requestedOrientation; |
| 2578 | mAppTokens.add(addPos, wtoken); |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 2579 | 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] | 2580 | mTokenMap.put(token.asBinder(), wtoken); |
| 2581 | mTokenList.add(wtoken); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2582 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2583 | // Application tokens start out hidden. |
| 2584 | wtoken.hidden = true; |
| 2585 | wtoken.hiddenRequested = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2586 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2587 | //dump(); |
| 2588 | } |
| 2589 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2590 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2591 | public void setAppGroupId(IBinder token, int groupId) { |
| 2592 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2593 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2594 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2595 | } |
| 2596 | |
| 2597 | synchronized(mWindowMap) { |
| 2598 | AppWindowToken wtoken = findAppWindowToken(token); |
| 2599 | if (wtoken == null) { |
| 2600 | Log.w(TAG, "Attempted to set group id of non-existing app token: " + token); |
| 2601 | return; |
| 2602 | } |
| 2603 | wtoken.groupId = groupId; |
| 2604 | } |
| 2605 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2606 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2607 | public int getOrientationFromWindowsLocked() { |
| 2608 | int pos = mWindows.size() - 1; |
| 2609 | while (pos >= 0) { |
| 2610 | WindowState wtoken = (WindowState) mWindows.get(pos); |
| 2611 | pos--; |
| 2612 | if (wtoken.mAppToken != null) { |
| 2613 | // We hit an application window. so the orientation will be determined by the |
| 2614 | // app window. No point in continuing further. |
| 2615 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2616 | } |
| 2617 | if (!wtoken.isVisibleLw()) { |
| 2618 | continue; |
| 2619 | } |
| 2620 | int req = wtoken.mAttrs.screenOrientation; |
| 2621 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 2622 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 2623 | continue; |
| 2624 | } else { |
| 2625 | return req; |
| 2626 | } |
| 2627 | } |
| 2628 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2629 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2630 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2631 | public int getOrientationFromAppTokensLocked() { |
| 2632 | int pos = mAppTokens.size() - 1; |
| 2633 | int curGroup = 0; |
| 2634 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2635 | boolean findingBehind = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2636 | boolean haveGroup = false; |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2637 | boolean lastFullscreen = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2638 | while (pos >= 0) { |
| 2639 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 2640 | pos--; |
| Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2641 | // if we're about to tear down this window and not seek for |
| 2642 | // the behind activity, don't use it for orientation |
| 2643 | if (!findingBehind |
| 2644 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2645 | continue; |
| 2646 | } |
| 2647 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2648 | if (!haveGroup) { |
| 2649 | // We ignore any hidden applications on the top. |
| 2650 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
| 2651 | continue; |
| 2652 | } |
| 2653 | haveGroup = true; |
| 2654 | curGroup = wtoken.groupId; |
| 2655 | lastOrientation = wtoken.requestedOrientation; |
| 2656 | } else if (curGroup != wtoken.groupId) { |
| 2657 | // If we have hit a new application group, and the bottom |
| 2658 | // 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] | 2659 | // the orientation behind it, and the last app was |
| 2660 | // full screen, then we'll stick with the |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2661 | // user's orientation. |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2662 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 2663 | && lastFullscreen) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2664 | return lastOrientation; |
| 2665 | } |
| 2666 | } |
| 2667 | int or = wtoken.requestedOrientation; |
| Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2668 | // If this application is fullscreen, and didn't explicitly say |
| 2669 | // 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] | 2670 | // orientation it has and ignores whatever is under it. |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2671 | lastFullscreen = wtoken.appFullscreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2672 | if (lastFullscreen |
| Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2673 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2674 | return or; |
| 2675 | } |
| 2676 | // If this application has requested an explicit orientation, |
| 2677 | // then use it. |
| 2678 | if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || |
| 2679 | or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || |
| 2680 | or == ActivityInfo.SCREEN_ORIENTATION_SENSOR || |
| 2681 | or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR || |
| 2682 | or == ActivityInfo.SCREEN_ORIENTATION_USER) { |
| 2683 | return or; |
| 2684 | } |
| Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2685 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2686 | } |
| 2687 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2688 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2689 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2690 | public Configuration updateOrientationFromAppTokens( |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2691 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2692 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2693 | "updateOrientationFromAppTokens()")) { |
| 2694 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 2695 | } |
| 2696 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2697 | Configuration config; |
| 2698 | long ident = Binder.clearCallingIdentity(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2699 | config = updateOrientationFromAppTokensUnchecked(currentConfig, |
| 2700 | freezeThisOneIfNeeded); |
| 2701 | Binder.restoreCallingIdentity(ident); |
| 2702 | return config; |
| 2703 | } |
| 2704 | |
| 2705 | Configuration updateOrientationFromAppTokensUnchecked( |
| 2706 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| 2707 | Configuration config; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2708 | synchronized(mWindowMap) { |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2709 | config = updateOrientationFromAppTokensLocked(currentConfig, freezeThisOneIfNeeded); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2710 | } |
| 2711 | if (config != null) { |
| 2712 | mLayoutNeeded = true; |
| 2713 | performLayoutAndPlaceSurfacesLocked(); |
| 2714 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2715 | return config; |
| 2716 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2717 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2718 | /* |
| 2719 | * The orientation is computed from non-application windows first. If none of |
| 2720 | * the non-application windows specify orientation, the orientation is computed from |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2721 | * application tokens. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2722 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 2723 | * android.os.IBinder) |
| 2724 | */ |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2725 | Configuration updateOrientationFromAppTokensLocked( |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2726 | Configuration appConfig, IBinder freezeThisOneIfNeeded) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2727 | boolean changed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2728 | long ident = Binder.clearCallingIdentity(); |
| 2729 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2730 | int req = computeForcedAppOrientationLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2731 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2732 | if (req != mForcedAppOrientation) { |
| 2733 | changed = true; |
| 2734 | mForcedAppOrientation = req; |
| 2735 | //send a message to Policy indicating orientation change to take |
| 2736 | //action like disabling/enabling sensors etc., |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2737 | mPolicy.setCurrentOrientationLw(req); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2738 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2739 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2740 | if (changed) { |
| 2741 | changed = setRotationUncheckedLocked( |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 2742 | WindowManagerPolicy.USE_LAST_ROTATION, |
| 2743 | mLastRotationFlags & (~Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2744 | if (changed) { |
| 2745 | if (freezeThisOneIfNeeded != null) { |
| 2746 | AppWindowToken wtoken = findAppWindowToken( |
| 2747 | freezeThisOneIfNeeded); |
| 2748 | if (wtoken != null) { |
| 2749 | startAppFreezingScreenLocked(wtoken, |
| 2750 | ActivityInfo.CONFIG_ORIENTATION); |
| 2751 | } |
| 2752 | } |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 2753 | return computeNewConfigurationLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2754 | } |
| 2755 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2756 | |
| 2757 | // No obvious action we need to take, but if our current |
| 2758 | // state mismatches the activity maanager's, update it |
| 2759 | if (appConfig != null) { |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 2760 | mTempConfiguration.setToDefaults(); |
| 2761 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 2762 | if (appConfig.diff(mTempConfiguration) != 0) { |
| 2763 | Log.i(TAG, "Config changed: " + mTempConfiguration); |
| 2764 | return new Configuration(mTempConfiguration); |
| 2765 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2766 | } |
| 2767 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2768 | } finally { |
| 2769 | Binder.restoreCallingIdentity(ident); |
| 2770 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2771 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2772 | return null; |
| 2773 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2774 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2775 | int computeForcedAppOrientationLocked() { |
| 2776 | int req = getOrientationFromWindowsLocked(); |
| 2777 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 2778 | req = getOrientationFromAppTokensLocked(); |
| 2779 | } |
| 2780 | return req; |
| 2781 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2782 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2783 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 2784 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2785 | "setAppOrientation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2786 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2787 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2788 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2789 | synchronized(mWindowMap) { |
| 2790 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 2791 | if (wtoken == null) { |
| 2792 | Log.w(TAG, "Attempted to set orientation of non-existing app token: " + token); |
| 2793 | return; |
| 2794 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2795 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2796 | wtoken.requestedOrientation = requestedOrientation; |
| 2797 | } |
| 2798 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2799 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2800 | public int getAppOrientation(IApplicationToken token) { |
| 2801 | synchronized(mWindowMap) { |
| 2802 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 2803 | if (wtoken == null) { |
| 2804 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2805 | } |
| 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 | return wtoken.requestedOrientation; |
| 2808 | } |
| 2809 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2810 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2811 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 2812 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2813 | "setFocusedApp()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2814 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2815 | } |
| 2816 | |
| 2817 | synchronized(mWindowMap) { |
| 2818 | boolean changed = false; |
| 2819 | if (token == null) { |
| 2820 | if (DEBUG_FOCUS) Log.v(TAG, "Clearing focused app, was " + mFocusedApp); |
| 2821 | changed = mFocusedApp != null; |
| 2822 | mFocusedApp = null; |
| 2823 | mKeyWaiter.tickle(); |
| 2824 | } else { |
| 2825 | AppWindowToken newFocus = findAppWindowToken(token); |
| 2826 | if (newFocus == null) { |
| 2827 | Log.w(TAG, "Attempted to set focus to non-existing app token: " + token); |
| 2828 | return; |
| 2829 | } |
| 2830 | changed = mFocusedApp != newFocus; |
| 2831 | mFocusedApp = newFocus; |
| 2832 | if (DEBUG_FOCUS) Log.v(TAG, "Set focused app to: " + mFocusedApp); |
| 2833 | mKeyWaiter.tickle(); |
| 2834 | } |
| 2835 | |
| 2836 | if (moveFocusNow && changed) { |
| 2837 | final long origId = Binder.clearCallingIdentity(); |
| 2838 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2839 | Binder.restoreCallingIdentity(origId); |
| 2840 | } |
| 2841 | } |
| 2842 | } |
| 2843 | |
| 2844 | public void prepareAppTransition(int transit) { |
| 2845 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2846 | "prepareAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2847 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2848 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2849 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2850 | synchronized(mWindowMap) { |
| 2851 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 2852 | TAG, "Prepare app transition: transit=" + transit |
| 2853 | + " mNextAppTransition=" + mNextAppTransition); |
| 2854 | if (!mDisplayFrozen) { |
| 2855 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
| 2856 | mNextAppTransition = transit; |
| Dianne Hackborn | d7cd29d | 2009-07-01 11:22:45 -0700 | [diff] [blame] | 2857 | } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 2858 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 2859 | // Opening a new task always supersedes a close for the anim. |
| 2860 | mNextAppTransition = transit; |
| 2861 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 2862 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 2863 | // Opening a new activity always supersedes a close for the anim. |
| 2864 | mNextAppTransition = transit; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2865 | } |
| 2866 | mAppTransitionReady = false; |
| 2867 | mAppTransitionTimeout = false; |
| 2868 | mStartingIconInTransition = false; |
| 2869 | mSkipAppTransitionAnimation = false; |
| 2870 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 2871 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 2872 | 5000); |
| 2873 | } |
| 2874 | } |
| 2875 | } |
| 2876 | |
| 2877 | public int getPendingAppTransition() { |
| 2878 | return mNextAppTransition; |
| 2879 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2880 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2881 | public void executeAppTransition() { |
| 2882 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2883 | "executeAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2884 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2885 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2886 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2887 | synchronized(mWindowMap) { |
| 2888 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 2889 | TAG, "Execute app transition: mNextAppTransition=" + mNextAppTransition); |
| 2890 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) { |
| 2891 | mAppTransitionReady = true; |
| 2892 | final long origId = Binder.clearCallingIdentity(); |
| 2893 | performLayoutAndPlaceSurfacesLocked(); |
| 2894 | Binder.restoreCallingIdentity(origId); |
| 2895 | } |
| 2896 | } |
| 2897 | } |
| 2898 | |
| 2899 | public void setAppStartingWindow(IBinder token, String pkg, |
| 2900 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| 2901 | IBinder transferFrom, boolean createIfNeeded) { |
| 2902 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2903 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2904 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2905 | } |
| 2906 | |
| 2907 | synchronized(mWindowMap) { |
| 2908 | if (DEBUG_STARTING_WINDOW) Log.v( |
| 2909 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 2910 | + " transferFrom=" + transferFrom); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2911 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2912 | AppWindowToken wtoken = findAppWindowToken(token); |
| 2913 | if (wtoken == null) { |
| 2914 | Log.w(TAG, "Attempted to set icon of non-existing app token: " + token); |
| 2915 | return; |
| 2916 | } |
| 2917 | |
| 2918 | // If the display is frozen, we won't do anything until the |
| 2919 | // actual window is displayed so there is no reason to put in |
| 2920 | // the starting window. |
| 2921 | if (mDisplayFrozen) { |
| 2922 | return; |
| 2923 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2924 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2925 | if (wtoken.startingData != null) { |
| 2926 | return; |
| 2927 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2928 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2929 | if (transferFrom != null) { |
| 2930 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 2931 | if (ttoken != null) { |
| 2932 | WindowState startingWindow = ttoken.startingWindow; |
| 2933 | if (startingWindow != null) { |
| 2934 | if (mStartingIconInTransition) { |
| 2935 | // In this case, the starting icon has already |
| 2936 | // been displayed, so start letting windows get |
| 2937 | // shown immediately without any more transitions. |
| 2938 | mSkipAppTransitionAnimation = true; |
| 2939 | } |
| 2940 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 2941 | "Moving existing starting from " + ttoken |
| 2942 | + " to " + wtoken); |
| 2943 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2944 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2945 | // Transfer the starting window over to the new |
| 2946 | // token. |
| 2947 | wtoken.startingData = ttoken.startingData; |
| 2948 | wtoken.startingView = ttoken.startingView; |
| 2949 | wtoken.startingWindow = startingWindow; |
| 2950 | ttoken.startingData = null; |
| 2951 | ttoken.startingView = null; |
| 2952 | ttoken.startingWindow = null; |
| 2953 | ttoken.startingMoved = true; |
| 2954 | startingWindow.mToken = wtoken; |
| Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 2955 | startingWindow.mRootToken = wtoken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2956 | startingWindow.mAppToken = wtoken; |
| 2957 | mWindows.remove(startingWindow); |
| 2958 | ttoken.windows.remove(startingWindow); |
| 2959 | ttoken.allAppWindows.remove(startingWindow); |
| 2960 | addWindowToListInOrderLocked(startingWindow, true); |
| 2961 | wtoken.allAppWindows.add(startingWindow); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2962 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2963 | // Propagate other interesting state between the |
| 2964 | // tokens. If the old token is displayed, we should |
| 2965 | // immediately force the new one to be displayed. If |
| 2966 | // it is animating, we need to move that animation to |
| 2967 | // the new one. |
| 2968 | if (ttoken.allDrawn) { |
| 2969 | wtoken.allDrawn = true; |
| 2970 | } |
| 2971 | if (ttoken.firstWindowDrawn) { |
| 2972 | wtoken.firstWindowDrawn = true; |
| 2973 | } |
| 2974 | if (!ttoken.hidden) { |
| 2975 | wtoken.hidden = false; |
| 2976 | wtoken.hiddenRequested = false; |
| 2977 | wtoken.willBeHidden = false; |
| 2978 | } |
| 2979 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 2980 | wtoken.clientHidden = ttoken.clientHidden; |
| 2981 | wtoken.sendAppVisibilityToClients(); |
| 2982 | } |
| 2983 | if (ttoken.animation != null) { |
| 2984 | wtoken.animation = ttoken.animation; |
| 2985 | wtoken.animating = ttoken.animating; |
| 2986 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 2987 | ttoken.animation = null; |
| 2988 | ttoken.animLayerAdjustment = 0; |
| 2989 | wtoken.updateLayers(); |
| 2990 | ttoken.updateLayers(); |
| 2991 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2992 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2993 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2994 | mLayoutNeeded = true; |
| 2995 | performLayoutAndPlaceSurfacesLocked(); |
| 2996 | Binder.restoreCallingIdentity(origId); |
| 2997 | return; |
| 2998 | } else if (ttoken.startingData != null) { |
| 2999 | // The previous app was getting ready to show a |
| 3000 | // starting window, but hasn't yet done so. Steal it! |
| 3001 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 3002 | "Moving pending starting from " + ttoken |
| 3003 | + " to " + wtoken); |
| 3004 | wtoken.startingData = ttoken.startingData; |
| 3005 | ttoken.startingData = null; |
| 3006 | ttoken.startingMoved = true; |
| 3007 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3008 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3009 | // want to process the message ASAP, before any other queued |
| 3010 | // messages. |
| 3011 | mH.sendMessageAtFrontOfQueue(m); |
| 3012 | return; |
| 3013 | } |
| 3014 | } |
| 3015 | } |
| 3016 | |
| 3017 | // There is no existing starting window, and the caller doesn't |
| 3018 | // want us to create one, so that's it! |
| 3019 | if (!createIfNeeded) { |
| 3020 | return; |
| 3021 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3022 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3023 | // If this is a translucent or wallpaper window, then don't |
| 3024 | // show a starting window -- the current effect (a full-screen |
| 3025 | // opaque starting window that fades away to the real contents |
| 3026 | // when it is ready) does not work for this. |
| 3027 | if (theme != 0) { |
| 3028 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3029 | com.android.internal.R.styleable.Window); |
| 3030 | if (ent.array.getBoolean( |
| 3031 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3032 | return; |
| 3033 | } |
| 3034 | if (ent.array.getBoolean( |
| 3035 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3036 | return; |
| 3037 | } |
| 3038 | } |
| 3039 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3040 | mStartingIconInTransition = true; |
| 3041 | wtoken.startingData = new StartingData( |
| 3042 | pkg, theme, nonLocalizedLabel, |
| 3043 | labelRes, icon); |
| 3044 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3045 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3046 | // want to process the message ASAP, before any other queued |
| 3047 | // messages. |
| 3048 | mH.sendMessageAtFrontOfQueue(m); |
| 3049 | } |
| 3050 | } |
| 3051 | |
| 3052 | public void setAppWillBeHidden(IBinder token) { |
| 3053 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3054 | "setAppWillBeHidden()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3055 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3056 | } |
| 3057 | |
| 3058 | AppWindowToken wtoken; |
| 3059 | |
| 3060 | synchronized(mWindowMap) { |
| 3061 | wtoken = findAppWindowToken(token); |
| 3062 | if (wtoken == null) { |
| 3063 | Log.w(TAG, "Attempted to set will be hidden of non-existing app token: " + token); |
| 3064 | return; |
| 3065 | } |
| 3066 | wtoken.willBeHidden = true; |
| 3067 | } |
| 3068 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3069 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3070 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3071 | boolean visible, int transit, boolean performLayout) { |
| 3072 | boolean delayed = false; |
| 3073 | |
| 3074 | if (wtoken.clientHidden == visible) { |
| 3075 | wtoken.clientHidden = !visible; |
| 3076 | wtoken.sendAppVisibilityToClients(); |
| 3077 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3078 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3079 | wtoken.willBeHidden = false; |
| 3080 | if (wtoken.hidden == visible) { |
| 3081 | final int N = wtoken.allAppWindows.size(); |
| 3082 | boolean changed = false; |
| 3083 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 3084 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3085 | + " performLayout=" + performLayout); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3086 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3087 | boolean runningAppAnimation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3088 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3089 | if (transit != WindowManagerPolicy.TRANSIT_NONE) { |
| 3090 | if (wtoken.animation == sDummyAnimation) { |
| 3091 | wtoken.animation = null; |
| 3092 | } |
| 3093 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3094 | changed = true; |
| 3095 | if (wtoken.animation != null) { |
| 3096 | delayed = runningAppAnimation = true; |
| 3097 | } |
| 3098 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3099 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3100 | for (int i=0; i<N; i++) { |
| 3101 | WindowState win = wtoken.allAppWindows.get(i); |
| 3102 | if (win == wtoken.startingWindow) { |
| 3103 | continue; |
| 3104 | } |
| 3105 | |
| 3106 | if (win.isAnimating()) { |
| 3107 | delayed = true; |
| 3108 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3109 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3110 | //Log.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
| 3111 | //win.dump(" "); |
| 3112 | if (visible) { |
| 3113 | if (!win.isVisibleNow()) { |
| 3114 | if (!runningAppAnimation) { |
| 3115 | applyAnimationLocked(win, |
| 3116 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3117 | } |
| 3118 | changed = true; |
| 3119 | } |
| 3120 | } else if (win.isVisibleNow()) { |
| 3121 | if (!runningAppAnimation) { |
| 3122 | applyAnimationLocked(win, |
| 3123 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3124 | } |
| 3125 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 3126 | KeyWaiter.RETURN_NOTHING); |
| 3127 | changed = true; |
| 3128 | } |
| 3129 | } |
| 3130 | |
| 3131 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3132 | if (!visible) { |
| 3133 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3134 | } else { |
| 3135 | // If we are being set visible, and the starting window is |
| 3136 | // not yet displayed, then make sure it doesn't get displayed. |
| 3137 | WindowState swin = wtoken.startingWindow; |
| 3138 | if (swin != null && (swin.mDrawPending |
| 3139 | || swin.mCommitDrawPending)) { |
| 3140 | swin.mPolicyVisibility = false; |
| 3141 | swin.mPolicyVisibilityAfterAnim = false; |
| 3142 | } |
| 3143 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3144 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3145 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "setTokenVisibilityLocked: " + wtoken |
| 3146 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3147 | + wtoken.hiddenRequested); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3148 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3149 | if (changed && performLayout) { |
| 3150 | mLayoutNeeded = true; |
| 3151 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3152 | performLayoutAndPlaceSurfacesLocked(); |
| 3153 | } |
| 3154 | } |
| 3155 | |
| 3156 | if (wtoken.animation != null) { |
| 3157 | delayed = true; |
| 3158 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3159 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3160 | return delayed; |
| 3161 | } |
| 3162 | |
| 3163 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3164 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3165 | "setAppVisibility()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3166 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3167 | } |
| 3168 | |
| 3169 | AppWindowToken wtoken; |
| 3170 | |
| 3171 | synchronized(mWindowMap) { |
| 3172 | wtoken = findAppWindowToken(token); |
| 3173 | if (wtoken == null) { |
| 3174 | Log.w(TAG, "Attempted to set visibility of non-existing app token: " + token); |
| 3175 | return; |
| 3176 | } |
| 3177 | |
| 3178 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
| 3179 | RuntimeException e = new RuntimeException(); |
| 3180 | e.fillInStackTrace(); |
| 3181 | Log.v(TAG, "setAppVisibility(" + token + ", " + visible |
| 3182 | + "): mNextAppTransition=" + mNextAppTransition |
| 3183 | + " hidden=" + wtoken.hidden |
| 3184 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3185 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3186 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3187 | // If we are preparing an app transition, then delay changing |
| 3188 | // the visibility of this token until we execute that transition. |
| 3189 | if (!mDisplayFrozen && mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) { |
| 3190 | // Already in requested state, don't do anything more. |
| 3191 | if (wtoken.hiddenRequested != visible) { |
| 3192 | return; |
| 3193 | } |
| 3194 | wtoken.hiddenRequested = !visible; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3195 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3196 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 3197 | TAG, "Setting dummy animation on: " + wtoken); |
| 3198 | wtoken.setDummyAnimation(); |
| 3199 | mOpeningApps.remove(wtoken); |
| 3200 | mClosingApps.remove(wtoken); |
| 3201 | wtoken.inPendingTransaction = true; |
| 3202 | if (visible) { |
| 3203 | mOpeningApps.add(wtoken); |
| 3204 | wtoken.allDrawn = false; |
| 3205 | wtoken.startingDisplayed = false; |
| 3206 | wtoken.startingMoved = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3207 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3208 | if (wtoken.clientHidden) { |
| 3209 | // In the case where we are making an app visible |
| 3210 | // but holding off for a transition, we still need |
| 3211 | // to tell the client to make its windows visible so |
| 3212 | // they get drawn. Otherwise, we will wait on |
| 3213 | // performing the transition until all windows have |
| 3214 | // been drawn, they never will be, and we are sad. |
| 3215 | wtoken.clientHidden = false; |
| 3216 | wtoken.sendAppVisibilityToClients(); |
| 3217 | } |
| 3218 | } else { |
| 3219 | mClosingApps.add(wtoken); |
| 3220 | } |
| 3221 | return; |
| 3222 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3223 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3224 | final long origId = Binder.clearCallingIdentity(); |
| 3225 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_NONE, true); |
| 3226 | wtoken.updateReportedVisibilityLocked(); |
| 3227 | Binder.restoreCallingIdentity(origId); |
| 3228 | } |
| 3229 | } |
| 3230 | |
| 3231 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3232 | boolean unfreezeSurfaceNow, boolean force) { |
| 3233 | if (wtoken.freezingScreen) { |
| 3234 | if (DEBUG_ORIENTATION) Log.v(TAG, "Clear freezing of " + wtoken |
| 3235 | + " force=" + force); |
| 3236 | final int N = wtoken.allAppWindows.size(); |
| 3237 | boolean unfrozeWindows = false; |
| 3238 | for (int i=0; i<N; i++) { |
| 3239 | WindowState w = wtoken.allAppWindows.get(i); |
| 3240 | if (w.mAppFreezing) { |
| 3241 | w.mAppFreezing = false; |
| 3242 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 3243 | w.mOrientationChanging = true; |
| 3244 | } |
| 3245 | unfrozeWindows = true; |
| 3246 | } |
| 3247 | } |
| 3248 | if (force || unfrozeWindows) { |
| 3249 | if (DEBUG_ORIENTATION) Log.v(TAG, "No longer freezing: " + wtoken); |
| 3250 | wtoken.freezingScreen = false; |
| 3251 | mAppsFreezingScreen--; |
| 3252 | } |
| 3253 | if (unfreezeSurfaceNow) { |
| 3254 | if (unfrozeWindows) { |
| 3255 | mLayoutNeeded = true; |
| 3256 | performLayoutAndPlaceSurfacesLocked(); |
| 3257 | } |
| 3258 | if (mAppsFreezingScreen == 0 && !mWindowsFreezingScreen) { |
| 3259 | stopFreezingDisplayLocked(); |
| 3260 | } |
| 3261 | } |
| 3262 | } |
| 3263 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3264 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3265 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3266 | int configChanges) { |
| 3267 | if (DEBUG_ORIENTATION) { |
| 3268 | RuntimeException e = new RuntimeException(); |
| 3269 | e.fillInStackTrace(); |
| 3270 | Log.i(TAG, "Set freezing of " + wtoken.appToken |
| 3271 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 3272 | + wtoken.freezingScreen, e); |
| 3273 | } |
| 3274 | if (!wtoken.hiddenRequested) { |
| 3275 | if (!wtoken.freezingScreen) { |
| 3276 | wtoken.freezingScreen = true; |
| 3277 | mAppsFreezingScreen++; |
| 3278 | if (mAppsFreezingScreen == 1) { |
| 3279 | startFreezingDisplayLocked(); |
| 3280 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 3281 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 3282 | 5000); |
| 3283 | } |
| 3284 | } |
| 3285 | final int N = wtoken.allAppWindows.size(); |
| 3286 | for (int i=0; i<N; i++) { |
| 3287 | WindowState w = wtoken.allAppWindows.get(i); |
| 3288 | w.mAppFreezing = true; |
| 3289 | } |
| 3290 | } |
| 3291 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3292 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3293 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 3294 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3295 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3296 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3297 | } |
| 3298 | |
| 3299 | synchronized(mWindowMap) { |
| 3300 | if (configChanges == 0 && !mDisplayFrozen) { |
| 3301 | if (DEBUG_ORIENTATION) Log.v(TAG, "Skipping set freeze of " + token); |
| 3302 | return; |
| 3303 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3304 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3305 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3306 | if (wtoken == null || wtoken.appToken == null) { |
| 3307 | Log.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken); |
| 3308 | return; |
| 3309 | } |
| 3310 | final long origId = Binder.clearCallingIdentity(); |
| 3311 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 3312 | Binder.restoreCallingIdentity(origId); |
| 3313 | } |
| 3314 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3315 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3316 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 3317 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3318 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3319 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3320 | } |
| 3321 | |
| 3322 | synchronized(mWindowMap) { |
| 3323 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3324 | if (wtoken == null || wtoken.appToken == null) { |
| 3325 | return; |
| 3326 | } |
| 3327 | final long origId = Binder.clearCallingIdentity(); |
| 3328 | if (DEBUG_ORIENTATION) Log.v(TAG, "Clear freezing of " + token |
| 3329 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 3330 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 3331 | Binder.restoreCallingIdentity(origId); |
| 3332 | } |
| 3333 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3334 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3335 | public void removeAppToken(IBinder token) { |
| 3336 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3337 | "removeAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3338 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3339 | } |
| 3340 | |
| 3341 | AppWindowToken wtoken = null; |
| 3342 | AppWindowToken startingToken = null; |
| 3343 | boolean delayed = false; |
| 3344 | |
| 3345 | final long origId = Binder.clearCallingIdentity(); |
| 3346 | synchronized(mWindowMap) { |
| 3347 | WindowToken basewtoken = mTokenMap.remove(token); |
| 3348 | mTokenList.remove(basewtoken); |
| 3349 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
| 3350 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "Removing app token: " + wtoken); |
| 3351 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_NONE, true); |
| 3352 | wtoken.inPendingTransaction = false; |
| 3353 | mOpeningApps.remove(wtoken); |
| 3354 | if (mClosingApps.contains(wtoken)) { |
| 3355 | delayed = true; |
| 3356 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) { |
| 3357 | mClosingApps.add(wtoken); |
| 3358 | delayed = true; |
| 3359 | } |
| 3360 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 3361 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 3362 | + " animation=" + wtoken.animation |
| 3363 | + " animating=" + wtoken.animating); |
| 3364 | if (delayed) { |
| 3365 | // set the token aside because it has an active animation to be finished |
| 3366 | mExitingAppTokens.add(wtoken); |
| 3367 | } |
| 3368 | mAppTokens.remove(wtoken); |
| 3369 | wtoken.removed = true; |
| 3370 | if (wtoken.startingData != null) { |
| 3371 | startingToken = wtoken; |
| 3372 | } |
| 3373 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3374 | if (mFocusedApp == wtoken) { |
| 3375 | if (DEBUG_FOCUS) Log.v(TAG, "Removing focused app token:" + wtoken); |
| 3376 | mFocusedApp = null; |
| 3377 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3378 | mKeyWaiter.tickle(); |
| 3379 | } |
| 3380 | } else { |
| 3381 | Log.w(TAG, "Attempted to remove non-existing app token: " + token); |
| 3382 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3383 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3384 | if (!delayed && wtoken != null) { |
| 3385 | wtoken.updateReportedVisibilityLocked(); |
| 3386 | } |
| 3387 | } |
| 3388 | Binder.restoreCallingIdentity(origId); |
| 3389 | |
| 3390 | if (startingToken != null) { |
| 3391 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Schedule remove starting " |
| 3392 | + startingToken + ": app token removed"); |
| 3393 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 3394 | mH.sendMessage(m); |
| 3395 | } |
| 3396 | } |
| 3397 | |
| 3398 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 3399 | final int NW = token.windows.size(); |
| 3400 | for (int i=0; i<NW; i++) { |
| 3401 | WindowState win = token.windows.get(i); |
| 3402 | mWindows.remove(win); |
| 3403 | int j = win.mChildWindows.size(); |
| 3404 | while (j > 0) { |
| 3405 | j--; |
| 3406 | mWindows.remove(win.mChildWindows.get(j)); |
| 3407 | } |
| 3408 | } |
| 3409 | return NW > 0; |
| 3410 | } |
| 3411 | |
| 3412 | void dumpAppTokensLocked() { |
| 3413 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| 3414 | Log.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
| 3415 | } |
| 3416 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3417 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3418 | void dumpWindowsLocked() { |
| 3419 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 3420 | Log.v(TAG, " #" + i + ": " + mWindows.get(i)); |
| 3421 | } |
| 3422 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3423 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3424 | private int findWindowOffsetLocked(int tokenPos) { |
| 3425 | final int NW = mWindows.size(); |
| 3426 | |
| 3427 | if (tokenPos >= mAppTokens.size()) { |
| 3428 | int i = NW; |
| 3429 | while (i > 0) { |
| 3430 | i--; |
| 3431 | WindowState win = (WindowState)mWindows.get(i); |
| 3432 | if (win.getAppToken() != null) { |
| 3433 | return i+1; |
| 3434 | } |
| 3435 | } |
| 3436 | } |
| 3437 | |
| 3438 | while (tokenPos > 0) { |
| 3439 | // Find the first app token below the new position that has |
| 3440 | // a window displayed. |
| 3441 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
| 3442 | if (DEBUG_REORDER) Log.v(TAG, "Looking for lower windows @ " |
| 3443 | + tokenPos + " -- " + wtoken.token); |
| 3444 | int i = wtoken.windows.size(); |
| 3445 | while (i > 0) { |
| 3446 | i--; |
| 3447 | WindowState win = wtoken.windows.get(i); |
| 3448 | int j = win.mChildWindows.size(); |
| 3449 | while (j > 0) { |
| 3450 | j--; |
| 3451 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| 3452 | if (cwin.mSubLayer >= 0 ) { |
| 3453 | for (int pos=NW-1; pos>=0; pos--) { |
| 3454 | if (mWindows.get(pos) == cwin) { |
| 3455 | if (DEBUG_REORDER) Log.v(TAG, |
| 3456 | "Found child win @" + (pos+1)); |
| 3457 | return pos+1; |
| 3458 | } |
| 3459 | } |
| 3460 | } |
| 3461 | } |
| 3462 | for (int pos=NW-1; pos>=0; pos--) { |
| 3463 | if (mWindows.get(pos) == win) { |
| 3464 | if (DEBUG_REORDER) Log.v(TAG, "Found win @" + (pos+1)); |
| 3465 | return pos+1; |
| 3466 | } |
| 3467 | } |
| 3468 | } |
| 3469 | tokenPos--; |
| 3470 | } |
| 3471 | |
| 3472 | return 0; |
| 3473 | } |
| 3474 | |
| 3475 | private final int reAddWindowLocked(int index, WindowState win) { |
| 3476 | final int NCW = win.mChildWindows.size(); |
| 3477 | boolean added = false; |
| 3478 | for (int j=0; j<NCW; j++) { |
| 3479 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| 3480 | if (!added && cwin.mSubLayer >= 0) { |
| 3481 | mWindows.add(index, win); |
| 3482 | index++; |
| 3483 | added = true; |
| 3484 | } |
| 3485 | mWindows.add(index, cwin); |
| 3486 | index++; |
| 3487 | } |
| 3488 | if (!added) { |
| 3489 | mWindows.add(index, win); |
| 3490 | index++; |
| 3491 | } |
| 3492 | return index; |
| 3493 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3494 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3495 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 3496 | final int NW = token.windows.size(); |
| 3497 | for (int i=0; i<NW; i++) { |
| 3498 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 3499 | } |
| 3500 | return index; |
| 3501 | } |
| 3502 | |
| 3503 | public void moveAppToken(int index, IBinder token) { |
| 3504 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3505 | "moveAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3506 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3507 | } |
| 3508 | |
| 3509 | synchronized(mWindowMap) { |
| 3510 | if (DEBUG_REORDER) Log.v(TAG, "Initial app tokens:"); |
| 3511 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 3512 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 3513 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
| 3514 | Log.w(TAG, "Attempting to reorder token that doesn't exist: " |
| 3515 | + token + " (" + wtoken + ")"); |
| 3516 | return; |
| 3517 | } |
| 3518 | mAppTokens.add(index, wtoken); |
| 3519 | if (DEBUG_REORDER) Log.v(TAG, "Moved " + token + " to " + index + ":"); |
| 3520 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3521 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3522 | final long origId = Binder.clearCallingIdentity(); |
| 3523 | if (DEBUG_REORDER) Log.v(TAG, "Removing windows in " + token + ":"); |
| 3524 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3525 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
| 3526 | if (DEBUG_REORDER) Log.v(TAG, "Adding windows back in:"); |
| 3527 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3528 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
| 3529 | if (DEBUG_REORDER) Log.v(TAG, "Final window list:"); |
| 3530 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3531 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3532 | mLayoutNeeded = true; |
| 3533 | performLayoutAndPlaceSurfacesLocked(); |
| 3534 | } |
| 3535 | Binder.restoreCallingIdentity(origId); |
| 3536 | } |
| 3537 | } |
| 3538 | |
| 3539 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 3540 | // XXX This should be done more efficiently! |
| 3541 | // (take advantage of the fact that both lists should be |
| 3542 | // ordered in the same way.) |
| 3543 | int N = tokens.size(); |
| 3544 | for (int i=0; i<N; i++) { |
| 3545 | IBinder token = tokens.get(i); |
| 3546 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 3547 | if (!mAppTokens.remove(wtoken)) { |
| 3548 | Log.w(TAG, "Attempting to reorder token that doesn't exist: " |
| 3549 | + token + " (" + wtoken + ")"); |
| 3550 | i--; |
| 3551 | N--; |
| 3552 | } |
| 3553 | } |
| 3554 | } |
| 3555 | |
| 3556 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 3557 | // First remove all of the windows from the list. |
| 3558 | final int N = tokens.size(); |
| 3559 | int i; |
| 3560 | for (i=0; i<N; i++) { |
| 3561 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 3562 | if (token != null) { |
| 3563 | tmpRemoveAppWindowsLocked(token); |
| 3564 | } |
| 3565 | } |
| 3566 | |
| 3567 | // Where to start adding? |
| 3568 | int pos = findWindowOffsetLocked(tokenPos); |
| 3569 | |
| 3570 | // And now add them back at the correct place. |
| 3571 | for (i=0; i<N; i++) { |
| 3572 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 3573 | if (token != null) { |
| 3574 | pos = reAddAppWindowsLocked(pos, token); |
| 3575 | } |
| 3576 | } |
| 3577 | |
| 3578 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3579 | mLayoutNeeded = true; |
| 3580 | performLayoutAndPlaceSurfacesLocked(); |
| 3581 | |
| 3582 | //dump(); |
| 3583 | } |
| 3584 | |
| 3585 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 3586 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3587 | "moveAppTokensToTop()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3588 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3589 | } |
| 3590 | |
| 3591 | final long origId = Binder.clearCallingIdentity(); |
| 3592 | synchronized(mWindowMap) { |
| 3593 | removeAppTokensLocked(tokens); |
| 3594 | final int N = tokens.size(); |
| 3595 | for (int i=0; i<N; i++) { |
| 3596 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 3597 | if (wt != null) { |
| 3598 | mAppTokens.add(wt); |
| 3599 | } |
| 3600 | } |
| 3601 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 3602 | } |
| 3603 | Binder.restoreCallingIdentity(origId); |
| 3604 | } |
| 3605 | |
| 3606 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 3607 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3608 | "moveAppTokensToBottom()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3609 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3610 | } |
| 3611 | |
| 3612 | final long origId = Binder.clearCallingIdentity(); |
| 3613 | synchronized(mWindowMap) { |
| 3614 | removeAppTokensLocked(tokens); |
| 3615 | final int N = tokens.size(); |
| 3616 | int pos = 0; |
| 3617 | for (int i=0; i<N; i++) { |
| 3618 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 3619 | if (wt != null) { |
| 3620 | mAppTokens.add(pos, wt); |
| 3621 | pos++; |
| 3622 | } |
| 3623 | } |
| 3624 | moveAppWindowsLocked(tokens, 0); |
| 3625 | } |
| 3626 | Binder.restoreCallingIdentity(origId); |
| 3627 | } |
| 3628 | |
| 3629 | // ------------------------------------------------------------- |
| 3630 | // Misc IWindowSession methods |
| 3631 | // ------------------------------------------------------------- |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3632 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3633 | public void disableKeyguard(IBinder token, String tag) { |
| 3634 | if (mContext.checkCallingPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| 3635 | != PackageManager.PERMISSION_GRANTED) { |
| 3636 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 3637 | } |
| 3638 | mKeyguardDisabled.acquire(token, tag); |
| 3639 | } |
| 3640 | |
| 3641 | public void reenableKeyguard(IBinder token) { |
| 3642 | if (mContext.checkCallingPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| 3643 | != PackageManager.PERMISSION_GRANTED) { |
| 3644 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 3645 | } |
| 3646 | synchronized (mKeyguardDisabled) { |
| 3647 | mKeyguardDisabled.release(token); |
| 3648 | |
| 3649 | if (!mKeyguardDisabled.isAcquired()) { |
| 3650 | // if we are the last one to reenable the keyguard wait until |
| 3651 | // we have actaully finished reenabling until returning |
| 3652 | mWaitingUntilKeyguardReenabled = true; |
| 3653 | while (mWaitingUntilKeyguardReenabled) { |
| 3654 | try { |
| 3655 | mKeyguardDisabled.wait(); |
| 3656 | } catch (InterruptedException e) { |
| 3657 | Thread.currentThread().interrupt(); |
| 3658 | } |
| 3659 | } |
| 3660 | } |
| 3661 | } |
| 3662 | } |
| 3663 | |
| 3664 | /** |
| 3665 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 3666 | */ |
| 3667 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
| 3668 | if (mContext.checkCallingPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| 3669 | != PackageManager.PERMISSION_GRANTED) { |
| 3670 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 3671 | } |
| 3672 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 3673 | public void onKeyguardExitResult(boolean success) { |
| 3674 | try { |
| 3675 | callback.onKeyguardExitResult(success); |
| 3676 | } catch (RemoteException e) { |
| 3677 | // Client has died, we don't care. |
| 3678 | } |
| 3679 | } |
| 3680 | }); |
| 3681 | } |
| 3682 | |
| 3683 | public boolean inKeyguardRestrictedInputMode() { |
| 3684 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 3685 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3686 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3687 | static float fixScale(float scale) { |
| 3688 | if (scale < 0) scale = 0; |
| 3689 | else if (scale > 20) scale = 20; |
| 3690 | return Math.abs(scale); |
| 3691 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3692 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3693 | public void setAnimationScale(int which, float scale) { |
| 3694 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 3695 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3696 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3697 | } |
| 3698 | |
| 3699 | if (scale < 0) scale = 0; |
| 3700 | else if (scale > 20) scale = 20; |
| 3701 | scale = Math.abs(scale); |
| 3702 | switch (which) { |
| 3703 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 3704 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 3705 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3706 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3707 | // Persist setting |
| 3708 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 3709 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3710 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3711 | public void setAnimationScales(float[] scales) { |
| 3712 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 3713 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3714 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3715 | } |
| 3716 | |
| 3717 | if (scales != null) { |
| 3718 | if (scales.length >= 1) { |
| 3719 | mWindowAnimationScale = fixScale(scales[0]); |
| 3720 | } |
| 3721 | if (scales.length >= 2) { |
| 3722 | mTransitionAnimationScale = fixScale(scales[1]); |
| 3723 | } |
| 3724 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3725 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3726 | // Persist setting |
| 3727 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 3728 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3729 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3730 | public float getAnimationScale(int which) { |
| 3731 | switch (which) { |
| 3732 | case 0: return mWindowAnimationScale; |
| 3733 | case 1: return mTransitionAnimationScale; |
| 3734 | } |
| 3735 | return 0; |
| 3736 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3737 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3738 | public float[] getAnimationScales() { |
| 3739 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 3740 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3741 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3742 | public int getSwitchState(int sw) { |
| 3743 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 3744 | "getSwitchState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3745 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3746 | } |
| 3747 | return KeyInputQueue.getSwitchState(sw); |
| 3748 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3749 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3750 | public int getSwitchStateForDevice(int devid, int sw) { |
| 3751 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 3752 | "getSwitchStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3753 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3754 | } |
| 3755 | return KeyInputQueue.getSwitchState(devid, sw); |
| 3756 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3757 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3758 | public int getScancodeState(int sw) { |
| 3759 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 3760 | "getScancodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3761 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3762 | } |
| 3763 | return KeyInputQueue.getScancodeState(sw); |
| 3764 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3765 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3766 | public int getScancodeStateForDevice(int devid, int sw) { |
| 3767 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 3768 | "getScancodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3769 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3770 | } |
| 3771 | return KeyInputQueue.getScancodeState(devid, sw); |
| 3772 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3773 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3774 | public int getKeycodeState(int sw) { |
| 3775 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 3776 | "getKeycodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3777 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3778 | } |
| 3779 | return KeyInputQueue.getKeycodeState(sw); |
| 3780 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3781 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3782 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 3783 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 3784 | "getKeycodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3785 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3786 | } |
| 3787 | return KeyInputQueue.getKeycodeState(devid, sw); |
| 3788 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3789 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3790 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
| 3791 | return KeyInputQueue.hasKeys(keycodes, keyExists); |
| 3792 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3793 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3794 | public void enableScreenAfterBoot() { |
| 3795 | synchronized(mWindowMap) { |
| 3796 | if (mSystemBooted) { |
| 3797 | return; |
| 3798 | } |
| 3799 | mSystemBooted = true; |
| 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 | performEnableScreen(); |
| 3803 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3804 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3805 | public void enableScreenIfNeededLocked() { |
| 3806 | if (mDisplayEnabled) { |
| 3807 | return; |
| 3808 | } |
| 3809 | if (!mSystemBooted) { |
| 3810 | return; |
| 3811 | } |
| 3812 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 3813 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3814 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3815 | public void performEnableScreen() { |
| 3816 | synchronized(mWindowMap) { |
| 3817 | if (mDisplayEnabled) { |
| 3818 | return; |
| 3819 | } |
| 3820 | if (!mSystemBooted) { |
| 3821 | return; |
| 3822 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3823 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3824 | // Don't enable the screen until all existing windows |
| 3825 | // have been drawn. |
| 3826 | final int N = mWindows.size(); |
| 3827 | for (int i=0; i<N; i++) { |
| 3828 | WindowState w = (WindowState)mWindows.get(i); |
| 3829 | if (w.isVisibleLw() && !w.isDisplayedLw()) { |
| 3830 | return; |
| 3831 | } |
| 3832 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3833 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3834 | mDisplayEnabled = true; |
| 3835 | if (false) { |
| 3836 | Log.i(TAG, "ENABLING SCREEN!"); |
| 3837 | StringWriter sw = new StringWriter(); |
| 3838 | PrintWriter pw = new PrintWriter(sw); |
| 3839 | this.dump(null, pw, null); |
| 3840 | Log.i(TAG, sw.toString()); |
| 3841 | } |
| 3842 | try { |
| 3843 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 3844 | if (surfaceFlinger != null) { |
| 3845 | //Log.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
| 3846 | Parcel data = Parcel.obtain(); |
| 3847 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 3848 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 3849 | data, null, 0); |
| 3850 | data.recycle(); |
| 3851 | } |
| 3852 | } catch (RemoteException ex) { |
| 3853 | Log.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
| 3854 | } |
| 3855 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3856 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3857 | mPolicy.enableScreenAfterBoot(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3858 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3859 | // Make sure the last requested orientation has been applied. |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 3860 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 3861 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3862 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3863 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3864 | public void setInTouchMode(boolean mode) { |
| 3865 | synchronized(mWindowMap) { |
| 3866 | mInTouchMode = mode; |
| 3867 | } |
| 3868 | } |
| 3869 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3870 | public void setRotation(int rotation, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3871 | boolean alwaysSendConfiguration, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3872 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3873 | "setRotation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3874 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3875 | } |
| 3876 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3877 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3878 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3879 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3880 | public void setRotationUnchecked(int rotation, |
| 3881 | boolean alwaysSendConfiguration, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3882 | if(DEBUG_ORIENTATION) Log.v(TAG, |
| 3883 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3884 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3885 | long origId = Binder.clearCallingIdentity(); |
| 3886 | boolean changed; |
| 3887 | synchronized(mWindowMap) { |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3888 | changed = setRotationUncheckedLocked(rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3889 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3890 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3891 | if (changed) { |
| 3892 | sendNewConfiguration(); |
| 3893 | synchronized(mWindowMap) { |
| 3894 | mLayoutNeeded = true; |
| 3895 | performLayoutAndPlaceSurfacesLocked(); |
| 3896 | } |
| 3897 | } else if (alwaysSendConfiguration) { |
| 3898 | //update configuration ignoring orientation change |
| 3899 | sendNewConfiguration(); |
| 3900 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3901 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3902 | Binder.restoreCallingIdentity(origId); |
| 3903 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3904 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3905 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3906 | boolean changed; |
| 3907 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 3908 | rotation = mRequestedRotation; |
| 3909 | } else { |
| 3910 | mRequestedRotation = rotation; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 3911 | mLastRotationFlags = animFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3912 | } |
| 3913 | 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] | 3914 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3915 | mRotation, mDisplayEnabled); |
| 3916 | if (DEBUG_ORIENTATION) Log.v(TAG, "new rotation is set to " + rotation); |
| 3917 | changed = mDisplayEnabled && mRotation != rotation; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3918 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3919 | if (changed) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3920 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3921 | "Rotation changed to " + rotation |
| 3922 | + " from " + mRotation |
| 3923 | + " (forceApp=" + mForcedAppOrientation |
| 3924 | + ", req=" + mRequestedRotation + ")"); |
| 3925 | mRotation = rotation; |
| 3926 | mWindowsFreezingScreen = true; |
| 3927 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 3928 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 3929 | 2000); |
| 3930 | startFreezingDisplayLocked(); |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 3931 | Log.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3932 | mQueue.setOrientation(rotation); |
| 3933 | if (mDisplayEnabled) { |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 3934 | Surface.setOrientation(0, rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3935 | } |
| 3936 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 3937 | WindowState w = (WindowState)mWindows.get(i); |
| 3938 | if (w.mSurface != null) { |
| 3939 | w.mOrientationChanging = true; |
| 3940 | } |
| 3941 | } |
| 3942 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 3943 | try { |
| 3944 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 3945 | } catch (RemoteException e) { |
| 3946 | } |
| 3947 | } |
| 3948 | } //end if changed |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3949 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3950 | return changed; |
| 3951 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3952 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3953 | public int getRotation() { |
| 3954 | return mRotation; |
| 3955 | } |
| 3956 | |
| 3957 | public int watchRotation(IRotationWatcher watcher) { |
| 3958 | final IBinder watcherBinder = watcher.asBinder(); |
| 3959 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 3960 | public void binderDied() { |
| 3961 | synchronized (mWindowMap) { |
| 3962 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 3963 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 3964 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 3965 | if (removed != null) { |
| 3966 | removed.asBinder().unlinkToDeath(this, 0); |
| 3967 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3968 | i--; |
| 3969 | } |
| 3970 | } |
| 3971 | } |
| 3972 | } |
| 3973 | }; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3974 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3975 | synchronized (mWindowMap) { |
| 3976 | try { |
| 3977 | watcher.asBinder().linkToDeath(dr, 0); |
| 3978 | mRotationWatchers.add(watcher); |
| 3979 | } catch (RemoteException e) { |
| 3980 | // Client died, no cleanup needed. |
| 3981 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3982 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3983 | return mRotation; |
| 3984 | } |
| 3985 | } |
| 3986 | |
| 3987 | /** |
| 3988 | * Starts the view server on the specified port. |
| 3989 | * |
| 3990 | * @param port The port to listener to. |
| 3991 | * |
| 3992 | * @return True if the server was successfully started, false otherwise. |
| 3993 | * |
| 3994 | * @see com.android.server.ViewServer |
| 3995 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 3996 | */ |
| 3997 | public boolean startViewServer(int port) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3998 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3999 | return false; |
| 4000 | } |
| 4001 | |
| 4002 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 4003 | return false; |
| 4004 | } |
| 4005 | |
| 4006 | if (port < 1024) { |
| 4007 | return false; |
| 4008 | } |
| 4009 | |
| 4010 | if (mViewServer != null) { |
| 4011 | if (!mViewServer.isRunning()) { |
| 4012 | try { |
| 4013 | return mViewServer.start(); |
| 4014 | } catch (IOException e) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4015 | Log.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4016 | } |
| 4017 | } |
| 4018 | return false; |
| 4019 | } |
| 4020 | |
| 4021 | try { |
| 4022 | mViewServer = new ViewServer(this, port); |
| 4023 | return mViewServer.start(); |
| 4024 | } catch (IOException e) { |
| 4025 | Log.w(TAG, "View server did not start"); |
| 4026 | } |
| 4027 | return false; |
| 4028 | } |
| 4029 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4030 | private boolean isSystemSecure() { |
| 4031 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 4032 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 4033 | } |
| 4034 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4035 | /** |
| 4036 | * Stops the view server if it exists. |
| 4037 | * |
| 4038 | * @return True if the server stopped, false if it wasn't started or |
| 4039 | * couldn't be stopped. |
| 4040 | * |
| 4041 | * @see com.android.server.ViewServer |
| 4042 | */ |
| 4043 | public boolean stopViewServer() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4044 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4045 | return false; |
| 4046 | } |
| 4047 | |
| 4048 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 4049 | return false; |
| 4050 | } |
| 4051 | |
| 4052 | if (mViewServer != null) { |
| 4053 | return mViewServer.stop(); |
| 4054 | } |
| 4055 | return false; |
| 4056 | } |
| 4057 | |
| 4058 | /** |
| 4059 | * Indicates whether the view server is running. |
| 4060 | * |
| 4061 | * @return True if the server is running, false otherwise. |
| 4062 | * |
| 4063 | * @see com.android.server.ViewServer |
| 4064 | */ |
| 4065 | public boolean isViewServerRunning() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4066 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4067 | return false; |
| 4068 | } |
| 4069 | |
| 4070 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 4071 | return false; |
| 4072 | } |
| 4073 | |
| 4074 | return mViewServer != null && mViewServer.isRunning(); |
| 4075 | } |
| 4076 | |
| 4077 | /** |
| 4078 | * Lists all availble windows in the system. The listing is written in the |
| 4079 | * specified Socket's output stream with the following syntax: |
| 4080 | * windowHashCodeInHexadecimal windowName |
| 4081 | * Each line of the ouput represents a different window. |
| 4082 | * |
| 4083 | * @param client The remote client to send the listing to. |
| 4084 | * @return False if an error occured, true otherwise. |
| 4085 | */ |
| 4086 | boolean viewServerListWindows(Socket client) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4087 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4088 | return false; |
| 4089 | } |
| 4090 | |
| 4091 | boolean result = true; |
| 4092 | |
| 4093 | Object[] windows; |
| 4094 | synchronized (mWindowMap) { |
| 4095 | windows = new Object[mWindows.size()]; |
| 4096 | //noinspection unchecked |
| 4097 | windows = mWindows.toArray(windows); |
| 4098 | } |
| 4099 | |
| 4100 | BufferedWriter out = null; |
| 4101 | |
| 4102 | // Any uncaught exception will crash the system process |
| 4103 | try { |
| 4104 | OutputStream clientStream = client.getOutputStream(); |
| 4105 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 4106 | |
| 4107 | final int count = windows.length; |
| 4108 | for (int i = 0; i < count; i++) { |
| 4109 | final WindowState w = (WindowState) windows[i]; |
| 4110 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 4111 | out.write(' '); |
| 4112 | out.append(w.mAttrs.getTitle()); |
| 4113 | out.write('\n'); |
| 4114 | } |
| 4115 | |
| 4116 | out.write("DONE.\n"); |
| 4117 | out.flush(); |
| 4118 | } catch (Exception e) { |
| 4119 | result = false; |
| 4120 | } finally { |
| 4121 | if (out != null) { |
| 4122 | try { |
| 4123 | out.close(); |
| 4124 | } catch (IOException e) { |
| 4125 | result = false; |
| 4126 | } |
| 4127 | } |
| 4128 | } |
| 4129 | |
| 4130 | return result; |
| 4131 | } |
| 4132 | |
| 4133 | /** |
| 4134 | * Sends a command to a target window. The result of the command, if any, will be |
| 4135 | * written in the output stream of the specified socket. |
| 4136 | * |
| 4137 | * The parameters must follow this syntax: |
| 4138 | * windowHashcode extra |
| 4139 | * |
| 4140 | * Where XX is the length in characeters of the windowTitle. |
| 4141 | * |
| 4142 | * The first parameter is the target window. The window with the specified hashcode |
| 4143 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 4144 | * will be delivered to the target window and as parameters to the command itself. |
| 4145 | * |
| 4146 | * @param client The remote client to sent the result, if any, to. |
| 4147 | * @param command The command to execute. |
| 4148 | * @param parameters The command parameters. |
| 4149 | * |
| 4150 | * @return True if the command was successfully delivered, false otherwise. This does |
| 4151 | * not indicate whether the command itself was successful. |
| 4152 | */ |
| 4153 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4154 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4155 | return false; |
| 4156 | } |
| 4157 | |
| 4158 | boolean success = true; |
| 4159 | Parcel data = null; |
| 4160 | Parcel reply = null; |
| 4161 | |
| 4162 | // Any uncaught exception will crash the system process |
| 4163 | try { |
| 4164 | // Find the hashcode of the window |
| 4165 | int index = parameters.indexOf(' '); |
| 4166 | if (index == -1) { |
| 4167 | index = parameters.length(); |
| 4168 | } |
| 4169 | final String code = parameters.substring(0, index); |
| 4170 | int hashCode = "ffffffff".equals(code) ? -1 : Integer.parseInt(code, 16); |
| 4171 | |
| 4172 | // Extract the command's parameter after the window description |
| 4173 | if (index < parameters.length()) { |
| 4174 | parameters = parameters.substring(index + 1); |
| 4175 | } else { |
| 4176 | parameters = ""; |
| 4177 | } |
| 4178 | |
| 4179 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 4180 | if (window == null) { |
| 4181 | return false; |
| 4182 | } |
| 4183 | |
| 4184 | data = Parcel.obtain(); |
| 4185 | data.writeInterfaceToken("android.view.IWindow"); |
| 4186 | data.writeString(command); |
| 4187 | data.writeString(parameters); |
| 4188 | data.writeInt(1); |
| 4189 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 4190 | |
| 4191 | reply = Parcel.obtain(); |
| 4192 | |
| 4193 | final IBinder binder = window.mClient.asBinder(); |
| 4194 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 4195 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 4196 | |
| 4197 | reply.readException(); |
| 4198 | |
| 4199 | } catch (Exception e) { |
| 4200 | Log.w(TAG, "Could not send command " + command + " with parameters " + parameters, e); |
| 4201 | success = false; |
| 4202 | } finally { |
| 4203 | if (data != null) { |
| 4204 | data.recycle(); |
| 4205 | } |
| 4206 | if (reply != null) { |
| 4207 | reply.recycle(); |
| 4208 | } |
| 4209 | } |
| 4210 | |
| 4211 | return success; |
| 4212 | } |
| 4213 | |
| 4214 | private WindowState findWindow(int hashCode) { |
| 4215 | if (hashCode == -1) { |
| 4216 | return getFocusedWindow(); |
| 4217 | } |
| 4218 | |
| 4219 | synchronized (mWindowMap) { |
| 4220 | final ArrayList windows = mWindows; |
| 4221 | final int count = windows.size(); |
| 4222 | |
| 4223 | for (int i = 0; i < count; i++) { |
| 4224 | WindowState w = (WindowState) windows.get(i); |
| 4225 | if (System.identityHashCode(w) == hashCode) { |
| 4226 | return w; |
| 4227 | } |
| 4228 | } |
| 4229 | } |
| 4230 | |
| 4231 | return null; |
| 4232 | } |
| 4233 | |
| 4234 | /* |
| 4235 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 4236 | * that to config-changed listeners if appropriate. |
| 4237 | */ |
| 4238 | void sendNewConfiguration() { |
| 4239 | try { |
| 4240 | mActivityManager.updateConfiguration(null); |
| 4241 | } catch (RemoteException e) { |
| 4242 | } |
| 4243 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4244 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4245 | public Configuration computeNewConfiguration() { |
| 4246 | synchronized (mWindowMap) { |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4247 | return computeNewConfigurationLocked(); |
| 4248 | } |
| 4249 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4250 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4251 | Configuration computeNewConfigurationLocked() { |
| 4252 | Configuration config = new Configuration(); |
| 4253 | if (!computeNewConfigurationLocked(config)) { |
| 4254 | return null; |
| 4255 | } |
| 4256 | Log.i(TAG, "Config changed: " + config); |
| 4257 | long now = SystemClock.uptimeMillis(); |
| 4258 | //Log.i(TAG, "Config changing, gc pending: " + mFreezeGcPending + ", now " + now); |
| 4259 | if (mFreezeGcPending != 0) { |
| 4260 | if (now > (mFreezeGcPending+1000)) { |
| 4261 | //Log.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| 4262 | mH.removeMessages(H.FORCE_GC); |
| 4263 | Runtime.getRuntime().gc(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4264 | mFreezeGcPending = now; |
| 4265 | } |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4266 | } else { |
| 4267 | mFreezeGcPending = now; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4268 | } |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4269 | return config; |
| 4270 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4271 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4272 | boolean computeNewConfigurationLocked(Configuration config) { |
| 4273 | if (mDisplay == null) { |
| 4274 | return false; |
| 4275 | } |
| 4276 | mQueue.getInputConfiguration(config); |
| 4277 | final int dw = mDisplay.getWidth(); |
| 4278 | final int dh = mDisplay.getHeight(); |
| 4279 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 4280 | if (dw < dh) { |
| 4281 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 4282 | } else if (dw > dh) { |
| 4283 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 4284 | } |
| 4285 | config.orientation = orientation; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4286 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4287 | DisplayMetrics dm = new DisplayMetrics(); |
| 4288 | mDisplay.getMetrics(dm); |
| 4289 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 4290 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4291 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4292 | // Note we only do this once because at this point we don't |
| 4293 | // expect the screen to change in this way at runtime, and want |
| 4294 | // to avoid all of this computation for every config change. |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4295 | int longSize = dw; |
| 4296 | int shortSize = dh; |
| 4297 | if (longSize < shortSize) { |
| 4298 | int tmp = longSize; |
| 4299 | longSize = shortSize; |
| 4300 | shortSize = tmp; |
| 4301 | } |
| 4302 | longSize = (int)(longSize/dm.density); |
| 4303 | shortSize = (int)(shortSize/dm.density); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4304 | |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4305 | // These semi-magic numbers define our compatibility modes for |
| 4306 | // applications with different screens. Don't change unless you |
| 4307 | // make sure to test lots and lots of apps! |
| 4308 | if (longSize < 470) { |
| 4309 | // This is shorter than an HVGA normal density screen (which |
| 4310 | // is 480 pixels on its long side). |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4311 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 4312 | | Configuration.SCREENLAYOUT_LONG_NO; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4313 | } else { |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4314 | // Is this a large screen? |
| 4315 | if (longSize > 640 && shortSize >= 480) { |
| 4316 | // VGA or larger screens at medium density are the point |
| 4317 | // at which we consider it to be a large screen. |
| 4318 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 4319 | } else { |
| 4320 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
| 4321 | |
| 4322 | // If this screen is wider than normal HVGA, or taller |
| 4323 | // than FWVGA, then for old apps we want to run in size |
| 4324 | // compatibility mode. |
| 4325 | if (shortSize > 321 || longSize > 570) { |
| 4326 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 4327 | } |
| 4328 | } |
| 4329 | |
| 4330 | // Is this a long screen? |
| 4331 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 4332 | // Anything wider than WVGA (5:3) is considering to be long. |
| 4333 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 4334 | } else { |
| 4335 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 4336 | } |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4337 | } |
| 4338 | } |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4339 | config.screenLayout = mScreenLayout; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4340 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4341 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 4342 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 4343 | mPolicy.adjustConfigurationLw(config); |
| 4344 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4345 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4346 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4347 | // ------------------------------------------------------------- |
| 4348 | // Input Events and Focus Management |
| 4349 | // ------------------------------------------------------------- |
| 4350 | |
| 4351 | private final void wakeupIfNeeded(WindowState targetWin, int eventType) { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4352 | long curTime = SystemClock.uptimeMillis(); |
| 4353 | |
| Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 4354 | if (eventType == TOUCH_EVENT || eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4355 | if (mLastTouchEventType == eventType && |
| 4356 | (curTime - mLastUserActivityCallTime) < MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 4357 | return; |
| 4358 | } |
| 4359 | mLastUserActivityCallTime = curTime; |
| 4360 | mLastTouchEventType = eventType; |
| 4361 | } |
| 4362 | |
| 4363 | if (targetWin == null |
| 4364 | || targetWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) { |
| 4365 | mPowerManager.userActivity(curTime, false, eventType, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4366 | } |
| 4367 | } |
| 4368 | |
| 4369 | // tells if it's a cheek event or not -- this function is stateful |
| 4370 | private static final int EVENT_NONE = 0; |
| 4371 | private static final int EVENT_UNKNOWN = 0; |
| 4372 | private static final int EVENT_CHEEK = 0; |
| 4373 | private static final int EVENT_IGNORE_DURATION = 300; // ms |
| 4374 | private static final float CHEEK_THRESHOLD = 0.6f; |
| 4375 | private int mEventState = EVENT_NONE; |
| 4376 | private float mEventSize; |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4377 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4378 | private int eventType(MotionEvent ev) { |
| 4379 | float size = ev.getSize(); |
| 4380 | switch (ev.getAction()) { |
| 4381 | case MotionEvent.ACTION_DOWN: |
| 4382 | mEventSize = size; |
| 4383 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_EVENT; |
| 4384 | case MotionEvent.ACTION_UP: |
| 4385 | if (size > mEventSize) mEventSize = size; |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4386 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_UP_EVENT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4387 | case MotionEvent.ACTION_MOVE: |
| 4388 | final int N = ev.getHistorySize(); |
| 4389 | if (size > mEventSize) mEventSize = size; |
| 4390 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 4391 | for (int i=0; i<N; i++) { |
| 4392 | size = ev.getHistoricalSize(i); |
| 4393 | if (size > mEventSize) mEventSize = size; |
| 4394 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 4395 | } |
| 4396 | if (ev.getEventTime() < ev.getDownTime() + EVENT_IGNORE_DURATION) { |
| 4397 | return TOUCH_EVENT; |
| 4398 | } else { |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4399 | return LONG_TOUCH_EVENT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4400 | } |
| 4401 | default: |
| 4402 | // not good |
| 4403 | return OTHER_EVENT; |
| 4404 | } |
| 4405 | } |
| 4406 | |
| 4407 | /** |
| 4408 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4409 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4410 | 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] | 4411 | if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Log.v(TAG, |
| 4412 | "dispatchPointer " + ev); |
| 4413 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4414 | if (MEASURE_LATENCY) { |
| 4415 | lt.sample("3 Wait for last dispatch ", System.nanoTime() - qev.whenNano); |
| 4416 | } |
| 4417 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4418 | Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4419 | ev, true, false, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4420 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4421 | if (MEASURE_LATENCY) { |
| 4422 | lt.sample("3 Last dispatch finished ", System.nanoTime() - qev.whenNano); |
| 4423 | } |
| 4424 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4425 | int action = ev.getAction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4426 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4427 | if (action == MotionEvent.ACTION_UP) { |
| 4428 | // let go of our target |
| 4429 | mKeyWaiter.mMotionTarget = null; |
| 4430 | mPowerManager.logPointerUpEvent(); |
| 4431 | } else if (action == MotionEvent.ACTION_DOWN) { |
| 4432 | mPowerManager.logPointerDownEvent(); |
| 4433 | } |
| 4434 | |
| 4435 | if (targetObj == null) { |
| 4436 | // In this case we are either dropping the event, or have received |
| 4437 | // a move or up without a down. It is common to receive move |
| 4438 | // events in such a way, since this means the user is moving the |
| 4439 | // pointer without actually pressing down. All other cases should |
| 4440 | // be atypical, so let's log them. |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4441 | if (action != MotionEvent.ACTION_MOVE) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4442 | Log.w(TAG, "No window to dispatch pointer action " + ev.getAction()); |
| 4443 | } |
| 4444 | if (qev != null) { |
| 4445 | mQueue.recycleEvent(qev); |
| 4446 | } |
| 4447 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4448 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4449 | } |
| 4450 | if (targetObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| 4451 | if (qev != null) { |
| 4452 | mQueue.recycleEvent(qev); |
| 4453 | } |
| 4454 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4455 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4456 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4457 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4458 | WindowState target = (WindowState)targetObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4459 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4460 | final long eventTime = ev.getEventTime(); |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4461 | final long eventTimeNano = ev.getEventTimeNano(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4462 | |
| 4463 | //Log.i(TAG, "Sending " + ev + " to " + target); |
| 4464 | |
| 4465 | if (uid != 0 && uid != target.mSession.mUid) { |
| 4466 | if (mContext.checkPermission( |
| 4467 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 4468 | != PackageManager.PERMISSION_GRANTED) { |
| 4469 | Log.w(TAG, "Permission denied: injecting pointer event from pid " |
| 4470 | + pid + " uid " + uid + " to window " + target |
| 4471 | + " owned by uid " + target.mSession.mUid); |
| 4472 | if (qev != null) { |
| 4473 | mQueue.recycleEvent(qev); |
| 4474 | } |
| 4475 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4476 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4477 | } |
| 4478 | } |
| 4479 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4480 | if (MEASURE_LATENCY) { |
| 4481 | lt.sample("4 in dispatchPointer ", System.nanoTime() - eventTimeNano); |
| 4482 | } |
| 4483 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4484 | if ((target.mAttrs.flags & |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4485 | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES) != 0) { |
| 4486 | //target wants to ignore fat touch events |
| 4487 | boolean cheekPress = mPolicy.isCheekPressedAgainstScreen(ev); |
| 4488 | //explicit flag to return without processing event further |
| 4489 | boolean returnFlag = false; |
| 4490 | if((action == MotionEvent.ACTION_DOWN)) { |
| 4491 | mFatTouch = false; |
| 4492 | if(cheekPress) { |
| 4493 | mFatTouch = true; |
| 4494 | returnFlag = true; |
| 4495 | } |
| 4496 | } else { |
| 4497 | if(action == MotionEvent.ACTION_UP) { |
| 4498 | if(mFatTouch) { |
| 4499 | //earlier even was invalid doesnt matter if current up is cheekpress or not |
| 4500 | mFatTouch = false; |
| 4501 | returnFlag = true; |
| 4502 | } else if(cheekPress) { |
| 4503 | //cancel the earlier event |
| 4504 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 4505 | action = MotionEvent.ACTION_CANCEL; |
| 4506 | } |
| 4507 | } else if(action == MotionEvent.ACTION_MOVE) { |
| 4508 | if(mFatTouch) { |
| 4509 | //two cases here |
| 4510 | //an invalid down followed by 0 or moves(valid or invalid) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4511 | //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] | 4512 | returnFlag = true; |
| 4513 | } else if(cheekPress) { |
| 4514 | //valid down followed by invalid moves |
| 4515 | //an invalid move have to cancel earlier action |
| 4516 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 4517 | action = MotionEvent.ACTION_CANCEL; |
| 4518 | if (DEBUG_INPUT) Log.v(TAG, "Sending cancel for invalid ACTION_MOVE"); |
| 4519 | //note that the subsequent invalid moves will not get here |
| 4520 | mFatTouch = true; |
| 4521 | } |
| 4522 | } |
| 4523 | } //else if action |
| 4524 | if(returnFlag) { |
| 4525 | //recycle que, ev |
| 4526 | if (qev != null) { |
| 4527 | mQueue.recycleEvent(qev); |
| 4528 | } |
| 4529 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4530 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4531 | } |
| 4532 | } //end if target |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4533 | |
| Michael Chan | 9f028e6 | 2009-08-04 17:37:46 -0700 | [diff] [blame] | 4534 | // Enable this for testing the "right" value |
| 4535 | if (false && action == MotionEvent.ACTION_DOWN) { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4536 | int max_events_per_sec = 35; |
| 4537 | try { |
| 4538 | max_events_per_sec = Integer.parseInt(SystemProperties |
| 4539 | .get("windowsmgr.max_events_per_sec")); |
| 4540 | if (max_events_per_sec < 1) { |
| 4541 | max_events_per_sec = 35; |
| 4542 | } |
| 4543 | } catch (NumberFormatException e) { |
| 4544 | } |
| 4545 | mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec; |
| 4546 | } |
| 4547 | |
| 4548 | /* |
| 4549 | * Throttle events to minimize CPU usage when there's a flood of events |
| 4550 | * e.g. constant contact with the screen |
| 4551 | */ |
| 4552 | if (action == MotionEvent.ACTION_MOVE) { |
| 4553 | long nextEventTime = mLastTouchEventTime + mMinWaitTimeBetweenTouchEvents; |
| 4554 | long now = SystemClock.uptimeMillis(); |
| 4555 | if (now < nextEventTime) { |
| 4556 | try { |
| 4557 | Thread.sleep(nextEventTime - now); |
| 4558 | } catch (InterruptedException e) { |
| 4559 | } |
| 4560 | mLastTouchEventTime = nextEventTime; |
| 4561 | } else { |
| 4562 | mLastTouchEventTime = now; |
| 4563 | } |
| 4564 | } |
| 4565 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4566 | if (MEASURE_LATENCY) { |
| 4567 | lt.sample("5 in dispatchPointer ", System.nanoTime() - eventTimeNano); |
| 4568 | } |
| 4569 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4570 | synchronized(mWindowMap) { |
| 4571 | if (qev != null && action == MotionEvent.ACTION_MOVE) { |
| 4572 | mKeyWaiter.bindTargetWindowLocked(target, |
| 4573 | KeyWaiter.RETURN_PENDING_POINTER, qev); |
| 4574 | ev = null; |
| 4575 | } else { |
| 4576 | if (action == MotionEvent.ACTION_DOWN) { |
| 4577 | WindowState out = mKeyWaiter.mOutsideTouchTargets; |
| 4578 | if (out != null) { |
| 4579 | MotionEvent oev = MotionEvent.obtain(ev); |
| 4580 | oev.setAction(MotionEvent.ACTION_OUTSIDE); |
| 4581 | do { |
| 4582 | final Rect frame = out.mFrame; |
| 4583 | oev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 4584 | try { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 4585 | out.mClient.dispatchPointer(oev, eventTime, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4586 | } catch (android.os.RemoteException e) { |
| 4587 | Log.i(TAG, "WINDOW DIED during outside motion dispatch: " + out); |
| 4588 | } |
| 4589 | oev.offsetLocation((float)frame.left, (float)frame.top); |
| 4590 | out = out.mNextOutsideTouch; |
| 4591 | } while (out != null); |
| 4592 | mKeyWaiter.mOutsideTouchTargets = null; |
| 4593 | } |
| 4594 | } |
| 4595 | final Rect frame = target.mFrame; |
| 4596 | ev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 4597 | mKeyWaiter.bindTargetWindowLocked(target); |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 4598 | |
| 4599 | // If we are on top of the wallpaper, then the wallpaper also |
| 4600 | // gets to see this movement. |
| 4601 | if (mWallpaperTarget == target) { |
| 4602 | sendPointerToWallpaperLocked(target, ev, eventTime); |
| 4603 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4604 | } |
| 4605 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4606 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4607 | // finally offset the event to the target's coordinate system and |
| 4608 | // dispatch the event. |
| 4609 | try { |
| 4610 | if (DEBUG_INPUT || DEBUG_FOCUS || WindowManagerPolicy.WATCH_POINTER) { |
| 4611 | Log.v(TAG, "Delivering pointer " + qev + " to " + target); |
| 4612 | } |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4613 | |
| 4614 | if (MEASURE_LATENCY) { |
| 4615 | lt.sample("6 before svr->client ipc ", System.nanoTime() - eventTimeNano); |
| 4616 | } |
| 4617 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 4618 | target.mClient.dispatchPointer(ev, eventTime, true); |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4619 | |
| 4620 | if (MEASURE_LATENCY) { |
| 4621 | lt.sample("7 after svr->client ipc ", System.nanoTime() - eventTimeNano); |
| 4622 | } |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4623 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4624 | } catch (android.os.RemoteException e) { |
| 4625 | Log.i(TAG, "WINDOW DIED during motion dispatch: " + target); |
| 4626 | mKeyWaiter.mMotionTarget = null; |
| 4627 | try { |
| 4628 | removeWindow(target.mSession, target.mClient); |
| 4629 | } catch (java.util.NoSuchElementException ex) { |
| 4630 | // This will happen if the window has already been |
| 4631 | // removed. |
| 4632 | } |
| 4633 | } |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4634 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4635 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4636 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4637 | /** |
| 4638 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4639 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4640 | 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] | 4641 | if (DEBUG_INPUT) Log.v( |
| 4642 | TAG, "dispatchTrackball [" + ev.getAction() +"] <" + ev.getX() + ", " + ev.getY() + ">"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4643 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4644 | Object focusObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4645 | ev, false, false, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4646 | if (focusObj == null) { |
| 4647 | Log.w(TAG, "No focus window, dropping trackball: " + ev); |
| 4648 | if (qev != null) { |
| 4649 | mQueue.recycleEvent(qev); |
| 4650 | } |
| 4651 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4652 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4653 | } |
| 4654 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| 4655 | if (qev != null) { |
| 4656 | mQueue.recycleEvent(qev); |
| 4657 | } |
| 4658 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4659 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4660 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4661 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4662 | WindowState focus = (WindowState)focusObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4663 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4664 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 4665 | if (mContext.checkPermission( |
| 4666 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 4667 | != PackageManager.PERMISSION_GRANTED) { |
| 4668 | Log.w(TAG, "Permission denied: injecting key event from pid " |
| 4669 | + pid + " uid " + uid + " to window " + focus |
| 4670 | + " owned by uid " + focus.mSession.mUid); |
| 4671 | if (qev != null) { |
| 4672 | mQueue.recycleEvent(qev); |
| 4673 | } |
| 4674 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4675 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4676 | } |
| 4677 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4678 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4679 | final long eventTime = ev.getEventTime(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4680 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4681 | synchronized(mWindowMap) { |
| 4682 | if (qev != null && ev.getAction() == MotionEvent.ACTION_MOVE) { |
| 4683 | mKeyWaiter.bindTargetWindowLocked(focus, |
| 4684 | KeyWaiter.RETURN_PENDING_TRACKBALL, qev); |
| 4685 | // We don't deliver movement events to the client, we hold |
| 4686 | // them and wait for them to call back. |
| 4687 | ev = null; |
| 4688 | } else { |
| 4689 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 4690 | } |
| 4691 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4692 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4693 | try { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 4694 | focus.mClient.dispatchTrackball(ev, eventTime, true); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4695 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4696 | } catch (android.os.RemoteException e) { |
| 4697 | Log.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| 4698 | try { |
| 4699 | removeWindow(focus.mSession, focus.mClient); |
| 4700 | } catch (java.util.NoSuchElementException ex) { |
| 4701 | // This will happen if the window has already been |
| 4702 | // removed. |
| 4703 | } |
| 4704 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4705 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4706 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4707 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4708 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4709 | /** |
| 4710 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4711 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4712 | private int dispatchKey(KeyEvent event, int pid, int uid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4713 | if (DEBUG_INPUT) Log.v(TAG, "Dispatch key: " + event); |
| 4714 | |
| 4715 | Object focusObj = mKeyWaiter.waitForNextEventTarget(event, null, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4716 | null, false, false, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4717 | if (focusObj == null) { |
| 4718 | Log.w(TAG, "No focus window, dropping: " + event); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4719 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4720 | } |
| 4721 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4722 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4723 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4724 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4725 | WindowState focus = (WindowState)focusObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4726 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4727 | if (DEBUG_INPUT) Log.v( |
| 4728 | TAG, "Dispatching to " + focus + ": " + event); |
| 4729 | |
| 4730 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 4731 | if (mContext.checkPermission( |
| 4732 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 4733 | != PackageManager.PERMISSION_GRANTED) { |
| 4734 | Log.w(TAG, "Permission denied: injecting key event from pid " |
| 4735 | + pid + " uid " + uid + " to window " + focus |
| 4736 | + " owned by uid " + focus.mSession.mUid); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4737 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4738 | } |
| 4739 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4740 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4741 | synchronized(mWindowMap) { |
| 4742 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 4743 | } |
| 4744 | |
| 4745 | // NOSHIP extra state logging |
| 4746 | mKeyWaiter.recordDispatchState(event, focus); |
| 4747 | // END NOSHIP |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4748 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4749 | try { |
| 4750 | if (DEBUG_INPUT || DEBUG_FOCUS) { |
| 4751 | Log.v(TAG, "Delivering key " + event.getKeyCode() |
| 4752 | + " to " + focus); |
| 4753 | } |
| 4754 | focus.mClient.dispatchKey(event); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4755 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4756 | } catch (android.os.RemoteException e) { |
| 4757 | Log.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| 4758 | try { |
| 4759 | removeWindow(focus.mSession, focus.mClient); |
| 4760 | } catch (java.util.NoSuchElementException ex) { |
| 4761 | // This will happen if the window has already been |
| 4762 | // removed. |
| 4763 | } |
| 4764 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4765 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4766 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4767 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4768 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4769 | public void pauseKeyDispatching(IBinder _token) { |
| 4770 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4771 | "pauseKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4772 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4773 | } |
| 4774 | |
| 4775 | synchronized (mWindowMap) { |
| 4776 | WindowToken token = mTokenMap.get(_token); |
| 4777 | if (token != null) { |
| 4778 | mKeyWaiter.pauseDispatchingLocked(token); |
| 4779 | } |
| 4780 | } |
| 4781 | } |
| 4782 | |
| 4783 | public void resumeKeyDispatching(IBinder _token) { |
| 4784 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4785 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4786 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4787 | } |
| 4788 | |
| 4789 | synchronized (mWindowMap) { |
| 4790 | WindowToken token = mTokenMap.get(_token); |
| 4791 | if (token != null) { |
| 4792 | mKeyWaiter.resumeDispatchingLocked(token); |
| 4793 | } |
| 4794 | } |
| 4795 | } |
| 4796 | |
| 4797 | public void setEventDispatching(boolean enabled) { |
| 4798 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4799 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4800 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4801 | } |
| 4802 | |
| 4803 | synchronized (mWindowMap) { |
| 4804 | mKeyWaiter.setEventDispatchingLocked(enabled); |
| 4805 | } |
| 4806 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4807 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4808 | /** |
| 4809 | * Injects a keystroke event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4810 | * |
| 4811 | * @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] | 4812 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 4813 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 4814 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4815 | */ |
| 4816 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 4817 | long downTime = ev.getDownTime(); |
| 4818 | long eventTime = ev.getEventTime(); |
| 4819 | |
| 4820 | int action = ev.getAction(); |
| 4821 | int code = ev.getKeyCode(); |
| 4822 | int repeatCount = ev.getRepeatCount(); |
| 4823 | int metaState = ev.getMetaState(); |
| 4824 | int deviceId = ev.getDeviceId(); |
| 4825 | int scancode = ev.getScanCode(); |
| 4826 | |
| 4827 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 4828 | if (downTime == 0) downTime = eventTime; |
| 4829 | |
| 4830 | 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] | 4831 | deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4832 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4833 | final int pid = Binder.getCallingPid(); |
| 4834 | final int uid = Binder.getCallingUid(); |
| 4835 | final long ident = Binder.clearCallingIdentity(); |
| 4836 | final int result = dispatchKey(newEvent, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4837 | if (sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4838 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4839 | } |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4840 | Binder.restoreCallingIdentity(ident); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4841 | switch (result) { |
| 4842 | case INJECT_NO_PERMISSION: |
| 4843 | throw new SecurityException( |
| 4844 | "Injecting to another application requires INJECT_EVENT permission"); |
| 4845 | case INJECT_SUCCEEDED: |
| 4846 | return true; |
| 4847 | } |
| 4848 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4849 | } |
| 4850 | |
| 4851 | /** |
| 4852 | * Inject a pointer (touch) event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4853 | * |
| 4854 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 4855 | * {@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] | 4856 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 4857 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 4858 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4859 | */ |
| 4860 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4861 | final int pid = Binder.getCallingPid(); |
| 4862 | final int uid = Binder.getCallingUid(); |
| 4863 | final long ident = Binder.clearCallingIdentity(); |
| 4864 | final int result = dispatchPointer(null, ev, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4865 | if (sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4866 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4867 | } |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4868 | Binder.restoreCallingIdentity(ident); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4869 | switch (result) { |
| 4870 | case INJECT_NO_PERMISSION: |
| 4871 | throw new SecurityException( |
| 4872 | "Injecting to another application requires INJECT_EVENT permission"); |
| 4873 | case INJECT_SUCCEEDED: |
| 4874 | return true; |
| 4875 | } |
| 4876 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4877 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4878 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4879 | /** |
| 4880 | * Inject a trackball (navigation device) event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4881 | * |
| 4882 | * @param ev A motion event describing the trackball action. (As noted in |
| 4883 | * {@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] | 4884 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 4885 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 4886 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4887 | */ |
| 4888 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4889 | final int pid = Binder.getCallingPid(); |
| 4890 | final int uid = Binder.getCallingUid(); |
| 4891 | final long ident = Binder.clearCallingIdentity(); |
| 4892 | final int result = dispatchTrackball(null, ev, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4893 | if (sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4894 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4895 | } |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4896 | Binder.restoreCallingIdentity(ident); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4897 | switch (result) { |
| 4898 | case INJECT_NO_PERMISSION: |
| 4899 | throw new SecurityException( |
| 4900 | "Injecting to another application requires INJECT_EVENT permission"); |
| 4901 | case INJECT_SUCCEEDED: |
| 4902 | return true; |
| 4903 | } |
| 4904 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4905 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4906 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4907 | private WindowState getFocusedWindow() { |
| 4908 | synchronized (mWindowMap) { |
| 4909 | return getFocusedWindowLocked(); |
| 4910 | } |
| 4911 | } |
| 4912 | |
| 4913 | private WindowState getFocusedWindowLocked() { |
| 4914 | return mCurrentFocus; |
| 4915 | } |
| 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 | /** |
| 4918 | * This class holds the state for dispatching key events. This state |
| 4919 | * is protected by the KeyWaiter instance, NOT by the window lock. You |
| 4920 | * can be holding the main window lock while acquire the KeyWaiter lock, |
| 4921 | * but not the other way around. |
| 4922 | */ |
| 4923 | final class KeyWaiter { |
| 4924 | // NOSHIP debugging |
| 4925 | public class DispatchState { |
| 4926 | private KeyEvent event; |
| 4927 | private WindowState focus; |
| 4928 | private long time; |
| 4929 | private WindowState lastWin; |
| 4930 | private IBinder lastBinder; |
| 4931 | private boolean finished; |
| 4932 | private boolean gotFirstWindow; |
| 4933 | private boolean eventDispatching; |
| 4934 | private long timeToSwitch; |
| 4935 | private boolean wasFrozen; |
| 4936 | private boolean focusPaused; |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 4937 | private WindowState curFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4938 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4939 | DispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 4940 | focus = theFocus; |
| 4941 | event = theEvent; |
| 4942 | time = System.currentTimeMillis(); |
| 4943 | // snapshot KeyWaiter state |
| 4944 | lastWin = mLastWin; |
| 4945 | lastBinder = mLastBinder; |
| 4946 | finished = mFinished; |
| 4947 | gotFirstWindow = mGotFirstWindow; |
| 4948 | eventDispatching = mEventDispatching; |
| 4949 | timeToSwitch = mTimeToSwitch; |
| 4950 | wasFrozen = mWasFrozen; |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 4951 | curFocus = mCurrentFocus; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4952 | // cache the paused state at ctor time as well |
| 4953 | if (theFocus == null || theFocus.mToken == null) { |
| 4954 | Log.i(TAG, "focus " + theFocus + " mToken is null at event dispatch!"); |
| 4955 | focusPaused = false; |
| 4956 | } else { |
| 4957 | focusPaused = theFocus.mToken.paused; |
| 4958 | } |
| 4959 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4960 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4961 | public String toString() { |
| 4962 | return "{{" + event + " to " + focus + " @ " + time |
| 4963 | + " lw=" + lastWin + " lb=" + lastBinder |
| 4964 | + " fin=" + finished + " gfw=" + gotFirstWindow |
| 4965 | + " ed=" + eventDispatching + " tts=" + timeToSwitch |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 4966 | + " wf=" + wasFrozen + " fp=" + focusPaused |
| 4967 | + " mcf=" + mCurrentFocus + "}}"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4968 | } |
| 4969 | }; |
| 4970 | private DispatchState mDispatchState = null; |
| 4971 | public void recordDispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 4972 | mDispatchState = new DispatchState(theEvent, theFocus); |
| 4973 | } |
| 4974 | // END NOSHIP |
| 4975 | |
| 4976 | public static final int RETURN_NOTHING = 0; |
| 4977 | public static final int RETURN_PENDING_POINTER = 1; |
| 4978 | public static final int RETURN_PENDING_TRACKBALL = 2; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4979 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4980 | final Object SKIP_TARGET_TOKEN = new Object(); |
| 4981 | final Object CONSUMED_EVENT_TOKEN = new Object(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4982 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4983 | private WindowState mLastWin = null; |
| 4984 | private IBinder mLastBinder = null; |
| 4985 | private boolean mFinished = true; |
| 4986 | private boolean mGotFirstWindow = false; |
| 4987 | private boolean mEventDispatching = true; |
| 4988 | private long mTimeToSwitch = 0; |
| 4989 | /* package */ boolean mWasFrozen = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4990 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4991 | // Target of Motion events |
| 4992 | WindowState mMotionTarget; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4993 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4994 | // Windows above the target who would like to receive an "outside" |
| 4995 | // touch event for any down events outside of them. |
| 4996 | WindowState mOutsideTouchTargets; |
| 4997 | |
| 4998 | /** |
| 4999 | * Wait for the last event dispatch to complete, then find the next |
| 5000 | * target that should receive the given event and wait for that one |
| 5001 | * to be ready to receive it. |
| 5002 | */ |
| 5003 | Object waitForNextEventTarget(KeyEvent nextKey, QueuedEvent qev, |
| 5004 | MotionEvent nextMotion, boolean isPointerEvent, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5005 | boolean failIfTimeout, int callingPid, int callingUid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5006 | long startTime = SystemClock.uptimeMillis(); |
| 5007 | long keyDispatchingTimeout = 5 * 1000; |
| 5008 | long waitedFor = 0; |
| 5009 | |
| 5010 | while (true) { |
| 5011 | // Figure out which window we care about. It is either the |
| 5012 | // last window we are waiting to have process the event or, |
| 5013 | // if none, then the next window we think the event should go |
| 5014 | // to. Note: we retrieve mLastWin outside of the lock, so |
| 5015 | // it may change before we lock. Thus we must check it again. |
| 5016 | WindowState targetWin = mLastWin; |
| 5017 | boolean targetIsNew = targetWin == null; |
| 5018 | if (DEBUG_INPUT) Log.v( |
| 5019 | TAG, "waitForLastKey: mFinished=" + mFinished + |
| 5020 | ", mLastWin=" + mLastWin); |
| 5021 | if (targetIsNew) { |
| 5022 | Object target = findTargetWindow(nextKey, qev, nextMotion, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5023 | isPointerEvent, callingPid, callingUid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5024 | if (target == SKIP_TARGET_TOKEN) { |
| 5025 | // The user has pressed a special key, and we are |
| 5026 | // dropping all pending events before it. |
| 5027 | if (DEBUG_INPUT) Log.v(TAG, "Skipping: " + nextKey |
| 5028 | + " " + nextMotion); |
| 5029 | return null; |
| 5030 | } |
| 5031 | if (target == CONSUMED_EVENT_TOKEN) { |
| 5032 | if (DEBUG_INPUT) Log.v(TAG, "Consumed: " + nextKey |
| 5033 | + " " + nextMotion); |
| 5034 | return target; |
| 5035 | } |
| 5036 | targetWin = (WindowState)target; |
| 5037 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5038 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5039 | AppWindowToken targetApp = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5040 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5041 | // Now: is it okay to send the next event to this window? |
| 5042 | synchronized (this) { |
| 5043 | // First: did we come here based on the last window not |
| 5044 | // being null, but it changed by the time we got here? |
| 5045 | // If so, try again. |
| 5046 | if (!targetIsNew && mLastWin == null) { |
| 5047 | continue; |
| 5048 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5049 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5050 | // We never dispatch events if not finished with the |
| 5051 | // last one, or the display is frozen. |
| 5052 | if (mFinished && !mDisplayFrozen) { |
| 5053 | // If event dispatching is disabled, then we |
| 5054 | // just consume the events. |
| 5055 | if (!mEventDispatching) { |
| 5056 | if (DEBUG_INPUT) Log.v(TAG, |
| 5057 | "Skipping event; dispatching disabled: " |
| 5058 | + nextKey + " " + nextMotion); |
| 5059 | return null; |
| 5060 | } |
| 5061 | if (targetWin != null) { |
| 5062 | // If this is a new target, and that target is not |
| 5063 | // paused or unresponsive, then all looks good to |
| 5064 | // handle the event. |
| 5065 | if (targetIsNew && !targetWin.mToken.paused) { |
| 5066 | return targetWin; |
| 5067 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5068 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5069 | // If we didn't find a target window, and there is no |
| 5070 | // focused app window, then just eat the events. |
| 5071 | } else if (mFocusedApp == null) { |
| 5072 | if (DEBUG_INPUT) Log.v(TAG, |
| 5073 | "Skipping event; no focused app: " |
| 5074 | + nextKey + " " + nextMotion); |
| 5075 | return null; |
| 5076 | } |
| 5077 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5078 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5079 | if (DEBUG_INPUT) Log.v( |
| 5080 | TAG, "Waiting for last key in " + mLastBinder |
| 5081 | + " target=" + targetWin |
| 5082 | + " mFinished=" + mFinished |
| 5083 | + " mDisplayFrozen=" + mDisplayFrozen |
| 5084 | + " targetIsNew=" + targetIsNew |
| 5085 | + " paused=" |
| 5086 | + (targetWin != null ? targetWin.mToken.paused : false) |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5087 | + " mFocusedApp=" + mFocusedApp |
| 5088 | + " mCurrentFocus=" + mCurrentFocus); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5089 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5090 | targetApp = targetWin != null |
| 5091 | ? targetWin.mAppToken : mFocusedApp; |
| 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 | long curTimeout = keyDispatchingTimeout; |
| 5094 | if (mTimeToSwitch != 0) { |
| 5095 | long now = SystemClock.uptimeMillis(); |
| 5096 | if (mTimeToSwitch <= now) { |
| 5097 | // If an app switch key has been pressed, and we have |
| 5098 | // waited too long for the current app to finish |
| 5099 | // processing keys, then wait no more! |
| 5100 | doFinishedKeyLocked(true); |
| 5101 | continue; |
| 5102 | } |
| 5103 | long switchTimeout = mTimeToSwitch - now; |
| 5104 | if (curTimeout > switchTimeout) { |
| 5105 | curTimeout = switchTimeout; |
| 5106 | } |
| 5107 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5108 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5109 | try { |
| 5110 | // after that continue |
| 5111 | // processing keys, so we don't get stuck. |
| 5112 | if (DEBUG_INPUT) Log.v( |
| 5113 | TAG, "Waiting for key dispatch: " + curTimeout); |
| 5114 | wait(curTimeout); |
| 5115 | if (DEBUG_INPUT) Log.v(TAG, "Finished waiting @" |
| 5116 | + SystemClock.uptimeMillis() + " startTime=" |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5117 | + startTime + " switchTime=" + mTimeToSwitch |
| 5118 | + " target=" + targetWin + " mLW=" + mLastWin |
| 5119 | + " mLB=" + mLastBinder + " fin=" + mFinished |
| 5120 | + " mCurrentFocus=" + mCurrentFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5121 | } catch (InterruptedException e) { |
| 5122 | } |
| 5123 | } |
| 5124 | |
| 5125 | // If we were frozen during configuration change, restart the |
| 5126 | // timeout checks from now; otherwise look at whether we timed |
| 5127 | // out before awakening. |
| 5128 | if (mWasFrozen) { |
| 5129 | waitedFor = 0; |
| 5130 | mWasFrozen = false; |
| 5131 | } else { |
| 5132 | waitedFor = SystemClock.uptimeMillis() - startTime; |
| 5133 | } |
| 5134 | |
| 5135 | if (waitedFor >= keyDispatchingTimeout && mTimeToSwitch == 0) { |
| 5136 | IApplicationToken at = null; |
| 5137 | synchronized (this) { |
| 5138 | Log.w(TAG, "Key dispatching timed out sending to " + |
| 5139 | (targetWin != null ? targetWin.mAttrs.getTitle() |
| 5140 | : "<null>")); |
| 5141 | // NOSHIP debugging |
| 5142 | Log.w(TAG, "Dispatch state: " + mDispatchState); |
| 5143 | Log.w(TAG, "Current state: " + new DispatchState(nextKey, targetWin)); |
| 5144 | // END NOSHIP |
| 5145 | //dump(); |
| 5146 | if (targetWin != null) { |
| 5147 | at = targetWin.getAppToken(); |
| 5148 | } else if (targetApp != null) { |
| 5149 | at = targetApp.appToken; |
| 5150 | } |
| 5151 | } |
| 5152 | |
| 5153 | boolean abort = true; |
| 5154 | if (at != null) { |
| 5155 | try { |
| 5156 | long timeout = at.getKeyDispatchingTimeout(); |
| 5157 | if (timeout > waitedFor) { |
| 5158 | // we did not wait the proper amount of time for this application. |
| 5159 | // set the timeout to be the real timeout and wait again. |
| 5160 | keyDispatchingTimeout = timeout - waitedFor; |
| 5161 | continue; |
| 5162 | } else { |
| 5163 | abort = at.keyDispatchingTimedOut(); |
| 5164 | } |
| 5165 | } catch (RemoteException ex) { |
| 5166 | } |
| 5167 | } |
| 5168 | |
| 5169 | synchronized (this) { |
| 5170 | if (abort && (mLastWin == targetWin || targetWin == null)) { |
| 5171 | mFinished = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5172 | if (mLastWin != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5173 | if (DEBUG_INPUT) Log.v(TAG, |
| 5174 | "Window " + mLastWin + |
| 5175 | " timed out on key input"); |
| 5176 | if (mLastWin.mToken.paused) { |
| 5177 | Log.w(TAG, "Un-pausing dispatching to this window"); |
| 5178 | mLastWin.mToken.paused = false; |
| 5179 | } |
| 5180 | } |
| 5181 | if (mMotionTarget == targetWin) { |
| 5182 | mMotionTarget = null; |
| 5183 | } |
| 5184 | mLastWin = null; |
| 5185 | mLastBinder = null; |
| 5186 | if (failIfTimeout || targetWin == null) { |
| 5187 | return null; |
| 5188 | } |
| 5189 | } else { |
| 5190 | Log.w(TAG, "Continuing to wait for key to be dispatched"); |
| 5191 | startTime = SystemClock.uptimeMillis(); |
| 5192 | } |
| 5193 | } |
| 5194 | } |
| 5195 | } |
| 5196 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5197 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5198 | Object findTargetWindow(KeyEvent nextKey, QueuedEvent qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5199 | MotionEvent nextMotion, boolean isPointerEvent, |
| 5200 | int callingPid, int callingUid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5201 | mOutsideTouchTargets = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5202 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5203 | if (nextKey != null) { |
| 5204 | // Find the target window for a normal key event. |
| 5205 | final int keycode = nextKey.getKeyCode(); |
| 5206 | final int repeatCount = nextKey.getRepeatCount(); |
| 5207 | final boolean down = nextKey.getAction() != KeyEvent.ACTION_UP; |
| 5208 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(keycode); |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5209 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5210 | if (!dispatch) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5211 | if (callingUid == 0 || |
| 5212 | mContext.checkPermission( |
| 5213 | android.Manifest.permission.INJECT_EVENTS, |
| 5214 | callingPid, callingUid) |
| 5215 | == PackageManager.PERMISSION_GRANTED) { |
| 5216 | mPolicy.interceptKeyTi(null, keycode, |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 5217 | nextKey.getMetaState(), down, repeatCount, |
| 5218 | nextKey.getFlags()); |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5219 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5220 | Log.w(TAG, "Event timeout during app switch: dropping " |
| 5221 | + nextKey); |
| 5222 | return SKIP_TARGET_TOKEN; |
| 5223 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5224 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5225 | // System.out.println("##### [" + SystemClock.uptimeMillis() + "] WindowManagerService.dispatchKey(" + keycode + ", " + down + ", " + repeatCount + ")"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5226 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5227 | WindowState focus = null; |
| 5228 | synchronized(mWindowMap) { |
| 5229 | focus = getFocusedWindowLocked(); |
| 5230 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5231 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5232 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5233 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5234 | if (callingUid == 0 || |
| 5235 | (focus != null && callingUid == focus.mSession.mUid) || |
| 5236 | mContext.checkPermission( |
| 5237 | android.Manifest.permission.INJECT_EVENTS, |
| 5238 | callingPid, callingUid) |
| 5239 | == PackageManager.PERMISSION_GRANTED) { |
| 5240 | if (mPolicy.interceptKeyTi(focus, |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 5241 | keycode, nextKey.getMetaState(), down, repeatCount, |
| 5242 | nextKey.getFlags())) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5243 | return CONSUMED_EVENT_TOKEN; |
| 5244 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5245 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5246 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5247 | return focus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5248 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5249 | } else if (!isPointerEvent) { |
| 5250 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(-1); |
| 5251 | if (!dispatch) { |
| 5252 | Log.w(TAG, "Event timeout during app switch: dropping trackball " |
| 5253 | + nextMotion); |
| 5254 | return SKIP_TARGET_TOKEN; |
| 5255 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5256 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5257 | WindowState focus = null; |
| 5258 | synchronized(mWindowMap) { |
| 5259 | focus = getFocusedWindowLocked(); |
| 5260 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5261 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5262 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
| 5263 | return focus; |
| 5264 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5265 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5266 | if (nextMotion == null) { |
| 5267 | return SKIP_TARGET_TOKEN; |
| 5268 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5269 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5270 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey( |
| 5271 | KeyEvent.KEYCODE_UNKNOWN); |
| 5272 | if (!dispatch) { |
| 5273 | Log.w(TAG, "Event timeout during app switch: dropping pointer " |
| 5274 | + nextMotion); |
| 5275 | return SKIP_TARGET_TOKEN; |
| 5276 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5277 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5278 | // Find the target window for a pointer event. |
| 5279 | int action = nextMotion.getAction(); |
| 5280 | final float xf = nextMotion.getX(); |
| 5281 | final float yf = nextMotion.getY(); |
| 5282 | final long eventTime = nextMotion.getEventTime(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5283 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5284 | final boolean screenWasOff = qev != null |
| 5285 | && (qev.flags&WindowManagerPolicy.FLAG_BRIGHT_HERE) != 0; |
| 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 | WindowState target = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5288 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5289 | synchronized(mWindowMap) { |
| 5290 | synchronized (this) { |
| 5291 | if (action == MotionEvent.ACTION_DOWN) { |
| 5292 | if (mMotionTarget != null) { |
| 5293 | // this is weird, we got a pen down, but we thought it was |
| 5294 | // already down! |
| 5295 | // XXX: We should probably send an ACTION_UP to the current |
| 5296 | // target. |
| 5297 | Log.w(TAG, "Pointer down received while already down in: " |
| 5298 | + mMotionTarget); |
| 5299 | mMotionTarget = null; |
| 5300 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5301 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5302 | // ACTION_DOWN is special, because we need to lock next events to |
| 5303 | // the window we'll land onto. |
| 5304 | final int x = (int)xf; |
| 5305 | final int y = (int)yf; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5306 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5307 | final ArrayList windows = mWindows; |
| 5308 | final int N = windows.size(); |
| 5309 | WindowState topErrWindow = null; |
| 5310 | final Rect tmpRect = mTempRect; |
| 5311 | for (int i=N-1; i>=0; i--) { |
| 5312 | WindowState child = (WindowState)windows.get(i); |
| 5313 | //Log.i(TAG, "Checking dispatch to: " + child); |
| 5314 | final int flags = child.mAttrs.flags; |
| 5315 | if ((flags & WindowManager.LayoutParams.FLAG_SYSTEM_ERROR) != 0) { |
| 5316 | if (topErrWindow == null) { |
| 5317 | topErrWindow = child; |
| 5318 | } |
| 5319 | } |
| 5320 | if (!child.isVisibleLw()) { |
| 5321 | //Log.i(TAG, "Not visible!"); |
| 5322 | continue; |
| 5323 | } |
| 5324 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 5325 | //Log.i(TAG, "Not touchable!"); |
| 5326 | if ((flags & WindowManager.LayoutParams |
| 5327 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 5328 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 5329 | mOutsideTouchTargets = child; |
| 5330 | } |
| 5331 | continue; |
| 5332 | } |
| 5333 | tmpRect.set(child.mFrame); |
| 5334 | if (child.mTouchableInsets == ViewTreeObserver |
| 5335 | .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) { |
| 5336 | // The touch is inside of the window if it is |
| 5337 | // inside the frame, AND the content part of that |
| 5338 | // frame that was given by the application. |
| 5339 | tmpRect.left += child.mGivenContentInsets.left; |
| 5340 | tmpRect.top += child.mGivenContentInsets.top; |
| 5341 | tmpRect.right -= child.mGivenContentInsets.right; |
| 5342 | tmpRect.bottom -= child.mGivenContentInsets.bottom; |
| 5343 | } else if (child.mTouchableInsets == ViewTreeObserver |
| 5344 | .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) { |
| 5345 | // The touch is inside of the window if it is |
| 5346 | // inside the frame, AND the visible part of that |
| 5347 | // frame that was given by the application. |
| 5348 | tmpRect.left += child.mGivenVisibleInsets.left; |
| 5349 | tmpRect.top += child.mGivenVisibleInsets.top; |
| 5350 | tmpRect.right -= child.mGivenVisibleInsets.right; |
| 5351 | tmpRect.bottom -= child.mGivenVisibleInsets.bottom; |
| 5352 | } |
| 5353 | final int touchFlags = flags & |
| 5354 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 5355 | |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 5356 | if (tmpRect.contains(x, y) || touchFlags == 0) { |
| 5357 | //Log.i(TAG, "Using this target!"); |
| 5358 | if (!screenWasOff || (flags & |
| 5359 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING) != 0) { |
| 5360 | mMotionTarget = child; |
| 5361 | } else { |
| 5362 | //Log.i(TAG, "Waking, skip!"); |
| 5363 | mMotionTarget = null; |
| 5364 | } |
| 5365 | break; |
| 5366 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5367 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5368 | if ((flags & WindowManager.LayoutParams |
| 5369 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 5370 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 5371 | mOutsideTouchTargets = child; |
| 5372 | //Log.i(TAG, "Adding to outside target list: " + child); |
| 5373 | } |
| 5374 | } |
| 5375 | |
| 5376 | // if there's an error window but it's not accepting |
| 5377 | // focus (typically because it is not yet visible) just |
| 5378 | // wait for it -- any other focused window may in fact |
| 5379 | // be in ANR state. |
| 5380 | if (topErrWindow != null && mMotionTarget != topErrWindow) { |
| 5381 | mMotionTarget = null; |
| 5382 | } |
| 5383 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5384 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5385 | target = mMotionTarget; |
| 5386 | } |
| 5387 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5388 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5389 | wakeupIfNeeded(target, eventType(nextMotion)); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5390 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5391 | // Pointer events are a little different -- if there isn't a |
| 5392 | // target found for any event, then just drop it. |
| 5393 | return target != null ? target : SKIP_TARGET_TOKEN; |
| 5394 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5395 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5396 | boolean checkShouldDispatchKey(int keycode) { |
| 5397 | synchronized (this) { |
| 5398 | if (mPolicy.isAppSwitchKeyTqTiLwLi(keycode)) { |
| 5399 | mTimeToSwitch = 0; |
| 5400 | return true; |
| 5401 | } |
| 5402 | if (mTimeToSwitch != 0 |
| 5403 | && mTimeToSwitch < SystemClock.uptimeMillis()) { |
| 5404 | return false; |
| 5405 | } |
| 5406 | return true; |
| 5407 | } |
| 5408 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5409 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5410 | void bindTargetWindowLocked(WindowState win, |
| 5411 | int pendingWhat, QueuedEvent pendingMotion) { |
| 5412 | synchronized (this) { |
| 5413 | bindTargetWindowLockedLocked(win, pendingWhat, pendingMotion); |
| 5414 | } |
| 5415 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5416 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5417 | void bindTargetWindowLocked(WindowState win) { |
| 5418 | synchronized (this) { |
| 5419 | bindTargetWindowLockedLocked(win, RETURN_NOTHING, null); |
| 5420 | } |
| 5421 | } |
| 5422 | |
| 5423 | void bindTargetWindowLockedLocked(WindowState win, |
| 5424 | int pendingWhat, QueuedEvent pendingMotion) { |
| 5425 | mLastWin = win; |
| 5426 | mLastBinder = win.mClient.asBinder(); |
| 5427 | mFinished = false; |
| 5428 | if (pendingMotion != null) { |
| 5429 | final Session s = win.mSession; |
| 5430 | if (pendingWhat == RETURN_PENDING_POINTER) { |
| 5431 | releasePendingPointerLocked(s); |
| 5432 | s.mPendingPointerMove = pendingMotion; |
| 5433 | s.mPendingPointerWindow = win; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5434 | if (DEBUG_INPUT) Log.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5435 | "bindTargetToWindow " + s.mPendingPointerMove); |
| 5436 | } else if (pendingWhat == RETURN_PENDING_TRACKBALL) { |
| 5437 | releasePendingTrackballLocked(s); |
| 5438 | s.mPendingTrackballMove = pendingMotion; |
| 5439 | s.mPendingTrackballWindow = win; |
| 5440 | } |
| 5441 | } |
| 5442 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5443 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5444 | void releasePendingPointerLocked(Session s) { |
| 5445 | if (DEBUG_INPUT) Log.v(TAG, |
| 5446 | "releasePendingPointer " + s.mPendingPointerMove); |
| 5447 | if (s.mPendingPointerMove != null) { |
| 5448 | mQueue.recycleEvent(s.mPendingPointerMove); |
| 5449 | s.mPendingPointerMove = null; |
| 5450 | } |
| 5451 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5452 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5453 | void releasePendingTrackballLocked(Session s) { |
| 5454 | if (s.mPendingTrackballMove != null) { |
| 5455 | mQueue.recycleEvent(s.mPendingTrackballMove); |
| 5456 | s.mPendingTrackballMove = null; |
| 5457 | } |
| 5458 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5459 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5460 | MotionEvent finishedKey(Session session, IWindow client, boolean force, |
| 5461 | int returnWhat) { |
| 5462 | if (DEBUG_INPUT) Log.v( |
| 5463 | TAG, "finishedKey: client=" + client + ", force=" + force); |
| 5464 | |
| 5465 | if (client == null) { |
| 5466 | return null; |
| 5467 | } |
| 5468 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5469 | MotionEvent res = null; |
| 5470 | QueuedEvent qev = null; |
| 5471 | WindowState win = null; |
| 5472 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5473 | synchronized (this) { |
| 5474 | if (DEBUG_INPUT) Log.v( |
| 5475 | TAG, "finishedKey: client=" + client.asBinder() |
| 5476 | + ", force=" + force + ", last=" + mLastBinder |
| 5477 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) + ")"); |
| 5478 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5479 | if (returnWhat == RETURN_PENDING_POINTER) { |
| 5480 | qev = session.mPendingPointerMove; |
| 5481 | win = session.mPendingPointerWindow; |
| 5482 | session.mPendingPointerMove = null; |
| 5483 | session.mPendingPointerWindow = null; |
| 5484 | } else if (returnWhat == RETURN_PENDING_TRACKBALL) { |
| 5485 | qev = session.mPendingTrackballMove; |
| 5486 | win = session.mPendingTrackballWindow; |
| 5487 | session.mPendingTrackballMove = null; |
| 5488 | session.mPendingTrackballWindow = null; |
| 5489 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5490 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5491 | if (mLastBinder == client.asBinder()) { |
| 5492 | if (DEBUG_INPUT) Log.v( |
| 5493 | TAG, "finishedKey: last paused=" |
| 5494 | + ((mLastWin != null) ? mLastWin.mToken.paused : "null")); |
| 5495 | if (mLastWin != null && (!mLastWin.mToken.paused || force |
| 5496 | || !mEventDispatching)) { |
| 5497 | doFinishedKeyLocked(false); |
| 5498 | } else { |
| 5499 | // Make sure to wake up anyone currently waiting to |
| 5500 | // dispatch a key, so they can re-evaluate their |
| 5501 | // current situation. |
| 5502 | mFinished = true; |
| 5503 | notifyAll(); |
| 5504 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5505 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5506 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5507 | if (qev != null) { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5508 | res = (MotionEvent)qev.event; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5509 | if (DEBUG_INPUT) Log.v(TAG, |
| 5510 | "Returning pending motion: " + res); |
| 5511 | mQueue.recycleEvent(qev); |
| 5512 | if (win != null && returnWhat == RETURN_PENDING_POINTER) { |
| 5513 | res.offsetLocation(-win.mFrame.left, -win.mFrame.top); |
| 5514 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5515 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5516 | } |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5517 | |
| 5518 | if (res != null && returnWhat == RETURN_PENDING_POINTER) { |
| 5519 | synchronized (mWindowMap) { |
| 5520 | if (mWallpaperTarget == win) { |
| 5521 | sendPointerToWallpaperLocked(win, res, res.getEventTime()); |
| 5522 | } |
| 5523 | } |
| 5524 | } |
| 5525 | |
| 5526 | return res; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5527 | } |
| 5528 | |
| 5529 | void tickle() { |
| 5530 | synchronized (this) { |
| 5531 | notifyAll(); |
| 5532 | } |
| 5533 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5534 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5535 | void handleNewWindowLocked(WindowState newWindow) { |
| 5536 | if (!newWindow.canReceiveKeys()) { |
| 5537 | return; |
| 5538 | } |
| 5539 | synchronized (this) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5540 | if (DEBUG_INPUT) Log.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5541 | TAG, "New key dispatch window: win=" |
| 5542 | + newWindow.mClient.asBinder() |
| 5543 | + ", last=" + mLastBinder |
| 5544 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 5545 | + "), finished=" + mFinished + ", paused=" |
| 5546 | + newWindow.mToken.paused); |
| 5547 | |
| 5548 | // Displaying a window implicitly causes dispatching to |
| 5549 | // be unpaused. (This is to protect against bugs if someone |
| 5550 | // pauses dispatching but forgets to resume.) |
| 5551 | newWindow.mToken.paused = false; |
| 5552 | |
| 5553 | mGotFirstWindow = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5554 | |
| 5555 | if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) { |
| 5556 | if (DEBUG_INPUT) Log.v(TAG, |
| 5557 | "New SYSTEM_ERROR window; resetting state"); |
| 5558 | mLastWin = null; |
| 5559 | mLastBinder = null; |
| 5560 | mMotionTarget = null; |
| 5561 | mFinished = true; |
| 5562 | } else if (mLastWin != null) { |
| 5563 | // If the new window is above the window we are |
| 5564 | // waiting on, then stop waiting and let key dispatching |
| 5565 | // start on the new guy. |
| 5566 | if (DEBUG_INPUT) Log.v( |
| 5567 | TAG, "Last win layer=" + mLastWin.mLayer |
| 5568 | + ", new win layer=" + newWindow.mLayer); |
| 5569 | if (newWindow.mLayer >= mLastWin.mLayer) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5570 | // The new window is above the old; finish pending input to the last |
| 5571 | // window and start directing it to the new one. |
| 5572 | mLastWin.mToken.paused = false; |
| 5573 | doFinishedKeyLocked(true); // does a notifyAll() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5574 | } |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5575 | // Either the new window is lower, so there is no need to wake key waiters, |
| 5576 | // or we just finished key input to the previous window, which implicitly |
| 5577 | // notified the key waiters. In both cases, we don't need to issue the |
| 5578 | // notification here. |
| 5579 | return; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5580 | } |
| 5581 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5582 | // Now that we've put a new window state in place, make the event waiter |
| 5583 | // take notice and retarget its attentions. |
| 5584 | notifyAll(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5585 | } |
| 5586 | } |
| 5587 | |
| 5588 | void pauseDispatchingLocked(WindowToken token) { |
| 5589 | synchronized (this) |
| 5590 | { |
| 5591 | if (DEBUG_INPUT) Log.v(TAG, "Pausing WindowToken " + token); |
| 5592 | token.paused = true; |
| 5593 | |
| 5594 | /* |
| 5595 | if (mLastWin != null && !mFinished && mLastWin.mBaseLayer <= layer) { |
| 5596 | mPaused = true; |
| 5597 | } else { |
| 5598 | if (mLastWin == null) { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 5599 | 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] | 5600 | } else if (mFinished) { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 5601 | 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] | 5602 | } else { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 5603 | 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] | 5604 | } |
| 5605 | } |
| 5606 | */ |
| 5607 | } |
| 5608 | } |
| 5609 | |
| 5610 | void resumeDispatchingLocked(WindowToken token) { |
| 5611 | synchronized (this) { |
| 5612 | if (token.paused) { |
| 5613 | if (DEBUG_INPUT) Log.v( |
| 5614 | TAG, "Resuming WindowToken " + token |
| 5615 | + ", last=" + mLastBinder |
| 5616 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 5617 | + "), finished=" + mFinished + ", paused=" |
| 5618 | + token.paused); |
| 5619 | token.paused = false; |
| 5620 | if (mLastWin != null && mLastWin.mToken == token && mFinished) { |
| 5621 | doFinishedKeyLocked(true); |
| 5622 | } else { |
| 5623 | notifyAll(); |
| 5624 | } |
| 5625 | } |
| 5626 | } |
| 5627 | } |
| 5628 | |
| 5629 | void setEventDispatchingLocked(boolean enabled) { |
| 5630 | synchronized (this) { |
| 5631 | mEventDispatching = enabled; |
| 5632 | notifyAll(); |
| 5633 | } |
| 5634 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5635 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5636 | void appSwitchComing() { |
| 5637 | synchronized (this) { |
| 5638 | // Don't wait for more than .5 seconds for app to finish |
| 5639 | // processing the pending events. |
| 5640 | long now = SystemClock.uptimeMillis() + 500; |
| 5641 | if (DEBUG_INPUT) Log.v(TAG, "appSwitchComing: " + now); |
| 5642 | if (mTimeToSwitch == 0 || now < mTimeToSwitch) { |
| 5643 | mTimeToSwitch = now; |
| 5644 | } |
| 5645 | notifyAll(); |
| 5646 | } |
| 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 | private final void doFinishedKeyLocked(boolean doRecycle) { |
| 5650 | if (mLastWin != null) { |
| 5651 | releasePendingPointerLocked(mLastWin.mSession); |
| 5652 | releasePendingTrackballLocked(mLastWin.mSession); |
| 5653 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5654 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5655 | if (mLastWin == null || !mLastWin.mToken.paused |
| 5656 | || !mLastWin.isVisibleLw()) { |
| 5657 | // If the current window has been paused, we aren't -really- |
| 5658 | // finished... so let the waiters still wait. |
| 5659 | mLastWin = null; |
| 5660 | mLastBinder = null; |
| 5661 | } |
| 5662 | mFinished = true; |
| 5663 | notifyAll(); |
| 5664 | } |
| 5665 | } |
| 5666 | |
| 5667 | private class KeyQ extends KeyInputQueue |
| 5668 | implements KeyInputQueue.FilterCallback { |
| 5669 | PowerManager.WakeLock mHoldingScreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5670 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5671 | KeyQ() { |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 5672 | super(mContext, WindowManagerService.this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5673 | PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE); |
| 5674 | mHoldingScreen = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 5675 | "KEEP_SCREEN_ON_FLAG"); |
| 5676 | mHoldingScreen.setReferenceCounted(false); |
| 5677 | } |
| 5678 | |
| 5679 | @Override |
| 5680 | boolean preprocessEvent(InputDevice device, RawInputEvent event) { |
| 5681 | if (mPolicy.preprocessInputEventTq(event)) { |
| 5682 | return true; |
| 5683 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5684 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5685 | switch (event.type) { |
| 5686 | case RawInputEvent.EV_KEY: { |
| 5687 | // XXX begin hack |
| 5688 | if (DEBUG) { |
| 5689 | if (event.keycode == KeyEvent.KEYCODE_G) { |
| 5690 | if (event.value != 0) { |
| 5691 | // G down |
| 5692 | mPolicy.screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 5693 | } |
| 5694 | return false; |
| 5695 | } |
| 5696 | if (event.keycode == KeyEvent.KEYCODE_D) { |
| 5697 | if (event.value != 0) { |
| 5698 | //dump(); |
| 5699 | } |
| 5700 | return false; |
| 5701 | } |
| 5702 | } |
| 5703 | // XXX end hack |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5704 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5705 | boolean screenIsOff = !mPowerManager.screenIsOn(); |
| 5706 | boolean screenIsDim = !mPowerManager.screenIsBright(); |
| 5707 | int actions = mPolicy.interceptKeyTq(event, !screenIsOff); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5708 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5709 | if ((actions & WindowManagerPolicy.ACTION_GO_TO_SLEEP) != 0) { |
| 5710 | mPowerManager.goToSleep(event.when); |
| 5711 | } |
| 5712 | |
| 5713 | if (screenIsOff) { |
| 5714 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 5715 | } |
| 5716 | if (screenIsDim) { |
| 5717 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 5718 | } |
| 5719 | if ((actions & WindowManagerPolicy.ACTION_POKE_USER_ACTIVITY) != 0) { |
| 5720 | mPowerManager.userActivity(event.when, false, |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5721 | LocalPowerManager.BUTTON_EVENT, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5722 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5723 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5724 | if ((actions & WindowManagerPolicy.ACTION_PASS_TO_USER) != 0) { |
| 5725 | if (event.value != 0 && mPolicy.isAppSwitchKeyTqTiLwLi(event.keycode)) { |
| 5726 | filterQueue(this); |
| 5727 | mKeyWaiter.appSwitchComing(); |
| 5728 | } |
| 5729 | return true; |
| 5730 | } else { |
| 5731 | return false; |
| 5732 | } |
| 5733 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5734 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5735 | case RawInputEvent.EV_REL: { |
| 5736 | boolean screenIsOff = !mPowerManager.screenIsOn(); |
| 5737 | boolean screenIsDim = !mPowerManager.screenIsBright(); |
| 5738 | if (screenIsOff) { |
| 5739 | if (!mPolicy.isWakeRelMovementTq(event.deviceId, |
| 5740 | device.classes, event)) { |
| 5741 | //Log.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| 5742 | return false; |
| 5743 | } |
| 5744 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 5745 | } |
| 5746 | if (screenIsDim) { |
| 5747 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 5748 | } |
| 5749 | return true; |
| 5750 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5751 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5752 | case RawInputEvent.EV_ABS: { |
| 5753 | boolean screenIsOff = !mPowerManager.screenIsOn(); |
| 5754 | boolean screenIsDim = !mPowerManager.screenIsBright(); |
| 5755 | if (screenIsOff) { |
| 5756 | if (!mPolicy.isWakeAbsMovementTq(event.deviceId, |
| 5757 | device.classes, event)) { |
| 5758 | //Log.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| 5759 | return false; |
| 5760 | } |
| 5761 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 5762 | } |
| 5763 | if (screenIsDim) { |
| 5764 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 5765 | } |
| 5766 | return true; |
| 5767 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5768 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5769 | default: |
| 5770 | return true; |
| 5771 | } |
| 5772 | } |
| 5773 | |
| 5774 | public int filterEvent(QueuedEvent ev) { |
| 5775 | switch (ev.classType) { |
| 5776 | case RawInputEvent.CLASS_KEYBOARD: |
| 5777 | KeyEvent ke = (KeyEvent)ev.event; |
| 5778 | if (mPolicy.isMovementKeyTi(ke.getKeyCode())) { |
| 5779 | Log.w(TAG, "Dropping movement key during app switch: " |
| 5780 | + ke.getKeyCode() + ", action=" + ke.getAction()); |
| 5781 | return FILTER_REMOVE; |
| 5782 | } |
| 5783 | return FILTER_ABORT; |
| 5784 | default: |
| 5785 | return FILTER_KEEP; |
| 5786 | } |
| 5787 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5788 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5789 | /** |
| 5790 | * Must be called with the main window manager lock held. |
| 5791 | */ |
| 5792 | void setHoldScreenLocked(boolean holding) { |
| 5793 | boolean state = mHoldingScreen.isHeld(); |
| 5794 | if (holding != state) { |
| 5795 | if (holding) { |
| 5796 | mHoldingScreen.acquire(); |
| 5797 | } else { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 5798 | mPolicy.screenOnStoppedLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5799 | mHoldingScreen.release(); |
| 5800 | } |
| 5801 | } |
| 5802 | } |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5803 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5804 | |
| 5805 | public boolean detectSafeMode() { |
| 5806 | mSafeMode = mPolicy.detectSafeMode(); |
| 5807 | return mSafeMode; |
| 5808 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5809 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5810 | public void systemReady() { |
| 5811 | mPolicy.systemReady(); |
| 5812 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5813 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5814 | private final class InputDispatcherThread extends Thread { |
| 5815 | // Time to wait when there is nothing to do: 9999 seconds. |
| 5816 | static final int LONG_WAIT=9999*1000; |
| 5817 | |
| 5818 | public InputDispatcherThread() { |
| 5819 | super("InputDispatcher"); |
| 5820 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5821 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5822 | @Override |
| 5823 | public void run() { |
| 5824 | while (true) { |
| 5825 | try { |
| 5826 | process(); |
| 5827 | } catch (Exception e) { |
| 5828 | Log.e(TAG, "Exception in input dispatcher", e); |
| 5829 | } |
| 5830 | } |
| 5831 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5832 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5833 | private void process() { |
| 5834 | android.os.Process.setThreadPriority( |
| 5835 | android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5836 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5837 | // The last key event we saw |
| 5838 | KeyEvent lastKey = null; |
| 5839 | |
| 5840 | // Last keydown time for auto-repeating keys |
| 5841 | long lastKeyTime = SystemClock.uptimeMillis(); |
| 5842 | long nextKeyTime = lastKeyTime+LONG_WAIT; |
| 5843 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5844 | // How many successive repeats we generated |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5845 | int keyRepeatCount = 0; |
| 5846 | |
| 5847 | // Need to report that configuration has changed? |
| 5848 | boolean configChanged = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5849 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5850 | while (true) { |
| 5851 | long curTime = SystemClock.uptimeMillis(); |
| 5852 | |
| 5853 | if (DEBUG_INPUT) Log.v( |
| 5854 | TAG, "Waiting for next key: now=" + curTime |
| 5855 | + ", repeat @ " + nextKeyTime); |
| 5856 | |
| 5857 | // Retrieve next event, waiting only as long as the next |
| 5858 | // repeat timeout. If the configuration has changed, then |
| 5859 | // don't wait at all -- we'll report the change as soon as |
| 5860 | // we have processed all events. |
| 5861 | QueuedEvent ev = mQueue.getEvent( |
| 5862 | (int)((!configChanged && curTime < nextKeyTime) |
| 5863 | ? (nextKeyTime-curTime) : 0)); |
| 5864 | |
| 5865 | if (DEBUG_INPUT && ev != null) Log.v( |
| 5866 | TAG, "Event: type=" + ev.classType + " data=" + ev.event); |
| 5867 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5868 | if (MEASURE_LATENCY) { |
| 5869 | lt.sample("2 got event ", System.nanoTime() - ev.whenNano); |
| 5870 | } |
| 5871 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5872 | try { |
| 5873 | if (ev != null) { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5874 | curTime = SystemClock.uptimeMillis(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5875 | int eventType; |
| 5876 | if (ev.classType == RawInputEvent.CLASS_TOUCHSCREEN) { |
| 5877 | eventType = eventType((MotionEvent)ev.event); |
| 5878 | } else if (ev.classType == RawInputEvent.CLASS_KEYBOARD || |
| 5879 | ev.classType == RawInputEvent.CLASS_TRACKBALL) { |
| 5880 | eventType = LocalPowerManager.BUTTON_EVENT; |
| 5881 | } else { |
| 5882 | eventType = LocalPowerManager.OTHER_EVENT; |
| 5883 | } |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5884 | try { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5885 | if ((curTime - mLastBatteryStatsCallTime) |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5886 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5887 | mLastBatteryStatsCallTime = curTime; |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5888 | mBatteryStats.noteInputEvent(); |
| 5889 | } |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5890 | } catch (RemoteException e) { |
| 5891 | // Ignore |
| 5892 | } |
| Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 5893 | |
| 5894 | if (eventType != TOUCH_EVENT |
| 5895 | && eventType != LONG_TOUCH_EVENT |
| 5896 | && eventType != CHEEK_EVENT) { |
| 5897 | mPowerManager.userActivity(curTime, false, |
| 5898 | eventType, false); |
| 5899 | } else if (mLastTouchEventType != eventType |
| 5900 | || (curTime - mLastUserActivityCallTime) |
| 5901 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 5902 | mLastUserActivityCallTime = curTime; |
| 5903 | mLastTouchEventType = eventType; |
| 5904 | mPowerManager.userActivity(curTime, false, |
| 5905 | eventType, false); |
| 5906 | } |
| 5907 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5908 | switch (ev.classType) { |
| 5909 | case RawInputEvent.CLASS_KEYBOARD: |
| 5910 | KeyEvent ke = (KeyEvent)ev.event; |
| 5911 | if (ke.isDown()) { |
| 5912 | lastKey = ke; |
| 5913 | keyRepeatCount = 0; |
| 5914 | lastKeyTime = curTime; |
| 5915 | nextKeyTime = lastKeyTime |
| 5916 | + KEY_REPEAT_FIRST_DELAY; |
| 5917 | if (DEBUG_INPUT) Log.v( |
| 5918 | TAG, "Received key down: first repeat @ " |
| 5919 | + nextKeyTime); |
| 5920 | } else { |
| 5921 | lastKey = null; |
| 5922 | // Arbitrary long timeout. |
| 5923 | lastKeyTime = curTime; |
| 5924 | nextKeyTime = curTime + LONG_WAIT; |
| 5925 | if (DEBUG_INPUT) Log.v( |
| 5926 | TAG, "Received key up: ignore repeat @ " |
| 5927 | + nextKeyTime); |
| 5928 | } |
| 5929 | dispatchKey((KeyEvent)ev.event, 0, 0); |
| 5930 | mQueue.recycleEvent(ev); |
| 5931 | break; |
| 5932 | case RawInputEvent.CLASS_TOUCHSCREEN: |
| 5933 | //Log.i(TAG, "Read next event " + ev); |
| 5934 | dispatchPointer(ev, (MotionEvent)ev.event, 0, 0); |
| 5935 | break; |
| 5936 | case RawInputEvent.CLASS_TRACKBALL: |
| 5937 | dispatchTrackball(ev, (MotionEvent)ev.event, 0, 0); |
| 5938 | break; |
| 5939 | case RawInputEvent.CLASS_CONFIGURATION_CHANGED: |
| 5940 | configChanged = true; |
| 5941 | break; |
| 5942 | default: |
| 5943 | mQueue.recycleEvent(ev); |
| 5944 | break; |
| 5945 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5946 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5947 | } else if (configChanged) { |
| 5948 | configChanged = false; |
| 5949 | sendNewConfiguration(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5950 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5951 | } else if (lastKey != null) { |
| 5952 | curTime = SystemClock.uptimeMillis(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5953 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5954 | // Timeout occurred while key was down. If it is at or |
| 5955 | // past the key repeat time, dispatch the repeat. |
| 5956 | if (DEBUG_INPUT) Log.v( |
| 5957 | TAG, "Key timeout: repeat=" + nextKeyTime |
| 5958 | + ", now=" + curTime); |
| 5959 | if (curTime < nextKeyTime) { |
| 5960 | continue; |
| 5961 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5962 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5963 | lastKeyTime = nextKeyTime; |
| 5964 | nextKeyTime = nextKeyTime + KEY_REPEAT_DELAY; |
| 5965 | keyRepeatCount++; |
| 5966 | if (DEBUG_INPUT) Log.v( |
| 5967 | TAG, "Key repeat: count=" + keyRepeatCount |
| 5968 | + ", next @ " + nextKeyTime); |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5969 | dispatchKey(KeyEvent.changeTimeRepeat(lastKey, curTime, keyRepeatCount), 0, 0); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5970 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5971 | } else { |
| 5972 | curTime = SystemClock.uptimeMillis(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5973 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5974 | lastKeyTime = curTime; |
| 5975 | nextKeyTime = curTime + LONG_WAIT; |
| 5976 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5977 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5978 | } catch (Exception e) { |
| 5979 | Log.e(TAG, |
| 5980 | "Input thread received uncaught exception: " + e, e); |
| 5981 | } |
| 5982 | } |
| 5983 | } |
| 5984 | } |
| 5985 | |
| 5986 | // ------------------------------------------------------------- |
| 5987 | // Client Session State |
| 5988 | // ------------------------------------------------------------- |
| 5989 | |
| 5990 | private final class Session extends IWindowSession.Stub |
| 5991 | implements IBinder.DeathRecipient { |
| 5992 | final IInputMethodClient mClient; |
| 5993 | final IInputContext mInputContext; |
| 5994 | final int mUid; |
| 5995 | final int mPid; |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5996 | final String mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5997 | SurfaceSession mSurfaceSession; |
| 5998 | int mNumWindow = 0; |
| 5999 | boolean mClientDead = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6000 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6001 | /** |
| 6002 | * Current pointer move event being dispatched to client window... must |
| 6003 | * hold key lock to access. |
| 6004 | */ |
| 6005 | QueuedEvent mPendingPointerMove; |
| 6006 | WindowState mPendingPointerWindow; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6007 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6008 | /** |
| 6009 | * Current trackball move event being dispatched to client window... must |
| 6010 | * hold key lock to access. |
| 6011 | */ |
| 6012 | QueuedEvent mPendingTrackballMove; |
| 6013 | WindowState mPendingTrackballWindow; |
| 6014 | |
| 6015 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 6016 | mClient = client; |
| 6017 | mInputContext = inputContext; |
| 6018 | mUid = Binder.getCallingUid(); |
| 6019 | mPid = Binder.getCallingPid(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6020 | StringBuilder sb = new StringBuilder(); |
| 6021 | sb.append("Session{"); |
| 6022 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 6023 | sb.append(" uid "); |
| 6024 | sb.append(mUid); |
| 6025 | sb.append("}"); |
| 6026 | mStringName = sb.toString(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6027 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6028 | synchronized (mWindowMap) { |
| 6029 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 6030 | IBinder b = ServiceManager.getService( |
| 6031 | Context.INPUT_METHOD_SERVICE); |
| 6032 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 6033 | } |
| 6034 | } |
| 6035 | long ident = Binder.clearCallingIdentity(); |
| 6036 | try { |
| 6037 | // Note: it is safe to call in to the input method manager |
| 6038 | // here because we are not holding our lock. |
| 6039 | if (mInputMethodManager != null) { |
| 6040 | mInputMethodManager.addClient(client, inputContext, |
| 6041 | mUid, mPid); |
| 6042 | } else { |
| 6043 | client.setUsingInputMethod(false); |
| 6044 | } |
| 6045 | client.asBinder().linkToDeath(this, 0); |
| 6046 | } catch (RemoteException e) { |
| 6047 | // The caller has died, so we can just forget about this. |
| 6048 | try { |
| 6049 | if (mInputMethodManager != null) { |
| 6050 | mInputMethodManager.removeClient(client); |
| 6051 | } |
| 6052 | } catch (RemoteException ee) { |
| 6053 | } |
| 6054 | } finally { |
| 6055 | Binder.restoreCallingIdentity(ident); |
| 6056 | } |
| 6057 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6058 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6059 | @Override |
| 6060 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 6061 | throws RemoteException { |
| 6062 | try { |
| 6063 | return super.onTransact(code, data, reply, flags); |
| 6064 | } catch (RuntimeException e) { |
| 6065 | // Log all 'real' exceptions thrown to the caller |
| 6066 | if (!(e instanceof SecurityException)) { |
| 6067 | Log.e(TAG, "Window Session Crash", e); |
| 6068 | } |
| 6069 | throw e; |
| 6070 | } |
| 6071 | } |
| 6072 | |
| 6073 | public void binderDied() { |
| 6074 | // Note: it is safe to call in to the input method manager |
| 6075 | // here because we are not holding our lock. |
| 6076 | try { |
| 6077 | if (mInputMethodManager != null) { |
| 6078 | mInputMethodManager.removeClient(mClient); |
| 6079 | } |
| 6080 | } catch (RemoteException e) { |
| 6081 | } |
| 6082 | synchronized(mWindowMap) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 6083 | mClient.asBinder().unlinkToDeath(this, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6084 | mClientDead = true; |
| 6085 | killSessionLocked(); |
| 6086 | } |
| 6087 | } |
| 6088 | |
| 6089 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
| 6090 | int viewVisibility, Rect outContentInsets) { |
| 6091 | return addWindow(this, window, attrs, viewVisibility, outContentInsets); |
| 6092 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6093 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6094 | public void remove(IWindow window) { |
| 6095 | removeWindow(this, window); |
| 6096 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6097 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6098 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 6099 | int requestedWidth, int requestedHeight, int viewFlags, |
| 6100 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
| 6101 | Rect outVisibleInsets, Surface outSurface) { |
| 6102 | return relayoutWindow(this, window, attrs, |
| 6103 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
| 6104 | outFrame, outContentInsets, outVisibleInsets, outSurface); |
| 6105 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6106 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6107 | public void setTransparentRegion(IWindow window, Region region) { |
| 6108 | setTransparentRegionWindow(this, window, region); |
| 6109 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6110 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6111 | public void setInsets(IWindow window, int touchableInsets, |
| 6112 | Rect contentInsets, Rect visibleInsets) { |
| 6113 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 6114 | visibleInsets); |
| 6115 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6116 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6117 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 6118 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 6119 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6120 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6121 | public void finishDrawing(IWindow window) { |
| 6122 | if (localLOGV) Log.v( |
| 6123 | TAG, "IWindow finishDrawing called for " + window); |
| 6124 | finishDrawingWindow(this, window); |
| 6125 | } |
| 6126 | |
| 6127 | public void finishKey(IWindow window) { |
| 6128 | if (localLOGV) Log.v( |
| 6129 | TAG, "IWindow finishKey called for " + window); |
| 6130 | mKeyWaiter.finishedKey(this, window, false, |
| 6131 | KeyWaiter.RETURN_NOTHING); |
| 6132 | } |
| 6133 | |
| 6134 | public MotionEvent getPendingPointerMove(IWindow window) { |
| 6135 | if (localLOGV) Log.v( |
| 6136 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 6137 | return mKeyWaiter.finishedKey(this, window, false, |
| 6138 | KeyWaiter.RETURN_PENDING_POINTER); |
| 6139 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6140 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6141 | public MotionEvent getPendingTrackballMove(IWindow window) { |
| 6142 | if (localLOGV) Log.v( |
| 6143 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 6144 | return mKeyWaiter.finishedKey(this, window, false, |
| 6145 | KeyWaiter.RETURN_PENDING_TRACKBALL); |
| 6146 | } |
| 6147 | |
| 6148 | public void setInTouchMode(boolean mode) { |
| 6149 | synchronized(mWindowMap) { |
| 6150 | mInTouchMode = mode; |
| 6151 | } |
| 6152 | } |
| 6153 | |
| 6154 | public boolean getInTouchMode() { |
| 6155 | synchronized(mWindowMap) { |
| 6156 | return mInTouchMode; |
| 6157 | } |
| 6158 | } |
| 6159 | |
| 6160 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 6161 | boolean always) { |
| 6162 | synchronized(mWindowMap) { |
| 6163 | long ident = Binder.clearCallingIdentity(); |
| 6164 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6165 | return mPolicy.performHapticFeedbackLw( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6166 | windowForClientLocked(this, window), effectId, always); |
| 6167 | } finally { |
| 6168 | Binder.restoreCallingIdentity(ident); |
| 6169 | } |
| 6170 | } |
| 6171 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6172 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6173 | public void setWallpaperPosition(IBinder window, float x, float y) { |
| 6174 | synchronized(mWindowMap) { |
| 6175 | long ident = Binder.clearCallingIdentity(); |
| 6176 | try { |
| 6177 | setWindowWallpaperPositionLocked(windowForClientLocked(this, window), |
| 6178 | x, y); |
| 6179 | } finally { |
| 6180 | Binder.restoreCallingIdentity(ident); |
| 6181 | } |
| 6182 | } |
| 6183 | } |
| 6184 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6185 | void windowAddedLocked() { |
| 6186 | if (mSurfaceSession == null) { |
| 6187 | if (localLOGV) Log.v( |
| 6188 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 6189 | mSurfaceSession = new SurfaceSession(); |
| 6190 | mSessions.add(this); |
| 6191 | } |
| 6192 | mNumWindow++; |
| 6193 | } |
| 6194 | |
| 6195 | void windowRemovedLocked() { |
| 6196 | mNumWindow--; |
| 6197 | killSessionLocked(); |
| 6198 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6199 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6200 | void killSessionLocked() { |
| 6201 | if (mNumWindow <= 0 && mClientDead) { |
| 6202 | mSessions.remove(this); |
| 6203 | if (mSurfaceSession != null) { |
| 6204 | if (localLOGV) Log.v( |
| 6205 | TAG, "Last window removed from " + this |
| 6206 | + ", destroying " + mSurfaceSession); |
| 6207 | try { |
| 6208 | mSurfaceSession.kill(); |
| 6209 | } catch (Exception e) { |
| 6210 | Log.w(TAG, "Exception thrown when killing surface session " |
| 6211 | + mSurfaceSession + " in session " + this |
| 6212 | + ": " + e.toString()); |
| 6213 | } |
| 6214 | mSurfaceSession = null; |
| 6215 | } |
| 6216 | } |
| 6217 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6218 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6219 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6220 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 6221 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 6222 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
| 6223 | if (mPendingPointerWindow != null || mPendingPointerMove != null) { |
| 6224 | pw.print(prefix); |
| 6225 | pw.print("mPendingPointerWindow="); pw.print(mPendingPointerWindow); |
| 6226 | pw.print(" mPendingPointerMove="); pw.println(mPendingPointerMove); |
| 6227 | } |
| 6228 | if (mPendingTrackballWindow != null || mPendingTrackballMove != null) { |
| 6229 | pw.print(prefix); |
| 6230 | pw.print("mPendingTrackballWindow="); pw.print(mPendingTrackballWindow); |
| 6231 | pw.print(" mPendingTrackballMove="); pw.println(mPendingTrackballMove); |
| 6232 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6233 | } |
| 6234 | |
| 6235 | @Override |
| 6236 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6237 | return mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6238 | } |
| 6239 | } |
| 6240 | |
| 6241 | // ------------------------------------------------------------- |
| 6242 | // Client Window State |
| 6243 | // ------------------------------------------------------------- |
| 6244 | |
| 6245 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 6246 | final Session mSession; |
| 6247 | final IWindow mClient; |
| 6248 | WindowToken mToken; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6249 | WindowToken mRootToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6250 | AppWindowToken mAppToken; |
| 6251 | AppWindowToken mTargetAppToken; |
| 6252 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 6253 | final DeathRecipient mDeathRecipient; |
| 6254 | final WindowState mAttachedWindow; |
| 6255 | final ArrayList mChildWindows = new ArrayList(); |
| 6256 | final int mBaseLayer; |
| 6257 | final int mSubLayer; |
| 6258 | final boolean mLayoutAttached; |
| 6259 | final boolean mIsImWindow; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6260 | final boolean mIsWallpaper; |
| 6261 | final boolean mIsFloatingLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6262 | int mViewVisibility; |
| 6263 | boolean mPolicyVisibility = true; |
| 6264 | boolean mPolicyVisibilityAfterAnim = true; |
| 6265 | boolean mAppFreezing; |
| 6266 | Surface mSurface; |
| 6267 | boolean mAttachedHidden; // is our parent window hidden? |
| 6268 | boolean mLastHidden; // was this window last hidden? |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6269 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6270 | int mRequestedWidth; |
| 6271 | int mRequestedHeight; |
| 6272 | int mLastRequestedWidth; |
| 6273 | int mLastRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6274 | int mLayer; |
| 6275 | int mAnimLayer; |
| 6276 | int mLastLayer; |
| 6277 | boolean mHaveFrame; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6278 | boolean mObscured; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6279 | |
| 6280 | WindowState mNextOutsideTouch; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6281 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6282 | // Actual frame shown on-screen (may be modified by animation) |
| 6283 | final Rect mShownFrame = new Rect(); |
| 6284 | final Rect mLastShownFrame = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6285 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6286 | /** |
| 6287 | * Insets that determine the actually visible area |
| 6288 | */ |
| 6289 | final Rect mVisibleInsets = new Rect(); |
| 6290 | final Rect mLastVisibleInsets = new Rect(); |
| 6291 | boolean mVisibleInsetsChanged; |
| 6292 | |
| 6293 | /** |
| 6294 | * Insets that are covered by system windows |
| 6295 | */ |
| 6296 | final Rect mContentInsets = new Rect(); |
| 6297 | final Rect mLastContentInsets = new Rect(); |
| 6298 | boolean mContentInsetsChanged; |
| 6299 | |
| 6300 | /** |
| 6301 | * Set to true if we are waiting for this window to receive its |
| 6302 | * given internal insets before laying out other windows based on it. |
| 6303 | */ |
| 6304 | boolean mGivenInsetsPending; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6305 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6306 | /** |
| 6307 | * These are the content insets that were given during layout for |
| 6308 | * this window, to be applied to windows behind it. |
| 6309 | */ |
| 6310 | final Rect mGivenContentInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6311 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6312 | /** |
| 6313 | * These are the visible insets that were given during layout for |
| 6314 | * this window, to be applied to windows behind it. |
| 6315 | */ |
| 6316 | final Rect mGivenVisibleInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6317 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6318 | /** |
| 6319 | * Flag indicating whether the touchable region should be adjusted by |
| 6320 | * the visible insets; if false the area outside the visible insets is |
| 6321 | * NOT touchable, so we must use those to adjust the frame during hit |
| 6322 | * tests. |
| 6323 | */ |
| 6324 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6325 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6326 | // Current transformation being applied. |
| 6327 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 6328 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 6329 | float mHScale=1, mVScale=1; |
| 6330 | float mLastHScale=1, mLastVScale=1; |
| 6331 | final Matrix mTmpMatrix = new Matrix(); |
| 6332 | |
| 6333 | // "Real" frame that the application sees. |
| 6334 | final Rect mFrame = new Rect(); |
| 6335 | final Rect mLastFrame = new Rect(); |
| 6336 | |
| 6337 | final Rect mContainingFrame = new Rect(); |
| 6338 | final Rect mDisplayFrame = new Rect(); |
| 6339 | final Rect mContentFrame = new Rect(); |
| 6340 | final Rect mVisibleFrame = new Rect(); |
| 6341 | |
| 6342 | float mShownAlpha = 1; |
| 6343 | float mAlpha = 1; |
| 6344 | float mLastAlpha = 1; |
| 6345 | |
| 6346 | // Set to true if, when the window gets displayed, it should perform |
| 6347 | // an enter animation. |
| 6348 | boolean mEnterAnimationPending; |
| 6349 | |
| 6350 | // Currently running animation. |
| 6351 | boolean mAnimating; |
| 6352 | boolean mLocalAnimating; |
| 6353 | Animation mAnimation; |
| 6354 | boolean mAnimationIsEntrance; |
| 6355 | boolean mHasTransformation; |
| 6356 | boolean mHasLocalTransformation; |
| 6357 | final Transformation mTransformation = new Transformation(); |
| 6358 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6359 | // If a window showing a wallpaper: the requested offset for the |
| 6360 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 6361 | float mWallpaperX = -1; |
| 6362 | float mWallpaperY = -1; |
| 6363 | |
| 6364 | // Wallpaper windows: pixels offset based on above variables. |
| 6365 | int mXOffset; |
| 6366 | int mYOffset; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6367 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6368 | // This is set after IWindowSession.relayout() has been called at |
| 6369 | // least once for the window. It allows us to detect the situation |
| 6370 | // where we don't yet have a surface, but should have one soon, so |
| 6371 | // we can give the window focus before waiting for the relayout. |
| 6372 | boolean mRelayoutCalled; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6373 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6374 | // This is set after the Surface has been created but before the |
| 6375 | // window has been drawn. During this time the surface is hidden. |
| 6376 | boolean mDrawPending; |
| 6377 | |
| 6378 | // This is set after the window has finished drawing for the first |
| 6379 | // time but before its surface is shown. The surface will be |
| 6380 | // displayed when the next layout is run. |
| 6381 | boolean mCommitDrawPending; |
| 6382 | |
| 6383 | // This is set during the time after the window's drawing has been |
| 6384 | // committed, and before its surface is actually shown. It is used |
| 6385 | // to delay showing the surface until all windows in a token are ready |
| 6386 | // to be shown. |
| 6387 | boolean mReadyToShow; |
| 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 | // Set when the window has been shown in the screen the first time. |
| 6390 | boolean mHasDrawn; |
| 6391 | |
| 6392 | // Currently running an exit animation? |
| 6393 | boolean mExiting; |
| 6394 | |
| 6395 | // Currently on the mDestroySurface list? |
| 6396 | boolean mDestroying; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6397 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6398 | // Completely remove from window manager after exit animation? |
| 6399 | boolean mRemoveOnExit; |
| 6400 | |
| 6401 | // Set when the orientation is changing and this window has not yet |
| 6402 | // been updated for the new orientation. |
| 6403 | boolean mOrientationChanging; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6404 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6405 | // Is this window now (or just being) removed? |
| 6406 | boolean mRemoved; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6407 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6408 | WindowState(Session s, IWindow c, WindowToken token, |
| 6409 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 6410 | int viewVisibility) { |
| 6411 | mSession = s; |
| 6412 | mClient = c; |
| 6413 | mToken = token; |
| 6414 | mAttrs.copyFrom(a); |
| 6415 | mViewVisibility = viewVisibility; |
| 6416 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 6417 | mAlpha = a.alpha; |
| 6418 | if (localLOGV) Log.v( |
| 6419 | TAG, "Window " + this + " client=" + c.asBinder() |
| 6420 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 6421 | try { |
| 6422 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 6423 | } catch (RemoteException e) { |
| 6424 | mDeathRecipient = null; |
| 6425 | mAttachedWindow = null; |
| 6426 | mLayoutAttached = false; |
| 6427 | mIsImWindow = false; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6428 | mIsWallpaper = false; |
| 6429 | mIsFloatingLayer = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6430 | mBaseLayer = 0; |
| 6431 | mSubLayer = 0; |
| 6432 | return; |
| 6433 | } |
| 6434 | mDeathRecipient = deathRecipient; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6435 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6436 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 6437 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 6438 | // The multiplier here is to reserve space for multiple |
| 6439 | // windows in the same type layer. |
| 6440 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 6441 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 6442 | + TYPE_LAYER_OFFSET; |
| 6443 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 6444 | mAttachedWindow = attachedWindow; |
| 6445 | mAttachedWindow.mChildWindows.add(this); |
| 6446 | mLayoutAttached = mAttrs.type != |
| 6447 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 6448 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 6449 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6450 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 6451 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6452 | } else { |
| 6453 | // The multiplier here is to reserve space for multiple |
| 6454 | // windows in the same type layer. |
| 6455 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 6456 | * TYPE_LAYER_MULTIPLIER |
| 6457 | + TYPE_LAYER_OFFSET; |
| 6458 | mSubLayer = 0; |
| 6459 | mAttachedWindow = null; |
| 6460 | mLayoutAttached = false; |
| 6461 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 6462 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6463 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 6464 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6465 | } |
| 6466 | |
| 6467 | WindowState appWin = this; |
| 6468 | while (appWin.mAttachedWindow != null) { |
| 6469 | appWin = mAttachedWindow; |
| 6470 | } |
| 6471 | WindowToken appToken = appWin.mToken; |
| 6472 | while (appToken.appWindowToken == null) { |
| 6473 | WindowToken parent = mTokenMap.get(appToken.token); |
| 6474 | if (parent == null || appToken == parent) { |
| 6475 | break; |
| 6476 | } |
| 6477 | appToken = parent; |
| 6478 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6479 | mRootToken = appToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6480 | mAppToken = appToken.appWindowToken; |
| 6481 | |
| 6482 | mSurface = null; |
| 6483 | mRequestedWidth = 0; |
| 6484 | mRequestedHeight = 0; |
| 6485 | mLastRequestedWidth = 0; |
| 6486 | mLastRequestedHeight = 0; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6487 | mXOffset = 0; |
| 6488 | mYOffset = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6489 | mLayer = 0; |
| 6490 | mAnimLayer = 0; |
| 6491 | mLastLayer = 0; |
| 6492 | } |
| 6493 | |
| 6494 | void attach() { |
| 6495 | if (localLOGV) Log.v( |
| 6496 | TAG, "Attaching " + this + " token=" + mToken |
| 6497 | + ", list=" + mToken.windows); |
| 6498 | mSession.windowAddedLocked(); |
| 6499 | } |
| 6500 | |
| 6501 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 6502 | mHaveFrame = true; |
| 6503 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6504 | final Rect container = mContainingFrame; |
| 6505 | container.set(pf); |
| 6506 | |
| 6507 | final Rect display = mDisplayFrame; |
| 6508 | display.set(df); |
| 6509 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6510 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6511 | container.intersect(mCompatibleScreenFrame); |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6512 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 6513 | display.intersect(mCompatibleScreenFrame); |
| 6514 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6515 | } |
| 6516 | |
| 6517 | final int pw = container.right - container.left; |
| 6518 | final int ph = container.bottom - container.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6519 | |
| 6520 | int w,h; |
| 6521 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 6522 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 6523 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 6524 | } else { |
| 6525 | w = mAttrs.width == mAttrs.FILL_PARENT ? pw : mRequestedWidth; |
| 6526 | h = mAttrs.height== mAttrs.FILL_PARENT ? ph : mRequestedHeight; |
| 6527 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6528 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6529 | final Rect content = mContentFrame; |
| 6530 | content.set(cf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6531 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6532 | final Rect visible = mVisibleFrame; |
| 6533 | visible.set(vf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6534 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6535 | final Rect frame = mFrame; |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6536 | final int fw = frame.width(); |
| 6537 | final int fh = frame.height(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6538 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6539 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 6540 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 6541 | |
| 6542 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 6543 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 6544 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 6545 | |
| 6546 | //System.out.println("Out: " + mFrame); |
| 6547 | |
| 6548 | // Now make sure the window fits in the overall display. |
| 6549 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6550 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6551 | // Make sure the content and visible frames are inside of the |
| 6552 | // final window frame. |
| 6553 | if (content.left < frame.left) content.left = frame.left; |
| 6554 | if (content.top < frame.top) content.top = frame.top; |
| 6555 | if (content.right > frame.right) content.right = frame.right; |
| 6556 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 6557 | if (visible.left < frame.left) visible.left = frame.left; |
| 6558 | if (visible.top < frame.top) visible.top = frame.top; |
| 6559 | if (visible.right > frame.right) visible.right = frame.right; |
| 6560 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6561 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6562 | final Rect contentInsets = mContentInsets; |
| 6563 | contentInsets.left = content.left-frame.left; |
| 6564 | contentInsets.top = content.top-frame.top; |
| 6565 | contentInsets.right = frame.right-content.right; |
| 6566 | contentInsets.bottom = frame.bottom-content.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6567 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6568 | final Rect visibleInsets = mVisibleInsets; |
| 6569 | visibleInsets.left = visible.left-frame.left; |
| 6570 | visibleInsets.top = visible.top-frame.top; |
| 6571 | visibleInsets.right = frame.right-visible.right; |
| 6572 | visibleInsets.bottom = frame.bottom-visible.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6573 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 6574 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 6575 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
| 6576 | mDisplay.getHeight()); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6577 | } |
| 6578 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6579 | if (localLOGV) { |
| 6580 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 6581 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
| 6582 | Log.v(TAG, "Resolving (mRequestedWidth=" |
| 6583 | + mRequestedWidth + ", mRequestedheight=" |
| 6584 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 6585 | + "): frame=" + mFrame.toShortString() |
| 6586 | + " ci=" + contentInsets.toShortString() |
| 6587 | + " vi=" + visibleInsets.toShortString()); |
| 6588 | //} |
| 6589 | } |
| 6590 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6591 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6592 | public Rect getFrameLw() { |
| 6593 | return mFrame; |
| 6594 | } |
| 6595 | |
| 6596 | public Rect getShownFrameLw() { |
| 6597 | return mShownFrame; |
| 6598 | } |
| 6599 | |
| 6600 | public Rect getDisplayFrameLw() { |
| 6601 | return mDisplayFrame; |
| 6602 | } |
| 6603 | |
| 6604 | public Rect getContentFrameLw() { |
| 6605 | return mContentFrame; |
| 6606 | } |
| 6607 | |
| 6608 | public Rect getVisibleFrameLw() { |
| 6609 | return mVisibleFrame; |
| 6610 | } |
| 6611 | |
| 6612 | public boolean getGivenInsetsPendingLw() { |
| 6613 | return mGivenInsetsPending; |
| 6614 | } |
| 6615 | |
| 6616 | public Rect getGivenContentInsetsLw() { |
| 6617 | return mGivenContentInsets; |
| 6618 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6619 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6620 | public Rect getGivenVisibleInsetsLw() { |
| 6621 | return mGivenVisibleInsets; |
| 6622 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6623 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6624 | public WindowManager.LayoutParams getAttrs() { |
| 6625 | return mAttrs; |
| 6626 | } |
| 6627 | |
| 6628 | public int getSurfaceLayer() { |
| 6629 | return mLayer; |
| 6630 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6631 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6632 | public IApplicationToken getAppToken() { |
| 6633 | return mAppToken != null ? mAppToken.appToken : null; |
| 6634 | } |
| 6635 | |
| 6636 | public boolean hasAppShownWindows() { |
| 6637 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 6638 | } |
| 6639 | |
| 6640 | public boolean hasAppStartingIcon() { |
| 6641 | return mAppToken != null ? (mAppToken.startingData != null) : false; |
| 6642 | } |
| 6643 | |
| 6644 | public WindowManagerPolicy.WindowState getAppStartingWindow() { |
| 6645 | return mAppToken != null ? mAppToken.startingWindow : null; |
| 6646 | } |
| 6647 | |
| 6648 | public void setAnimation(Animation anim) { |
| 6649 | if (localLOGV) Log.v( |
| 6650 | TAG, "Setting animation in " + this + ": " + anim); |
| 6651 | mAnimating = false; |
| 6652 | mLocalAnimating = false; |
| 6653 | mAnimation = anim; |
| 6654 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 6655 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 6656 | } |
| 6657 | |
| 6658 | public void clearAnimation() { |
| 6659 | if (mAnimation != null) { |
| 6660 | mAnimating = true; |
| 6661 | mLocalAnimating = false; |
| 6662 | mAnimation = null; |
| 6663 | } |
| 6664 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6665 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6666 | Surface createSurfaceLocked() { |
| 6667 | if (mSurface == null) { |
| 6668 | mDrawPending = true; |
| 6669 | mCommitDrawPending = false; |
| 6670 | mReadyToShow = false; |
| 6671 | if (mAppToken != null) { |
| 6672 | mAppToken.allDrawn = false; |
| 6673 | } |
| 6674 | |
| 6675 | int flags = 0; |
| Mathias Agopian | 317a628 | 2009-08-13 17:29:02 -0700 | [diff] [blame] | 6676 | if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6677 | flags |= Surface.PUSH_BUFFERS; |
| 6678 | } |
| 6679 | |
| 6680 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 6681 | flags |= Surface.SECURE; |
| 6682 | } |
| 6683 | if (DEBUG_VISIBILITY) Log.v( |
| 6684 | TAG, "Creating surface in session " |
| 6685 | + mSession.mSurfaceSession + " window " + this |
| 6686 | + " w=" + mFrame.width() |
| 6687 | + " h=" + mFrame.height() + " format=" |
| 6688 | + mAttrs.format + " flags=" + flags); |
| 6689 | |
| 6690 | int w = mFrame.width(); |
| 6691 | int h = mFrame.height(); |
| 6692 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 6693 | // for a scaled surface, we always want the requested |
| 6694 | // size. |
| 6695 | w = mRequestedWidth; |
| 6696 | h = mRequestedHeight; |
| 6697 | } |
| 6698 | |
| 6699 | try { |
| 6700 | mSurface = new Surface( |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6701 | mSession.mSurfaceSession, mSession.mPid, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6702 | 0, w, h, mAttrs.format, flags); |
| 6703 | } catch (Surface.OutOfResourcesException e) { |
| 6704 | Log.w(TAG, "OutOfResourcesException creating surface"); |
| 6705 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 6706 | return null; |
| 6707 | } catch (Exception e) { |
| 6708 | Log.e(TAG, "Exception creating surface", e); |
| 6709 | return null; |
| 6710 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6711 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6712 | if (localLOGV) Log.v( |
| 6713 | TAG, "Got surface: " + mSurface |
| 6714 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 6715 | + ", animLayer=" + mAnimLayer); |
| 6716 | if (SHOW_TRANSACTIONS) { |
| 6717 | Log.i(TAG, ">>> OPEN TRANSACTION"); |
| 6718 | Log.i(TAG, " SURFACE " + mSurface + ": CREATE (" |
| 6719 | + mAttrs.getTitle() + ") pos=(" + |
| 6720 | mFrame.left + "," + mFrame.top + ") (" + |
| 6721 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 6722 | mAnimLayer + " HIDE"); |
| 6723 | } |
| 6724 | Surface.openTransaction(); |
| 6725 | try { |
| 6726 | try { |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6727 | mSurface.setPosition(mFrame.left + mXOffset, |
| 6728 | mFrame.top + mYOffset); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6729 | mSurface.setLayer(mAnimLayer); |
| 6730 | mSurface.hide(); |
| 6731 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
| 6732 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 6733 | Surface.SURFACE_DITHER); |
| 6734 | } |
| 6735 | } catch (RuntimeException e) { |
| 6736 | Log.w(TAG, "Error creating surface in " + w, e); |
| 6737 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 6738 | } |
| 6739 | mLastHidden = true; |
| 6740 | } finally { |
| 6741 | if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION"); |
| 6742 | Surface.closeTransaction(); |
| 6743 | } |
| 6744 | if (localLOGV) Log.v( |
| 6745 | TAG, "Created surface " + this); |
| 6746 | } |
| 6747 | return mSurface; |
| 6748 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6749 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6750 | void destroySurfaceLocked() { |
| 6751 | // Window is no longer on-screen, so can no longer receive |
| 6752 | // key events... if we were waiting for it to finish |
| 6753 | // handling a key event, the wait is over! |
| 6754 | mKeyWaiter.finishedKey(mSession, mClient, true, |
| 6755 | KeyWaiter.RETURN_NOTHING); |
| 6756 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 6757 | mKeyWaiter.releasePendingTrackballLocked(mSession); |
| 6758 | |
| 6759 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 6760 | mAppToken.startingDisplayed = false; |
| 6761 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6762 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6763 | if (mSurface != null) { |
| 6764 | try { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6765 | if (DEBUG_VISIBILITY) { |
| 6766 | RuntimeException e = new RuntimeException(); |
| 6767 | e.fillInStackTrace(); |
| 6768 | Log.w(TAG, "Window " + this + " destroying surface " |
| 6769 | + mSurface + ", session " + mSession, e); |
| 6770 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6771 | if (SHOW_TRANSACTIONS) { |
| 6772 | RuntimeException ex = new RuntimeException(); |
| 6773 | ex.fillInStackTrace(); |
| 6774 | Log.i(TAG, " SURFACE " + mSurface + ": DESTROY (" |
| 6775 | + mAttrs.getTitle() + ")", ex); |
| 6776 | } |
| 6777 | mSurface.clear(); |
| 6778 | } catch (RuntimeException e) { |
| 6779 | Log.w(TAG, "Exception thrown when destroying Window " + this |
| 6780 | + " surface " + mSurface + " session " + mSession |
| 6781 | + ": " + e.toString()); |
| 6782 | } |
| 6783 | mSurface = null; |
| 6784 | mDrawPending = false; |
| 6785 | mCommitDrawPending = false; |
| 6786 | mReadyToShow = false; |
| 6787 | |
| 6788 | int i = mChildWindows.size(); |
| 6789 | while (i > 0) { |
| 6790 | i--; |
| 6791 | WindowState c = (WindowState)mChildWindows.get(i); |
| 6792 | c.mAttachedHidden = true; |
| 6793 | } |
| 6794 | } |
| 6795 | } |
| 6796 | |
| 6797 | boolean finishDrawingLocked() { |
| 6798 | if (mDrawPending) { |
| 6799 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Log.v( |
| 6800 | TAG, "finishDrawingLocked: " + mSurface); |
| 6801 | mCommitDrawPending = true; |
| 6802 | mDrawPending = false; |
| 6803 | return true; |
| 6804 | } |
| 6805 | return false; |
| 6806 | } |
| 6807 | |
| 6808 | // This must be called while inside a transaction. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6809 | boolean commitFinishDrawingLocked(long currentTime) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6810 | //Log.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
| 6811 | if (!mCommitDrawPending) { |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6812 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6813 | } |
| 6814 | mCommitDrawPending = false; |
| 6815 | mReadyToShow = true; |
| 6816 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 6817 | final AppWindowToken atoken = mAppToken; |
| 6818 | if (atoken == null || atoken.allDrawn || starting) { |
| 6819 | performShowLocked(); |
| 6820 | } |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6821 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6822 | } |
| 6823 | |
| 6824 | // This must be called while inside a transaction. |
| 6825 | boolean performShowLocked() { |
| 6826 | if (DEBUG_VISIBILITY) { |
| 6827 | RuntimeException e = new RuntimeException(); |
| 6828 | e.fillInStackTrace(); |
| 6829 | Log.v(TAG, "performShow on " + this |
| 6830 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 6831 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 6832 | } |
| 6833 | if (mReadyToShow && isReadyForDisplay()) { |
| 6834 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Log.i( |
| 6835 | TAG, " SURFACE " + mSurface + ": SHOW (performShowLocked)"); |
| 6836 | if (DEBUG_VISIBILITY) Log.v(TAG, "Showing " + this |
| 6837 | + " during animation: policyVis=" + mPolicyVisibility |
| 6838 | + " attHidden=" + mAttachedHidden |
| 6839 | + " tok.hiddenRequested=" |
| 6840 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
| 6841 | + " tok.idden=" |
| 6842 | + (mAppToken != null ? mAppToken.hidden : false) |
| 6843 | + " animating=" + mAnimating |
| 6844 | + " tok animating=" |
| 6845 | + (mAppToken != null ? mAppToken.animating : false)); |
| 6846 | if (!showSurfaceRobustlyLocked(this)) { |
| 6847 | return false; |
| 6848 | } |
| 6849 | mLastAlpha = -1; |
| 6850 | mHasDrawn = true; |
| 6851 | mLastHidden = false; |
| 6852 | mReadyToShow = false; |
| 6853 | enableScreenIfNeededLocked(); |
| 6854 | |
| 6855 | applyEnterAnimationLocked(this); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6856 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6857 | int i = mChildWindows.size(); |
| 6858 | while (i > 0) { |
| 6859 | i--; |
| 6860 | WindowState c = (WindowState)mChildWindows.get(i); |
| 6861 | if (c.mSurface != null && c.mAttachedHidden) { |
| 6862 | c.mAttachedHidden = false; |
| 6863 | c.performShowLocked(); |
| 6864 | } |
| 6865 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6866 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6867 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 6868 | && mAppToken != null) { |
| 6869 | mAppToken.firstWindowDrawn = true; |
| 6870 | if (mAnimation == null && mAppToken.startingData != null) { |
| 6871 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Finish starting " |
| 6872 | + mToken |
| 6873 | + ": first real window is shown, no animation"); |
| 6874 | mFinishedStarting.add(mAppToken); |
| 6875 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 6876 | } |
| 6877 | mAppToken.updateReportedVisibilityLocked(); |
| 6878 | } |
| 6879 | } |
| 6880 | return true; |
| 6881 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6882 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6883 | // This must be called while inside a transaction. Returns true if |
| 6884 | // there is more animation to run. |
| 6885 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| 6886 | if (!mDisplayFrozen) { |
| 6887 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6888 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6889 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 6890 | mHasTransformation = true; |
| 6891 | mHasLocalTransformation = true; |
| 6892 | if (!mLocalAnimating) { |
| 6893 | if (DEBUG_ANIM) Log.v( |
| 6894 | TAG, "Starting animation in " + this + |
| 6895 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 6896 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 6897 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 6898 | mAnimation.setStartTime(currentTime); |
| 6899 | mLocalAnimating = true; |
| 6900 | mAnimating = true; |
| 6901 | } |
| 6902 | mTransformation.clear(); |
| 6903 | final boolean more = mAnimation.getTransformation( |
| 6904 | currentTime, mTransformation); |
| 6905 | if (DEBUG_ANIM) Log.v( |
| 6906 | TAG, "Stepped animation in " + this + |
| 6907 | ": more=" + more + ", xform=" + mTransformation); |
| 6908 | if (more) { |
| 6909 | // we're not done! |
| 6910 | return true; |
| 6911 | } |
| 6912 | if (DEBUG_ANIM) Log.v( |
| 6913 | TAG, "Finished animation in " + this + |
| 6914 | " @ " + currentTime); |
| 6915 | mAnimation = null; |
| 6916 | //WindowManagerService.this.dump(); |
| 6917 | } |
| 6918 | mHasLocalTransformation = false; |
| 6919 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6920 | && mAppToken.animation != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6921 | // When our app token is animating, we kind-of pretend like |
| 6922 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 6923 | // part of this check means that we will only do this if |
| 6924 | // our window is not currently exiting, or it is not |
| 6925 | // locally animating itself. The idea being that one that |
| 6926 | // is exiting and doing a local animation should be removed |
| 6927 | // once that animation is done. |
| 6928 | mAnimating = true; |
| 6929 | mHasTransformation = true; |
| 6930 | mTransformation.clear(); |
| 6931 | return false; |
| 6932 | } else if (mHasTransformation) { |
| 6933 | // Little trick to get through the path below to act like |
| 6934 | // we have finished an animation. |
| 6935 | mAnimating = true; |
| 6936 | } else if (isAnimating()) { |
| 6937 | mAnimating = true; |
| 6938 | } |
| 6939 | } else if (mAnimation != null) { |
| 6940 | // If the display is frozen, and there is a pending animation, |
| 6941 | // clear it and make sure we run the cleanup code. |
| 6942 | mAnimating = true; |
| 6943 | mLocalAnimating = true; |
| 6944 | mAnimation = null; |
| 6945 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6946 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6947 | if (!mAnimating && !mLocalAnimating) { |
| 6948 | return false; |
| 6949 | } |
| 6950 | |
| 6951 | if (DEBUG_ANIM) Log.v( |
| 6952 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 6953 | + ", reportedVisible=" |
| 6954 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6955 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6956 | mAnimating = false; |
| 6957 | mLocalAnimating = false; |
| 6958 | mAnimation = null; |
| 6959 | mAnimLayer = mLayer; |
| 6960 | if (mIsImWindow) { |
| 6961 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6962 | } else if (mIsWallpaper) { |
| 6963 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6964 | } |
| 6965 | if (DEBUG_LAYERS) Log.v(TAG, "Stepping win " + this |
| 6966 | + " anim layer: " + mAnimLayer); |
| 6967 | mHasTransformation = false; |
| 6968 | mHasLocalTransformation = false; |
| 6969 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 6970 | mTransformation.clear(); |
| 6971 | if (mHasDrawn |
| 6972 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 6973 | && mAppToken != null |
| 6974 | && mAppToken.firstWindowDrawn |
| 6975 | && mAppToken.startingData != null) { |
| 6976 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Finish starting " |
| 6977 | + mToken + ": first real window done animating"); |
| 6978 | mFinishedStarting.add(mAppToken); |
| 6979 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 6980 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6981 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6982 | finishExit(); |
| 6983 | |
| 6984 | if (mAppToken != null) { |
| 6985 | mAppToken.updateReportedVisibilityLocked(); |
| 6986 | } |
| 6987 | |
| 6988 | return false; |
| 6989 | } |
| 6990 | |
| 6991 | void finishExit() { |
| 6992 | if (DEBUG_ANIM) Log.v( |
| 6993 | TAG, "finishExit in " + this |
| 6994 | + ": exiting=" + mExiting |
| 6995 | + " remove=" + mRemoveOnExit |
| 6996 | + " windowAnimating=" + isWindowAnimating()); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6997 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6998 | final int N = mChildWindows.size(); |
| 6999 | for (int i=0; i<N; i++) { |
| 7000 | ((WindowState)mChildWindows.get(i)).finishExit(); |
| 7001 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7002 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7003 | if (!mExiting) { |
| 7004 | return; |
| 7005 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7006 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7007 | if (isWindowAnimating()) { |
| 7008 | return; |
| 7009 | } |
| 7010 | |
| 7011 | if (localLOGV) Log.v( |
| 7012 | TAG, "Exit animation finished in " + this |
| 7013 | + ": remove=" + mRemoveOnExit); |
| 7014 | if (mSurface != null) { |
| 7015 | mDestroySurface.add(this); |
| 7016 | mDestroying = true; |
| 7017 | if (SHOW_TRANSACTIONS) Log.i( |
| 7018 | TAG, " SURFACE " + mSurface + ": HIDE (finishExit)"); |
| 7019 | try { |
| 7020 | mSurface.hide(); |
| 7021 | } catch (RuntimeException e) { |
| 7022 | Log.w(TAG, "Error hiding surface in " + this, e); |
| 7023 | } |
| 7024 | mLastHidden = true; |
| 7025 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 7026 | } |
| 7027 | mExiting = false; |
| 7028 | if (mRemoveOnExit) { |
| 7029 | mPendingRemove.add(this); |
| 7030 | mRemoveOnExit = false; |
| 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 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 7035 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 7036 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 7037 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 7038 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 7039 | return true; |
| 7040 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7041 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7042 | void computeShownFrameLocked() { |
| 7043 | final boolean selfTransformation = mHasLocalTransformation; |
| 7044 | Transformation attachedTransformation = |
| 7045 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 7046 | ? mAttachedWindow.mTransformation : null; |
| 7047 | Transformation appTransformation = |
| 7048 | (mAppToken != null && mAppToken.hasTransformation) |
| 7049 | ? mAppToken.transformation : null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7050 | |
| 7051 | // Wallpapers are animated based on the "real" window they |
| 7052 | // are currently targeting. |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7053 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7054 | && mWallpaperTarget != null) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7055 | if (mWallpaperTarget.mHasLocalTransformation) { |
| 7056 | attachedTransformation = mWallpaperTarget.mTransformation; |
| 7057 | } |
| 7058 | if (mWallpaperTarget.mAppToken != null && |
| 7059 | mWallpaperTarget.mAppToken.hasTransformation) { |
| 7060 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
| 7061 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7062 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
| 7063 | Log.v(TAG, "WP target attached xform: " + attachedTransformation); |
| 7064 | } |
| 7065 | if (DEBUG_WALLPAPER && appTransformation != null) { |
| 7066 | Log.v(TAG, "WP target app xform: " + appTransformation); |
| 7067 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7068 | } |
| 7069 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7070 | if (selfTransformation || attachedTransformation != null |
| 7071 | || appTransformation != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7072 | // cache often used attributes locally |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7073 | final Rect frame = mFrame; |
| 7074 | final float tmpFloats[] = mTmpFloats; |
| 7075 | final Matrix tmpMatrix = mTmpMatrix; |
| 7076 | |
| 7077 | // Compute the desired transformation. |
| 7078 | tmpMatrix.setTranslate(frame.left, frame.top); |
| 7079 | if (selfTransformation) { |
| 7080 | tmpMatrix.preConcat(mTransformation.getMatrix()); |
| 7081 | } |
| 7082 | if (attachedTransformation != null) { |
| 7083 | tmpMatrix.preConcat(attachedTransformation.getMatrix()); |
| 7084 | } |
| 7085 | if (appTransformation != null) { |
| 7086 | tmpMatrix.preConcat(appTransformation.getMatrix()); |
| 7087 | } |
| 7088 | |
| 7089 | // "convert" it into SurfaceFlinger's format |
| 7090 | // (a 2x2 matrix + an offset) |
| 7091 | // Here we must not transform the position of the surface |
| 7092 | // since it is already included in the transformation. |
| 7093 | //Log.i(TAG, "Transform: " + matrix); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7094 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7095 | tmpMatrix.getValues(tmpFloats); |
| 7096 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 7097 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 7098 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 7099 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7100 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 7101 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7102 | int w = frame.width(); |
| 7103 | int h = frame.height(); |
| 7104 | mShownFrame.set(x, y, x+w, y+h); |
| 7105 | |
| 7106 | // Now set the alpha... but because our current hardware |
| 7107 | // can't do alpha transformation on a non-opaque surface, |
| 7108 | // turn it off if we are running an animation that is also |
| 7109 | // transforming since it is more important to have that |
| 7110 | // animation be smooth. |
| 7111 | mShownAlpha = mAlpha; |
| 7112 | if (!mLimitedAlphaCompositing |
| 7113 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 7114 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 7115 | && x == frame.left && y == frame.top))) { |
| 7116 | //Log.i(TAG, "Applying alpha transform"); |
| 7117 | if (selfTransformation) { |
| 7118 | mShownAlpha *= mTransformation.getAlpha(); |
| 7119 | } |
| 7120 | if (attachedTransformation != null) { |
| 7121 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 7122 | } |
| 7123 | if (appTransformation != null) { |
| 7124 | mShownAlpha *= appTransformation.getAlpha(); |
| 7125 | } |
| 7126 | } else { |
| 7127 | //Log.i(TAG, "Not applying alpha transform"); |
| 7128 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7129 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7130 | if (localLOGV) Log.v( |
| 7131 | TAG, "Continuing animation in " + this + |
| 7132 | ": " + mShownFrame + |
| 7133 | ", alpha=" + mTransformation.getAlpha()); |
| 7134 | return; |
| 7135 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7136 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7137 | mShownFrame.set(mFrame); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7138 | if (mXOffset != 0 || mYOffset != 0) { |
| 7139 | mShownFrame.offset(mXOffset, mYOffset); |
| 7140 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7141 | mShownAlpha = mAlpha; |
| 7142 | mDsDx = 1; |
| 7143 | mDtDx = 0; |
| 7144 | mDsDy = 0; |
| 7145 | mDtDy = 1; |
| 7146 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7147 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7148 | /** |
| 7149 | * Is this window visible? It is not visible if there is no |
| 7150 | * surface, or we are in the process of running an exit animation |
| 7151 | * that will remove the surface, or its app token has been hidden. |
| 7152 | */ |
| 7153 | public boolean isVisibleLw() { |
| 7154 | final AppWindowToken atoken = mAppToken; |
| 7155 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7156 | && (atoken == null || !atoken.hiddenRequested) |
| 7157 | && !mExiting && !mDestroying; |
| 7158 | } |
| 7159 | |
| 7160 | /** |
| 7161 | * Is this window visible, ignoring its app token? It is not visible |
| 7162 | * if there is no surface, or we are in the process of running an exit animation |
| 7163 | * that will remove the surface. |
| 7164 | */ |
| 7165 | public boolean isWinVisibleLw() { |
| 7166 | final AppWindowToken atoken = mAppToken; |
| 7167 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7168 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 7169 | && !mExiting && !mDestroying; |
| 7170 | } |
| 7171 | |
| 7172 | /** |
| 7173 | * The same as isVisible(), but follows the current hidden state of |
| 7174 | * the associated app token, not the pending requested hidden state. |
| 7175 | */ |
| 7176 | boolean isVisibleNow() { |
| 7177 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7178 | && !mRootToken.hidden && !mExiting && !mDestroying; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7179 | } |
| 7180 | |
| 7181 | /** |
| 7182 | * Same as isVisible(), but we also count it as visible between the |
| 7183 | * call to IWindowSession.add() and the first relayout(). |
| 7184 | */ |
| 7185 | boolean isVisibleOrAdding() { |
| 7186 | final AppWindowToken atoken = mAppToken; |
| 7187 | return (mSurface != null |
| 7188 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 7189 | && mPolicyVisibility && !mAttachedHidden |
| 7190 | && (atoken == null || !atoken.hiddenRequested) |
| 7191 | && !mExiting && !mDestroying; |
| 7192 | } |
| 7193 | |
| 7194 | /** |
| 7195 | * Is this window currently on-screen? It is on-screen either if it |
| 7196 | * is visible or it is currently running an animation before no longer |
| 7197 | * being visible. |
| 7198 | */ |
| 7199 | boolean isOnScreen() { |
| 7200 | final AppWindowToken atoken = mAppToken; |
| 7201 | if (atoken != null) { |
| 7202 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7203 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7204 | || mAnimation != null || atoken.animation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7205 | } else { |
| 7206 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7207 | && (!mAttachedHidden || mAnimation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7208 | } |
| 7209 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7210 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7211 | /** |
| 7212 | * Like isOnScreen(), but we don't return true if the window is part |
| 7213 | * of a transition that has not yet been started. |
| 7214 | */ |
| 7215 | boolean isReadyForDisplay() { |
| 7216 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7217 | final boolean animating = atoken != null |
| 7218 | ? (atoken.animation != null) : false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7219 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7220 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 7221 | && !mRootToken.hidden) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7222 | || mAnimation != null || animating); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7223 | } |
| 7224 | |
| 7225 | /** Is the window or its container currently animating? */ |
| 7226 | boolean isAnimating() { |
| 7227 | final WindowState attached = mAttachedWindow; |
| 7228 | final AppWindowToken atoken = mAppToken; |
| 7229 | return mAnimation != null |
| 7230 | || (attached != null && attached.mAnimation != null) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7231 | || (atoken != null && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7232 | (atoken.animation != null |
| 7233 | || atoken.inPendingTransaction)); |
| 7234 | } |
| 7235 | |
| 7236 | /** Is this window currently animating? */ |
| 7237 | boolean isWindowAnimating() { |
| 7238 | return mAnimation != null; |
| 7239 | } |
| 7240 | |
| 7241 | /** |
| 7242 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 7243 | * been drawn. |
| 7244 | */ |
| 7245 | public boolean isDisplayedLw() { |
| 7246 | final AppWindowToken atoken = mAppToken; |
| 7247 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7248 | && !mDrawPending && !mCommitDrawPending |
| 7249 | && ((!mAttachedHidden && |
| 7250 | (atoken == null || !atoken.hiddenRequested)) |
| 7251 | || mAnimating); |
| 7252 | } |
| 7253 | |
| 7254 | public boolean fillsScreenLw(int screenWidth, int screenHeight, |
| 7255 | boolean shownFrame, boolean onlyOpaque) { |
| 7256 | if (mSurface == null) { |
| 7257 | return false; |
| 7258 | } |
| 7259 | if (mAppToken != null && !mAppToken.appFullscreen) { |
| 7260 | return false; |
| 7261 | } |
| 7262 | if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) { |
| 7263 | return false; |
| 7264 | } |
| 7265 | final Rect frame = shownFrame ? mShownFrame : mFrame; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7266 | |
| 7267 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| 7268 | return frame.left <= mCompatibleScreenFrame.left && |
| 7269 | frame.top <= mCompatibleScreenFrame.top && |
| 7270 | frame.right >= mCompatibleScreenFrame.right && |
| 7271 | frame.bottom >= mCompatibleScreenFrame.bottom; |
| 7272 | } else { |
| 7273 | return frame.left <= 0 && frame.top <= 0 |
| 7274 | && frame.right >= screenWidth |
| 7275 | && frame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7276 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7277 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7278 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7279 | /** |
| 7280 | * Return true if the window is opaque and fully drawn. |
| 7281 | */ |
| 7282 | boolean isOpaqueDrawn() { |
| 7283 | return mAttrs.format == PixelFormat.OPAQUE && mSurface != null |
| 7284 | && mAnimation == null && !mDrawPending && !mCommitDrawPending; |
| 7285 | } |
| 7286 | |
| 7287 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 7288 | return |
| 7289 | // only if the application is requesting compatible window |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7290 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 7291 | // only if it's visible |
| 7292 | mHasDrawn && mViewVisibility == View.VISIBLE && |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7293 | // and only if the application fills the compatible screen |
| 7294 | mFrame.left <= mCompatibleScreenFrame.left && |
| 7295 | mFrame.top <= mCompatibleScreenFrame.top && |
| 7296 | mFrame.right >= mCompatibleScreenFrame.right && |
| 7297 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7298 | // and starting window do not need background filler |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7299 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7300 | } |
| 7301 | |
| 7302 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 7303 | return mFrame.left <= 0 && mFrame.top <= 0 && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7304 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7305 | } |
| 7306 | |
| 7307 | void removeLocked() { |
| 7308 | if (mAttachedWindow != null) { |
| 7309 | mAttachedWindow.mChildWindows.remove(this); |
| 7310 | } |
| 7311 | destroySurfaceLocked(); |
| 7312 | mSession.windowRemovedLocked(); |
| 7313 | try { |
| 7314 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 7315 | } catch (RuntimeException e) { |
| 7316 | // Ignore if it has already been removed (usually because |
| 7317 | // we are doing this as part of processing a death note.) |
| 7318 | } |
| 7319 | } |
| 7320 | |
| 7321 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 7322 | public void binderDied() { |
| 7323 | try { |
| 7324 | synchronized(mWindowMap) { |
| 7325 | WindowState win = windowForClientLocked(mSession, mClient); |
| 7326 | Log.i(TAG, "WIN DEATH: " + win); |
| 7327 | if (win != null) { |
| 7328 | removeWindowLocked(mSession, win); |
| 7329 | } |
| 7330 | } |
| 7331 | } catch (IllegalArgumentException ex) { |
| 7332 | // This will happen if the window has already been |
| 7333 | // removed. |
| 7334 | } |
| 7335 | } |
| 7336 | } |
| 7337 | |
| 7338 | /** Returns true if this window desires key events. */ |
| 7339 | public final boolean canReceiveKeys() { |
| 7340 | return isVisibleOrAdding() |
| 7341 | && (mViewVisibility == View.VISIBLE) |
| 7342 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 7343 | } |
| 7344 | |
| 7345 | public boolean hasDrawnLw() { |
| 7346 | return mHasDrawn; |
| 7347 | } |
| 7348 | |
| 7349 | public boolean showLw(boolean doAnimation) { |
| 7350 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim) { |
| 7351 | mPolicyVisibility = true; |
| 7352 | mPolicyVisibilityAfterAnim = true; |
| 7353 | if (doAnimation) { |
| 7354 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 7355 | } |
| 7356 | requestAnimationLocked(0); |
| 7357 | return true; |
| 7358 | } |
| 7359 | return false; |
| 7360 | } |
| 7361 | |
| 7362 | public boolean hideLw(boolean doAnimation) { |
| 7363 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 7364 | : mPolicyVisibility; |
| 7365 | if (current) { |
| 7366 | if (doAnimation) { |
| 7367 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 7368 | if (mAnimation == null) { |
| 7369 | doAnimation = false; |
| 7370 | } |
| 7371 | } |
| 7372 | if (doAnimation) { |
| 7373 | mPolicyVisibilityAfterAnim = false; |
| 7374 | } else { |
| 7375 | mPolicyVisibilityAfterAnim = false; |
| 7376 | mPolicyVisibility = false; |
| 7377 | } |
| 7378 | requestAnimationLocked(0); |
| 7379 | return true; |
| 7380 | } |
| 7381 | return false; |
| 7382 | } |
| 7383 | |
| 7384 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7385 | StringBuilder sb = new StringBuilder(64); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7386 | |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7387 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 7388 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 7389 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 7390 | if (mAttachedWindow != null || mLayoutAttached) { |
| 7391 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 7392 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 7393 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7394 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 7395 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 7396 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7397 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 7398 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7399 | } |
| 7400 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 7401 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 7402 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 7403 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 7404 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 7405 | pw.print("="); pw.print(mAnimLayer); |
| 7406 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 7407 | if (mSurface != null) { |
| 7408 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
| 7409 | } |
| 7410 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 7411 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 7412 | if (mAppToken != null) { |
| 7413 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 7414 | } |
| 7415 | if (mTargetAppToken != null) { |
| 7416 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 7417 | } |
| 7418 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 7419 | pw.print(Integer.toHexString(mViewVisibility)); |
| 7420 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7421 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 7422 | pw.print(" mObscured="); pw.println(mObscured); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7423 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 7424 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 7425 | pw.print(mPolicyVisibility); |
| 7426 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 7427 | pw.print(mPolicyVisibilityAfterAnim); |
| 7428 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 7429 | } |
| 7430 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7431 | pw.print(" h="); pw.println(mRequestedHeight); |
| 7432 | if (mXOffset != 0 || mYOffset != 0) { |
| 7433 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 7434 | pw.print(" y="); pw.println(mYOffset); |
| 7435 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7436 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 7437 | mGivenContentInsets.printShortString(pw); |
| 7438 | pw.print(" mGivenVisibleInsets="); |
| 7439 | mGivenVisibleInsets.printShortString(pw); |
| 7440 | pw.println(); |
| 7441 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 7442 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 7443 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 7444 | } |
| 7445 | pw.print(prefix); pw.print("mShownFrame="); |
| 7446 | mShownFrame.printShortString(pw); |
| 7447 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 7448 | pw.println(); |
| 7449 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 7450 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 7451 | pw.println(); |
| 7452 | pw.print(prefix); pw.print("mContainingFrame="); |
| 7453 | mContainingFrame.printShortString(pw); |
| 7454 | pw.print(" mDisplayFrame="); |
| 7455 | mDisplayFrame.printShortString(pw); |
| 7456 | pw.println(); |
| 7457 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 7458 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 7459 | pw.println(); |
| 7460 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 7461 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 7462 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 7463 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 7464 | pw.println(); |
| 7465 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 7466 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 7467 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 7468 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 7469 | } |
| 7470 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 7471 | || mAnimation != null) { |
| 7472 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 7473 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 7474 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 7475 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 7476 | } |
| 7477 | if (mHasTransformation || mHasLocalTransformation) { |
| 7478 | pw.print(prefix); pw.print("XForm: has="); |
| 7479 | pw.print(mHasTransformation); |
| 7480 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 7481 | pw.print(" "); mTransformation.printShortString(pw); |
| 7482 | pw.println(); |
| 7483 | } |
| 7484 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 7485 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 7486 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 7487 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 7488 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 7489 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 7490 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 7491 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 7492 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 7493 | } |
| 7494 | if (mOrientationChanging || mAppFreezing) { |
| 7495 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 7496 | pw.print(mOrientationChanging); |
| 7497 | pw.print(" mAppFreezing="); pw.println(mAppFreezing); |
| 7498 | } |
| Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 7499 | if (mHScale != 1 || mVScale != 1) { |
| 7500 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 7501 | pw.print(" mVScale="); pw.println(mVScale); |
| 7502 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7503 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7504 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 7505 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 7506 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7507 | } |
| 7508 | |
| 7509 | @Override |
| 7510 | public String toString() { |
| 7511 | return "Window{" |
| 7512 | + Integer.toHexString(System.identityHashCode(this)) |
| 7513 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 7514 | } |
| 7515 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7516 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7517 | // ------------------------------------------------------------- |
| 7518 | // Window Token State |
| 7519 | // ------------------------------------------------------------- |
| 7520 | |
| 7521 | class WindowToken { |
| 7522 | // The actual token. |
| 7523 | final IBinder token; |
| 7524 | |
| 7525 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 7526 | final int windowType; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7527 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7528 | // Set if this token was explicitly added by a client, so should |
| 7529 | // not be removed when all windows are removed. |
| 7530 | final boolean explicit; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7531 | |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7532 | // For printing. |
| 7533 | String stringName; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7534 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7535 | // If this is an AppWindowToken, this is non-null. |
| 7536 | AppWindowToken appWindowToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7537 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7538 | // All of the windows associated with this token. |
| 7539 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 7540 | |
| 7541 | // Is key dispatching paused for this token? |
| 7542 | boolean paused = false; |
| 7543 | |
| 7544 | // Should this token's windows be hidden? |
| 7545 | boolean hidden; |
| 7546 | |
| 7547 | // Temporary for finding which tokens no longer have visible windows. |
| 7548 | boolean hasVisible; |
| 7549 | |
| 7550 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 7551 | token = _token; |
| 7552 | windowType = type; |
| 7553 | explicit = _explicit; |
| 7554 | } |
| 7555 | |
| 7556 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7557 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 7558 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 7559 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 7560 | pw.print(" hidden="); pw.print(hidden); |
| 7561 | pw.print(" hasVisible="); pw.println(hasVisible); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7562 | } |
| 7563 | |
| 7564 | @Override |
| 7565 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7566 | if (stringName == null) { |
| 7567 | StringBuilder sb = new StringBuilder(); |
| 7568 | sb.append("WindowToken{"); |
| 7569 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7570 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 7571 | stringName = sb.toString(); |
| 7572 | } |
| 7573 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7574 | } |
| 7575 | }; |
| 7576 | |
| 7577 | class AppWindowToken extends WindowToken { |
| 7578 | // Non-null only for application tokens. |
| 7579 | final IApplicationToken appToken; |
| 7580 | |
| 7581 | // All of the windows and child windows that are included in this |
| 7582 | // application token. Note this list is NOT sorted! |
| 7583 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 7584 | |
| 7585 | int groupId = -1; |
| 7586 | boolean appFullscreen; |
| 7587 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7588 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7589 | // These are used for determining when all windows associated with |
| 7590 | // an activity have been drawn, so they can be made visible together |
| 7591 | // at the same time. |
| 7592 | int lastTransactionSequence = mTransactionSequence-1; |
| 7593 | int numInterestingWindows; |
| 7594 | int numDrawnWindows; |
| 7595 | boolean inPendingTransaction; |
| 7596 | boolean allDrawn; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7597 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7598 | // Is this token going to be hidden in a little while? If so, it |
| 7599 | // won't be taken into account for setting the screen orientation. |
| 7600 | boolean willBeHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7601 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7602 | // Is this window's surface needed? This is almost like hidden, except |
| 7603 | // it will sometimes be true a little earlier: when the token has |
| 7604 | // been shown, but is still waiting for its app transition to execute |
| 7605 | // before making its windows shown. |
| 7606 | boolean hiddenRequested; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7607 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7608 | // Have we told the window clients to hide themselves? |
| 7609 | boolean clientHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7610 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7611 | // Last visibility state we reported to the app token. |
| 7612 | boolean reportedVisible; |
| 7613 | |
| 7614 | // Set to true when the token has been removed from the window mgr. |
| 7615 | boolean removed; |
| 7616 | |
| 7617 | // Have we been asked to have this token keep the screen frozen? |
| 7618 | boolean freezingScreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7619 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7620 | boolean animating; |
| 7621 | Animation animation; |
| 7622 | boolean hasTransformation; |
| 7623 | final Transformation transformation = new Transformation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7624 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7625 | // Offset to the window of all layers in the token, for use by |
| 7626 | // AppWindowToken animations. |
| 7627 | int animLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7628 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7629 | // Information about an application starting window if displayed. |
| 7630 | StartingData startingData; |
| 7631 | WindowState startingWindow; |
| 7632 | View startingView; |
| 7633 | boolean startingDisplayed; |
| 7634 | boolean startingMoved; |
| 7635 | boolean firstWindowDrawn; |
| 7636 | |
| 7637 | AppWindowToken(IApplicationToken _token) { |
| 7638 | super(_token.asBinder(), |
| 7639 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 7640 | appWindowToken = this; |
| 7641 | appToken = _token; |
| 7642 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7643 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7644 | public void setAnimation(Animation anim) { |
| 7645 | if (localLOGV) Log.v( |
| 7646 | TAG, "Setting animation in " + this + ": " + anim); |
| 7647 | animation = anim; |
| 7648 | animating = false; |
| 7649 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 7650 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 7651 | int zorder = anim.getZAdjustment(); |
| 7652 | int adj = 0; |
| 7653 | if (zorder == Animation.ZORDER_TOP) { |
| 7654 | adj = TYPE_LAYER_OFFSET; |
| 7655 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 7656 | adj = -TYPE_LAYER_OFFSET; |
| 7657 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7658 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7659 | if (animLayerAdjustment != adj) { |
| 7660 | animLayerAdjustment = adj; |
| 7661 | updateLayers(); |
| 7662 | } |
| 7663 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7664 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7665 | public void setDummyAnimation() { |
| 7666 | if (animation == null) { |
| 7667 | if (localLOGV) Log.v( |
| 7668 | TAG, "Setting dummy animation in " + this); |
| 7669 | animation = sDummyAnimation; |
| 7670 | } |
| 7671 | } |
| 7672 | |
| 7673 | public void clearAnimation() { |
| 7674 | if (animation != null) { |
| 7675 | animation = null; |
| 7676 | animating = true; |
| 7677 | } |
| 7678 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7679 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7680 | void updateLayers() { |
| 7681 | final int N = allAppWindows.size(); |
| 7682 | final int adj = animLayerAdjustment; |
| 7683 | for (int i=0; i<N; i++) { |
| 7684 | WindowState w = allAppWindows.get(i); |
| 7685 | w.mAnimLayer = w.mLayer + adj; |
| 7686 | if (DEBUG_LAYERS) Log.v(TAG, "Updating layer " + w + ": " |
| 7687 | + w.mAnimLayer); |
| 7688 | if (w == mInputMethodTarget) { |
| 7689 | setInputMethodAnimLayerAdjustment(adj); |
| 7690 | } |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7691 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7692 | setWallpaperAnimLayerAdjustmentLocked(adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7693 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7694 | } |
| 7695 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7696 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7697 | void sendAppVisibilityToClients() { |
| 7698 | final int N = allAppWindows.size(); |
| 7699 | for (int i=0; i<N; i++) { |
| 7700 | WindowState win = allAppWindows.get(i); |
| 7701 | if (win == startingWindow && clientHidden) { |
| 7702 | // Don't hide the starting window. |
| 7703 | continue; |
| 7704 | } |
| 7705 | try { |
| 7706 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 7707 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 7708 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 7709 | } catch (RemoteException e) { |
| 7710 | } |
| 7711 | } |
| 7712 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7713 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7714 | void showAllWindowsLocked() { |
| 7715 | final int NW = allAppWindows.size(); |
| 7716 | for (int i=0; i<NW; i++) { |
| 7717 | WindowState w = allAppWindows.get(i); |
| 7718 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 7719 | "performing show on: " + w); |
| 7720 | w.performShowLocked(); |
| 7721 | } |
| 7722 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7723 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7724 | // This must be called while inside a transaction. |
| 7725 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| 7726 | if (!mDisplayFrozen) { |
| 7727 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7728 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7729 | if (animation == sDummyAnimation) { |
| 7730 | // This guy is going to animate, but not yet. For now count |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7731 | // it as not animating for purposes of scheduling transactions; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7732 | // when it is really time to animate, this will be set to |
| 7733 | // a real animation and the next call will execute normally. |
| 7734 | return false; |
| 7735 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7736 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7737 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 7738 | if (!animating) { |
| 7739 | if (DEBUG_ANIM) Log.v( |
| 7740 | TAG, "Starting animation in " + this + |
| 7741 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 7742 | + " scale=" + mTransitionAnimationScale |
| 7743 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 7744 | animation.initialize(dw, dh, dw, dh); |
| 7745 | animation.setStartTime(currentTime); |
| 7746 | animating = true; |
| 7747 | } |
| 7748 | transformation.clear(); |
| 7749 | final boolean more = animation.getTransformation( |
| 7750 | currentTime, transformation); |
| 7751 | if (DEBUG_ANIM) Log.v( |
| 7752 | TAG, "Stepped animation in " + this + |
| 7753 | ": more=" + more + ", xform=" + transformation); |
| 7754 | if (more) { |
| 7755 | // we're done! |
| 7756 | hasTransformation = true; |
| 7757 | return true; |
| 7758 | } |
| 7759 | if (DEBUG_ANIM) Log.v( |
| 7760 | TAG, "Finished animation in " + this + |
| 7761 | " @ " + currentTime); |
| 7762 | animation = null; |
| 7763 | } |
| 7764 | } else if (animation != null) { |
| 7765 | // If the display is frozen, and there is a pending animation, |
| 7766 | // clear it and make sure we run the cleanup code. |
| 7767 | animating = true; |
| 7768 | animation = null; |
| 7769 | } |
| 7770 | |
| 7771 | hasTransformation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7772 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7773 | if (!animating) { |
| 7774 | return false; |
| 7775 | } |
| 7776 | |
| 7777 | clearAnimation(); |
| 7778 | animating = false; |
| 7779 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 7780 | moveInputMethodWindowsIfNeededLocked(true); |
| 7781 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7782 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7783 | if (DEBUG_ANIM) Log.v( |
| 7784 | TAG, "Animation done in " + this |
| 7785 | + ": reportedVisible=" + reportedVisible); |
| 7786 | |
| 7787 | transformation.clear(); |
| 7788 | if (animLayerAdjustment != 0) { |
| 7789 | animLayerAdjustment = 0; |
| 7790 | updateLayers(); |
| 7791 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7792 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7793 | final int N = windows.size(); |
| 7794 | for (int i=0; i<N; i++) { |
| 7795 | ((WindowState)windows.get(i)).finishExit(); |
| 7796 | } |
| 7797 | updateReportedVisibilityLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7798 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7799 | return false; |
| 7800 | } |
| 7801 | |
| 7802 | void updateReportedVisibilityLocked() { |
| 7803 | if (appToken == null) { |
| 7804 | return; |
| 7805 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7806 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7807 | int numInteresting = 0; |
| 7808 | int numVisible = 0; |
| 7809 | boolean nowGone = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7810 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7811 | if (DEBUG_VISIBILITY) Log.v(TAG, "Update reported visibility: " + this); |
| 7812 | final int N = allAppWindows.size(); |
| 7813 | for (int i=0; i<N; i++) { |
| 7814 | WindowState win = allAppWindows.get(i); |
| 7815 | if (win == startingWindow || win.mAppFreezing) { |
| 7816 | continue; |
| 7817 | } |
| 7818 | if (DEBUG_VISIBILITY) { |
| 7819 | Log.v(TAG, "Win " + win + ": isDisplayed=" |
| 7820 | + win.isDisplayedLw() |
| 7821 | + ", isAnimating=" + win.isAnimating()); |
| 7822 | if (!win.isDisplayedLw()) { |
| 7823 | Log.v(TAG, "Not displayed: s=" + win.mSurface |
| 7824 | + " pv=" + win.mPolicyVisibility |
| 7825 | + " dp=" + win.mDrawPending |
| 7826 | + " cdp=" + win.mCommitDrawPending |
| 7827 | + " ah=" + win.mAttachedHidden |
| 7828 | + " th=" |
| 7829 | + (win.mAppToken != null |
| 7830 | ? win.mAppToken.hiddenRequested : false) |
| 7831 | + " a=" + win.mAnimating); |
| 7832 | } |
| 7833 | } |
| 7834 | numInteresting++; |
| 7835 | if (win.isDisplayedLw()) { |
| 7836 | if (!win.isAnimating()) { |
| 7837 | numVisible++; |
| 7838 | } |
| 7839 | nowGone = false; |
| 7840 | } else if (win.isAnimating()) { |
| 7841 | nowGone = false; |
| 7842 | } |
| 7843 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7844 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7845 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
| 7846 | if (DEBUG_VISIBILITY) Log.v(TAG, "VIS " + this + ": interesting=" |
| 7847 | + numInteresting + " visible=" + numVisible); |
| 7848 | if (nowVisible != reportedVisible) { |
| 7849 | if (DEBUG_VISIBILITY) Log.v( |
| 7850 | TAG, "Visibility changed in " + this |
| 7851 | + ": vis=" + nowVisible); |
| 7852 | reportedVisible = nowVisible; |
| 7853 | Message m = mH.obtainMessage( |
| 7854 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 7855 | nowVisible ? 1 : 0, |
| 7856 | nowGone ? 1 : 0, |
| 7857 | this); |
| 7858 | mH.sendMessage(m); |
| 7859 | } |
| 7860 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7861 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7862 | void dump(PrintWriter pw, String prefix) { |
| 7863 | super.dump(pw, prefix); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7864 | if (appToken != null) { |
| 7865 | pw.print(prefix); pw.println("app=true"); |
| 7866 | } |
| 7867 | if (allAppWindows.size() > 0) { |
| 7868 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 7869 | } |
| 7870 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7871 | pw.print(" appFullscreen="); pw.println(appFullscreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7872 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 7873 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 7874 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 7875 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 7876 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 7877 | if (paused || freezingScreen) { |
| 7878 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 7879 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 7880 | } |
| 7881 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 7882 | || inPendingTransaction || allDrawn) { |
| 7883 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 7884 | pw.print(numInterestingWindows); |
| 7885 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 7886 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 7887 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 7888 | } |
| 7889 | if (animating || animation != null) { |
| 7890 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 7891 | pw.print(" animation="); pw.println(animation); |
| 7892 | } |
| 7893 | if (animLayerAdjustment != 0) { |
| 7894 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 7895 | } |
| 7896 | if (hasTransformation) { |
| 7897 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 7898 | pw.print(" transformation="); transformation.printShortString(pw); |
| 7899 | pw.println(); |
| 7900 | } |
| 7901 | if (startingData != null || removed || firstWindowDrawn) { |
| 7902 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 7903 | pw.print(" removed="); pw.print(removed); |
| 7904 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 7905 | } |
| 7906 | if (startingWindow != null || startingView != null |
| 7907 | || startingDisplayed || startingMoved) { |
| 7908 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 7909 | pw.print(" startingView="); pw.print(startingView); |
| 7910 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 7911 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 7912 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7913 | } |
| 7914 | |
| 7915 | @Override |
| 7916 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7917 | if (stringName == null) { |
| 7918 | StringBuilder sb = new StringBuilder(); |
| 7919 | sb.append("AppWindowToken{"); |
| 7920 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7921 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 7922 | stringName = sb.toString(); |
| 7923 | } |
| 7924 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7925 | } |
| 7926 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7927 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7928 | public static WindowManager.LayoutParams findAnimations( |
| 7929 | ArrayList<AppWindowToken> order, |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 7930 | ArrayList<AppWindowToken> openingTokenList1, |
| 7931 | ArrayList<AppWindowToken> closingTokenList2) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7932 | // We need to figure out which animation to use... |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 7933 | |
| 7934 | // First, check if there is a compatible window in opening/closing |
| 7935 | // apps, and use it if exists. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7936 | WindowManager.LayoutParams animParams = null; |
| 7937 | int animSrc = 0; |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 7938 | animParams = findCompatibleWindowParams(openingTokenList1); |
| 7939 | if (animParams == null) { |
| 7940 | animParams = findCompatibleWindowParams(closingTokenList2); |
| 7941 | } |
| 7942 | if (animParams != null) { |
| 7943 | return animParams; |
| 7944 | } |
| 7945 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7946 | //Log.i(TAG, "Looking for animations..."); |
| 7947 | for (int i=order.size()-1; i>=0; i--) { |
| 7948 | AppWindowToken wtoken = order.get(i); |
| 7949 | //Log.i(TAG, "Token " + wtoken + " with " + wtoken.windows.size() + " windows"); |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 7950 | if (openingTokenList1.contains(wtoken) || closingTokenList2.contains(wtoken)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7951 | int j = wtoken.windows.size(); |
| 7952 | while (j > 0) { |
| 7953 | j--; |
| 7954 | WindowState win = wtoken.windows.get(j); |
| 7955 | //Log.i(TAG, "Window " + win + ": type=" + win.mAttrs.type); |
| 7956 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 7957 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 7958 | //Log.i(TAG, "Found base or application window, done!"); |
| 7959 | if (wtoken.appFullscreen) { |
| 7960 | return win.mAttrs; |
| 7961 | } |
| 7962 | if (animSrc < 2) { |
| 7963 | animParams = win.mAttrs; |
| 7964 | animSrc = 2; |
| 7965 | } |
| 7966 | } else if (animSrc < 1 && win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION) { |
| 7967 | //Log.i(TAG, "Found normal window, we may use this..."); |
| 7968 | animParams = win.mAttrs; |
| 7969 | animSrc = 1; |
| 7970 | } |
| 7971 | } |
| 7972 | } |
| 7973 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7974 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7975 | return animParams; |
| 7976 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7977 | |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 7978 | private static LayoutParams findCompatibleWindowParams(ArrayList<AppWindowToken> tokenList) { |
| 7979 | for (int appCount = tokenList.size() - 1; appCount >= 0; appCount--) { |
| 7980 | AppWindowToken wtoken = tokenList.get(appCount); |
| 7981 | // Just checking one window is sufficient as all windows have the compatible flag |
| 7982 | // if the application is in compatibility mode. |
| 7983 | if (wtoken.windows.size() > 0) { |
| 7984 | WindowManager.LayoutParams params = wtoken.windows.get(0).mAttrs; |
| 7985 | if ((params.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| 7986 | return params; |
| 7987 | } |
| 7988 | } |
| 7989 | } |
| 7990 | return null; |
| 7991 | } |
| 7992 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7993 | // ------------------------------------------------------------- |
| 7994 | // DummyAnimation |
| 7995 | // ------------------------------------------------------------- |
| 7996 | |
| 7997 | // This is an animation that does nothing: it just immediately finishes |
| 7998 | // itself every time it is called. It is used as a stub animation in cases |
| 7999 | // where we want to synchronize multiple things that may be animating. |
| 8000 | static final class DummyAnimation extends Animation { |
| 8001 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 8002 | return false; |
| 8003 | } |
| 8004 | } |
| 8005 | static final Animation sDummyAnimation = new DummyAnimation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8006 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8007 | // ------------------------------------------------------------- |
| 8008 | // Async Handler |
| 8009 | // ------------------------------------------------------------- |
| 8010 | |
| 8011 | static final class StartingData { |
| 8012 | final String pkg; |
| 8013 | final int theme; |
| 8014 | final CharSequence nonLocalizedLabel; |
| 8015 | final int labelRes; |
| 8016 | final int icon; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8017 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8018 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 8019 | int _labelRes, int _icon) { |
| 8020 | pkg = _pkg; |
| 8021 | theme = _theme; |
| 8022 | nonLocalizedLabel = _nonLocalizedLabel; |
| 8023 | labelRes = _labelRes; |
| 8024 | icon = _icon; |
| 8025 | } |
| 8026 | } |
| 8027 | |
| 8028 | private final class H extends Handler { |
| 8029 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 8030 | public static final int REPORT_LOSING_FOCUS = 3; |
| 8031 | public static final int ANIMATE = 4; |
| 8032 | public static final int ADD_STARTING = 5; |
| 8033 | public static final int REMOVE_STARTING = 6; |
| 8034 | public static final int FINISHED_STARTING = 7; |
| 8035 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8036 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 8037 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 8038 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 8039 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 8040 | public static final int FORCE_GC = 15; |
| 8041 | public static final int ENABLE_SCREEN = 16; |
| 8042 | public static final int APP_FREEZE_TIMEOUT = 17; |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8043 | public static final int COMPUTE_AND_SEND_NEW_CONFIGURATION = 18; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8044 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8045 | private Session mLastReportedHold; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8046 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8047 | public H() { |
| 8048 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8049 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8050 | @Override |
| 8051 | public void handleMessage(Message msg) { |
| 8052 | switch (msg.what) { |
| 8053 | case REPORT_FOCUS_CHANGE: { |
| 8054 | WindowState lastFocus; |
| 8055 | WindowState newFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8056 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8057 | synchronized(mWindowMap) { |
| 8058 | lastFocus = mLastFocus; |
| 8059 | newFocus = mCurrentFocus; |
| 8060 | if (lastFocus == newFocus) { |
| 8061 | // Focus is not changing, so nothing to do. |
| 8062 | return; |
| 8063 | } |
| 8064 | mLastFocus = newFocus; |
| 8065 | //Log.i(TAG, "Focus moving from " + lastFocus |
| 8066 | // + " to " + newFocus); |
| 8067 | if (newFocus != null && lastFocus != null |
| 8068 | && !newFocus.isDisplayedLw()) { |
| 8069 | //Log.i(TAG, "Delaying loss of focus..."); |
| 8070 | mLosingFocus.add(lastFocus); |
| 8071 | lastFocus = null; |
| 8072 | } |
| 8073 | } |
| 8074 | |
| 8075 | if (lastFocus != newFocus) { |
| 8076 | //System.out.println("Changing focus from " + lastFocus |
| 8077 | // + " to " + newFocus); |
| 8078 | if (newFocus != null) { |
| 8079 | try { |
| 8080 | //Log.i(TAG, "Gaining focus: " + newFocus); |
| 8081 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 8082 | } catch (RemoteException e) { |
| 8083 | // Ignore if process has died. |
| 8084 | } |
| 8085 | } |
| 8086 | |
| 8087 | if (lastFocus != null) { |
| 8088 | try { |
| 8089 | //Log.i(TAG, "Losing focus: " + lastFocus); |
| 8090 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 8091 | } catch (RemoteException e) { |
| 8092 | // Ignore if process has died. |
| 8093 | } |
| 8094 | } |
| 8095 | } |
| 8096 | } break; |
| 8097 | |
| 8098 | case REPORT_LOSING_FOCUS: { |
| 8099 | ArrayList<WindowState> losers; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8100 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8101 | synchronized(mWindowMap) { |
| 8102 | losers = mLosingFocus; |
| 8103 | mLosingFocus = new ArrayList<WindowState>(); |
| 8104 | } |
| 8105 | |
| 8106 | final int N = losers.size(); |
| 8107 | for (int i=0; i<N; i++) { |
| 8108 | try { |
| 8109 | //Log.i(TAG, "Losing delayed focus: " + losers.get(i)); |
| 8110 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 8111 | } catch (RemoteException e) { |
| 8112 | // Ignore if process has died. |
| 8113 | } |
| 8114 | } |
| 8115 | } break; |
| 8116 | |
| 8117 | case ANIMATE: { |
| 8118 | synchronized(mWindowMap) { |
| 8119 | mAnimationPending = false; |
| 8120 | performLayoutAndPlaceSurfacesLocked(); |
| 8121 | } |
| 8122 | } break; |
| 8123 | |
| 8124 | case ADD_STARTING: { |
| 8125 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8126 | final StartingData sd = wtoken.startingData; |
| 8127 | |
| 8128 | if (sd == null) { |
| 8129 | // Animation has been canceled... do nothing. |
| 8130 | return; |
| 8131 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8132 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8133 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Add starting " |
| 8134 | + wtoken + ": pkg=" + sd.pkg); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8135 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8136 | View view = null; |
| 8137 | try { |
| 8138 | view = mPolicy.addStartingWindow( |
| 8139 | wtoken.token, sd.pkg, |
| 8140 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 8141 | sd.icon); |
| 8142 | } catch (Exception e) { |
| 8143 | Log.w(TAG, "Exception when adding starting window", e); |
| 8144 | } |
| 8145 | |
| 8146 | if (view != null) { |
| 8147 | boolean abort = false; |
| 8148 | |
| 8149 | synchronized(mWindowMap) { |
| 8150 | if (wtoken.removed || wtoken.startingData == null) { |
| 8151 | // If the window was successfully added, then |
| 8152 | // we need to remove it. |
| 8153 | if (wtoken.startingWindow != null) { |
| 8154 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 8155 | "Aborted starting " + wtoken |
| 8156 | + ": removed=" + wtoken.removed |
| 8157 | + " startingData=" + wtoken.startingData); |
| 8158 | wtoken.startingWindow = null; |
| 8159 | wtoken.startingData = null; |
| 8160 | abort = true; |
| 8161 | } |
| 8162 | } else { |
| 8163 | wtoken.startingView = view; |
| 8164 | } |
| 8165 | if (DEBUG_STARTING_WINDOW && !abort) Log.v(TAG, |
| 8166 | "Added starting " + wtoken |
| 8167 | + ": startingWindow=" |
| 8168 | + wtoken.startingWindow + " startingView=" |
| 8169 | + wtoken.startingView); |
| 8170 | } |
| 8171 | |
| 8172 | if (abort) { |
| 8173 | try { |
| 8174 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 8175 | } catch (Exception e) { |
| 8176 | Log.w(TAG, "Exception when removing starting window", e); |
| 8177 | } |
| 8178 | } |
| 8179 | } |
| 8180 | } break; |
| 8181 | |
| 8182 | case REMOVE_STARTING: { |
| 8183 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8184 | IBinder token = null; |
| 8185 | View view = null; |
| 8186 | synchronized (mWindowMap) { |
| 8187 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Remove starting " |
| 8188 | + wtoken + ": startingWindow=" |
| 8189 | + wtoken.startingWindow + " startingView=" |
| 8190 | + wtoken.startingView); |
| 8191 | if (wtoken.startingWindow != null) { |
| 8192 | view = wtoken.startingView; |
| 8193 | token = wtoken.token; |
| 8194 | wtoken.startingData = null; |
| 8195 | wtoken.startingView = null; |
| 8196 | wtoken.startingWindow = null; |
| 8197 | } |
| 8198 | } |
| 8199 | if (view != null) { |
| 8200 | try { |
| 8201 | mPolicy.removeStartingWindow(token, view); |
| 8202 | } catch (Exception e) { |
| 8203 | Log.w(TAG, "Exception when removing starting window", e); |
| 8204 | } |
| 8205 | } |
| 8206 | } break; |
| 8207 | |
| 8208 | case FINISHED_STARTING: { |
| 8209 | IBinder token = null; |
| 8210 | View view = null; |
| 8211 | while (true) { |
| 8212 | synchronized (mWindowMap) { |
| 8213 | final int N = mFinishedStarting.size(); |
| 8214 | if (N <= 0) { |
| 8215 | break; |
| 8216 | } |
| 8217 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 8218 | |
| 8219 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 8220 | "Finished starting " + wtoken |
| 8221 | + ": startingWindow=" + wtoken.startingWindow |
| 8222 | + " startingView=" + wtoken.startingView); |
| 8223 | |
| 8224 | if (wtoken.startingWindow == null) { |
| 8225 | continue; |
| 8226 | } |
| 8227 | |
| 8228 | view = wtoken.startingView; |
| 8229 | token = wtoken.token; |
| 8230 | wtoken.startingData = null; |
| 8231 | wtoken.startingView = null; |
| 8232 | wtoken.startingWindow = null; |
| 8233 | } |
| 8234 | |
| 8235 | try { |
| 8236 | mPolicy.removeStartingWindow(token, view); |
| 8237 | } catch (Exception e) { |
| 8238 | Log.w(TAG, "Exception when removing starting window", e); |
| 8239 | } |
| 8240 | } |
| 8241 | } break; |
| 8242 | |
| 8243 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 8244 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8245 | |
| 8246 | boolean nowVisible = msg.arg1 != 0; |
| 8247 | boolean nowGone = msg.arg2 != 0; |
| 8248 | |
| 8249 | try { |
| 8250 | if (DEBUG_VISIBILITY) Log.v( |
| 8251 | TAG, "Reporting visible in " + wtoken |
| 8252 | + " visible=" + nowVisible |
| 8253 | + " gone=" + nowGone); |
| 8254 | if (nowVisible) { |
| 8255 | wtoken.appToken.windowsVisible(); |
| 8256 | } else { |
| 8257 | wtoken.appToken.windowsGone(); |
| 8258 | } |
| 8259 | } catch (RemoteException ex) { |
| 8260 | } |
| 8261 | } break; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8262 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8263 | case WINDOW_FREEZE_TIMEOUT: { |
| 8264 | synchronized (mWindowMap) { |
| 8265 | Log.w(TAG, "Window freeze timeout expired."); |
| 8266 | int i = mWindows.size(); |
| 8267 | while (i > 0) { |
| 8268 | i--; |
| 8269 | WindowState w = (WindowState)mWindows.get(i); |
| 8270 | if (w.mOrientationChanging) { |
| 8271 | w.mOrientationChanging = false; |
| 8272 | Log.w(TAG, "Force clearing orientation change: " + w); |
| 8273 | } |
| 8274 | } |
| 8275 | performLayoutAndPlaceSurfacesLocked(); |
| 8276 | } |
| 8277 | break; |
| 8278 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8279 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8280 | case HOLD_SCREEN_CHANGED: { |
| 8281 | Session oldHold; |
| 8282 | Session newHold; |
| 8283 | synchronized (mWindowMap) { |
| 8284 | oldHold = mLastReportedHold; |
| 8285 | newHold = (Session)msg.obj; |
| 8286 | mLastReportedHold = newHold; |
| 8287 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8288 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8289 | if (oldHold != newHold) { |
| 8290 | try { |
| 8291 | if (oldHold != null) { |
| 8292 | mBatteryStats.noteStopWakelock(oldHold.mUid, |
| 8293 | "window", |
| 8294 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8295 | } |
| 8296 | if (newHold != null) { |
| 8297 | mBatteryStats.noteStartWakelock(newHold.mUid, |
| 8298 | "window", |
| 8299 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8300 | } |
| 8301 | } catch (RemoteException e) { |
| 8302 | } |
| 8303 | } |
| 8304 | break; |
| 8305 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8306 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8307 | case APP_TRANSITION_TIMEOUT: { |
| 8308 | synchronized (mWindowMap) { |
| 8309 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) { |
| 8310 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 8311 | "*** APP TRANSITION TIMEOUT"); |
| 8312 | mAppTransitionReady = true; |
| 8313 | mAppTransitionTimeout = true; |
| 8314 | performLayoutAndPlaceSurfacesLocked(); |
| 8315 | } |
| 8316 | } |
| 8317 | break; |
| 8318 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8319 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8320 | case PERSIST_ANIMATION_SCALE: { |
| 8321 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8322 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 8323 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8324 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 8325 | break; |
| 8326 | } |
| 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 | case FORCE_GC: { |
| 8329 | synchronized(mWindowMap) { |
| 8330 | if (mAnimationPending) { |
| 8331 | // If we are animating, don't do the gc now but |
| 8332 | // delay a bit so we don't interrupt the animation. |
| 8333 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 8334 | 2000); |
| 8335 | return; |
| 8336 | } |
| 8337 | // If we are currently rotating the display, it will |
| 8338 | // schedule a new message when done. |
| 8339 | if (mDisplayFrozen) { |
| 8340 | return; |
| 8341 | } |
| 8342 | mFreezeGcPending = 0; |
| 8343 | } |
| 8344 | Runtime.getRuntime().gc(); |
| 8345 | break; |
| 8346 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8347 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8348 | case ENABLE_SCREEN: { |
| 8349 | performEnableScreen(); |
| 8350 | break; |
| 8351 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8352 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8353 | case APP_FREEZE_TIMEOUT: { |
| 8354 | synchronized (mWindowMap) { |
| 8355 | Log.w(TAG, "App freeze timeout expired."); |
| 8356 | int i = mAppTokens.size(); |
| 8357 | while (i > 0) { |
| 8358 | i--; |
| 8359 | AppWindowToken tok = mAppTokens.get(i); |
| 8360 | if (tok.freezingScreen) { |
| 8361 | Log.w(TAG, "Force clearing freeze: " + tok); |
| 8362 | unsetAppFreezingScreenLocked(tok, true, true); |
| 8363 | } |
| 8364 | } |
| 8365 | } |
| 8366 | break; |
| 8367 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8368 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8369 | case COMPUTE_AND_SEND_NEW_CONFIGURATION: { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 8370 | if (updateOrientationFromAppTokensUnchecked(null, null) != null) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8371 | sendNewConfiguration(); |
| 8372 | } |
| 8373 | break; |
| 8374 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8375 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8376 | } |
| 8377 | } |
| 8378 | } |
| 8379 | |
| 8380 | // ------------------------------------------------------------- |
| 8381 | // IWindowManager API |
| 8382 | // ------------------------------------------------------------- |
| 8383 | |
| 8384 | public IWindowSession openSession(IInputMethodClient client, |
| 8385 | IInputContext inputContext) { |
| 8386 | if (client == null) throw new IllegalArgumentException("null client"); |
| 8387 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
| 8388 | return new Session(client, inputContext); |
| 8389 | } |
| 8390 | |
| 8391 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 8392 | synchronized (mWindowMap) { |
| 8393 | // The focus for the client is the window immediately below |
| 8394 | // where we would place the input method window. |
| 8395 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 8396 | WindowState imFocus; |
| 8397 | if (idx > 0) { |
| 8398 | imFocus = (WindowState)mWindows.get(idx-1); |
| 8399 | if (imFocus != null) { |
| 8400 | if (imFocus.mSession.mClient != null && |
| 8401 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 8402 | return true; |
| 8403 | } |
| 8404 | } |
| 8405 | } |
| 8406 | } |
| 8407 | return false; |
| 8408 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8409 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8410 | // ------------------------------------------------------------- |
| 8411 | // Internals |
| 8412 | // ------------------------------------------------------------- |
| 8413 | |
| 8414 | final WindowState windowForClientLocked(Session session, IWindow client) { |
| 8415 | return windowForClientLocked(session, client.asBinder()); |
| 8416 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8417 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8418 | final WindowState windowForClientLocked(Session session, IBinder client) { |
| 8419 | WindowState win = mWindowMap.get(client); |
| 8420 | if (localLOGV) Log.v( |
| 8421 | TAG, "Looking up client " + client + ": " + win); |
| 8422 | if (win == null) { |
| 8423 | RuntimeException ex = new RuntimeException(); |
| 8424 | Log.w(TAG, "Requested window " + client + " does not exist", ex); |
| 8425 | return null; |
| 8426 | } |
| 8427 | if (session != null && win.mSession != session) { |
| 8428 | RuntimeException ex = new RuntimeException(); |
| 8429 | Log.w(TAG, "Requested window " + client + " is in session " + |
| 8430 | win.mSession + ", not " + session, ex); |
| 8431 | return null; |
| 8432 | } |
| 8433 | |
| 8434 | return win; |
| 8435 | } |
| 8436 | |
| 8437 | private final void assignLayersLocked() { |
| 8438 | int N = mWindows.size(); |
| 8439 | int curBaseLayer = 0; |
| 8440 | int curLayer = 0; |
| 8441 | int i; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8442 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8443 | for (i=0; i<N; i++) { |
| 8444 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8445 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 8446 | || (i > 0 && w.mIsWallpaper)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8447 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 8448 | w.mLayer = curLayer; |
| 8449 | } else { |
| 8450 | curBaseLayer = curLayer = w.mBaseLayer; |
| 8451 | w.mLayer = curLayer; |
| 8452 | } |
| 8453 | if (w.mTargetAppToken != null) { |
| 8454 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 8455 | } else if (w.mAppToken != null) { |
| 8456 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 8457 | } else { |
| 8458 | w.mAnimLayer = w.mLayer; |
| 8459 | } |
| 8460 | if (w.mIsImWindow) { |
| 8461 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8462 | } else if (w.mIsWallpaper) { |
| 8463 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8464 | } |
| 8465 | if (DEBUG_LAYERS) Log.v(TAG, "Assign layer " + w + ": " |
| 8466 | + w.mAnimLayer); |
| 8467 | //System.out.println( |
| 8468 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 8469 | } |
| 8470 | } |
| 8471 | |
| 8472 | private boolean mInLayout = false; |
| 8473 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 8474 | if (mInLayout) { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 8475 | if (DEBUG) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8476 | throw new RuntimeException("Recursive call!"); |
| 8477 | } |
| 8478 | Log.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
| 8479 | return; |
| 8480 | } |
| 8481 | |
| 8482 | boolean recoveringMemory = false; |
| 8483 | if (mForceRemoves != null) { |
| 8484 | recoveringMemory = true; |
| 8485 | // Wait a little it for things to settle down, and off we go. |
| 8486 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 8487 | WindowState ws = mForceRemoves.get(i); |
| 8488 | Log.i(TAG, "Force removing: " + ws); |
| 8489 | removeWindowInnerLocked(ws.mSession, ws); |
| 8490 | } |
| 8491 | mForceRemoves = null; |
| 8492 | Log.w(TAG, "Due to memory failure, waiting a bit for next layout"); |
| 8493 | Object tmp = new Object(); |
| 8494 | synchronized (tmp) { |
| 8495 | try { |
| 8496 | tmp.wait(250); |
| 8497 | } catch (InterruptedException e) { |
| 8498 | } |
| 8499 | } |
| 8500 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8501 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8502 | mInLayout = true; |
| 8503 | try { |
| 8504 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8505 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8506 | int i = mPendingRemove.size()-1; |
| 8507 | if (i >= 0) { |
| 8508 | while (i >= 0) { |
| 8509 | WindowState w = mPendingRemove.get(i); |
| 8510 | removeWindowInnerLocked(w.mSession, w); |
| 8511 | i--; |
| 8512 | } |
| 8513 | mPendingRemove.clear(); |
| 8514 | |
| 8515 | mInLayout = false; |
| 8516 | assignLayersLocked(); |
| 8517 | mLayoutNeeded = true; |
| 8518 | performLayoutAndPlaceSurfacesLocked(); |
| 8519 | |
| 8520 | } else { |
| 8521 | mInLayout = false; |
| 8522 | if (mLayoutNeeded) { |
| 8523 | requestAnimationLocked(0); |
| 8524 | } |
| 8525 | } |
| 8526 | } catch (RuntimeException e) { |
| 8527 | mInLayout = false; |
| 8528 | Log.e(TAG, "Unhandled exception while layout out windows", e); |
| 8529 | } |
| 8530 | } |
| 8531 | |
| 8532 | private final void performLayoutLockedInner() { |
| 8533 | final int dw = mDisplay.getWidth(); |
| 8534 | final int dh = mDisplay.getHeight(); |
| 8535 | |
| 8536 | final int N = mWindows.size(); |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 8537 | int repeats = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8538 | int i; |
| 8539 | |
| 8540 | // FIRST LOOP: Perform a layout, if needed. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8541 | |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 8542 | while (mLayoutNeeded) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8543 | mPolicy.beginLayoutLw(dw, dh); |
| 8544 | |
| 8545 | // First perform layout of any root windows (not attached |
| 8546 | // to another window). |
| 8547 | int topAttached = -1; |
| 8548 | for (i = N-1; i >= 0; i--) { |
| 8549 | WindowState win = (WindowState) mWindows.get(i); |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 8550 | |
| 8551 | // Don't do layout of a window if it is not visible, or |
| 8552 | // soon won't be visible, to avoid wasting time and funky |
| 8553 | // changes while a window is animating away. |
| 8554 | final AppWindowToken atoken = win.mAppToken; |
| 8555 | final boolean gone = win.mViewVisibility == View.GONE |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8556 | || !win.mRelayoutCalled |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 8557 | || win.mRootToken.hidden |
| 8558 | || (atoken != null && atoken.hiddenRequested) |
| 8559 | || !win.mPolicyVisibility |
| 8560 | || win.mAttachedHidden |
| 8561 | || win.mExiting || win.mDestroying; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8562 | |
| 8563 | // If this view is GONE, then skip it -- keep the current |
| 8564 | // frame, and let the caller know so they can ignore it |
| 8565 | // if they want. (We do the normal layout for INVISIBLE |
| 8566 | // windows, since that means "perform layout as normal, |
| 8567 | // just don't display"). |
| 8568 | if (!gone || !win.mHaveFrame) { |
| 8569 | if (!win.mLayoutAttached) { |
| 8570 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 8571 | } else { |
| 8572 | if (topAttached < 0) topAttached = i; |
| 8573 | } |
| 8574 | } |
| 8575 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8576 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8577 | // Now perform layout of attached windows, which usually |
| 8578 | // depend on the position of the window they are attached to. |
| 8579 | // XXX does not deal with windows that are attached to windows |
| 8580 | // that are themselves attached. |
| 8581 | for (i = topAttached; i >= 0; i--) { |
| 8582 | WindowState win = (WindowState) mWindows.get(i); |
| 8583 | |
| 8584 | // If this view is GONE, then skip it -- keep the current |
| 8585 | // frame, and let the caller know so they can ignore it |
| 8586 | // if they want. (We do the normal layout for INVISIBLE |
| 8587 | // windows, since that means "perform layout as normal, |
| 8588 | // just don't display"). |
| 8589 | if (win.mLayoutAttached) { |
| 8590 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 8591 | || !win.mHaveFrame) { |
| 8592 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 8593 | } |
| 8594 | } |
| 8595 | } |
| 8596 | |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 8597 | if (!mPolicy.finishLayoutLw()) { |
| 8598 | mLayoutNeeded = false; |
| 8599 | } else if (repeats > 2) { |
| 8600 | Log.w(TAG, "Layout repeat aborted after too many iterations"); |
| 8601 | mLayoutNeeded = false; |
| 8602 | } else { |
| 8603 | repeats++; |
| 8604 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8605 | } |
| 8606 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8607 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8608 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 8609 | boolean recoveringMemory) { |
| 8610 | final long currentTime = SystemClock.uptimeMillis(); |
| 8611 | final int dw = mDisplay.getWidth(); |
| 8612 | final int dh = mDisplay.getHeight(); |
| 8613 | |
| 8614 | final int N = mWindows.size(); |
| 8615 | int i; |
| 8616 | |
| 8617 | // FIRST LOOP: Perform a layout, if needed. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8618 | performLayoutLockedInner(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8619 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8620 | if (mFxSession == null) { |
| 8621 | mFxSession = new SurfaceSession(); |
| 8622 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8623 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8624 | if (SHOW_TRANSACTIONS) Log.i(TAG, ">>> OPEN TRANSACTION"); |
| 8625 | |
| 8626 | // Initialize state of exiting tokens. |
| 8627 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 8628 | mExitingTokens.get(i).hasVisible = false; |
| 8629 | } |
| 8630 | |
| 8631 | // Initialize state of exiting applications. |
| 8632 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 8633 | mExitingAppTokens.get(i).hasVisible = false; |
| 8634 | } |
| 8635 | |
| 8636 | // SECOND LOOP: Execute animations and update visibility of windows. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8637 | boolean orientationChangeComplete = true; |
| 8638 | Session holdScreen = null; |
| 8639 | float screenBrightness = -1; |
| 8640 | boolean focusDisplayed = false; |
| 8641 | boolean animating = false; |
| 8642 | |
| 8643 | Surface.openTransaction(); |
| 8644 | try { |
| 8645 | boolean restart; |
| 8646 | |
| 8647 | do { |
| 8648 | final int transactionSequence = ++mTransactionSequence; |
| 8649 | |
| 8650 | // Update animations of all applications, including those |
| 8651 | // associated with exiting/removed apps |
| 8652 | boolean tokensAnimating = false; |
| 8653 | final int NAT = mAppTokens.size(); |
| 8654 | for (i=0; i<NAT; i++) { |
| 8655 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 8656 | tokensAnimating = true; |
| 8657 | } |
| 8658 | } |
| 8659 | final int NEAT = mExitingAppTokens.size(); |
| 8660 | for (i=0; i<NEAT; i++) { |
| 8661 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 8662 | tokensAnimating = true; |
| 8663 | } |
| 8664 | } |
| 8665 | |
| 8666 | animating = tokensAnimating; |
| 8667 | restart = false; |
| 8668 | |
| 8669 | boolean tokenMayBeDrawn = false; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8670 | boolean wallpaperMayChange = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8671 | |
| 8672 | mPolicy.beginAnimationLw(dw, dh); |
| 8673 | |
| 8674 | for (i=N-1; i>=0; i--) { |
| 8675 | WindowState w = (WindowState)mWindows.get(i); |
| 8676 | |
| 8677 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 8678 | |
| 8679 | if (w.mSurface != null) { |
| 8680 | // Execute animation. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8681 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 8682 | if ((w.mAttrs.flags |
| 8683 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 8684 | wallpaperMayChange = true; |
| 8685 | } |
| 8686 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8687 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 8688 | animating = true; |
| 8689 | //w.dump(" "); |
| 8690 | } |
| 8691 | |
| 8692 | mPolicy.animatingWindowLw(w, attrs); |
| 8693 | } |
| 8694 | |
| 8695 | final AppWindowToken atoken = w.mAppToken; |
| 8696 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 8697 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 8698 | atoken.lastTransactionSequence = transactionSequence; |
| 8699 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 8700 | atoken.startingDisplayed = false; |
| 8701 | } |
| 8702 | if ((w.isOnScreen() || w.mAttrs.type |
| 8703 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 8704 | && !w.mExiting && !w.mDestroying) { |
| 8705 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
| 8706 | Log.v(TAG, "Eval win " + w + ": isDisplayed=" |
| 8707 | + w.isDisplayedLw() |
| 8708 | + ", isAnimating=" + w.isAnimating()); |
| 8709 | if (!w.isDisplayedLw()) { |
| 8710 | Log.v(TAG, "Not displayed: s=" + w.mSurface |
| 8711 | + " pv=" + w.mPolicyVisibility |
| 8712 | + " dp=" + w.mDrawPending |
| 8713 | + " cdp=" + w.mCommitDrawPending |
| 8714 | + " ah=" + w.mAttachedHidden |
| 8715 | + " th=" + atoken.hiddenRequested |
| 8716 | + " a=" + w.mAnimating); |
| 8717 | } |
| 8718 | } |
| 8719 | if (w != atoken.startingWindow) { |
| 8720 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 8721 | atoken.numInterestingWindows++; |
| 8722 | if (w.isDisplayedLw()) { |
| 8723 | atoken.numDrawnWindows++; |
| 8724 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Log.v(TAG, |
| 8725 | "tokenMayBeDrawn: " + atoken |
| 8726 | + " freezingScreen=" + atoken.freezingScreen |
| 8727 | + " mAppFreezing=" + w.mAppFreezing); |
| 8728 | tokenMayBeDrawn = true; |
| 8729 | } |
| 8730 | } |
| 8731 | } else if (w.isDisplayedLw()) { |
| 8732 | atoken.startingDisplayed = true; |
| 8733 | } |
| 8734 | } |
| 8735 | } else if (w.mReadyToShow) { |
| 8736 | w.performShowLocked(); |
| 8737 | } |
| 8738 | } |
| 8739 | |
| 8740 | if (mPolicy.finishAnimationLw()) { |
| 8741 | restart = true; |
| 8742 | } |
| 8743 | |
| 8744 | if (tokenMayBeDrawn) { |
| 8745 | // See if any windows have been drawn, so they (and others |
| 8746 | // associated with them) can now be shown. |
| 8747 | final int NT = mTokenList.size(); |
| 8748 | for (i=0; i<NT; i++) { |
| 8749 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 8750 | if (wtoken == null) { |
| 8751 | continue; |
| 8752 | } |
| 8753 | if (wtoken.freezingScreen) { |
| 8754 | int numInteresting = wtoken.numInterestingWindows; |
| 8755 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| 8756 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 8757 | "allDrawn: " + wtoken |
| 8758 | + " interesting=" + numInteresting |
| 8759 | + " drawn=" + wtoken.numDrawnWindows); |
| 8760 | wtoken.showAllWindowsLocked(); |
| 8761 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 8762 | orientationChangeComplete = true; |
| 8763 | } |
| 8764 | } else if (!wtoken.allDrawn) { |
| 8765 | int numInteresting = wtoken.numInterestingWindows; |
| 8766 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| 8767 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 8768 | "allDrawn: " + wtoken |
| 8769 | + " interesting=" + numInteresting |
| 8770 | + " drawn=" + wtoken.numDrawnWindows); |
| 8771 | wtoken.allDrawn = true; |
| 8772 | restart = true; |
| 8773 | |
| 8774 | // We can now show all of the drawn windows! |
| 8775 | if (!mOpeningApps.contains(wtoken)) { |
| 8776 | wtoken.showAllWindowsLocked(); |
| 8777 | } |
| 8778 | } |
| 8779 | } |
| 8780 | } |
| 8781 | } |
| 8782 | |
| 8783 | // If we are ready to perform an app transition, check through |
| 8784 | // all of the app tokens to be shown and see if they are ready |
| 8785 | // to go. |
| 8786 | if (mAppTransitionReady) { |
| 8787 | int NN = mOpeningApps.size(); |
| 8788 | boolean goodToGo = true; |
| 8789 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 8790 | "Checking " + NN + " opening apps (frozen=" |
| 8791 | + mDisplayFrozen + " timeout=" |
| 8792 | + mAppTransitionTimeout + ")..."); |
| 8793 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 8794 | // If the display isn't frozen, wait to do anything until |
| 8795 | // all of the apps are ready. Otherwise just go because |
| 8796 | // we'll unfreeze the display when everyone is ready. |
| 8797 | for (i=0; i<NN && goodToGo; i++) { |
| 8798 | AppWindowToken wtoken = mOpeningApps.get(i); |
| 8799 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 8800 | "Check opening app" + wtoken + ": allDrawn=" |
| 8801 | + wtoken.allDrawn + " startingDisplayed=" |
| 8802 | + wtoken.startingDisplayed); |
| 8803 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 8804 | && !wtoken.startingMoved) { |
| 8805 | goodToGo = false; |
| 8806 | } |
| 8807 | } |
| 8808 | } |
| 8809 | if (goodToGo) { |
| 8810 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "**** GOOD TO GO"); |
| 8811 | int transit = mNextAppTransition; |
| 8812 | if (mSkipAppTransitionAnimation) { |
| 8813 | transit = WindowManagerPolicy.TRANSIT_NONE; |
| 8814 | } |
| 8815 | mNextAppTransition = WindowManagerPolicy.TRANSIT_NONE; |
| 8816 | mAppTransitionReady = false; |
| 8817 | mAppTransitionTimeout = false; |
| 8818 | mStartingIconInTransition = false; |
| 8819 | mSkipAppTransitionAnimation = false; |
| 8820 | |
| 8821 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 8822 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8823 | adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8824 | wallpaperMayChange = false; |
| 8825 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 8826 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8827 | "New wallpaper target=" + mWallpaperTarget |
| 8828 | + ", lower target=" + mLowerWallpaperTarget |
| 8829 | + ", upper target=" + mUpperWallpaperTarget); |
| 8830 | if (mLowerWallpaperTarget != null) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 8831 | // Need to determine if both the closing and |
| 8832 | // opening app token sets are wallpaper targets, |
| 8833 | // in which case special animations are needed |
| 8834 | // (since the wallpaper needs to stay static |
| 8835 | // behind them). |
| 8836 | int found = 0; |
| 8837 | NN = mOpeningApps.size(); |
| 8838 | for (i=0; i<NN; i++) { |
| 8839 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8840 | if (mLowerWallpaperTarget.mAppToken == wtoken) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 8841 | found |= 1; |
| 8842 | } |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8843 | if (mUpperWallpaperTarget.mAppToken == wtoken) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 8844 | found |= 1; |
| 8845 | } |
| 8846 | } |
| 8847 | NN = mClosingApps.size(); |
| 8848 | for (i=0; i<NN; i++) { |
| 8849 | AppWindowToken wtoken = mClosingApps.get(i); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8850 | if (mLowerWallpaperTarget.mAppToken == wtoken) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 8851 | found |= 2; |
| 8852 | } |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8853 | if (mUpperWallpaperTarget.mAppToken == wtoken) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 8854 | found |= 2; |
| 8855 | } |
| 8856 | } |
| 8857 | |
| 8858 | if (found == 3) { |
| 8859 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 8860 | "Wallpaper animation!"); |
| 8861 | switch (transit) { |
| 8862 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 8863 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 8864 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 8865 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_ACTIVITY_OPEN; |
| 8866 | break; |
| 8867 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 8868 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 8869 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 8870 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_ACTIVITY_CLOSE; |
| 8871 | break; |
| 8872 | } |
| 8873 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 8874 | "New transit: " + transit); |
| 8875 | } |
| 8876 | } |
| 8877 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8878 | // We need to figure out which animation to use... |
| 8879 | WindowManager.LayoutParams lp = findAnimations(mAppTokens, |
| 8880 | mOpeningApps, mClosingApps); |
| 8881 | |
| 8882 | NN = mOpeningApps.size(); |
| 8883 | for (i=0; i<NN; i++) { |
| 8884 | AppWindowToken wtoken = mOpeningApps.get(i); |
| 8885 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 8886 | "Now opening app" + wtoken); |
| 8887 | wtoken.reportedVisible = false; |
| 8888 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 8889 | wtoken.animation = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8890 | setTokenVisibilityLocked(wtoken, lp, true, transit, false); |
| 8891 | wtoken.updateReportedVisibilityLocked(); |
| 8892 | wtoken.showAllWindowsLocked(); |
| 8893 | } |
| 8894 | NN = mClosingApps.size(); |
| 8895 | for (i=0; i<NN; i++) { |
| 8896 | AppWindowToken wtoken = mClosingApps.get(i); |
| 8897 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 8898 | "Now closing app" + wtoken); |
| 8899 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 8900 | wtoken.animation = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8901 | setTokenVisibilityLocked(wtoken, lp, false, transit, false); |
| 8902 | wtoken.updateReportedVisibilityLocked(); |
| 8903 | // Force the allDrawn flag, because we want to start |
| 8904 | // this guy's animations regardless of whether it's |
| 8905 | // gotten drawn. |
| 8906 | wtoken.allDrawn = true; |
| 8907 | } |
| 8908 | |
| 8909 | mOpeningApps.clear(); |
| 8910 | mClosingApps.clear(); |
| 8911 | |
| 8912 | // This has changed the visibility of windows, so perform |
| 8913 | // a new layout to get them all up-to-date. |
| 8914 | mLayoutNeeded = true; |
| Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 8915 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 8916 | assignLayersLocked(); |
| 8917 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8918 | performLayoutLockedInner(); |
| 8919 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
| 8920 | |
| 8921 | restart = true; |
| 8922 | } |
| 8923 | } |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8924 | |
| 8925 | if (wallpaperMayChange) { |
| 8926 | if (adjustWallpaperWindowsLocked()) { |
| 8927 | assignLayersLocked(); |
| 8928 | } |
| 8929 | } |
| 8930 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8931 | } while (restart); |
| 8932 | |
| 8933 | // THIRD LOOP: Update the surfaces of all windows. |
| 8934 | |
| 8935 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 8936 | |
| 8937 | boolean obscured = false; |
| 8938 | boolean blurring = false; |
| 8939 | boolean dimming = false; |
| 8940 | boolean covered = false; |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 8941 | boolean syswin = false; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8942 | boolean backgroundFillerShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8943 | |
| 8944 | for (i=N-1; i>=0; i--) { |
| 8945 | WindowState w = (WindowState)mWindows.get(i); |
| 8946 | |
| 8947 | boolean displayed = false; |
| 8948 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 8949 | final int attrFlags = attrs.flags; |
| 8950 | |
| 8951 | if (w.mSurface != null) { |
| 8952 | w.computeShownFrameLocked(); |
| 8953 | if (localLOGV) Log.v( |
| 8954 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 8955 | + ": new=" + w.mShownFrame + ", old=" |
| 8956 | + w.mLastShownFrame); |
| 8957 | |
| 8958 | boolean resize; |
| 8959 | int width, height; |
| 8960 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 8961 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 8962 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 8963 | // for a scaled surface, we just want to use |
| 8964 | // the requested size. |
| 8965 | width = w.mRequestedWidth; |
| 8966 | height = w.mRequestedHeight; |
| 8967 | w.mLastRequestedWidth = width; |
| 8968 | w.mLastRequestedHeight = height; |
| 8969 | w.mLastShownFrame.set(w.mShownFrame); |
| 8970 | try { |
| 8971 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 8972 | } catch (RuntimeException e) { |
| 8973 | Log.w(TAG, "Error positioning surface in " + w, e); |
| 8974 | if (!recoveringMemory) { |
| 8975 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 8976 | } |
| 8977 | } |
| 8978 | } else { |
| 8979 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 8980 | width = w.mShownFrame.width(); |
| 8981 | height = w.mShownFrame.height(); |
| 8982 | w.mLastShownFrame.set(w.mShownFrame); |
| 8983 | if (resize) { |
| 8984 | if (SHOW_TRANSACTIONS) Log.i( |
| 8985 | TAG, " SURFACE " + w.mSurface + ": (" |
| 8986 | + w.mShownFrame.left + "," |
| 8987 | + w.mShownFrame.top + ") (" |
| 8988 | + w.mShownFrame.width() + "x" |
| 8989 | + w.mShownFrame.height() + ")"); |
| 8990 | } |
| 8991 | } |
| 8992 | |
| 8993 | if (resize) { |
| 8994 | if (width < 1) width = 1; |
| 8995 | if (height < 1) height = 1; |
| 8996 | if (w.mSurface != null) { |
| 8997 | try { |
| 8998 | w.mSurface.setSize(width, height); |
| 8999 | w.mSurface.setPosition(w.mShownFrame.left, |
| 9000 | w.mShownFrame.top); |
| 9001 | } catch (RuntimeException e) { |
| 9002 | // If something goes wrong with the surface (such |
| 9003 | // as running out of memory), don't take down the |
| 9004 | // entire system. |
| 9005 | Log.e(TAG, "Failure updating surface of " + w |
| 9006 | + "size=(" + width + "x" + height |
| 9007 | + "), pos=(" + w.mShownFrame.left |
| 9008 | + "," + w.mShownFrame.top + ")", e); |
| 9009 | if (!recoveringMemory) { |
| 9010 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 9011 | } |
| 9012 | } |
| 9013 | } |
| 9014 | } |
| 9015 | if (!w.mAppFreezing) { |
| 9016 | w.mContentInsetsChanged = |
| 9017 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 9018 | w.mVisibleInsetsChanged = |
| 9019 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9020 | if (!w.mLastFrame.equals(w.mFrame) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9021 | || w.mContentInsetsChanged |
| 9022 | || w.mVisibleInsetsChanged) { |
| 9023 | w.mLastFrame.set(w.mFrame); |
| 9024 | w.mLastContentInsets.set(w.mContentInsets); |
| 9025 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
| 9026 | // If the orientation is changing, then we need to |
| 9027 | // hold off on unfreezing the display until this |
| 9028 | // window has been redrawn; to do that, we need |
| 9029 | // to go through the process of getting informed |
| 9030 | // by the application when it has finished drawing. |
| 9031 | if (w.mOrientationChanging) { |
| 9032 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 9033 | "Orientation start waiting for draw in " |
| 9034 | + w + ", surface " + w.mSurface); |
| 9035 | w.mDrawPending = true; |
| 9036 | w.mCommitDrawPending = false; |
| 9037 | w.mReadyToShow = false; |
| 9038 | if (w.mAppToken != null) { |
| 9039 | w.mAppToken.allDrawn = false; |
| 9040 | } |
| 9041 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9042 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9043 | "Resizing window " + w + " to " + w.mFrame); |
| 9044 | mResizingWindows.add(w); |
| 9045 | } else if (w.mOrientationChanging) { |
| 9046 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
| 9047 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 9048 | "Orientation not waiting for draw in " |
| 9049 | + w + ", surface " + w.mSurface); |
| 9050 | w.mOrientationChanging = false; |
| 9051 | } |
| 9052 | } |
| 9053 | } |
| 9054 | |
| 9055 | if (w.mAttachedHidden) { |
| 9056 | if (!w.mLastHidden) { |
| 9057 | //dump(); |
| 9058 | w.mLastHidden = true; |
| 9059 | if (SHOW_TRANSACTIONS) Log.i( |
| 9060 | TAG, " SURFACE " + w.mSurface + ": HIDE (performLayout-attached)"); |
| 9061 | if (w.mSurface != null) { |
| 9062 | try { |
| 9063 | w.mSurface.hide(); |
| 9064 | } catch (RuntimeException e) { |
| 9065 | Log.w(TAG, "Exception hiding surface in " + w); |
| 9066 | } |
| 9067 | } |
| 9068 | mKeyWaiter.releasePendingPointerLocked(w.mSession); |
| 9069 | } |
| 9070 | // If we are waiting for this window to handle an |
| 9071 | // orientation change, well, it is hidden, so |
| 9072 | // doesn't really matter. Note that this does |
| 9073 | // introduce a potential glitch if the window |
| 9074 | // becomes unhidden before it has drawn for the |
| 9075 | // new orientation. |
| 9076 | if (w.mOrientationChanging) { |
| 9077 | w.mOrientationChanging = false; |
| 9078 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 9079 | "Orientation change skips hidden " + w); |
| 9080 | } |
| 9081 | } else if (!w.isReadyForDisplay()) { |
| 9082 | if (!w.mLastHidden) { |
| 9083 | //dump(); |
| 9084 | w.mLastHidden = true; |
| 9085 | if (SHOW_TRANSACTIONS) Log.i( |
| 9086 | TAG, " SURFACE " + w.mSurface + ": HIDE (performLayout-ready)"); |
| 9087 | if (w.mSurface != null) { |
| 9088 | try { |
| 9089 | w.mSurface.hide(); |
| 9090 | } catch (RuntimeException e) { |
| 9091 | Log.w(TAG, "Exception exception hiding surface in " + w); |
| 9092 | } |
| 9093 | } |
| 9094 | mKeyWaiter.releasePendingPointerLocked(w.mSession); |
| 9095 | } |
| 9096 | // If we are waiting for this window to handle an |
| 9097 | // orientation change, well, it is hidden, so |
| 9098 | // doesn't really matter. Note that this does |
| 9099 | // introduce a potential glitch if the window |
| 9100 | // becomes unhidden before it has drawn for the |
| 9101 | // new orientation. |
| 9102 | if (w.mOrientationChanging) { |
| 9103 | w.mOrientationChanging = false; |
| 9104 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 9105 | "Orientation change skips hidden " + w); |
| 9106 | } |
| 9107 | } else if (w.mLastLayer != w.mAnimLayer |
| 9108 | || w.mLastAlpha != w.mShownAlpha |
| 9109 | || w.mLastDsDx != w.mDsDx |
| 9110 | || w.mLastDtDx != w.mDtDx |
| 9111 | || w.mLastDsDy != w.mDsDy |
| 9112 | || w.mLastDtDy != w.mDtDy |
| 9113 | || w.mLastHScale != w.mHScale |
| 9114 | || w.mLastVScale != w.mVScale |
| 9115 | || w.mLastHidden) { |
| 9116 | displayed = true; |
| 9117 | w.mLastAlpha = w.mShownAlpha; |
| 9118 | w.mLastLayer = w.mAnimLayer; |
| 9119 | w.mLastDsDx = w.mDsDx; |
| 9120 | w.mLastDtDx = w.mDtDx; |
| 9121 | w.mLastDsDy = w.mDsDy; |
| 9122 | w.mLastDtDy = w.mDtDy; |
| 9123 | w.mLastHScale = w.mHScale; |
| 9124 | w.mLastVScale = w.mVScale; |
| 9125 | if (SHOW_TRANSACTIONS) Log.i( |
| 9126 | TAG, " SURFACE " + w.mSurface + ": alpha=" |
| 9127 | + w.mShownAlpha + " layer=" + w.mAnimLayer); |
| 9128 | if (w.mSurface != null) { |
| 9129 | try { |
| 9130 | w.mSurface.setAlpha(w.mShownAlpha); |
| 9131 | w.mSurface.setLayer(w.mAnimLayer); |
| 9132 | w.mSurface.setMatrix( |
| 9133 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 9134 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 9135 | } catch (RuntimeException e) { |
| 9136 | Log.w(TAG, "Error updating surface in " + w, e); |
| 9137 | if (!recoveringMemory) { |
| 9138 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 9139 | } |
| 9140 | } |
| 9141 | } |
| 9142 | |
| 9143 | if (w.mLastHidden && !w.mDrawPending |
| 9144 | && !w.mCommitDrawPending |
| 9145 | && !w.mReadyToShow) { |
| 9146 | if (SHOW_TRANSACTIONS) Log.i( |
| 9147 | TAG, " SURFACE " + w.mSurface + ": SHOW (performLayout)"); |
| 9148 | if (DEBUG_VISIBILITY) Log.v(TAG, "Showing " + w |
| 9149 | + " during relayout"); |
| 9150 | if (showSurfaceRobustlyLocked(w)) { |
| 9151 | w.mHasDrawn = true; |
| 9152 | w.mLastHidden = false; |
| 9153 | } else { |
| 9154 | w.mOrientationChanging = false; |
| 9155 | } |
| 9156 | } |
| 9157 | if (w.mSurface != null) { |
| 9158 | w.mToken.hasVisible = true; |
| 9159 | } |
| 9160 | } else { |
| 9161 | displayed = true; |
| 9162 | } |
| 9163 | |
| 9164 | if (displayed) { |
| 9165 | if (!covered) { |
| 9166 | if (attrs.width == LayoutParams.FILL_PARENT |
| 9167 | && attrs.height == LayoutParams.FILL_PARENT) { |
| 9168 | covered = true; |
| 9169 | } |
| 9170 | } |
| 9171 | if (w.mOrientationChanging) { |
| 9172 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 9173 | orientationChangeComplete = false; |
| 9174 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 9175 | "Orientation continue waiting for draw in " + w); |
| 9176 | } else { |
| 9177 | w.mOrientationChanging = false; |
| 9178 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 9179 | "Orientation change complete in " + w); |
| 9180 | } |
| 9181 | } |
| 9182 | w.mToken.hasVisible = true; |
| 9183 | } |
| 9184 | } else if (w.mOrientationChanging) { |
| 9185 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 9186 | "Orientation change skips hidden " + w); |
| 9187 | w.mOrientationChanging = false; |
| 9188 | } |
| 9189 | |
| 9190 | final boolean canBeSeen = w.isDisplayedLw(); |
| 9191 | |
| 9192 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 9193 | focusDisplayed = true; |
| 9194 | } |
| 9195 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 9196 | final boolean obscuredChanged = w.mObscured != obscured; |
| 9197 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9198 | // Update effect. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9199 | if (!(w.mObscured=obscured)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9200 | if (w.mSurface != null) { |
| 9201 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 9202 | holdScreen = w.mSession; |
| 9203 | } |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9204 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 9205 | && screenBrightness < 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9206 | screenBrightness = w.mAttrs.screenBrightness; |
| 9207 | } |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9208 | if (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 9209 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 9210 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR) { |
| 9211 | syswin = true; |
| 9212 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9213 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9214 | |
| 9215 | boolean opaqueDrawn = w.isOpaqueDrawn(); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 9216 | if ((opaqueDrawn && w.isFullscreen(dw, dh)) |
| 9217 | || attrs.type == TYPE_WALLPAPER) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9218 | // This window completely covers everything behind it, |
| 9219 | // so we want to leave all of them as unblurred (for |
| 9220 | // performance reasons). |
| 9221 | obscured = true; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9222 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
| 9223 | if (SHOW_TRANSACTIONS) Log.d(TAG, "showing background filler"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9224 | // This window is in compatibility mode, and needs background filler. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9225 | obscured = true; |
| 9226 | if (mBackgroundFillerSurface == null) { |
| 9227 | try { |
| 9228 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
| 9229 | 0, dw, dh, |
| 9230 | PixelFormat.OPAQUE, |
| 9231 | Surface.FX_SURFACE_NORMAL); |
| 9232 | } catch (Exception e) { |
| 9233 | Log.e(TAG, "Exception creating filler surface", e); |
| 9234 | } |
| 9235 | } |
| 9236 | try { |
| 9237 | mBackgroundFillerSurface.setPosition(0, 0); |
| 9238 | mBackgroundFillerSurface.setSize(dw, dh); |
| 9239 | // Using the same layer as Dim because they will never be shown at the |
| 9240 | // same time. |
| 9241 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 9242 | mBackgroundFillerSurface.show(); |
| 9243 | } catch (RuntimeException e) { |
| 9244 | Log.e(TAG, "Exception showing filler surface"); |
| 9245 | } |
| 9246 | backgroundFillerShown = true; |
| 9247 | mBackgroundFillerShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9248 | } else if (canBeSeen && !obscured && |
| 9249 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
| 9250 | if (localLOGV) Log.v(TAG, "Win " + w |
| 9251 | + ": blurring=" + blurring |
| 9252 | + " obscured=" + obscured |
| 9253 | + " displayed=" + displayed); |
| 9254 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 9255 | if (!dimming) { |
| 9256 | //Log.i(TAG, "DIM BEHIND: " + w); |
| 9257 | dimming = true; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9258 | if (mDimAnimator == null) { |
| 9259 | mDimAnimator = new DimAnimator(mFxSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9260 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9261 | mDimAnimator.show(dw, dh); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9262 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9263 | mDimAnimator.updateParameters(w, currentTime); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9264 | } |
| 9265 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 9266 | if (!blurring) { |
| 9267 | //Log.i(TAG, "BLUR BEHIND: " + w); |
| 9268 | blurring = true; |
| 9269 | mBlurShown = true; |
| 9270 | if (mBlurSurface == null) { |
| 9271 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " |
| 9272 | + mBlurSurface + ": CREATE"); |
| 9273 | try { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9274 | mBlurSurface = new Surface(mFxSession, 0, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9275 | -1, 16, 16, |
| 9276 | PixelFormat.OPAQUE, |
| 9277 | Surface.FX_SURFACE_BLUR); |
| 9278 | } catch (Exception e) { |
| 9279 | Log.e(TAG, "Exception creating Blur surface", e); |
| 9280 | } |
| 9281 | } |
| 9282 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " |
| 9283 | + mBlurSurface + ": SHOW pos=(0,0) (" + |
| 9284 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
| 9285 | if (mBlurSurface != null) { |
| 9286 | mBlurSurface.setPosition(0, 0); |
| 9287 | mBlurSurface.setSize(dw, dh); |
| 9288 | try { |
| 9289 | mBlurSurface.show(); |
| 9290 | } catch (RuntimeException e) { |
| 9291 | Log.w(TAG, "Failure showing blur surface", e); |
| 9292 | } |
| 9293 | } |
| 9294 | } |
| 9295 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 9296 | } |
| 9297 | } |
| 9298 | } |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 9299 | |
| 9300 | if (obscuredChanged && mWallpaperTarget == w) { |
| 9301 | // This is the wallpaper target and its obscured state |
| 9302 | // changed... make sure the current wallaper's visibility |
| 9303 | // has been updated accordingly. |
| 9304 | updateWallpaperVisibilityLocked(); |
| 9305 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9306 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9307 | |
| 9308 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 9309 | mBackgroundFillerShown = false; |
| 9310 | if (SHOW_TRANSACTIONS) Log.d(TAG, "hiding background filler"); |
| 9311 | try { |
| 9312 | mBackgroundFillerSurface.hide(); |
| 9313 | } catch (RuntimeException e) { |
| 9314 | Log.e(TAG, "Exception hiding filler surface", e); |
| 9315 | } |
| 9316 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9317 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9318 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
| 9319 | animating |= mDimAnimator.updateSurface(dimming, currentTime, mDisplayFrozen); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9320 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9321 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9322 | if (!blurring && mBlurShown) { |
| 9323 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " + mBlurSurface |
| 9324 | + ": HIDE"); |
| 9325 | try { |
| 9326 | mBlurSurface.hide(); |
| 9327 | } catch (IllegalArgumentException e) { |
| 9328 | Log.w(TAG, "Illegal argument exception hiding blur surface"); |
| 9329 | } |
| 9330 | mBlurShown = false; |
| 9331 | } |
| 9332 | |
| 9333 | if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION"); |
| 9334 | } catch (RuntimeException e) { |
| 9335 | Log.e(TAG, "Unhandled exception in Window Manager", e); |
| 9336 | } |
| 9337 | |
| 9338 | Surface.closeTransaction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9339 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9340 | if (DEBUG_ORIENTATION && mDisplayFrozen) Log.v(TAG, |
| 9341 | "With display frozen, orientationChangeComplete=" |
| 9342 | + orientationChangeComplete); |
| 9343 | if (orientationChangeComplete) { |
| 9344 | if (mWindowsFreezingScreen) { |
| 9345 | mWindowsFreezingScreen = false; |
| 9346 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 9347 | } |
| 9348 | if (mAppsFreezingScreen == 0) { |
| 9349 | stopFreezingDisplayLocked(); |
| 9350 | } |
| 9351 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9352 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9353 | i = mResizingWindows.size(); |
| 9354 | if (i > 0) { |
| 9355 | do { |
| 9356 | i--; |
| 9357 | WindowState win = mResizingWindows.get(i); |
| 9358 | try { |
| 9359 | win.mClient.resized(win.mFrame.width(), |
| 9360 | win.mFrame.height(), win.mLastContentInsets, |
| 9361 | win.mLastVisibleInsets, win.mDrawPending); |
| 9362 | win.mContentInsetsChanged = false; |
| 9363 | win.mVisibleInsetsChanged = false; |
| 9364 | } catch (RemoteException e) { |
| 9365 | win.mOrientationChanging = false; |
| 9366 | } |
| 9367 | } while (i > 0); |
| 9368 | mResizingWindows.clear(); |
| 9369 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9370 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9371 | // Destroy the surface of any windows that are no longer visible. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9372 | boolean wallpaperDestroyed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9373 | i = mDestroySurface.size(); |
| 9374 | if (i > 0) { |
| 9375 | do { |
| 9376 | i--; |
| 9377 | WindowState win = mDestroySurface.get(i); |
| 9378 | win.mDestroying = false; |
| 9379 | if (mInputMethodWindow == win) { |
| 9380 | mInputMethodWindow = null; |
| 9381 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9382 | if (win == mWallpaperTarget) { |
| 9383 | wallpaperDestroyed = true; |
| 9384 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9385 | win.destroySurfaceLocked(); |
| 9386 | } while (i > 0); |
| 9387 | mDestroySurface.clear(); |
| 9388 | } |
| 9389 | |
| 9390 | // Time to remove any exiting tokens? |
| 9391 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9392 | WindowToken token = mExitingTokens.get(i); |
| 9393 | if (!token.hasVisible) { |
| 9394 | mExitingTokens.remove(i); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 9395 | if (token.windowType == TYPE_WALLPAPER) { |
| 9396 | mWallpaperTokens.remove(token); |
| 9397 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9398 | } |
| 9399 | } |
| 9400 | |
| 9401 | // Time to remove any exiting applications? |
| 9402 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9403 | AppWindowToken token = mExitingAppTokens.get(i); |
| 9404 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
| 9405 | mAppTokens.remove(token); |
| 9406 | mExitingAppTokens.remove(i); |
| 9407 | } |
| 9408 | } |
| 9409 | |
| 9410 | if (focusDisplayed) { |
| 9411 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 9412 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9413 | if (wallpaperDestroyed) { |
| 9414 | wallpaperDestroyed = adjustWallpaperWindowsLocked(); |
| 9415 | } |
| 9416 | if (wallpaperDestroyed) { |
| 9417 | requestAnimationLocked(0); |
| 9418 | } else if (animating) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9419 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 9420 | } |
| 9421 | mQueue.setHoldScreenLocked(holdScreen != null); |
| 9422 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 9423 | mPowerManager.setScreenBrightnessOverride(-1); |
| 9424 | } else { |
| 9425 | mPowerManager.setScreenBrightnessOverride((int) |
| 9426 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 9427 | } |
| 9428 | if (holdScreen != mHoldingScreenOn) { |
| 9429 | mHoldingScreenOn = holdScreen; |
| 9430 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 9431 | mH.sendMessage(m); |
| 9432 | } |
| 9433 | } |
| 9434 | |
| 9435 | void requestAnimationLocked(long delay) { |
| 9436 | if (!mAnimationPending) { |
| 9437 | mAnimationPending = true; |
| 9438 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 9439 | } |
| 9440 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9441 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9442 | /** |
| 9443 | * Have the surface flinger show a surface, robustly dealing with |
| 9444 | * error conditions. In particular, if there is not enough memory |
| 9445 | * to show the surface, then we will try to get rid of other surfaces |
| 9446 | * in order to succeed. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9447 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9448 | * @return Returns true if the surface was successfully shown. |
| 9449 | */ |
| 9450 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 9451 | try { |
| 9452 | if (win.mSurface != null) { |
| 9453 | win.mSurface.show(); |
| 9454 | } |
| 9455 | return true; |
| 9456 | } catch (RuntimeException e) { |
| 9457 | Log.w(TAG, "Failure showing surface " + win.mSurface + " in " + win); |
| 9458 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9459 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9460 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9461 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9462 | return false; |
| 9463 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9464 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9465 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 9466 | final Surface surface = win.mSurface; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9467 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9468 | EventLog.writeEvent(LOG_WM_NO_SURFACE_MEMORY, win.toString(), |
| 9469 | win.mSession.mPid, operation); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9470 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9471 | if (mForceRemoves == null) { |
| 9472 | mForceRemoves = new ArrayList<WindowState>(); |
| 9473 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9474 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9475 | long callingIdentity = Binder.clearCallingIdentity(); |
| 9476 | try { |
| 9477 | // There was some problem... first, do a sanity check of the |
| 9478 | // window list to make sure we haven't left any dangling surfaces |
| 9479 | // around. |
| 9480 | int N = mWindows.size(); |
| 9481 | boolean leakedSurface = false; |
| 9482 | Log.i(TAG, "Out of memory for surface! Looking for leaks..."); |
| 9483 | for (int i=0; i<N; i++) { |
| 9484 | WindowState ws = (WindowState)mWindows.get(i); |
| 9485 | if (ws.mSurface != null) { |
| 9486 | if (!mSessions.contains(ws.mSession)) { |
| 9487 | Log.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
| 9488 | + ws + " surface=" + ws.mSurface |
| 9489 | + " token=" + win.mToken |
| 9490 | + " pid=" + ws.mSession.mPid |
| 9491 | + " uid=" + ws.mSession.mUid); |
| 9492 | ws.mSurface.clear(); |
| 9493 | ws.mSurface = null; |
| 9494 | mForceRemoves.add(ws); |
| 9495 | i--; |
| 9496 | N--; |
| 9497 | leakedSurface = true; |
| 9498 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
| 9499 | Log.w(TAG, "LEAKED SURFACE (app token hidden): " |
| 9500 | + ws + " surface=" + ws.mSurface |
| 9501 | + " token=" + win.mAppToken); |
| 9502 | ws.mSurface.clear(); |
| 9503 | ws.mSurface = null; |
| 9504 | leakedSurface = true; |
| 9505 | } |
| 9506 | } |
| 9507 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9508 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9509 | boolean killedApps = false; |
| 9510 | if (!leakedSurface) { |
| 9511 | Log.w(TAG, "No leaked surfaces; killing applicatons!"); |
| 9512 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 9513 | for (int i=0; i<N; i++) { |
| 9514 | WindowState ws = (WindowState)mWindows.get(i); |
| 9515 | if (ws.mSurface != null) { |
| 9516 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 9517 | } |
| 9518 | } |
| 9519 | if (pidCandidates.size() > 0) { |
| 9520 | int[] pids = new int[pidCandidates.size()]; |
| 9521 | for (int i=0; i<pids.length; i++) { |
| 9522 | pids[i] = pidCandidates.keyAt(i); |
| 9523 | } |
| 9524 | try { |
| 9525 | if (mActivityManager.killPidsForMemory(pids)) { |
| 9526 | killedApps = true; |
| 9527 | } |
| 9528 | } catch (RemoteException e) { |
| 9529 | } |
| 9530 | } |
| 9531 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9532 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9533 | if (leakedSurface || killedApps) { |
| 9534 | // We managed to reclaim some memory, so get rid of the trouble |
| 9535 | // surface and ask the app to request another one. |
| 9536 | Log.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry."); |
| 9537 | if (surface != null) { |
| 9538 | surface.clear(); |
| 9539 | win.mSurface = null; |
| 9540 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9541 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9542 | try { |
| 9543 | win.mClient.dispatchGetNewSurface(); |
| 9544 | } catch (RemoteException e) { |
| 9545 | } |
| 9546 | } |
| 9547 | } finally { |
| 9548 | Binder.restoreCallingIdentity(callingIdentity); |
| 9549 | } |
| 9550 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9551 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9552 | private boolean updateFocusedWindowLocked(int mode) { |
| 9553 | WindowState newFocus = computeFocusedWindowLocked(); |
| 9554 | if (mCurrentFocus != newFocus) { |
| 9555 | // This check makes sure that we don't already have the focus |
| 9556 | // change message pending. |
| 9557 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 9558 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
| 9559 | if (localLOGV) Log.v( |
| 9560 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 9561 | final WindowState oldFocus = mCurrentFocus; |
| 9562 | mCurrentFocus = newFocus; |
| 9563 | mLosingFocus.remove(newFocus); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9564 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9565 | final WindowState imWindow = mInputMethodWindow; |
| 9566 | if (newFocus != imWindow && oldFocus != imWindow) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9567 | if (moveInputMethodWindowsIfNeededLocked( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9568 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9569 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 9570 | mLayoutNeeded = true; |
| 9571 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9572 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 9573 | performLayoutLockedInner(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9574 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 9575 | // Client will do the layout, but we need to assign layers |
| 9576 | // for handleNewWindowLocked() below. |
| 9577 | assignLayersLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9578 | } |
| 9579 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9580 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9581 | if (newFocus != null && mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 9582 | mKeyWaiter.handleNewWindowLocked(newFocus); |
| 9583 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9584 | return true; |
| 9585 | } |
| 9586 | return false; |
| 9587 | } |
| 9588 | |
| 9589 | private WindowState computeFocusedWindowLocked() { |
| 9590 | WindowState result = null; |
| 9591 | WindowState win; |
| 9592 | |
| 9593 | int i = mWindows.size() - 1; |
| 9594 | int nextAppIndex = mAppTokens.size()-1; |
| 9595 | WindowToken nextApp = nextAppIndex >= 0 |
| 9596 | ? mAppTokens.get(nextAppIndex) : null; |
| 9597 | |
| 9598 | while (i >= 0) { |
| 9599 | win = (WindowState)mWindows.get(i); |
| 9600 | |
| 9601 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 9602 | TAG, "Looking for focus: " + i |
| 9603 | + " = " + win |
| 9604 | + ", flags=" + win.mAttrs.flags |
| 9605 | + ", canReceive=" + win.canReceiveKeys()); |
| 9606 | |
| 9607 | AppWindowToken thisApp = win.mAppToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9608 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9609 | // If this window's application has been removed, just skip it. |
| 9610 | if (thisApp != null && thisApp.removed) { |
| 9611 | i--; |
| 9612 | continue; |
| 9613 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9614 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9615 | // If there is a focused app, don't allow focus to go to any |
| 9616 | // windows below it. If this is an application window, step |
| 9617 | // through the app tokens until we find its app. |
| 9618 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 9619 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 9620 | int origAppIndex = nextAppIndex; |
| 9621 | while (nextAppIndex > 0) { |
| 9622 | if (nextApp == mFocusedApp) { |
| 9623 | // Whoops, we are below the focused app... no focus |
| 9624 | // for you! |
| 9625 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 9626 | TAG, "Reached focused app: " + mFocusedApp); |
| 9627 | return null; |
| 9628 | } |
| 9629 | nextAppIndex--; |
| 9630 | nextApp = mAppTokens.get(nextAppIndex); |
| 9631 | if (nextApp == thisApp) { |
| 9632 | break; |
| 9633 | } |
| 9634 | } |
| 9635 | if (thisApp != nextApp) { |
| 9636 | // Uh oh, the app token doesn't exist! This shouldn't |
| 9637 | // happen, but if it does we can get totally hosed... |
| 9638 | // so restart at the original app. |
| 9639 | nextAppIndex = origAppIndex; |
| 9640 | nextApp = mAppTokens.get(nextAppIndex); |
| 9641 | } |
| 9642 | } |
| 9643 | |
| 9644 | // Dispatch to this window if it is wants key events. |
| 9645 | if (win.canReceiveKeys()) { |
| 9646 | if (DEBUG_FOCUS) Log.v( |
| 9647 | TAG, "Found focus @ " + i + " = " + win); |
| 9648 | result = win; |
| 9649 | break; |
| 9650 | } |
| 9651 | |
| 9652 | i--; |
| 9653 | } |
| 9654 | |
| 9655 | return result; |
| 9656 | } |
| 9657 | |
| 9658 | private void startFreezingDisplayLocked() { |
| 9659 | if (mDisplayFrozen) { |
| Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 9660 | // Freezing the display also suspends key event delivery, to |
| 9661 | // keep events from going astray while the display is reconfigured. |
| 9662 | // If someone has changed orientation again while the screen is |
| 9663 | // still frozen, the events will continue to be blocked while the |
| 9664 | // successive orientation change is processed. To prevent spurious |
| 9665 | // ANRs, we reset the event dispatch timeout in this case. |
| 9666 | synchronized (mKeyWaiter) { |
| 9667 | mKeyWaiter.mWasFrozen = true; |
| 9668 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9669 | return; |
| 9670 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9671 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9672 | mScreenFrozenLock.acquire(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9673 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9674 | long now = SystemClock.uptimeMillis(); |
| 9675 | //Log.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
| 9676 | if (mFreezeGcPending != 0) { |
| 9677 | if (now > (mFreezeGcPending+1000)) { |
| 9678 | //Log.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| 9679 | mH.removeMessages(H.FORCE_GC); |
| 9680 | Runtime.getRuntime().gc(); |
| 9681 | mFreezeGcPending = now; |
| 9682 | } |
| 9683 | } else { |
| 9684 | mFreezeGcPending = now; |
| 9685 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9686 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9687 | mDisplayFrozen = true; |
| 9688 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) { |
| 9689 | mNextAppTransition = WindowManagerPolicy.TRANSIT_NONE; |
| 9690 | mAppTransitionReady = true; |
| 9691 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9692 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9693 | if (PROFILE_ORIENTATION) { |
| 9694 | File file = new File("/data/system/frozen"); |
| 9695 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 9696 | } |
| 9697 | Surface.freezeDisplay(0); |
| 9698 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9699 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9700 | private void stopFreezingDisplayLocked() { |
| 9701 | if (!mDisplayFrozen) { |
| 9702 | return; |
| 9703 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9704 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9705 | mDisplayFrozen = false; |
| 9706 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 9707 | if (PROFILE_ORIENTATION) { |
| 9708 | Debug.stopMethodTracing(); |
| 9709 | } |
| 9710 | Surface.unfreezeDisplay(0); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9711 | |
| Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 9712 | // Reset the key delivery timeout on unfreeze, too. We force a wakeup here |
| 9713 | // too because regular key delivery processing should resume immediately. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9714 | synchronized (mKeyWaiter) { |
| 9715 | mKeyWaiter.mWasFrozen = true; |
| 9716 | mKeyWaiter.notifyAll(); |
| 9717 | } |
| 9718 | |
| 9719 | // A little kludge: a lot could have happened while the |
| 9720 | // display was frozen, so now that we are coming back we |
| 9721 | // do a gc so that any remote references the system |
| 9722 | // processes holds on others can be released if they are |
| 9723 | // no longer needed. |
| 9724 | mH.removeMessages(H.FORCE_GC); |
| 9725 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 9726 | 2000); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9727 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9728 | mScreenFrozenLock.release(); |
| 9729 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9730 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9731 | @Override |
| 9732 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 9733 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 9734 | != PackageManager.PERMISSION_GRANTED) { |
| 9735 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 9736 | + Binder.getCallingPid() |
| 9737 | + ", uid=" + Binder.getCallingUid()); |
| 9738 | return; |
| 9739 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9740 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9741 | synchronized(mWindowMap) { |
| 9742 | pw.println("Current Window Manager state:"); |
| 9743 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 9744 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9745 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 9746 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9747 | w.dump(pw, " "); |
| 9748 | } |
| 9749 | if (mInputMethodDialogs.size() > 0) { |
| 9750 | pw.println(" "); |
| 9751 | pw.println(" Input method dialogs:"); |
| 9752 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 9753 | WindowState w = mInputMethodDialogs.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9754 | 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] | 9755 | } |
| 9756 | } |
| 9757 | if (mPendingRemove.size() > 0) { |
| 9758 | pw.println(" "); |
| 9759 | pw.println(" Remove pending for:"); |
| 9760 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 9761 | WindowState w = mPendingRemove.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9762 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 9763 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9764 | w.dump(pw, " "); |
| 9765 | } |
| 9766 | } |
| 9767 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 9768 | pw.println(" "); |
| 9769 | pw.println(" Windows force removing:"); |
| 9770 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 9771 | WindowState w = mForceRemoves.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9772 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 9773 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9774 | w.dump(pw, " "); |
| 9775 | } |
| 9776 | } |
| 9777 | if (mDestroySurface.size() > 0) { |
| 9778 | pw.println(" "); |
| 9779 | pw.println(" Windows waiting to destroy their surface:"); |
| 9780 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 9781 | WindowState w = mDestroySurface.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9782 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 9783 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9784 | w.dump(pw, " "); |
| 9785 | } |
| 9786 | } |
| 9787 | if (mLosingFocus.size() > 0) { |
| 9788 | pw.println(" "); |
| 9789 | pw.println(" Windows losing focus:"); |
| 9790 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 9791 | WindowState w = mLosingFocus.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9792 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 9793 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9794 | w.dump(pw, " "); |
| 9795 | } |
| 9796 | } |
| 9797 | if (mSessions.size() > 0) { |
| 9798 | pw.println(" "); |
| 9799 | pw.println(" All active sessions:"); |
| 9800 | Iterator<Session> it = mSessions.iterator(); |
| 9801 | while (it.hasNext()) { |
| 9802 | Session s = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9803 | pw.print(" Session "); pw.print(s); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9804 | s.dump(pw, " "); |
| 9805 | } |
| 9806 | } |
| 9807 | if (mTokenMap.size() > 0) { |
| 9808 | pw.println(" "); |
| 9809 | pw.println(" All tokens:"); |
| 9810 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 9811 | while (it.hasNext()) { |
| 9812 | WindowToken token = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9813 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9814 | token.dump(pw, " "); |
| 9815 | } |
| 9816 | } |
| 9817 | if (mTokenList.size() > 0) { |
| 9818 | pw.println(" "); |
| 9819 | pw.println(" Window token list:"); |
| 9820 | for (int i=0; i<mTokenList.size(); i++) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9821 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 9822 | pw.println(mTokenList.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9823 | } |
| 9824 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 9825 | if (mWallpaperTokens.size() > 0) { |
| 9826 | pw.println(" "); |
| 9827 | pw.println(" Wallpaper tokens:"); |
| 9828 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 9829 | WindowToken token = mWallpaperTokens.get(i); |
| 9830 | pw.print(" Wallpaper #"); pw.print(i); |
| 9831 | pw.print(' '); pw.print(token); pw.println(':'); |
| 9832 | token.dump(pw, " "); |
| 9833 | } |
| 9834 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9835 | if (mAppTokens.size() > 0) { |
| 9836 | pw.println(" "); |
| 9837 | pw.println(" Application tokens in Z order:"); |
| 9838 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9839 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 9840 | pw.println(mAppTokens.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9841 | } |
| 9842 | } |
| 9843 | if (mFinishedStarting.size() > 0) { |
| 9844 | pw.println(" "); |
| 9845 | pw.println(" Finishing start of application tokens:"); |
| 9846 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 9847 | WindowToken token = mFinishedStarting.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9848 | pw.print(" Finished Starting #"); pw.print(i); |
| 9849 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9850 | token.dump(pw, " "); |
| 9851 | } |
| 9852 | } |
| 9853 | if (mExitingTokens.size() > 0) { |
| 9854 | pw.println(" "); |
| 9855 | pw.println(" Exiting tokens:"); |
| 9856 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 9857 | WindowToken token = mExitingTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9858 | pw.print(" Exiting #"); pw.print(i); |
| 9859 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9860 | token.dump(pw, " "); |
| 9861 | } |
| 9862 | } |
| 9863 | if (mExitingAppTokens.size() > 0) { |
| 9864 | pw.println(" "); |
| 9865 | pw.println(" Exiting application tokens:"); |
| 9866 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9867 | WindowToken token = mExitingAppTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9868 | pw.print(" Exiting App #"); pw.print(i); |
| 9869 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9870 | token.dump(pw, " "); |
| 9871 | } |
| 9872 | } |
| 9873 | pw.println(" "); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9874 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 9875 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 9876 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 9877 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 9878 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
| Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 9879 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 9880 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 9881 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 9882 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 9883 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9884 | pw.print(" mInTouchMode="); pw.println(mInTouchMode); |
| 9885 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 9886 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 9887 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 9888 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9889 | if (mDimAnimator != null) { |
| 9890 | mDimAnimator.printTo(pw); |
| 9891 | } else { |
| 9892 | pw.print( " no DimAnimator "); |
| 9893 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9894 | pw.print(" mInputMethodAnimLayerAdjustment="); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 9895 | pw.print(mInputMethodAnimLayerAdjustment); |
| 9896 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 9897 | pw.println(mWallpaperAnimLayerAdjustment); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 9898 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 9899 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9900 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 9901 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
| 9902 | pw.print(" mAppsFreezingScreen="); pw.println(mAppsFreezingScreen); |
| 9903 | pw.print(" mRotation="); pw.print(mRotation); |
| 9904 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 9905 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 9906 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 9907 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 9908 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 9909 | pw.print(" mNextAppTransition=0x"); |
| 9910 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 9911 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
| 9912 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
| 9913 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 9914 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| 9915 | if (mOpeningApps.size() > 0) { |
| 9916 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 9917 | } |
| 9918 | if (mClosingApps.size() > 0) { |
| 9919 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 9920 | } |
| 9921 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 9922 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9923 | pw.println(" KeyWaiter state:"); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9924 | pw.print(" mLastWin="); pw.print(mKeyWaiter.mLastWin); |
| 9925 | pw.print(" mLastBinder="); pw.println(mKeyWaiter.mLastBinder); |
| 9926 | pw.print(" mFinished="); pw.print(mKeyWaiter.mFinished); |
| 9927 | pw.print(" mGotFirstWindow="); pw.print(mKeyWaiter.mGotFirstWindow); |
| 9928 | pw.print(" mEventDispatching="); pw.print(mKeyWaiter.mEventDispatching); |
| 9929 | pw.print(" mTimeToSwitch="); pw.println(mKeyWaiter.mTimeToSwitch); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9930 | } |
| 9931 | } |
| 9932 | |
| 9933 | public void monitor() { |
| 9934 | synchronized (mWindowMap) { } |
| 9935 | synchronized (mKeyguardDisabled) { } |
| 9936 | synchronized (mKeyWaiter) { } |
| 9937 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9938 | |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 9939 | public void virtualKeyFeedback(KeyEvent event) { |
| 9940 | mPolicy.keyFeedbackFromInput(event); |
| 9941 | } |
| 9942 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9943 | /** |
| 9944 | * DimAnimator class that controls the dim animation. This holds the surface and |
| 9945 | * all state used for dim animation. |
| 9946 | */ |
| 9947 | private static class DimAnimator { |
| 9948 | Surface mDimSurface; |
| 9949 | boolean mDimShown = false; |
| 9950 | float mDimCurrentAlpha; |
| 9951 | float mDimTargetAlpha; |
| 9952 | float mDimDeltaPerMs; |
| 9953 | long mLastDimAnimTime; |
| 9954 | |
| 9955 | DimAnimator (SurfaceSession session) { |
| 9956 | if (mDimSurface == null) { |
| 9957 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 9958 | + mDimSurface + ": CREATE"); |
| 9959 | try { |
| 9960 | mDimSurface = new Surface(session, 0, -1, 16, 16, PixelFormat.OPAQUE, |
| 9961 | Surface.FX_SURFACE_DIM); |
| 9962 | } catch (Exception e) { |
| 9963 | Log.e(TAG, "Exception creating Dim surface", e); |
| 9964 | } |
| 9965 | } |
| 9966 | } |
| 9967 | |
| 9968 | /** |
| 9969 | * Show the dim surface. |
| 9970 | */ |
| 9971 | void show(int dw, int dh) { |
| 9972 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 9973 | dw + "x" + dh + ")"); |
| 9974 | mDimShown = true; |
| 9975 | try { |
| 9976 | mDimSurface.setPosition(0, 0); |
| 9977 | mDimSurface.setSize(dw, dh); |
| 9978 | mDimSurface.show(); |
| 9979 | } catch (RuntimeException e) { |
| 9980 | Log.w(TAG, "Failure showing dim surface", e); |
| 9981 | } |
| 9982 | } |
| 9983 | |
| 9984 | /** |
| 9985 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 9986 | * {@link updateSurface} after all windows are examined. |
| 9987 | */ |
| 9988 | void updateParameters(WindowState w, long currentTime) { |
| 9989 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 9990 | |
| 9991 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
| 9992 | if (SHOW_TRANSACTIONS) Log.i(TAG, "layer=" + (w.mAnimLayer-1) + ", target=" + target); |
| 9993 | if (mDimTargetAlpha != target) { |
| 9994 | // If the desired dim level has changed, then |
| 9995 | // start an animation to it. |
| 9996 | mLastDimAnimTime = currentTime; |
| 9997 | long duration = (w.mAnimating && w.mAnimation != null) |
| 9998 | ? w.mAnimation.computeDurationHint() |
| 9999 | : DEFAULT_DIM_DURATION; |
| 10000 | if (target > mDimTargetAlpha) { |
| 10001 | // This is happening behind the activity UI, |
| 10002 | // so we can make it run a little longer to |
| 10003 | // give a stronger impression without disrupting |
| 10004 | // the user. |
| 10005 | duration *= DIM_DURATION_MULTIPLIER; |
| 10006 | } |
| 10007 | if (duration < 1) { |
| 10008 | // Don't divide by zero |
| 10009 | duration = 1; |
| 10010 | } |
| 10011 | mDimTargetAlpha = target; |
| 10012 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 10013 | } |
| 10014 | } |
| 10015 | |
| 10016 | /** |
| 10017 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 10018 | * false when the animation is finished and the dim surface is hidden. |
| 10019 | */ |
| 10020 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 10021 | if (!dimming) { |
| 10022 | if (mDimTargetAlpha != 0) { |
| 10023 | mLastDimAnimTime = currentTime; |
| 10024 | mDimTargetAlpha = 0; |
| 10025 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 10026 | } |
| 10027 | } |
| 10028 | |
| 10029 | boolean animating = false; |
| 10030 | if (mLastDimAnimTime != 0) { |
| 10031 | mDimCurrentAlpha += mDimDeltaPerMs |
| 10032 | * (currentTime-mLastDimAnimTime); |
| 10033 | boolean more = true; |
| 10034 | if (displayFrozen) { |
| 10035 | // If the display is frozen, there is no reason to animate. |
| 10036 | more = false; |
| 10037 | } else if (mDimDeltaPerMs > 0) { |
| 10038 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 10039 | more = false; |
| 10040 | } |
| 10041 | } else if (mDimDeltaPerMs < 0) { |
| 10042 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 10043 | more = false; |
| 10044 | } |
| 10045 | } else { |
| 10046 | more = false; |
| 10047 | } |
| 10048 | |
| 10049 | // Do we need to continue animating? |
| 10050 | if (more) { |
| 10051 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 10052 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 10053 | mLastDimAnimTime = currentTime; |
| 10054 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 10055 | animating = true; |
| 10056 | } else { |
| 10057 | mDimCurrentAlpha = mDimTargetAlpha; |
| 10058 | mLastDimAnimTime = 0; |
| 10059 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 10060 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 10061 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 10062 | if (!dimming) { |
| 10063 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface |
| 10064 | + ": HIDE"); |
| 10065 | try { |
| 10066 | mDimSurface.hide(); |
| 10067 | } catch (RuntimeException e) { |
| 10068 | Log.w(TAG, "Illegal argument exception hiding dim surface"); |
| 10069 | } |
| 10070 | mDimShown = false; |
| 10071 | } |
| 10072 | } |
| 10073 | } |
| 10074 | return animating; |
| 10075 | } |
| 10076 | |
| 10077 | public void printTo(PrintWriter pw) { |
| 10078 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 10079 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 10080 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 10081 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 10082 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 10083 | } |
| 10084 | } |
| 10085 | |
| 10086 | /** |
| 10087 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 10088 | * This is used for opening/closing transition for apps in compatible mode. |
| 10089 | */ |
| 10090 | private static class FadeInOutAnimation extends Animation { |
| 10091 | int mWidth; |
| 10092 | boolean mFadeIn; |
| 10093 | |
| 10094 | public FadeInOutAnimation(boolean fadeIn) { |
| 10095 | setInterpolator(new AccelerateInterpolator()); |
| 10096 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 10097 | mFadeIn = fadeIn; |
| 10098 | } |
| 10099 | |
| 10100 | @Override |
| 10101 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 10102 | float x = interpolatedTime; |
| 10103 | if (!mFadeIn) { |
| 10104 | x = 1.0f - x; // reverse the interpolation for fade out |
| 10105 | } |
| 10106 | if (x < 0.5) { |
| 10107 | // move the window out of the screen. |
| 10108 | t.getMatrix().setTranslate(mWidth, 0); |
| 10109 | } else { |
| 10110 | t.getMatrix().setTranslate(0, 0);// show |
| 10111 | t.setAlpha((x - 0.5f) * 2); |
| 10112 | } |
| 10113 | } |
| 10114 | |
| 10115 | @Override |
| 10116 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 10117 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 10118 | mWidth = width; |
| 10119 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10120 | |
| 10121 | @Override |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 10122 | public int getZAdjustment() { |
| 10123 | return Animation.ZORDER_TOP; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10124 | } |
| 10125 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10126 | } |