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; |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 102 | import android.view.ViewConfiguration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | import android.view.ViewTreeObserver; |
| 104 | import android.view.WindowManager; |
| 105 | import android.view.WindowManagerImpl; |
| 106 | import android.view.WindowManagerPolicy; |
| 107 | import android.view.WindowManager.LayoutParams; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 108 | import android.view.animation.AccelerateInterpolator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | import android.view.animation.Animation; |
| 110 | import android.view.animation.AnimationUtils; |
| 111 | import android.view.animation.Transformation; |
| 112 | |
| 113 | import java.io.BufferedWriter; |
| 114 | import java.io.File; |
| 115 | import java.io.FileDescriptor; |
| 116 | import java.io.IOException; |
| 117 | import java.io.OutputStream; |
| 118 | import java.io.OutputStreamWriter; |
| 119 | import java.io.PrintWriter; |
| 120 | import java.io.StringWriter; |
| 121 | import java.net.Socket; |
| 122 | import java.util.ArrayList; |
| 123 | import java.util.HashMap; |
| 124 | import java.util.HashSet; |
| 125 | import java.util.Iterator; |
| 126 | import java.util.List; |
| 127 | |
| 128 | /** {@hide} */ |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 129 | public class WindowManagerService extends IWindowManager.Stub |
| 130 | implements Watchdog.Monitor, KeyInputQueue.HapticFeedbackCallback { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | static final String TAG = "WindowManager"; |
| 132 | static final boolean DEBUG = false; |
| 133 | static final boolean DEBUG_FOCUS = false; |
| 134 | static final boolean DEBUG_ANIM = false; |
| 135 | static final boolean DEBUG_LAYERS = false; |
| 136 | static final boolean DEBUG_INPUT = false; |
| 137 | static final boolean DEBUG_INPUT_METHOD = false; |
| 138 | static final boolean DEBUG_VISIBILITY = false; |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 139 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | static final boolean DEBUG_ORIENTATION = false; |
| 141 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 142 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 143 | static final boolean DEBUG_REORDER = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 144 | static final boolean DEBUG_WALLPAPER = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | static final boolean SHOW_TRANSACTIONS = false; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 146 | static final boolean HIDE_STACK_CRAWLS = true; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 147 | static final boolean MEASURE_LATENCY = false; |
| 148 | static private LatencyTimer lt; |
| 149 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | static final boolean PROFILE_ORIENTATION = false; |
| 151 | static final boolean BLUR = true; |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 152 | static final boolean localLOGV = DEBUG; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 153 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | static final int LOG_WM_NO_SURFACE_MEMORY = 31000; |
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() { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame^] | 236 | mPolicy.enableKeyguard(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | synchronized (mKeyguardDisabled) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | /** |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 305 | * This was the app token that was used to retrieve the last enter |
| 306 | * animation. It will be used for the next exit animation. |
| 307 | */ |
| 308 | AppWindowToken mLastEnterAnimToken; |
| 309 | |
| 310 | /** |
| 311 | * These were the layout params used to retrieve the last enter animation. |
| 312 | * They will be used for the next exit animation. |
| 313 | */ |
| 314 | LayoutParams mLastEnterAnimParams; |
| 315 | |
| 316 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 317 | * Z-ordered (bottom-most first) list of all Window objects. |
| 318 | */ |
| 319 | final ArrayList mWindows = new ArrayList(); |
| 320 | |
| 321 | /** |
| 322 | * Windows that are being resized. Used so we can tell the client about |
| 323 | * the resize after closing the transaction in which we resized the |
| 324 | * underlying surface. |
| 325 | */ |
| 326 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 327 | |
| 328 | /** |
| 329 | * Windows whose animations have ended and now must be removed. |
| 330 | */ |
| 331 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 332 | |
| 333 | /** |
| 334 | * Windows whose surface should be destroyed. |
| 335 | */ |
| 336 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 337 | |
| 338 | /** |
| 339 | * Windows that have lost input focus and are waiting for the new |
| 340 | * focus window to be displayed before they are told about this. |
| 341 | */ |
| 342 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 343 | |
| 344 | /** |
| 345 | * This is set when we have run out of memory, and will either be an empty |
| 346 | * list or contain windows that need to be force removed. |
| 347 | */ |
| 348 | ArrayList<WindowState> mForceRemoves; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 349 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | IInputMethodManager mInputMethodManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 351 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 352 | SurfaceSession mFxSession; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 353 | private DimAnimator mDimAnimator = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 354 | Surface mBlurSurface; |
| 355 | boolean mBlurShown; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 356 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 357 | int mTransactionSequence = 0; |
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 | final float[] mTmpFloats = new float[9]; |
| 360 | |
| 361 | boolean mSafeMode; |
| 362 | boolean mDisplayEnabled = false; |
| 363 | boolean mSystemBooted = false; |
| 364 | int mRotation = 0; |
| 365 | int mRequestedRotation = 0; |
| 366 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 367 | int mLastRotationFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | ArrayList<IRotationWatcher> mRotationWatchers |
| 369 | = new ArrayList<IRotationWatcher>(); |
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 | boolean mLayoutNeeded = true; |
| 372 | boolean mAnimationPending = false; |
| 373 | boolean mDisplayFrozen = false; |
| 374 | boolean mWindowsFreezingScreen = false; |
| 375 | long mFreezeGcPending = 0; |
| 376 | int mAppsFreezingScreen = 0; |
| 377 | |
| 378 | // This is held as long as we have the screen frozen, to give us time to |
| 379 | // perform a rotation animation when turning off shows the lock screen which |
| 380 | // changes the orientation. |
| 381 | PowerManager.WakeLock mScreenFrozenLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 382 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | // State management of app transitions. When we are preparing for a |
| 384 | // transition, mNextAppTransition will be the kind of transition to |
| 385 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 386 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 387 | // made visible or hidden at the next transition. |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 388 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 389 | String mNextAppTransitionPackage; |
| 390 | int mNextAppTransitionEnter; |
| 391 | int mNextAppTransitionExit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 392 | boolean mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 393 | boolean mAppTransitionRunning = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | boolean mAppTransitionTimeout = false; |
| 395 | boolean mStartingIconInTransition = false; |
| 396 | boolean mSkipAppTransitionAnimation = false; |
| 397 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 398 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 399 | final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>(); |
| 400 | final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 401 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | //flag to detect fat touch events |
| 403 | boolean mFatTouch = false; |
| 404 | Display mDisplay; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 405 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | H mH = new H(); |
| 407 | |
| 408 | WindowState mCurrentFocus = null; |
| 409 | WindowState mLastFocus = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 410 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | // This just indicates the window the input method is on top of, not |
| 412 | // necessarily the window its input is going to. |
| 413 | WindowState mInputMethodTarget = null; |
| 414 | WindowState mUpcomingInputMethodTarget = null; |
| 415 | boolean mInputMethodTargetWaitingAnim; |
| 416 | int mInputMethodAnimLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 417 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | WindowState mInputMethodWindow = null; |
| 419 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 420 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 421 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
| 422 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 423 | // If non-null, this is the currently visible window that is associated |
| 424 | // with the wallpaper. |
| 425 | WindowState mWallpaperTarget = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 426 | // If non-null, we are in the middle of animating from one wallpaper target |
| 427 | // to another, and this is the lower one in Z-order. |
| 428 | WindowState mLowerWallpaperTarget = null; |
| 429 | // If non-null, we are in the middle of animating from one wallpaper target |
| 430 | // to another, and this is the higher one in Z-order. |
| 431 | WindowState mUpperWallpaperTarget = null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 432 | int mWallpaperAnimLayerAdjustment; |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 433 | float mLastWallpaperX; |
| 434 | float mLastWallpaperY; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 435 | // Lock for waiting for the wallpaper. |
| 436 | final Object mWaitingOnWallpaperLock = new Object(); |
| 437 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 438 | // changing its scroll position. |
| 439 | WindowState mWaitingOnWallpaper; |
| 440 | // The last time we had a timeout when waiting for a wallpaper. |
| 441 | long mLastWallpaperTimeoutTime; |
| 442 | // We give a wallpaper up to 150ms to finish scrolling. |
| 443 | static final long WALLPAPER_TIMEOUT = 150; |
| 444 | // Time we wait after a timeout before trying to wait again. |
| 445 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 446 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 447 | AppWindowToken mFocusedApp = null; |
| 448 | |
| 449 | PowerManagerService mPowerManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | float mWindowAnimationScale = 1.0f; |
| 452 | float mTransitionAnimationScale = 1.0f; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 453 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 454 | final KeyWaiter mKeyWaiter = new KeyWaiter(); |
| 455 | final KeyQ mQueue; |
| 456 | final InputDispatcherThread mInputThread; |
| 457 | |
| 458 | // Who is holding the screen on. |
| 459 | Session mHoldingScreenOn; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 460 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 461 | boolean mTurnOnScreen; |
| 462 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 463 | /** |
| 464 | * Whether the UI is currently running in touch mode (not showing |
| 465 | * navigational focus because the user is directly pressing the screen). |
| 466 | */ |
| 467 | boolean mInTouchMode = false; |
| 468 | |
| 469 | private ViewServer mViewServer; |
| 470 | |
| 471 | final Rect mTempRect = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 472 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 473 | final Configuration mTempConfiguration = new Configuration(); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 474 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 475 | |
| 476 | // The frame use to limit the size of the app running in compatibility mode. |
| 477 | Rect mCompatibleScreenFrame = new Rect(); |
| 478 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 479 | Surface mBackgroundFillerSurface = null; |
| 480 | boolean mBackgroundFillerShown = false; |
| 481 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 482 | public static WindowManagerService main(Context context, |
| 483 | PowerManagerService pm, boolean haveInputMethods) { |
| 484 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 485 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 486 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 487 | synchronized (thr) { |
| 488 | while (thr.mService == null) { |
| 489 | try { |
| 490 | thr.wait(); |
| 491 | } catch (InterruptedException e) { |
| 492 | } |
| 493 | } |
| 494 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 495 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | return thr.mService; |
| 497 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 498 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 499 | static class WMThread extends Thread { |
| 500 | WindowManagerService mService; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 501 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 502 | private final Context mContext; |
| 503 | private final PowerManagerService mPM; |
| 504 | private final boolean mHaveInputMethods; |
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 WMThread(Context context, PowerManagerService pm, |
| 507 | boolean haveInputMethods) { |
| 508 | super("WindowManager"); |
| 509 | mContext = context; |
| 510 | mPM = pm; |
| 511 | mHaveInputMethods = haveInputMethods; |
| 512 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 513 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 514 | public void run() { |
| 515 | Looper.prepare(); |
| 516 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 517 | mHaveInputMethods); |
| 518 | android.os.Process.setThreadPriority( |
| 519 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 520 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 521 | synchronized (this) { |
| 522 | mService = s; |
| 523 | notifyAll(); |
| 524 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 525 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 526 | Looper.loop(); |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | static class PolicyThread extends Thread { |
| 531 | private final WindowManagerPolicy mPolicy; |
| 532 | private final WindowManagerService mService; |
| 533 | private final Context mContext; |
| 534 | private final PowerManagerService mPM; |
| 535 | boolean mRunning = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 536 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 537 | public PolicyThread(WindowManagerPolicy policy, |
| 538 | WindowManagerService service, Context context, |
| 539 | PowerManagerService pm) { |
| 540 | super("WindowManagerPolicy"); |
| 541 | mPolicy = policy; |
| 542 | mService = service; |
| 543 | mContext = context; |
| 544 | mPM = pm; |
| 545 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 546 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 547 | public void run() { |
| 548 | Looper.prepare(); |
| 549 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
| 550 | // Log.VERBOSE, "WindowManagerPolicy")); |
| 551 | android.os.Process.setThreadPriority( |
| 552 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
| 553 | mPolicy.init(mContext, mService, mPM); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 554 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 555 | synchronized (this) { |
| 556 | mRunning = true; |
| 557 | notifyAll(); |
| 558 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 559 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 560 | Looper.loop(); |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | private WindowManagerService(Context context, PowerManagerService pm, |
| 565 | boolean haveInputMethods) { |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 566 | if (MEASURE_LATENCY) { |
| 567 | lt = new LatencyTimer(100, 1000); |
| 568 | } |
| 569 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 570 | mContext = context; |
| 571 | mHaveInputMethods = haveInputMethods; |
| 572 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 573 | com.android.internal.R.bool.config_sf_limitedAlpha); |
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 | mPowerManager = pm; |
| 576 | mPowerManager.setPolicy(mPolicy); |
| 577 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 578 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 579 | "SCREEN_FROZEN"); |
| 580 | mScreenFrozenLock.setReferenceCounted(false); |
| 581 | |
| 582 | mActivityManager = ActivityManagerNative.getDefault(); |
| 583 | mBatteryStats = BatteryStatsService.getService(); |
| 584 | |
| 585 | // Get persisted window scale setting |
| 586 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 587 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 588 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 589 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 590 | |
Michael Chan | 9f028e6 | 2009-08-04 17:37:46 -0700 | [diff] [blame] | 591 | int max_events_per_sec = 35; |
| 592 | try { |
| 593 | max_events_per_sec = Integer.parseInt(SystemProperties |
| 594 | .get("windowsmgr.max_events_per_sec")); |
| 595 | if (max_events_per_sec < 1) { |
| 596 | max_events_per_sec = 35; |
| 597 | } |
| 598 | } catch (NumberFormatException e) { |
| 599 | } |
| 600 | mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec; |
| 601 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 602 | mQueue = new KeyQ(); |
| 603 | |
| 604 | mInputThread = new InputDispatcherThread(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 605 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 606 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 607 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 608 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 609 | synchronized (thr) { |
| 610 | while (!thr.mRunning) { |
| 611 | try { |
| 612 | thr.wait(); |
| 613 | } catch (InterruptedException e) { |
| 614 | } |
| 615 | } |
| 616 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 617 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 618 | mInputThread.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 619 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 620 | // Add ourself to the Watchdog monitors. |
| 621 | Watchdog.getInstance().addMonitor(this); |
| 622 | } |
| 623 | |
| 624 | @Override |
| 625 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 626 | throws RemoteException { |
| 627 | try { |
| 628 | return super.onTransact(code, data, reply, flags); |
| 629 | } catch (RuntimeException e) { |
| 630 | // The window manager only throws security exceptions, so let's |
| 631 | // log all others. |
| 632 | if (!(e instanceof SecurityException)) { |
| 633 | Log.e(TAG, "Window Manager Crash", e); |
| 634 | } |
| 635 | throw e; |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | private void placeWindowAfter(Object pos, WindowState window) { |
| 640 | final int i = mWindows.indexOf(pos); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 641 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Log.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 642 | TAG, "Adding window " + window + " at " |
| 643 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 644 | mWindows.add(i+1, window); |
| 645 | } |
| 646 | |
| 647 | private void placeWindowBefore(Object pos, WindowState window) { |
| 648 | final int i = mWindows.indexOf(pos); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 649 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Log.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 650 | TAG, "Adding window " + window + " at " |
| 651 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 652 | mWindows.add(i, window); |
| 653 | } |
| 654 | |
| 655 | //This method finds out the index of a window that has the same app token as |
| 656 | //win. used for z ordering the windows in mWindows |
| 657 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 658 | //use a local variable to cache mWindows |
| 659 | ArrayList localmWindows = mWindows; |
| 660 | int jmax = localmWindows.size(); |
| 661 | if(jmax == 0) { |
| 662 | return -1; |
| 663 | } |
| 664 | for(int j = (jmax-1); j >= 0; j--) { |
| 665 | WindowState wentry = (WindowState)localmWindows.get(j); |
| 666 | if(wentry.mAppToken == win.mAppToken) { |
| 667 | return j; |
| 668 | } |
| 669 | } |
| 670 | return -1; |
| 671 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 672 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 673 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 674 | final IWindow client = win.mClient; |
| 675 | final WindowToken token = win.mToken; |
| 676 | final ArrayList localmWindows = mWindows; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 677 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 678 | final int N = localmWindows.size(); |
| 679 | final WindowState attached = win.mAttachedWindow; |
| 680 | int i; |
| 681 | if (attached == null) { |
| 682 | int tokenWindowsPos = token.windows.size(); |
| 683 | if (token.appWindowToken != null) { |
| 684 | int index = tokenWindowsPos-1; |
| 685 | if (index >= 0) { |
| 686 | // If this application has existing windows, we |
| 687 | // simply place the new window on top of them... but |
| 688 | // keep the starting window on top. |
| 689 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 690 | // Base windows go behind everything else. |
| 691 | placeWindowBefore(token.windows.get(0), win); |
| 692 | tokenWindowsPos = 0; |
| 693 | } else { |
| 694 | AppWindowToken atoken = win.mAppToken; |
| 695 | if (atoken != null && |
| 696 | token.windows.get(index) == atoken.startingWindow) { |
| 697 | placeWindowBefore(token.windows.get(index), win); |
| 698 | tokenWindowsPos--; |
| 699 | } else { |
| 700 | int newIdx = findIdxBasedOnAppTokens(win); |
| 701 | if(newIdx != -1) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 702 | //there is a window above this one associated with the same |
| 703 | //apptoken note that the window could be a floating window |
| 704 | //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] | 705 | //windows associated with this token. |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 706 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Log.v( |
| 707 | TAG, "Adding window " + win + " at " |
| 708 | + (newIdx+1) + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 709 | localmWindows.add(newIdx+1, win); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 710 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 711 | } |
| 712 | } |
| 713 | } else { |
| 714 | if (localLOGV) Log.v( |
| 715 | TAG, "Figuring out where to add app window " |
| 716 | + client.asBinder() + " (token=" + token + ")"); |
| 717 | // Figure out where the window should go, based on the |
| 718 | // order of applications. |
| 719 | final int NA = mAppTokens.size(); |
| 720 | Object pos = null; |
| 721 | for (i=NA-1; i>=0; i--) { |
| 722 | AppWindowToken t = mAppTokens.get(i); |
| 723 | if (t == token) { |
| 724 | i--; |
| 725 | break; |
| 726 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 727 | |
| 728 | // We haven't reached the token yet; if this token |
| 729 | // is not going to the bottom and has windows, we can |
| 730 | // use it as an anchor for when we do reach the token. |
| 731 | if (!t.sendingToBottom && t.windows.size() > 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 732 | pos = t.windows.get(0); |
| 733 | } |
| 734 | } |
| 735 | // We now know the index into the apps. If we found |
| 736 | // an app window above, that gives us the position; else |
| 737 | // we need to look some more. |
| 738 | if (pos != null) { |
| 739 | // Move behind any windows attached to this one. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 740 | WindowToken atoken = |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 741 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 742 | if (atoken != null) { |
| 743 | final int NC = atoken.windows.size(); |
| 744 | if (NC > 0) { |
| 745 | WindowState bottom = atoken.windows.get(0); |
| 746 | if (bottom.mSubLayer < 0) { |
| 747 | pos = bottom; |
| 748 | } |
| 749 | } |
| 750 | } |
| 751 | placeWindowBefore(pos, win); |
| 752 | } else { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 753 | // Continue looking down until we find the first |
| 754 | // token that has windows. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 755 | while (i >= 0) { |
| 756 | AppWindowToken t = mAppTokens.get(i); |
| 757 | final int NW = t.windows.size(); |
| 758 | if (NW > 0) { |
| 759 | pos = t.windows.get(NW-1); |
| 760 | break; |
| 761 | } |
| 762 | i--; |
| 763 | } |
| 764 | if (pos != null) { |
| 765 | // Move in front of any windows attached to this |
| 766 | // one. |
| 767 | WindowToken atoken = |
| 768 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 769 | if (atoken != null) { |
| 770 | final int NC = atoken.windows.size(); |
| 771 | if (NC > 0) { |
| 772 | WindowState top = atoken.windows.get(NC-1); |
| 773 | if (top.mSubLayer >= 0) { |
| 774 | pos = top; |
| 775 | } |
| 776 | } |
| 777 | } |
| 778 | placeWindowAfter(pos, win); |
| 779 | } else { |
| 780 | // Just search for the start of this layer. |
| 781 | final int myLayer = win.mBaseLayer; |
| 782 | for (i=0; i<N; i++) { |
| 783 | WindowState w = (WindowState)localmWindows.get(i); |
| 784 | if (w.mBaseLayer > myLayer) { |
| 785 | break; |
| 786 | } |
| 787 | } |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 788 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Log.v( |
| 789 | TAG, "Adding window " + win + " at " |
| 790 | + i + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 791 | localmWindows.add(i, win); |
| 792 | } |
| 793 | } |
| 794 | } |
| 795 | } else { |
| 796 | // Figure out where window should go, based on layer. |
| 797 | final int myLayer = win.mBaseLayer; |
| 798 | for (i=N-1; i>=0; i--) { |
| 799 | if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) { |
| 800 | i++; |
| 801 | break; |
| 802 | } |
| 803 | } |
| 804 | if (i < 0) i = 0; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 805 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Log.v( |
| 806 | TAG, "Adding window " + win + " at " |
| 807 | + i + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 808 | localmWindows.add(i, win); |
| 809 | } |
| 810 | if (addToToken) { |
| 811 | token.windows.add(tokenWindowsPos, win); |
| 812 | } |
| 813 | |
| 814 | } else { |
| 815 | // Figure out this window's ordering relative to the window |
| 816 | // it is attached to. |
| 817 | final int NA = token.windows.size(); |
| 818 | final int sublayer = win.mSubLayer; |
| 819 | int largestSublayer = Integer.MIN_VALUE; |
| 820 | WindowState windowWithLargestSublayer = null; |
| 821 | for (i=0; i<NA; i++) { |
| 822 | WindowState w = token.windows.get(i); |
| 823 | final int wSublayer = w.mSubLayer; |
| 824 | if (wSublayer >= largestSublayer) { |
| 825 | largestSublayer = wSublayer; |
| 826 | windowWithLargestSublayer = w; |
| 827 | } |
| 828 | if (sublayer < 0) { |
| 829 | // For negative sublayers, we go below all windows |
| 830 | // in the same sublayer. |
| 831 | if (wSublayer >= sublayer) { |
| 832 | if (addToToken) { |
| 833 | token.windows.add(i, win); |
| 834 | } |
| 835 | placeWindowBefore( |
| 836 | wSublayer >= 0 ? attached : w, win); |
| 837 | break; |
| 838 | } |
| 839 | } else { |
| 840 | // For positive sublayers, we go above all windows |
| 841 | // in the same sublayer. |
| 842 | if (wSublayer > sublayer) { |
| 843 | if (addToToken) { |
| 844 | token.windows.add(i, win); |
| 845 | } |
| 846 | placeWindowBefore(w, win); |
| 847 | break; |
| 848 | } |
| 849 | } |
| 850 | } |
| 851 | if (i >= NA) { |
| 852 | if (addToToken) { |
| 853 | token.windows.add(win); |
| 854 | } |
| 855 | if (sublayer < 0) { |
| 856 | placeWindowBefore(attached, win); |
| 857 | } else { |
| 858 | placeWindowAfter(largestSublayer >= 0 |
| 859 | ? windowWithLargestSublayer |
| 860 | : attached, |
| 861 | win); |
| 862 | } |
| 863 | } |
| 864 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 865 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 866 | if (win.mAppToken != null && addToToken) { |
| 867 | win.mAppToken.allAppWindows.add(win); |
| 868 | } |
| 869 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 870 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 871 | static boolean canBeImeTarget(WindowState w) { |
| 872 | final int fl = w.mAttrs.flags |
| 873 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 874 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 875 | return w.isVisibleOrAdding(); |
| 876 | } |
| 877 | return false; |
| 878 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 879 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 880 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
| 881 | final ArrayList localmWindows = mWindows; |
| 882 | final int N = localmWindows.size(); |
| 883 | WindowState w = null; |
| 884 | int i = N; |
| 885 | while (i > 0) { |
| 886 | i--; |
| 887 | w = (WindowState)localmWindows.get(i); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 888 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 889 | //Log.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
| 890 | // + Integer.toHexString(w.mAttrs.flags)); |
| 891 | if (canBeImeTarget(w)) { |
| 892 | //Log.i(TAG, "Putting input method here!"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 893 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 894 | // Yet more tricksyness! If this window is a "starting" |
| 895 | // window, we do actually want to be on top of it, but |
| 896 | // it is not -really- where input will go. So if the caller |
| 897 | // is not actually looking to move the IME, look down below |
| 898 | // for a real window to target... |
| 899 | if (!willMove |
| 900 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 901 | && i > 0) { |
| 902 | WindowState wb = (WindowState)localmWindows.get(i-1); |
| 903 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 904 | i--; |
| 905 | w = wb; |
| 906 | } |
| 907 | } |
| 908 | break; |
| 909 | } |
| 910 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 911 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 912 | mUpcomingInputMethodTarget = w; |
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 (DEBUG_INPUT_METHOD) Log.v(TAG, "Desired input method target=" |
| 915 | + w + " willMove=" + willMove); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 916 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 917 | if (willMove && w != null) { |
| 918 | final WindowState curTarget = mInputMethodTarget; |
| 919 | if (curTarget != null && curTarget.mAppToken != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 920 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 921 | // Now some fun for dealing with window animations that |
| 922 | // modify the Z order. We need to look at all windows below |
| 923 | // the current target that are in this app, finding the highest |
| 924 | // visible one in layering. |
| 925 | AppWindowToken token = curTarget.mAppToken; |
| 926 | WindowState highestTarget = null; |
| 927 | int highestPos = 0; |
| 928 | if (token.animating || token.animation != null) { |
| 929 | int pos = 0; |
| 930 | pos = localmWindows.indexOf(curTarget); |
| 931 | while (pos >= 0) { |
| 932 | WindowState win = (WindowState)localmWindows.get(pos); |
| 933 | if (win.mAppToken != token) { |
| 934 | break; |
| 935 | } |
| 936 | if (!win.mRemoved) { |
| 937 | if (highestTarget == null || win.mAnimLayer > |
| 938 | highestTarget.mAnimLayer) { |
| 939 | highestTarget = win; |
| 940 | highestPos = pos; |
| 941 | } |
| 942 | } |
| 943 | pos--; |
| 944 | } |
| 945 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 946 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 947 | if (highestTarget != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 948 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "mNextAppTransition=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 949 | + mNextAppTransition + " " + highestTarget |
| 950 | + " animating=" + highestTarget.isAnimating() |
| 951 | + " layer=" + highestTarget.mAnimLayer |
| 952 | + " new layer=" + w.mAnimLayer); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 953 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 954 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 955 | // If we are currently setting up for an animation, |
| 956 | // hold everything until we can find out what will happen. |
| 957 | mInputMethodTargetWaitingAnim = true; |
| 958 | mInputMethodTarget = highestTarget; |
| 959 | return highestPos + 1; |
| 960 | } else if (highestTarget.isAnimating() && |
| 961 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 962 | // If the window we are currently targeting is involved |
| 963 | // with an animation, and it is on top of the next target |
| 964 | // we will be over, then hold off on moving until |
| 965 | // that is done. |
| 966 | mInputMethodTarget = highestTarget; |
| 967 | return highestPos + 1; |
| 968 | } |
| 969 | } |
| 970 | } |
| 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 | //Log.i(TAG, "Placing input method @" + (i+1)); |
| 974 | if (w != null) { |
| 975 | if (willMove) { |
| 976 | RuntimeException e = new RuntimeException(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 977 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 978 | if (DEBUG_INPUT_METHOD) Log.w(TAG, "Moving IM target from " |
| 979 | + mInputMethodTarget + " to " + w, e); |
| 980 | mInputMethodTarget = w; |
| 981 | if (w.mAppToken != null) { |
| 982 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 983 | } else { |
| 984 | setInputMethodAnimLayerAdjustment(0); |
| 985 | } |
| 986 | } |
| 987 | return i+1; |
| 988 | } |
| 989 | if (willMove) { |
| 990 | RuntimeException e = new RuntimeException(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 991 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 992 | if (DEBUG_INPUT_METHOD) Log.w(TAG, "Moving IM target from " |
| 993 | + mInputMethodTarget + " to null", e); |
| 994 | mInputMethodTarget = null; |
| 995 | setInputMethodAnimLayerAdjustment(0); |
| 996 | } |
| 997 | return -1; |
| 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 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1001 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1002 | if (pos >= 0) { |
| 1003 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1004 | if (DEBUG_WINDOW_MOVEMENT) Log.v( |
| 1005 | TAG, "Adding input method window " + win + " at " + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1006 | mWindows.add(pos, win); |
| 1007 | moveInputMethodDialogsLocked(pos+1); |
| 1008 | return; |
| 1009 | } |
| 1010 | win.mTargetAppToken = null; |
| 1011 | addWindowToListInOrderLocked(win, true); |
| 1012 | moveInputMethodDialogsLocked(pos); |
| 1013 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1014 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1015 | void setInputMethodAnimLayerAdjustment(int adj) { |
| 1016 | if (DEBUG_LAYERS) Log.v(TAG, "Setting im layer adj to " + adj); |
| 1017 | mInputMethodAnimLayerAdjustment = adj; |
| 1018 | WindowState imw = mInputMethodWindow; |
| 1019 | if (imw != null) { |
| 1020 | imw.mAnimLayer = imw.mLayer + adj; |
| 1021 | if (DEBUG_LAYERS) Log.v(TAG, "IM win " + imw |
| 1022 | + " anim layer: " + imw.mAnimLayer); |
| 1023 | int wi = imw.mChildWindows.size(); |
| 1024 | while (wi > 0) { |
| 1025 | wi--; |
| 1026 | WindowState cw = (WindowState)imw.mChildWindows.get(wi); |
| 1027 | cw.mAnimLayer = cw.mLayer + adj; |
| 1028 | if (DEBUG_LAYERS) Log.v(TAG, "IM win " + cw |
| 1029 | + " anim layer: " + cw.mAnimLayer); |
| 1030 | } |
| 1031 | } |
| 1032 | int di = mInputMethodDialogs.size(); |
| 1033 | while (di > 0) { |
| 1034 | di --; |
| 1035 | imw = mInputMethodDialogs.get(di); |
| 1036 | imw.mAnimLayer = imw.mLayer + adj; |
| 1037 | if (DEBUG_LAYERS) Log.v(TAG, "IM win " + imw |
| 1038 | + " anim layer: " + imw.mAnimLayer); |
| 1039 | } |
| 1040 | } |
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 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1043 | int wpos = mWindows.indexOf(win); |
| 1044 | if (wpos >= 0) { |
| 1045 | if (wpos < interestingPos) interestingPos--; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1046 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Temp removing at " + wpos + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1047 | mWindows.remove(wpos); |
| 1048 | int NC = win.mChildWindows.size(); |
| 1049 | while (NC > 0) { |
| 1050 | NC--; |
| 1051 | WindowState cw = (WindowState)win.mChildWindows.get(NC); |
| 1052 | int cpos = mWindows.indexOf(cw); |
| 1053 | if (cpos >= 0) { |
| 1054 | if (cpos < interestingPos) interestingPos--; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1055 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Temp removing child at " |
| 1056 | + cpos + ": " + cw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1057 | mWindows.remove(cpos); |
| 1058 | } |
| 1059 | } |
| 1060 | } |
| 1061 | return interestingPos; |
| 1062 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1063 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1064 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1065 | addWindowToListInOrderLocked(win, false); |
| 1066 | // This is a hack to get all of the child windows added as well |
| 1067 | // at the right position. Child windows should be rare and |
| 1068 | // this case should be rare, so it shouldn't be that big a deal. |
| 1069 | int wpos = mWindows.indexOf(win); |
| 1070 | if (wpos >= 0) { |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1071 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "ReAdd removing from " + wpos |
| 1072 | + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1073 | mWindows.remove(wpos); |
| 1074 | reAddWindowLocked(wpos, win); |
| 1075 | } |
| 1076 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1077 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1078 | void logWindowList(String prefix) { |
| 1079 | int N = mWindows.size(); |
| 1080 | while (N > 0) { |
| 1081 | N--; |
| 1082 | Log.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
| 1083 | } |
| 1084 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1085 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1086 | void moveInputMethodDialogsLocked(int pos) { |
| 1087 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1088 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1089 | final int N = dialogs.size(); |
| 1090 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Removing " + N + " dialogs w/pos=" + pos); |
| 1091 | for (int i=0; i<N; i++) { |
| 1092 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1093 | } |
| 1094 | if (DEBUG_INPUT_METHOD) { |
| 1095 | Log.v(TAG, "Window list w/pos=" + pos); |
| 1096 | logWindowList(" "); |
| 1097 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1098 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1099 | if (pos >= 0) { |
| 1100 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1101 | if (pos < mWindows.size()) { |
| 1102 | WindowState wp = (WindowState)mWindows.get(pos); |
| 1103 | if (wp == mInputMethodWindow) { |
| 1104 | pos++; |
| 1105 | } |
| 1106 | } |
| 1107 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Adding " + N + " dialogs at pos=" + pos); |
| 1108 | for (int i=0; i<N; i++) { |
| 1109 | WindowState win = dialogs.get(i); |
| 1110 | win.mTargetAppToken = targetAppToken; |
| 1111 | pos = reAddWindowLocked(pos, win); |
| 1112 | } |
| 1113 | if (DEBUG_INPUT_METHOD) { |
| 1114 | Log.v(TAG, "Final window list:"); |
| 1115 | logWindowList(" "); |
| 1116 | } |
| 1117 | return; |
| 1118 | } |
| 1119 | for (int i=0; i<N; i++) { |
| 1120 | WindowState win = dialogs.get(i); |
| 1121 | win.mTargetAppToken = null; |
| 1122 | reAddWindowToListInOrderLocked(win); |
| 1123 | if (DEBUG_INPUT_METHOD) { |
| 1124 | Log.v(TAG, "No IM target, final list:"); |
| 1125 | logWindowList(" "); |
| 1126 | } |
| 1127 | } |
| 1128 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1129 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1130 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1131 | final WindowState imWin = mInputMethodWindow; |
| 1132 | final int DN = mInputMethodDialogs.size(); |
| 1133 | if (imWin == null && DN == 0) { |
| 1134 | return false; |
| 1135 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1136 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1137 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1138 | if (imPos >= 0) { |
| 1139 | // In this case, the input method windows are to be placed |
| 1140 | // immediately above the window they are targeting. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1141 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1142 | // First check to see if the input method windows are already |
| 1143 | // located here, and contiguous. |
| 1144 | final int N = mWindows.size(); |
| 1145 | WindowState firstImWin = imPos < N |
| 1146 | ? (WindowState)mWindows.get(imPos) : null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1147 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1148 | // Figure out the actual input method window that should be |
| 1149 | // at the bottom of their stack. |
| 1150 | WindowState baseImWin = imWin != null |
| 1151 | ? imWin : mInputMethodDialogs.get(0); |
| 1152 | if (baseImWin.mChildWindows.size() > 0) { |
| 1153 | WindowState cw = (WindowState)baseImWin.mChildWindows.get(0); |
| 1154 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1155 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1156 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1157 | if (firstImWin == baseImWin) { |
| 1158 | // The windows haven't moved... but are they still contiguous? |
| 1159 | // First find the top IM window. |
| 1160 | int pos = imPos+1; |
| 1161 | while (pos < N) { |
| 1162 | if (!((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1163 | break; |
| 1164 | } |
| 1165 | pos++; |
| 1166 | } |
| 1167 | pos++; |
| 1168 | // Now there should be no more input method windows above. |
| 1169 | while (pos < N) { |
| 1170 | if (((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1171 | break; |
| 1172 | } |
| 1173 | pos++; |
| 1174 | } |
| 1175 | if (pos >= N) { |
| 1176 | // All is good! |
| 1177 | return false; |
| 1178 | } |
| 1179 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1180 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1181 | if (imWin != null) { |
| 1182 | if (DEBUG_INPUT_METHOD) { |
| 1183 | Log.v(TAG, "Moving IM from " + imPos); |
| 1184 | logWindowList(" "); |
| 1185 | } |
| 1186 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1187 | if (DEBUG_INPUT_METHOD) { |
| 1188 | Log.v(TAG, "List after moving with new pos " + imPos + ":"); |
| 1189 | logWindowList(" "); |
| 1190 | } |
| 1191 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1192 | reAddWindowLocked(imPos, imWin); |
| 1193 | if (DEBUG_INPUT_METHOD) { |
| 1194 | Log.v(TAG, "List after moving IM to " + imPos + ":"); |
| 1195 | logWindowList(" "); |
| 1196 | } |
| 1197 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1198 | } else { |
| 1199 | moveInputMethodDialogsLocked(imPos); |
| 1200 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1201 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1202 | } else { |
| 1203 | // In this case, the input method windows go in a fixed layer, |
| 1204 | // because they aren't currently associated with a focus window. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1205 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1206 | if (imWin != null) { |
| 1207 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Moving IM from " + imPos); |
| 1208 | tmpRemoveWindowLocked(0, imWin); |
| 1209 | imWin.mTargetAppToken = null; |
| 1210 | reAddWindowToListInOrderLocked(imWin); |
| 1211 | if (DEBUG_INPUT_METHOD) { |
| 1212 | Log.v(TAG, "List with no IM target:"); |
| 1213 | logWindowList(" "); |
| 1214 | } |
| 1215 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1216 | } else { |
| 1217 | moveInputMethodDialogsLocked(-1);; |
| 1218 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1219 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1220 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1221 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1222 | if (needAssignLayers) { |
| 1223 | assignLayersLocked(); |
| 1224 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1225 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1226 | return true; |
| 1227 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1228 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1229 | void adjustInputMethodDialogsLocked() { |
| 1230 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1231 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1232 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1233 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
| 1234 | if (DEBUG_WALLPAPER) Log.v(TAG, "Wallpaper vis: target obscured=" |
| 1235 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1236 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1237 | ? wallpaperTarget.mAppToken.animation : null) |
| 1238 | + " upper=" + mUpperWallpaperTarget |
| 1239 | + " lower=" + mLowerWallpaperTarget); |
| 1240 | return (wallpaperTarget != null |
| 1241 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1242 | && wallpaperTarget.mAppToken.animation != null))) |
| 1243 | || mUpperWallpaperTarget != null |
| 1244 | || mLowerWallpaperTarget != null; |
| 1245 | } |
| 1246 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1247 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1248 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
| 1249 | |
| 1250 | int adjustWallpaperWindowsLocked() { |
| 1251 | int changed = 0; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1252 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1253 | final int dw = mDisplay.getWidth(); |
| 1254 | final int dh = mDisplay.getHeight(); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1255 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1256 | // First find top-most window that has asked to be on top of the |
| 1257 | // wallpaper; all wallpapers go behind it. |
| 1258 | final ArrayList localmWindows = mWindows; |
| 1259 | int N = localmWindows.size(); |
| 1260 | WindowState w = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1261 | WindowState foundW = null; |
| 1262 | int foundI = 0; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1263 | WindowState topCurW = null; |
| 1264 | int topCurI = 0; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1265 | int i = N; |
| 1266 | while (i > 0) { |
| 1267 | i--; |
| 1268 | w = (WindowState)localmWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1269 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1270 | if (topCurW == null) { |
| 1271 | topCurW = w; |
| 1272 | topCurI = i; |
| 1273 | } |
| 1274 | continue; |
| 1275 | } |
| 1276 | topCurW = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1277 | if (w.mAppToken != null) { |
| 1278 | // If this window's app token is hidden and not animating, |
| 1279 | // it is of no interest to us. |
| 1280 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
| 1281 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 1282 | "Skipping hidden or animating token: " + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1283 | topCurW = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1284 | continue; |
| 1285 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1286 | } |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1287 | if (DEBUG_WALLPAPER) Log.v(TAG, "Win " + w + ": readyfordisplay=" |
| 1288 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1289 | + " commitdrawpending=" + w.mCommitDrawPending); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1290 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1291 | && (mWallpaperTarget == w |
| 1292 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1293 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 1294 | "Found wallpaper activity: #" + i + "=" + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1295 | foundW = w; |
| 1296 | foundI = i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1297 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1298 | && w.mAppToken.animation != null) |
| 1299 | || w.mAnimation != null)) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1300 | // The current wallpaper target is animating, so we'll |
| 1301 | // look behind it for another possible target and figure |
| 1302 | // out what is going on below. |
| 1303 | if (DEBUG_WALLPAPER) Log.v(TAG, "Win " + w |
| 1304 | + ": token animating, looking behind."); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1305 | continue; |
| 1306 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1307 | break; |
| 1308 | } |
| 1309 | } |
| 1310 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1311 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1312 | // If we are currently waiting for an app transition, and either |
| 1313 | // the current target or the next target are involved with it, |
| 1314 | // then hold off on doing anything with the wallpaper. |
| 1315 | // Note that we are checking here for just whether the target |
| 1316 | // is part of an app token... which is potentially overly aggressive |
| 1317 | // (the app token may not be involved in the transition), but good |
| 1318 | // enough (we'll just wait until whatever transition is pending |
| 1319 | // executes). |
| 1320 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1321 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 1322 | "Wallpaper not changing: waiting for app anim in current target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1323 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1324 | } |
| 1325 | if (foundW != null && foundW.mAppToken != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1326 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 1327 | "Wallpaper not changing: waiting for app anim in found target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1328 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1329 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1330 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1331 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1332 | if (mWallpaperTarget != foundW) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1333 | if (DEBUG_WALLPAPER) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1334 | Log.v(TAG, "New wallpaper target: " + foundW |
| 1335 | + " oldTarget: " + mWallpaperTarget); |
| 1336 | } |
| 1337 | |
| 1338 | mLowerWallpaperTarget = null; |
| 1339 | mUpperWallpaperTarget = null; |
| 1340 | |
| 1341 | WindowState oldW = mWallpaperTarget; |
| 1342 | mWallpaperTarget = foundW; |
| 1343 | |
| 1344 | // Now what is happening... if the current and new targets are |
| 1345 | // animating, then we are in our super special mode! |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1346 | if (foundW != null && oldW != null) { |
| 1347 | boolean oldAnim = oldW.mAnimation != null |
| 1348 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1349 | boolean foundAnim = foundW.mAnimation != null |
| 1350 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1351 | if (DEBUG_WALLPAPER) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1352 | Log.v(TAG, "New animation: " + foundAnim |
| 1353 | + " old animation: " + oldAnim); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1354 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1355 | if (foundAnim && oldAnim) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1356 | int oldI = localmWindows.indexOf(oldW); |
| 1357 | if (DEBUG_WALLPAPER) { |
| 1358 | Log.v(TAG, "New i: " + foundI + " old i: " + oldI); |
| 1359 | } |
| 1360 | if (oldI >= 0) { |
| 1361 | if (DEBUG_WALLPAPER) { |
| 1362 | Log.v(TAG, "Animating wallpapers: old#" + oldI |
| 1363 | + "=" + oldW + "; new#" + foundI |
| 1364 | + "=" + foundW); |
| 1365 | } |
| 1366 | |
| 1367 | // Set the new target correctly. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1368 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1369 | if (DEBUG_WALLPAPER) { |
| 1370 | Log.v(TAG, "Old wallpaper still the target."); |
| 1371 | } |
| 1372 | mWallpaperTarget = oldW; |
| 1373 | } |
| 1374 | |
| 1375 | // Now set the upper and lower wallpaper targets |
| 1376 | // correctly, and make sure that we are positioning |
| 1377 | // the wallpaper below the lower. |
| 1378 | if (foundI > oldI) { |
| 1379 | // The new target is on top of the old one. |
| 1380 | if (DEBUG_WALLPAPER) { |
| 1381 | Log.v(TAG, "Found target above old target."); |
| 1382 | } |
| 1383 | mUpperWallpaperTarget = foundW; |
| 1384 | mLowerWallpaperTarget = oldW; |
| 1385 | foundW = oldW; |
| 1386 | foundI = oldI; |
| 1387 | } else { |
| 1388 | // The new target is below the old one. |
| 1389 | if (DEBUG_WALLPAPER) { |
| 1390 | Log.v(TAG, "Found target below old target."); |
| 1391 | } |
| 1392 | mUpperWallpaperTarget = oldW; |
| 1393 | mLowerWallpaperTarget = foundW; |
| 1394 | } |
| 1395 | } |
| 1396 | } |
| 1397 | } |
| 1398 | |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1399 | } else if (mLowerWallpaperTarget != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1400 | // Is it time to stop animating? |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1401 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1402 | || (mLowerWallpaperTarget.mAppToken != null |
| 1403 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1404 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1405 | || (mUpperWallpaperTarget.mAppToken != null |
| 1406 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1407 | if (!lowerAnimating || !upperAnimating) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1408 | if (DEBUG_WALLPAPER) { |
| 1409 | Log.v(TAG, "No longer animating wallpaper targets!"); |
| 1410 | } |
| 1411 | mLowerWallpaperTarget = null; |
| 1412 | mUpperWallpaperTarget = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1413 | } |
| 1414 | } |
| 1415 | |
| 1416 | boolean visible = foundW != null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1417 | if (visible) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1418 | // The window is visible to the compositor... but is it visible |
| 1419 | // to the user? That is what the wallpaper cares about. |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1420 | visible = isWallpaperVisible(foundW); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1421 | if (DEBUG_WALLPAPER) Log.v(TAG, "Wallpaper visibility: " + visible); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1422 | |
| 1423 | // If the wallpaper target is animating, we may need to copy |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1424 | // its layer adjustment. Only do this if we are not transfering |
| 1425 | // between two wallpaper targets. |
| 1426 | mWallpaperAnimLayerAdjustment = |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1427 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1428 | ? foundW.mAppToken.animLayerAdjustment : 0; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1429 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1430 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1431 | * TYPE_LAYER_MULTIPLIER |
| 1432 | + TYPE_LAYER_OFFSET; |
| 1433 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1434 | // Now w is the window we are supposed to be behind... but we |
| 1435 | // need to be sure to also be behind any of its attached windows, |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1436 | // AND any starting window associated with it, AND below the |
| 1437 | // maximum layer the policy allows for wallpapers. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1438 | while (foundI > 0) { |
| 1439 | WindowState wb = (WindowState)localmWindows.get(foundI-1); |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1440 | if (wb.mBaseLayer < maxLayer && |
| 1441 | wb.mAttachedWindow != foundW && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1442 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1443 | wb.mToken != foundW.mToken)) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1444 | // This window is not related to the previous one in any |
| 1445 | // interesting way, so stop here. |
| 1446 | break; |
| 1447 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1448 | foundW = wb; |
| 1449 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1450 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1451 | } else { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1452 | if (DEBUG_WALLPAPER) Log.v(TAG, "No wallpaper target"); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1453 | } |
| 1454 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1455 | if (foundW == null && topCurW != null) { |
| 1456 | // There is no wallpaper target, so it goes at the bottom. |
| 1457 | // We will assume it is the same place as last time, if known. |
| 1458 | foundW = topCurW; |
| 1459 | foundI = topCurI+1; |
| 1460 | } else { |
| 1461 | // Okay i is the position immediately above the wallpaper. Look at |
| 1462 | // what is below it for later. |
| 1463 | foundW = foundI > 0 ? (WindowState)localmWindows.get(foundI-1) : null; |
| 1464 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1465 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1466 | if (visible) { |
| 1467 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
| 1468 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
| 1469 | } |
| 1470 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1471 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1472 | // are correctly placed. |
| 1473 | int curTokenIndex = mWallpaperTokens.size(); |
| 1474 | while (curTokenIndex > 0) { |
| 1475 | curTokenIndex--; |
| 1476 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1477 | if (token.hidden == visible) { |
| 1478 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1479 | token.hidden = !visible; |
| 1480 | // Need to do a layout to ensure the wallpaper now has the |
| 1481 | // correct size. |
| 1482 | mLayoutNeeded = true; |
| 1483 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1484 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1485 | int curWallpaperIndex = token.windows.size(); |
| 1486 | while (curWallpaperIndex > 0) { |
| 1487 | curWallpaperIndex--; |
| 1488 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1489 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1490 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1491 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1492 | } |
| 1493 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1494 | // First, make sure the client has the current visibility |
| 1495 | // state. |
| 1496 | if (wallpaper.mWallpaperVisible != visible) { |
| 1497 | wallpaper.mWallpaperVisible = visible; |
| 1498 | try { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1499 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Log.v(TAG, |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1500 | "Setting visibility of wallpaper " + wallpaper |
| 1501 | + ": " + visible); |
| 1502 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1503 | } catch (RemoteException e) { |
| 1504 | } |
| 1505 | } |
| 1506 | |
| 1507 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1508 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Log.v(TAG, "Wallpaper win " |
| 1509 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1510 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1511 | // First, if this window is at the current index, then all |
| 1512 | // is well. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1513 | if (wallpaper == foundW) { |
| 1514 | foundI--; |
| 1515 | foundW = foundI > 0 |
| 1516 | ? (WindowState)localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1517 | continue; |
| 1518 | } |
| 1519 | |
| 1520 | // The window didn't match... the current wallpaper window, |
| 1521 | // wherever it is, is in the wrong place, so make sure it is |
| 1522 | // not in the list. |
| 1523 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1524 | if (oldIndex >= 0) { |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1525 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Wallpaper removing at " |
| 1526 | + oldIndex + ": " + wallpaper); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1527 | localmWindows.remove(oldIndex); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1528 | if (oldIndex < foundI) { |
| 1529 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1530 | } |
| 1531 | } |
| 1532 | |
| 1533 | // Now stick it in. |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1534 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Log.v(TAG, |
| 1535 | "Moving wallpaper " + wallpaper |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1536 | + " from " + oldIndex + " to " + foundI); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1537 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1538 | localmWindows.add(foundI, wallpaper); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1539 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1540 | } |
| 1541 | } |
| 1542 | |
| 1543 | return changed; |
| 1544 | } |
| 1545 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1546 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1547 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Log.v(TAG, |
| 1548 | "Setting wallpaper layer adj to " + adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1549 | mWallpaperAnimLayerAdjustment = adj; |
| 1550 | int curTokenIndex = mWallpaperTokens.size(); |
| 1551 | while (curTokenIndex > 0) { |
| 1552 | curTokenIndex--; |
| 1553 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1554 | int curWallpaperIndex = token.windows.size(); |
| 1555 | while (curWallpaperIndex > 0) { |
| 1556 | curWallpaperIndex--; |
| 1557 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1558 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1559 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Log.v(TAG, "Wallpaper win " |
| 1560 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1561 | } |
| 1562 | } |
| 1563 | } |
| 1564 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1565 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 1566 | boolean sync) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1567 | boolean changed = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1568 | boolean rawChanged = false; |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1569 | if (mLastWallpaperX >= 0) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1570 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1571 | int offset = availw > 0 ? -(int)(availw*mLastWallpaperX+.5f) : 0; |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1572 | changed = wallpaperWin.mXOffset != offset; |
| 1573 | if (changed) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1574 | if (DEBUG_WALLPAPER) Log.v(TAG, "Update wallpaper " |
| 1575 | + wallpaperWin + " x: " + offset); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1576 | wallpaperWin.mXOffset = offset; |
| 1577 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1578 | if (wallpaperWin.mWallpaperX != mLastWallpaperX) { |
| 1579 | wallpaperWin.mWallpaperX = mLastWallpaperX; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1580 | rawChanged = true; |
| 1581 | } |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1582 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1583 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1584 | if (mLastWallpaperY >= 0) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1585 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1586 | int offset = availh > 0 ? -(int)(availh*mLastWallpaperY+.5f) : 0; |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1587 | if (wallpaperWin.mYOffset != offset) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1588 | if (DEBUG_WALLPAPER) Log.v(TAG, "Update wallpaper " |
| 1589 | + wallpaperWin + " y: " + offset); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1590 | changed = true; |
| 1591 | wallpaperWin.mYOffset = offset; |
| 1592 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1593 | if (wallpaperWin.mWallpaperY != mLastWallpaperY) { |
| 1594 | wallpaperWin.mWallpaperY = mLastWallpaperY; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1595 | rawChanged = true; |
| 1596 | } |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1597 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1598 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1599 | if (rawChanged) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1600 | try { |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1601 | if (DEBUG_WALLPAPER) Log.v(TAG, "Report new wp offset " |
| 1602 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 1603 | + " y=" + wallpaperWin.mWallpaperY); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1604 | if (sync) { |
| 1605 | synchronized (mWaitingOnWallpaperLock) { |
| 1606 | mWaitingOnWallpaper = wallpaperWin; |
| 1607 | } |
| 1608 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1609 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1610 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, sync); |
| 1611 | if (sync) { |
| 1612 | synchronized (mWaitingOnWallpaperLock) { |
| 1613 | if (mWaitingOnWallpaper != null) { |
| 1614 | long start = SystemClock.uptimeMillis(); |
| 1615 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 1616 | < start) { |
| 1617 | try { |
| 1618 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 1619 | "Waiting for offset complete..."); |
| 1620 | mWaitingOnWallpaperLock.wait(WALLPAPER_TIMEOUT); |
| 1621 | } catch (InterruptedException e) { |
| 1622 | } |
| 1623 | if (DEBUG_WALLPAPER) Log.v(TAG, "Offset complete!"); |
| 1624 | if ((start+WALLPAPER_TIMEOUT) |
| 1625 | < SystemClock.uptimeMillis()) { |
| 1626 | Log.i(TAG, "Timeout waiting for wallpaper to offset: " |
| 1627 | + wallpaperWin); |
| 1628 | mLastWallpaperTimeoutTime = start; |
| 1629 | } |
| 1630 | } |
| 1631 | mWaitingOnWallpaper = null; |
| 1632 | } |
| 1633 | } |
| 1634 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1635 | } catch (RemoteException e) { |
| 1636 | } |
| 1637 | } |
| 1638 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1639 | return changed; |
| 1640 | } |
| 1641 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1642 | void wallpaperOffsetsComplete(IBinder window) { |
| 1643 | synchronized (mWaitingOnWallpaperLock) { |
| 1644 | if (mWaitingOnWallpaper != null && |
| 1645 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 1646 | mWaitingOnWallpaper = null; |
| 1647 | mWaitingOnWallpaperLock.notifyAll(); |
| 1648 | } |
| 1649 | } |
| 1650 | } |
| 1651 | |
| 1652 | boolean updateWallpaperOffsetLocked(boolean sync) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1653 | final int dw = mDisplay.getWidth(); |
| 1654 | final int dh = mDisplay.getHeight(); |
| 1655 | |
| 1656 | boolean changed = false; |
| 1657 | |
| 1658 | WindowState target = mWallpaperTarget; |
| 1659 | if (target != null) { |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1660 | mLastWallpaperX = target.mWallpaperX; |
| 1661 | mLastWallpaperY = target.mWallpaperY; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1662 | int curTokenIndex = mWallpaperTokens.size(); |
| 1663 | while (curTokenIndex > 0) { |
| 1664 | curTokenIndex--; |
| 1665 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1666 | int curWallpaperIndex = token.windows.size(); |
| 1667 | while (curWallpaperIndex > 0) { |
| 1668 | curWallpaperIndex--; |
| 1669 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1670 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1671 | wallpaper.computeShownFrameLocked(); |
| 1672 | changed = true; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1673 | // We only want to be synchronous with one wallpaper. |
| 1674 | sync = false; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1675 | } |
| 1676 | } |
| 1677 | } |
| 1678 | } |
| 1679 | |
| 1680 | return changed; |
| 1681 | } |
| 1682 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1683 | void updateWallpaperVisibilityLocked() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1684 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1685 | final int dw = mDisplay.getWidth(); |
| 1686 | final int dh = mDisplay.getHeight(); |
| 1687 | |
| 1688 | int curTokenIndex = mWallpaperTokens.size(); |
| 1689 | while (curTokenIndex > 0) { |
| 1690 | curTokenIndex--; |
| 1691 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1692 | if (token.hidden == visible) { |
| 1693 | token.hidden = !visible; |
| 1694 | // Need to do a layout to ensure the wallpaper now has the |
| 1695 | // correct size. |
| 1696 | mLayoutNeeded = true; |
| 1697 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1698 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1699 | int curWallpaperIndex = token.windows.size(); |
| 1700 | while (curWallpaperIndex > 0) { |
| 1701 | curWallpaperIndex--; |
| 1702 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1703 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1704 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1705 | } |
| 1706 | |
| 1707 | if (wallpaper.mWallpaperVisible != visible) { |
| 1708 | wallpaper.mWallpaperVisible = visible; |
| 1709 | try { |
| 1710 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Log.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1711 | "Updating visibility of wallpaper " + wallpaper |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1712 | + ": " + visible); |
| 1713 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1714 | } catch (RemoteException e) { |
| 1715 | } |
| 1716 | } |
| 1717 | } |
| 1718 | } |
| 1719 | } |
| 1720 | |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1721 | void sendPointerToWallpaperLocked(WindowState srcWin, |
| 1722 | MotionEvent pointer, long eventTime) { |
| 1723 | int curTokenIndex = mWallpaperTokens.size(); |
| 1724 | while (curTokenIndex > 0) { |
| 1725 | curTokenIndex--; |
| 1726 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1727 | int curWallpaperIndex = token.windows.size(); |
| 1728 | while (curWallpaperIndex > 0) { |
| 1729 | curWallpaperIndex--; |
| 1730 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1731 | if ((wallpaper.mAttrs.flags & |
| 1732 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 1733 | continue; |
| 1734 | } |
| 1735 | try { |
| 1736 | MotionEvent ev = MotionEvent.obtainNoHistory(pointer); |
| 1737 | ev.offsetLocation(srcWin.mFrame.left-wallpaper.mFrame.left, |
| 1738 | srcWin.mFrame.top-wallpaper.mFrame.top); |
| 1739 | wallpaper.mClient.dispatchPointer(ev, eventTime, false); |
| 1740 | } catch (RemoteException e) { |
| 1741 | Log.w(TAG, "Failure sending pointer to wallpaper", e); |
| 1742 | } |
| 1743 | } |
| 1744 | } |
| 1745 | } |
| 1746 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1747 | public int addWindow(Session session, IWindow client, |
| 1748 | WindowManager.LayoutParams attrs, int viewVisibility, |
| 1749 | Rect outContentInsets) { |
| 1750 | int res = mPolicy.checkAddPermission(attrs); |
| 1751 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1752 | return res; |
| 1753 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1754 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1755 | boolean reportNewConfig = false; |
| 1756 | WindowState attachedWindow = null; |
| 1757 | WindowState win = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1758 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1759 | synchronized(mWindowMap) { |
| 1760 | // Instantiating a Display requires talking with the simulator, |
| 1761 | // so don't do it until we know the system is mostly up and |
| 1762 | // running. |
| 1763 | if (mDisplay == null) { |
| 1764 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 1765 | mDisplay = wm.getDefaultDisplay(); |
| 1766 | mQueue.setDisplay(mDisplay); |
| 1767 | reportNewConfig = true; |
| 1768 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1769 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1770 | if (mWindowMap.containsKey(client.asBinder())) { |
| 1771 | Log.w(TAG, "Window " + client + " is already added"); |
| 1772 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 1773 | } |
| 1774 | |
| 1775 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1776 | attachedWindow = windowForClientLocked(null, attrs.token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1777 | if (attachedWindow == null) { |
| 1778 | Log.w(TAG, "Attempted to add window with token that is not a window: " |
| 1779 | + attrs.token + ". Aborting."); |
| 1780 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1781 | } |
| 1782 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 1783 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
| 1784 | Log.w(TAG, "Attempted to add window with token that is a sub-window: " |
| 1785 | + attrs.token + ". Aborting."); |
| 1786 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1787 | } |
| 1788 | } |
| 1789 | |
| 1790 | boolean addToken = false; |
| 1791 | WindowToken token = mTokenMap.get(attrs.token); |
| 1792 | if (token == null) { |
| 1793 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1794 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1795 | Log.w(TAG, "Attempted to add application window with unknown token " |
| 1796 | + attrs.token + ". Aborting."); |
| 1797 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1798 | } |
| 1799 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 1800 | Log.w(TAG, "Attempted to add input method window with unknown token " |
| 1801 | + attrs.token + ". Aborting."); |
| 1802 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1803 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1804 | if (attrs.type == TYPE_WALLPAPER) { |
| 1805 | Log.w(TAG, "Attempted to add wallpaper window with unknown token " |
| 1806 | + attrs.token + ". Aborting."); |
| 1807 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1808 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1809 | token = new WindowToken(attrs.token, -1, false); |
| 1810 | addToken = true; |
| 1811 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1812 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1813 | AppWindowToken atoken = token.appWindowToken; |
| 1814 | if (atoken == null) { |
| 1815 | Log.w(TAG, "Attempted to add window with non-application token " |
| 1816 | + token + ". Aborting."); |
| 1817 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 1818 | } else if (atoken.removed) { |
| 1819 | Log.w(TAG, "Attempted to add window with exiting application token " |
| 1820 | + token + ". Aborting."); |
| 1821 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1822 | } |
| 1823 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 1824 | // No need for this guy! |
| 1825 | if (localLOGV) Log.v( |
| 1826 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 1827 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 1828 | } |
| 1829 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 1830 | if (token.windowType != TYPE_INPUT_METHOD) { |
| 1831 | Log.w(TAG, "Attempted to add input method window with bad token " |
| 1832 | + attrs.token + ". Aborting."); |
| 1833 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1834 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1835 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 1836 | if (token.windowType != TYPE_WALLPAPER) { |
| 1837 | Log.w(TAG, "Attempted to add wallpaper window with bad token " |
| 1838 | + attrs.token + ". Aborting."); |
| 1839 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1840 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1841 | } |
| 1842 | |
| 1843 | win = new WindowState(session, client, token, |
| 1844 | attachedWindow, attrs, viewVisibility); |
| 1845 | if (win.mDeathRecipient == null) { |
| 1846 | // Client has apparently died, so there is no reason to |
| 1847 | // continue. |
| 1848 | Log.w(TAG, "Adding window client " + client.asBinder() |
| 1849 | + " that is dead, aborting."); |
| 1850 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1851 | } |
| 1852 | |
| 1853 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1854 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1855 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 1856 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1857 | return res; |
| 1858 | } |
| 1859 | |
| 1860 | // From now on, no exceptions or errors allowed! |
| 1861 | |
| 1862 | res = WindowManagerImpl.ADD_OKAY; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1863 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1864 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1865 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1866 | if (addToken) { |
| 1867 | mTokenMap.put(attrs.token, token); |
| 1868 | mTokenList.add(token); |
| 1869 | } |
| 1870 | win.attach(); |
| 1871 | mWindowMap.put(client.asBinder(), win); |
| 1872 | |
| 1873 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 1874 | token.appWindowToken != null) { |
| 1875 | token.appWindowToken.startingWindow = win; |
| 1876 | } |
| 1877 | |
| 1878 | boolean imMayMove = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1879 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1880 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 1881 | mInputMethodWindow = win; |
| 1882 | addInputMethodWindowToListLocked(win); |
| 1883 | imMayMove = false; |
| 1884 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 1885 | mInputMethodDialogs.add(win); |
| 1886 | addWindowToListInOrderLocked(win, true); |
| 1887 | adjustInputMethodDialogsLocked(); |
| 1888 | imMayMove = false; |
| 1889 | } else { |
| 1890 | addWindowToListInOrderLocked(win, true); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1891 | if (attrs.type == TYPE_WALLPAPER) { |
| 1892 | mLastWallpaperTimeoutTime = 0; |
| 1893 | adjustWallpaperWindowsLocked(); |
| 1894 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1895 | adjustWallpaperWindowsLocked(); |
| 1896 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1897 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1898 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1899 | win.mEnterAnimationPending = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1900 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1901 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1902 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1903 | if (mInTouchMode) { |
| 1904 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 1905 | } |
| 1906 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 1907 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 1908 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1909 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1910 | boolean focusChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1911 | if (win.canReceiveKeys()) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1912 | if ((focusChanged=updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS)) |
| 1913 | == true) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1914 | imMayMove = false; |
| 1915 | } |
| 1916 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1917 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1918 | if (imMayMove) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1919 | moveInputMethodWindowsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1920 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1921 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1922 | assignLayersLocked(); |
| 1923 | // Don't do layout here, the window must call |
| 1924 | // relayout to be displayed, so we'll do it there. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1925 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1926 | //dump(); |
| 1927 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1928 | if (focusChanged) { |
| 1929 | if (mCurrentFocus != null) { |
| 1930 | mKeyWaiter.handleNewWindowLocked(mCurrentFocus); |
| 1931 | } |
| 1932 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1933 | if (localLOGV) Log.v( |
| 1934 | TAG, "New client " + client.asBinder() |
| 1935 | + ": window=" + win); |
| 1936 | } |
| 1937 | |
| 1938 | // sendNewConfiguration() checks caller permissions so we must call it with |
| 1939 | // privilege. updateOrientationFromAppTokens() clears and resets the caller |
| 1940 | // identity anyway, so it's safe to just clear & restore around this whole |
| 1941 | // block. |
| 1942 | final long origId = Binder.clearCallingIdentity(); |
| 1943 | if (reportNewConfig) { |
| 1944 | sendNewConfiguration(); |
| 1945 | } else { |
| 1946 | // Update Orientation after adding a window, only if the window needs to be |
| 1947 | // displayed right away |
| 1948 | if (win.isVisibleOrAdding()) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 1949 | if (updateOrientationFromAppTokensUnchecked(null, null) != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1950 | sendNewConfiguration(); |
| 1951 | } |
| 1952 | } |
| 1953 | } |
| 1954 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1955 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1956 | return res; |
| 1957 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1958 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1959 | public void removeWindow(Session session, IWindow client) { |
| 1960 | synchronized(mWindowMap) { |
| 1961 | WindowState win = windowForClientLocked(session, client); |
| 1962 | if (win == null) { |
| 1963 | return; |
| 1964 | } |
| 1965 | removeWindowLocked(session, win); |
| 1966 | } |
| 1967 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1968 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1969 | public void removeWindowLocked(Session session, WindowState win) { |
| 1970 | |
| 1971 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 1972 | TAG, "Remove " + win + " client=" |
| 1973 | + Integer.toHexString(System.identityHashCode( |
| 1974 | win.mClient.asBinder())) |
| 1975 | + ", surface=" + win.mSurface); |
| 1976 | |
| 1977 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1978 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1979 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 1980 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 1981 | + " mExiting=" + win.mExiting |
| 1982 | + " isAnimating=" + win.isAnimating() |
| 1983 | + " app-animation=" |
| 1984 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 1985 | + " inPendingTransaction=" |
| 1986 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 1987 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 1988 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 1989 | boolean wasVisible = false; |
| 1990 | // First, see if we need to run an animation. If we do, we have |
| 1991 | // to hold off on removing the window until the animation is done. |
| 1992 | // If the display is frozen, just remove immediately, since the |
| 1993 | // animation wouldn't be seen. |
| 1994 | if (win.mSurface != null && !mDisplayFrozen) { |
| 1995 | // If we are not currently running the exit animation, we |
| 1996 | // need to see about starting one. |
| 1997 | if (wasVisible=win.isWinVisibleLw()) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1998 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1999 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2000 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2001 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2002 | } |
| 2003 | // Try starting an animation. |
| 2004 | if (applyAnimationLocked(win, transit, false)) { |
| 2005 | win.mExiting = true; |
| 2006 | } |
| 2007 | } |
| 2008 | if (win.mExiting || win.isAnimating()) { |
| 2009 | // The exit animation is running... wait for it! |
| 2010 | //Log.i(TAG, "*** Running exit animation..."); |
| 2011 | win.mExiting = true; |
| 2012 | win.mRemoveOnExit = true; |
| 2013 | mLayoutNeeded = true; |
| 2014 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 2015 | performLayoutAndPlaceSurfacesLocked(); |
| 2016 | if (win.mAppToken != null) { |
| 2017 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2018 | } |
| 2019 | //dump(); |
| 2020 | Binder.restoreCallingIdentity(origId); |
| 2021 | return; |
| 2022 | } |
| 2023 | } |
| 2024 | |
| 2025 | removeWindowInnerLocked(session, win); |
| 2026 | // Removing a visible window will effect the computed orientation |
| 2027 | // So just update orientation if needed. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2028 | if (wasVisible && computeForcedAppOrientationLocked() |
| 2029 | != mForcedAppOrientation) { |
| 2030 | 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] | 2031 | } |
| 2032 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2033 | Binder.restoreCallingIdentity(origId); |
| 2034 | } |
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 | private void removeWindowInnerLocked(Session session, WindowState win) { |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 2037 | mKeyWaiter.finishedKey(session, win.mClient, true, |
| 2038 | KeyWaiter.RETURN_NOTHING); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2039 | mKeyWaiter.releasePendingPointerLocked(win.mSession); |
| 2040 | mKeyWaiter.releasePendingTrackballLocked(win.mSession); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2041 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2042 | win.mRemoved = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2043 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2044 | if (mInputMethodTarget == win) { |
| 2045 | moveInputMethodWindowsIfNeededLocked(false); |
| 2046 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2047 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2048 | if (false) { |
| 2049 | RuntimeException e = new RuntimeException("here"); |
| 2050 | e.fillInStackTrace(); |
| 2051 | Log.w(TAG, "Removing window " + win, e); |
| 2052 | } |
| 2053 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2054 | mPolicy.removeWindowLw(win); |
| 2055 | win.removeLocked(); |
| 2056 | |
| 2057 | mWindowMap.remove(win.mClient.asBinder()); |
| 2058 | mWindows.remove(win); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 2059 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Final remove of window: " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2060 | |
| 2061 | if (mInputMethodWindow == win) { |
| 2062 | mInputMethodWindow = null; |
| 2063 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2064 | mInputMethodDialogs.remove(win); |
| 2065 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2066 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2067 | final WindowToken token = win.mToken; |
| 2068 | final AppWindowToken atoken = win.mAppToken; |
| 2069 | token.windows.remove(win); |
| 2070 | if (atoken != null) { |
| 2071 | atoken.allAppWindows.remove(win); |
| 2072 | } |
| 2073 | if (localLOGV) Log.v( |
| 2074 | TAG, "**** Removing window " + win + ": count=" |
| 2075 | + token.windows.size()); |
| 2076 | if (token.windows.size() == 0) { |
| 2077 | if (!token.explicit) { |
| 2078 | mTokenMap.remove(token.token); |
| 2079 | mTokenList.remove(token); |
| 2080 | } else if (atoken != null) { |
| 2081 | atoken.firstWindowDrawn = false; |
| 2082 | } |
| 2083 | } |
| 2084 | |
| 2085 | if (atoken != null) { |
| 2086 | if (atoken.startingWindow == win) { |
| 2087 | atoken.startingWindow = null; |
| 2088 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2089 | // If this is the last window and we had requested a starting |
| 2090 | // transition window, well there is no point now. |
| 2091 | atoken.startingData = null; |
| 2092 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2093 | // If this is the last window except for a starting transition |
| 2094 | // window, we need to get rid of the starting transition. |
| 2095 | if (DEBUG_STARTING_WINDOW) { |
| 2096 | Log.v(TAG, "Schedule remove starting " + token |
| 2097 | + ": no more real windows"); |
| 2098 | } |
| 2099 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2100 | mH.sendMessage(m); |
| 2101 | } |
| 2102 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2103 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2104 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2105 | mLastWallpaperTimeoutTime = 0; |
| 2106 | adjustWallpaperWindowsLocked(); |
| 2107 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2108 | adjustWallpaperWindowsLocked(); |
| 2109 | } |
| 2110 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2111 | if (!mInLayout) { |
| 2112 | assignLayersLocked(); |
| 2113 | mLayoutNeeded = true; |
| 2114 | performLayoutAndPlaceSurfacesLocked(); |
| 2115 | if (win.mAppToken != null) { |
| 2116 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2117 | } |
| 2118 | } |
| 2119 | } |
| 2120 | |
| 2121 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 2122 | long origId = Binder.clearCallingIdentity(); |
| 2123 | try { |
| 2124 | synchronized (mWindowMap) { |
| 2125 | WindowState w = windowForClientLocked(session, client); |
| 2126 | if ((w != null) && (w.mSurface != null)) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2127 | if (SHOW_TRANSACTIONS) Log.i(TAG, ">>> OPEN TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2128 | Surface.openTransaction(); |
| 2129 | try { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2130 | if (SHOW_TRANSACTIONS) Log.i( |
| 2131 | TAG, " SURFACE " + w.mSurface |
| 2132 | + ": transparentRegionHint=" + region); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2133 | w.mSurface.setTransparentRegionHint(region); |
| 2134 | } finally { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2135 | if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2136 | Surface.closeTransaction(); |
| 2137 | } |
| 2138 | } |
| 2139 | } |
| 2140 | } finally { |
| 2141 | Binder.restoreCallingIdentity(origId); |
| 2142 | } |
| 2143 | } |
| 2144 | |
| 2145 | void setInsetsWindow(Session session, IWindow client, |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2146 | int touchableInsets, Rect contentInsets, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2147 | Rect visibleInsets) { |
| 2148 | long origId = Binder.clearCallingIdentity(); |
| 2149 | try { |
| 2150 | synchronized (mWindowMap) { |
| 2151 | WindowState w = windowForClientLocked(session, client); |
| 2152 | if (w != null) { |
| 2153 | w.mGivenInsetsPending = false; |
| 2154 | w.mGivenContentInsets.set(contentInsets); |
| 2155 | w.mGivenVisibleInsets.set(visibleInsets); |
| 2156 | w.mTouchableInsets = touchableInsets; |
| 2157 | mLayoutNeeded = true; |
| 2158 | performLayoutAndPlaceSurfacesLocked(); |
| 2159 | } |
| 2160 | } |
| 2161 | } finally { |
| 2162 | Binder.restoreCallingIdentity(origId); |
| 2163 | } |
| 2164 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2165 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2166 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2167 | Rect outDisplayFrame) { |
| 2168 | synchronized(mWindowMap) { |
| 2169 | WindowState win = windowForClientLocked(session, client); |
| 2170 | if (win == null) { |
| 2171 | outDisplayFrame.setEmpty(); |
| 2172 | return; |
| 2173 | } |
| 2174 | outDisplayFrame.set(win.mDisplayFrame); |
| 2175 | } |
| 2176 | } |
| 2177 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2178 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y) { |
| 2179 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2180 | window.mWallpaperX = x; |
| 2181 | window.mWallpaperY = y; |
| 2182 | |
| 2183 | if (mWallpaperTarget == window) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2184 | if (updateWallpaperOffsetLocked(true)) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2185 | performLayoutAndPlaceSurfacesLocked(); |
| 2186 | } |
| 2187 | } |
| 2188 | } |
| 2189 | } |
| 2190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2191 | public int relayoutWindow(Session session, IWindow client, |
| 2192 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2193 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2194 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
| 2195 | Surface outSurface) { |
| 2196 | boolean displayed = false; |
| 2197 | boolean inTouchMode; |
| 2198 | Configuration newConfig = null; |
| 2199 | long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2200 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2201 | synchronized(mWindowMap) { |
| 2202 | WindowState win = windowForClientLocked(session, client); |
| 2203 | if (win == null) { |
| 2204 | return 0; |
| 2205 | } |
| 2206 | win.mRequestedWidth = requestedWidth; |
| 2207 | win.mRequestedHeight = requestedHeight; |
| 2208 | |
| 2209 | if (attrs != null) { |
| 2210 | mPolicy.adjustWindowParamsLw(attrs); |
| 2211 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2212 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2213 | int attrChanges = 0; |
| 2214 | int flagChanges = 0; |
| 2215 | if (attrs != null) { |
| 2216 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2217 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2218 | } |
| 2219 | |
| 2220 | if (localLOGV) Log.v( |
| 2221 | TAG, "Relayout given client " + client.asBinder() |
| 2222 | + " (" + win.mAttrs.getTitle() + ")"); |
| 2223 | |
| 2224 | |
| 2225 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2226 | win.mAlpha = attrs.alpha; |
| 2227 | } |
| 2228 | |
| 2229 | final boolean scaledWindow = |
| 2230 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2231 | |
| 2232 | if (scaledWindow) { |
| 2233 | // requested{Width|Height} Surface's physical size |
| 2234 | // attrs.{width|height} Size on screen |
| 2235 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2236 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2237 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2238 | (attrs.height / (float)requestedHeight) : 1.0f; |
| 2239 | } |
| 2240 | |
| 2241 | boolean imMayMove = (flagChanges&( |
| 2242 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2243 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2244 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2245 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2246 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2247 | || (!win.mRelayoutCalled); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2248 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2249 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2250 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
| 2251 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2252 | win.mRelayoutCalled = true; |
| 2253 | final int oldVisibility = win.mViewVisibility; |
| 2254 | win.mViewVisibility = viewVisibility; |
| 2255 | if (viewVisibility == View.VISIBLE && |
| 2256 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2257 | displayed = !win.isVisibleLw(); |
| 2258 | if (win.mExiting) { |
| 2259 | win.mExiting = false; |
| 2260 | win.mAnimation = null; |
| 2261 | } |
| 2262 | if (win.mDestroying) { |
| 2263 | win.mDestroying = false; |
| 2264 | mDestroySurface.remove(win); |
| 2265 | } |
| 2266 | if (oldVisibility == View.GONE) { |
| 2267 | win.mEnterAnimationPending = true; |
| 2268 | } |
| 2269 | if (displayed && win.mSurface != null && !win.mDrawPending |
| 2270 | && !win.mCommitDrawPending && !mDisplayFrozen) { |
| 2271 | applyEnterAnimationLocked(win); |
| 2272 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2273 | if (displayed && (win.mAttrs.flags |
| 2274 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2275 | win.mTurnOnScreen = true; |
| 2276 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2277 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2278 | // To change the format, we need to re-build the surface. |
| 2279 | win.destroySurfaceLocked(); |
| 2280 | displayed = true; |
| 2281 | } |
| 2282 | try { |
| 2283 | Surface surface = win.createSurfaceLocked(); |
| 2284 | if (surface != null) { |
| 2285 | outSurface.copyFrom(surface); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2286 | win.mReportDestroySurface = false; |
| 2287 | win.mSurfacePendingDestroy = false; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2288 | if (SHOW_TRANSACTIONS) Log.i(TAG, |
| 2289 | " OUT SURFACE " + outSurface + ": copied"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2290 | } else { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2291 | // For some reason there isn't a surface. Clear the |
| 2292 | // caller's object so they see the same state. |
| 2293 | outSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2294 | } |
| 2295 | } catch (Exception e) { |
| 2296 | Log.w(TAG, "Exception thrown when creating surface for client " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2297 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2298 | e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2299 | Binder.restoreCallingIdentity(origId); |
| 2300 | return 0; |
| 2301 | } |
| 2302 | if (displayed) { |
| 2303 | focusMayChange = true; |
| 2304 | } |
| 2305 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2306 | && mInputMethodWindow == null) { |
| 2307 | mInputMethodWindow = win; |
| 2308 | imMayMove = true; |
| 2309 | } |
| 2310 | } else { |
| 2311 | win.mEnterAnimationPending = false; |
| 2312 | if (win.mSurface != null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2313 | if (DEBUG_VISIBILITY) Log.i(TAG, "Relayout invis " + win |
| 2314 | + ": mExiting=" + win.mExiting |
| 2315 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2316 | // If we are not currently running the exit animation, we |
| 2317 | // need to see about starting one. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2318 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2319 | // Try starting an animation; if there isn't one, we |
| 2320 | // can destroy the surface right away. |
| 2321 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2322 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2323 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2324 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2325 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2326 | applyAnimationLocked(win, transit, false)) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2327 | focusMayChange = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2328 | win.mExiting = true; |
| 2329 | mKeyWaiter.finishedKey(session, client, true, |
| 2330 | KeyWaiter.RETURN_NOTHING); |
| 2331 | } else if (win.isAnimating()) { |
| 2332 | // Currently in a hide animation... turn this into |
| 2333 | // an exit. |
| 2334 | win.mExiting = true; |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2335 | } else if (win == mWallpaperTarget) { |
| 2336 | // If the wallpaper is currently behind this |
| 2337 | // window, we need to change both of them inside |
| 2338 | // of a transaction to avoid artifacts. |
| 2339 | win.mExiting = true; |
| 2340 | win.mAnimating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2341 | } else { |
| 2342 | if (mInputMethodWindow == win) { |
| 2343 | mInputMethodWindow = null; |
| 2344 | } |
| 2345 | win.destroySurfaceLocked(); |
| 2346 | } |
| 2347 | } |
| 2348 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2349 | |
| 2350 | if (win.mSurface == null || (win.getAttrs().flags |
| 2351 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2352 | || win.mSurfacePendingDestroy) { |
| 2353 | // We are being called from a local process, which |
| 2354 | // means outSurface holds its current surface. Ensure the |
| 2355 | // surface object is cleared, but we don't want it actually |
| 2356 | // destroyed at this point. |
| 2357 | win.mSurfacePendingDestroy = false; |
| 2358 | outSurface.release(); |
| 2359 | if (DEBUG_VISIBILITY) Log.i(TAG, "Releasing surface in: " + win); |
| 2360 | } else if (win.mSurface != null) { |
| 2361 | if (DEBUG_VISIBILITY) Log.i(TAG, |
| 2362 | "Keeping surface, will report destroy: " + win); |
| 2363 | win.mReportDestroySurface = true; |
| 2364 | outSurface.copyFrom(win.mSurface); |
| 2365 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2366 | } |
| 2367 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2368 | if (focusMayChange) { |
| 2369 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 2370 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2371 | imMayMove = false; |
| 2372 | } |
| 2373 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2374 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2375 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2376 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2377 | // reassign them at this point if the IM window state gets shuffled |
| 2378 | boolean assignLayers = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2379 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2380 | if (imMayMove) { |
| 2381 | if (moveInputMethodWindowsIfNeededLocked(false)) { |
| 2382 | assignLayers = true; |
| 2383 | } |
| 2384 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2385 | if (wallpaperMayMove) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2386 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2387 | assignLayers = true; |
| 2388 | } |
| 2389 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2390 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2391 | mLayoutNeeded = true; |
| 2392 | win.mGivenInsetsPending = insetsPending; |
| 2393 | if (assignLayers) { |
| 2394 | assignLayersLocked(); |
| 2395 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2396 | newConfig = updateOrientationFromAppTokensLocked(null, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2397 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2398 | if (displayed && win.mIsWallpaper) { |
| 2399 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2400 | mDisplay.getHeight(), false); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2401 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2402 | if (win.mAppToken != null) { |
| 2403 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2404 | } |
| 2405 | outFrame.set(win.mFrame); |
| 2406 | outContentInsets.set(win.mContentInsets); |
| 2407 | outVisibleInsets.set(win.mVisibleInsets); |
| 2408 | if (localLOGV) Log.v( |
| 2409 | TAG, "Relayout given client " + client.asBinder() |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2410 | + ", requestedWidth=" + requestedWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2411 | + ", requestedHeight=" + requestedHeight |
| 2412 | + ", viewVisibility=" + viewVisibility |
| 2413 | + "\nRelayout returning frame=" + outFrame |
| 2414 | + ", surface=" + outSurface); |
| 2415 | |
| 2416 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 2417 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2418 | |
| 2419 | inTouchMode = mInTouchMode; |
| 2420 | } |
| 2421 | |
| 2422 | if (newConfig != null) { |
| 2423 | sendNewConfiguration(); |
| 2424 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2425 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2426 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2427 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2428 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2429 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2430 | } |
| 2431 | |
| 2432 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2433 | final long origId = Binder.clearCallingIdentity(); |
| 2434 | synchronized(mWindowMap) { |
| 2435 | WindowState win = windowForClientLocked(session, client); |
| 2436 | if (win != null && win.finishDrawingLocked()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2437 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2438 | adjustWallpaperWindowsLocked(); |
| 2439 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2440 | mLayoutNeeded = true; |
| 2441 | performLayoutAndPlaceSurfacesLocked(); |
| 2442 | } |
| 2443 | } |
| 2444 | Binder.restoreCallingIdentity(origId); |
| 2445 | } |
| 2446 | |
| 2447 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
| 2448 | if (DEBUG_ANIM) Log.v(TAG, "Loading animations: params package=" |
| 2449 | + (lp != null ? lp.packageName : null) |
| 2450 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2451 | if (lp != null && lp.windowAnimations != 0) { |
| 2452 | // If this is a system resource, don't try to load it from the |
| 2453 | // application resources. It is nice to avoid loading application |
| 2454 | // resources if we can. |
| 2455 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2456 | int resId = lp.windowAnimations; |
| 2457 | if ((resId&0xFF000000) == 0x01000000) { |
| 2458 | packageName = "android"; |
| 2459 | } |
| 2460 | if (DEBUG_ANIM) Log.v(TAG, "Loading animations: picked package=" |
| 2461 | + packageName); |
| 2462 | return AttributeCache.instance().get(packageName, resId, |
| 2463 | com.android.internal.R.styleable.WindowAnimation); |
| 2464 | } |
| 2465 | return null; |
| 2466 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2467 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2468 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
| 2469 | if (DEBUG_ANIM) Log.v(TAG, "Loading animations: params package=" |
| 2470 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 2471 | if (packageName != null) { |
| 2472 | if ((resId&0xFF000000) == 0x01000000) { |
| 2473 | packageName = "android"; |
| 2474 | } |
| 2475 | if (DEBUG_ANIM) Log.v(TAG, "Loading animations: picked package=" |
| 2476 | + packageName); |
| 2477 | return AttributeCache.instance().get(packageName, resId, |
| 2478 | com.android.internal.R.styleable.WindowAnimation); |
| 2479 | } |
| 2480 | return null; |
| 2481 | } |
| 2482 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2483 | private void applyEnterAnimationLocked(WindowState win) { |
| 2484 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 2485 | if (win.mEnterAnimationPending) { |
| 2486 | win.mEnterAnimationPending = false; |
| 2487 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 2488 | } |
| 2489 | |
| 2490 | applyAnimationLocked(win, transit, true); |
| 2491 | } |
| 2492 | |
| 2493 | private boolean applyAnimationLocked(WindowState win, |
| 2494 | int transit, boolean isEntrance) { |
| 2495 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 2496 | // If we are trying to apply an animation, but already running |
| 2497 | // an animation of the same type, then just leave that one alone. |
| 2498 | return true; |
| 2499 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2500 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2501 | // Only apply an animation if the display isn't frozen. If it is |
| 2502 | // frozen, there is no reason to animate and it can cause strange |
| 2503 | // artifacts when we unfreeze the display if some different animation |
| 2504 | // is running. |
| 2505 | if (!mDisplayFrozen) { |
| 2506 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 2507 | int attr = -1; |
| 2508 | Animation a = null; |
| 2509 | if (anim != 0) { |
| 2510 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 2511 | } else { |
| 2512 | switch (transit) { |
| 2513 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 2514 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 2515 | break; |
| 2516 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 2517 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 2518 | break; |
| 2519 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 2520 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 2521 | break; |
| 2522 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 2523 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 2524 | break; |
| 2525 | } |
| 2526 | if (attr >= 0) { |
| 2527 | a = loadAnimation(win.mAttrs, attr); |
| 2528 | } |
| 2529 | } |
| 2530 | if (DEBUG_ANIM) Log.v(TAG, "applyAnimation: win=" + win |
| 2531 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 2532 | + " mAnimation=" + win.mAnimation |
| 2533 | + " isEntrance=" + isEntrance); |
| 2534 | if (a != null) { |
| 2535 | if (DEBUG_ANIM) { |
| 2536 | RuntimeException e = new RuntimeException(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 2537 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2538 | Log.v(TAG, "Loaded animation " + a + " for " + win, e); |
| 2539 | } |
| 2540 | win.setAnimation(a); |
| 2541 | win.mAnimationIsEntrance = isEntrance; |
| 2542 | } |
| 2543 | } else { |
| 2544 | win.clearAnimation(); |
| 2545 | } |
| 2546 | |
| 2547 | return win.mAnimation != null; |
| 2548 | } |
| 2549 | |
| 2550 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 2551 | int anim = 0; |
| 2552 | Context context = mContext; |
| 2553 | if (animAttr >= 0) { |
| 2554 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 2555 | if (ent != null) { |
| 2556 | context = ent.context; |
| 2557 | anim = ent.array.getResourceId(animAttr, 0); |
| 2558 | } |
| 2559 | } |
| 2560 | if (anim != 0) { |
| 2561 | return AnimationUtils.loadAnimation(context, anim); |
| 2562 | } |
| 2563 | return null; |
| 2564 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2565 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2566 | private Animation loadAnimation(String packageName, int resId) { |
| 2567 | int anim = 0; |
| 2568 | Context context = mContext; |
| 2569 | if (resId >= 0) { |
| 2570 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 2571 | if (ent != null) { |
| 2572 | context = ent.context; |
| 2573 | anim = resId; |
| 2574 | } |
| 2575 | } |
| 2576 | if (anim != 0) { |
| 2577 | return AnimationUtils.loadAnimation(context, anim); |
| 2578 | } |
| 2579 | return null; |
| 2580 | } |
| 2581 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2582 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 2583 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 2584 | // Only apply an animation if the display isn't frozen. If it is |
| 2585 | // frozen, there is no reason to animate and it can cause strange |
| 2586 | // artifacts when we unfreeze the display if some different animation |
| 2587 | // is running. |
| 2588 | if (!mDisplayFrozen) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2589 | Animation a; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 2590 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2591 | a = new FadeInOutAnimation(enter); |
| 2592 | if (DEBUG_ANIM) Log.v(TAG, |
| 2593 | "applying FadeInOutAnimation for a window in compatibility mode"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2594 | } else if (mNextAppTransitionPackage != null) { |
| 2595 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 2596 | mNextAppTransitionEnter : mNextAppTransitionExit); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2597 | } else { |
| 2598 | int animAttr = 0; |
| 2599 | switch (transit) { |
| 2600 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 2601 | animAttr = enter |
| 2602 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 2603 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 2604 | break; |
| 2605 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 2606 | animAttr = enter |
| 2607 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 2608 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 2609 | break; |
| 2610 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 2611 | animAttr = enter |
| 2612 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 2613 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 2614 | break; |
| 2615 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 2616 | animAttr = enter |
| 2617 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 2618 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 2619 | break; |
| 2620 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 2621 | animAttr = enter |
| 2622 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 2623 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 2624 | break; |
| 2625 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 2626 | animAttr = enter |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 2627 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2628 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 2629 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2630 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2631 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2632 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 2633 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2634 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2635 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2636 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2637 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 2638 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 2639 | break; |
| 2640 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 2641 | animAttr = enter |
| 2642 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 2643 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 2644 | break; |
| 2645 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 2646 | animAttr = enter |
| 2647 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 2648 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2649 | break; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2650 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 2651 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2652 | if (DEBUG_ANIM) Log.v(TAG, "applyAnimation: wtoken=" + wtoken |
| 2653 | + " anim=" + a |
| 2654 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 2655 | + " transit=" + transit); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2656 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2657 | if (a != null) { |
| 2658 | if (DEBUG_ANIM) { |
| 2659 | RuntimeException e = new RuntimeException(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 2660 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2661 | Log.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
| 2662 | } |
| 2663 | wtoken.setAnimation(a); |
| 2664 | } |
| 2665 | } else { |
| 2666 | wtoken.clearAnimation(); |
| 2667 | } |
| 2668 | |
| 2669 | return wtoken.animation != null; |
| 2670 | } |
| 2671 | |
| 2672 | // ------------------------------------------------------------- |
| 2673 | // Application Window Tokens |
| 2674 | // ------------------------------------------------------------- |
| 2675 | |
| 2676 | public void validateAppTokens(List tokens) { |
| 2677 | int v = tokens.size()-1; |
| 2678 | int m = mAppTokens.size()-1; |
| 2679 | while (v >= 0 && m >= 0) { |
| 2680 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2681 | if (wtoken.removed) { |
| 2682 | m--; |
| 2683 | continue; |
| 2684 | } |
| 2685 | if (tokens.get(v) != wtoken.token) { |
| 2686 | Log.w(TAG, "Tokens out of sync: external is " + tokens.get(v) |
| 2687 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 2688 | } |
| 2689 | v--; |
| 2690 | m--; |
| 2691 | } |
| 2692 | while (v >= 0) { |
| 2693 | Log.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v); |
| 2694 | v--; |
| 2695 | } |
| 2696 | while (m >= 0) { |
| 2697 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2698 | if (!wtoken.removed) { |
| 2699 | Log.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
| 2700 | } |
| 2701 | m--; |
| 2702 | } |
| 2703 | } |
| 2704 | |
| 2705 | boolean checkCallingPermission(String permission, String func) { |
| 2706 | // Quick check: if the calling permission is me, it's all okay. |
| 2707 | if (Binder.getCallingPid() == Process.myPid()) { |
| 2708 | return true; |
| 2709 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2710 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2711 | if (mContext.checkCallingPermission(permission) |
| 2712 | == PackageManager.PERMISSION_GRANTED) { |
| 2713 | return true; |
| 2714 | } |
| 2715 | String msg = "Permission Denial: " + func + " from pid=" |
| 2716 | + Binder.getCallingPid() |
| 2717 | + ", uid=" + Binder.getCallingUid() |
| 2718 | + " requires " + permission; |
| 2719 | Log.w(TAG, msg); |
| 2720 | return false; |
| 2721 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2722 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2723 | AppWindowToken findAppWindowToken(IBinder token) { |
| 2724 | WindowToken wtoken = mTokenMap.get(token); |
| 2725 | if (wtoken == null) { |
| 2726 | return null; |
| 2727 | } |
| 2728 | return wtoken.appWindowToken; |
| 2729 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2730 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2731 | public void addWindowToken(IBinder token, int type) { |
| 2732 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2733 | "addWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2734 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2735 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2736 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2737 | synchronized(mWindowMap) { |
| 2738 | WindowToken wtoken = mTokenMap.get(token); |
| 2739 | if (wtoken != null) { |
| 2740 | Log.w(TAG, "Attempted to add existing input method token: " + token); |
| 2741 | return; |
| 2742 | } |
| 2743 | wtoken = new WindowToken(token, type, true); |
| 2744 | mTokenMap.put(token, wtoken); |
| 2745 | mTokenList.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2746 | if (type == TYPE_WALLPAPER) { |
| 2747 | mWallpaperTokens.add(wtoken); |
| 2748 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2749 | } |
| 2750 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2751 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2752 | public void removeWindowToken(IBinder token) { |
| 2753 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2754 | "removeWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2755 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2756 | } |
| 2757 | |
| 2758 | final long origId = Binder.clearCallingIdentity(); |
| 2759 | synchronized(mWindowMap) { |
| 2760 | WindowToken wtoken = mTokenMap.remove(token); |
| 2761 | mTokenList.remove(wtoken); |
| 2762 | if (wtoken != null) { |
| 2763 | boolean delayed = false; |
| 2764 | if (!wtoken.hidden) { |
| 2765 | wtoken.hidden = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2766 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2767 | final int N = wtoken.windows.size(); |
| 2768 | boolean changed = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2769 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2770 | for (int i=0; i<N; i++) { |
| 2771 | WindowState win = wtoken.windows.get(i); |
| 2772 | |
| 2773 | if (win.isAnimating()) { |
| 2774 | delayed = true; |
| 2775 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2776 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2777 | if (win.isVisibleNow()) { |
| 2778 | applyAnimationLocked(win, |
| 2779 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 2780 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 2781 | KeyWaiter.RETURN_NOTHING); |
| 2782 | changed = true; |
| 2783 | } |
| 2784 | } |
| 2785 | |
| 2786 | if (changed) { |
| 2787 | mLayoutNeeded = true; |
| 2788 | performLayoutAndPlaceSurfacesLocked(); |
| 2789 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2790 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2791 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2792 | if (delayed) { |
| 2793 | mExitingTokens.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2794 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 2795 | mWallpaperTokens.remove(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2796 | } |
| 2797 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2798 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2799 | } else { |
| 2800 | Log.w(TAG, "Attempted to remove non-existing token: " + token); |
| 2801 | } |
| 2802 | } |
| 2803 | Binder.restoreCallingIdentity(origId); |
| 2804 | } |
| 2805 | |
| 2806 | public void addAppToken(int addPos, IApplicationToken token, |
| 2807 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 2808 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2809 | "addAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2810 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2811 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2812 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2813 | synchronized(mWindowMap) { |
| 2814 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 2815 | if (wtoken != null) { |
| 2816 | Log.w(TAG, "Attempted to add existing app token: " + token); |
| 2817 | return; |
| 2818 | } |
| 2819 | wtoken = new AppWindowToken(token); |
| 2820 | wtoken.groupId = groupId; |
| 2821 | wtoken.appFullscreen = fullscreen; |
| 2822 | wtoken.requestedOrientation = requestedOrientation; |
| 2823 | mAppTokens.add(addPos, wtoken); |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 2824 | 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] | 2825 | mTokenMap.put(token.asBinder(), wtoken); |
| 2826 | mTokenList.add(wtoken); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2827 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2828 | // Application tokens start out hidden. |
| 2829 | wtoken.hidden = true; |
| 2830 | wtoken.hiddenRequested = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2831 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2832 | //dump(); |
| 2833 | } |
| 2834 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2835 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2836 | public void setAppGroupId(IBinder token, int groupId) { |
| 2837 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2838 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2839 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2840 | } |
| 2841 | |
| 2842 | synchronized(mWindowMap) { |
| 2843 | AppWindowToken wtoken = findAppWindowToken(token); |
| 2844 | if (wtoken == null) { |
| 2845 | Log.w(TAG, "Attempted to set group id of non-existing app token: " + token); |
| 2846 | return; |
| 2847 | } |
| 2848 | wtoken.groupId = groupId; |
| 2849 | } |
| 2850 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2851 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2852 | public int getOrientationFromWindowsLocked() { |
| 2853 | int pos = mWindows.size() - 1; |
| 2854 | while (pos >= 0) { |
| 2855 | WindowState wtoken = (WindowState) mWindows.get(pos); |
| 2856 | pos--; |
| 2857 | if (wtoken.mAppToken != null) { |
| 2858 | // We hit an application window. so the orientation will be determined by the |
| 2859 | // app window. No point in continuing further. |
| 2860 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2861 | } |
| 2862 | if (!wtoken.isVisibleLw()) { |
| 2863 | continue; |
| 2864 | } |
| 2865 | int req = wtoken.mAttrs.screenOrientation; |
| 2866 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 2867 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 2868 | continue; |
| 2869 | } else { |
| 2870 | return req; |
| 2871 | } |
| 2872 | } |
| 2873 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2874 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2875 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2876 | public int getOrientationFromAppTokensLocked() { |
| 2877 | int pos = mAppTokens.size() - 1; |
| 2878 | int curGroup = 0; |
| 2879 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2880 | boolean findingBehind = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2881 | boolean haveGroup = false; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2882 | boolean lastFullscreen = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2883 | while (pos >= 0) { |
| 2884 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 2885 | pos--; |
Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2886 | // if we're about to tear down this window and not seek for |
| 2887 | // the behind activity, don't use it for orientation |
| 2888 | if (!findingBehind |
| 2889 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2890 | continue; |
| 2891 | } |
| 2892 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2893 | if (!haveGroup) { |
| 2894 | // We ignore any hidden applications on the top. |
| 2895 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
| 2896 | continue; |
| 2897 | } |
| 2898 | haveGroup = true; |
| 2899 | curGroup = wtoken.groupId; |
| 2900 | lastOrientation = wtoken.requestedOrientation; |
| 2901 | } else if (curGroup != wtoken.groupId) { |
| 2902 | // If we have hit a new application group, and the bottom |
| 2903 | // 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] | 2904 | // the orientation behind it, and the last app was |
| 2905 | // full screen, then we'll stick with the |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2906 | // user's orientation. |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2907 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 2908 | && lastFullscreen) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2909 | return lastOrientation; |
| 2910 | } |
| 2911 | } |
| 2912 | int or = wtoken.requestedOrientation; |
Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2913 | // If this application is fullscreen, and didn't explicitly say |
| 2914 | // 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] | 2915 | // orientation it has and ignores whatever is under it. |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2916 | lastFullscreen = wtoken.appFullscreen; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2917 | if (lastFullscreen |
Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2918 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2919 | return or; |
| 2920 | } |
| 2921 | // If this application has requested an explicit orientation, |
| 2922 | // then use it. |
| 2923 | if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || |
| 2924 | or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || |
| 2925 | or == ActivityInfo.SCREEN_ORIENTATION_SENSOR || |
| 2926 | or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR || |
| 2927 | or == ActivityInfo.SCREEN_ORIENTATION_USER) { |
| 2928 | return or; |
| 2929 | } |
Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2930 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2931 | } |
| 2932 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2933 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2934 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2935 | public Configuration updateOrientationFromAppTokens( |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2936 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2937 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2938 | "updateOrientationFromAppTokens()")) { |
| 2939 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 2940 | } |
| 2941 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2942 | Configuration config; |
| 2943 | long ident = Binder.clearCallingIdentity(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2944 | config = updateOrientationFromAppTokensUnchecked(currentConfig, |
| 2945 | freezeThisOneIfNeeded); |
| 2946 | Binder.restoreCallingIdentity(ident); |
| 2947 | return config; |
| 2948 | } |
| 2949 | |
| 2950 | Configuration updateOrientationFromAppTokensUnchecked( |
| 2951 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| 2952 | Configuration config; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2953 | synchronized(mWindowMap) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2954 | config = updateOrientationFromAppTokensLocked(currentConfig, freezeThisOneIfNeeded); |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2955 | if (config != null) { |
| 2956 | mLayoutNeeded = true; |
| 2957 | performLayoutAndPlaceSurfacesLocked(); |
| 2958 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2959 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2960 | return config; |
| 2961 | } |
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 | /* |
| 2964 | * The orientation is computed from non-application windows first. If none of |
| 2965 | * the non-application windows specify orientation, the orientation is computed from |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2966 | * application tokens. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2967 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 2968 | * android.os.IBinder) |
| 2969 | */ |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2970 | Configuration updateOrientationFromAppTokensLocked( |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2971 | Configuration appConfig, IBinder freezeThisOneIfNeeded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2972 | boolean changed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2973 | long ident = Binder.clearCallingIdentity(); |
| 2974 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2975 | int req = computeForcedAppOrientationLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2976 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2977 | if (req != mForcedAppOrientation) { |
| 2978 | changed = true; |
| 2979 | mForcedAppOrientation = req; |
| 2980 | //send a message to Policy indicating orientation change to take |
| 2981 | //action like disabling/enabling sensors etc., |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2982 | mPolicy.setCurrentOrientationLw(req); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2983 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2984 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2985 | if (changed) { |
| 2986 | changed = setRotationUncheckedLocked( |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 2987 | WindowManagerPolicy.USE_LAST_ROTATION, |
| 2988 | mLastRotationFlags & (~Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2989 | if (changed) { |
| 2990 | if (freezeThisOneIfNeeded != null) { |
| 2991 | AppWindowToken wtoken = findAppWindowToken( |
| 2992 | freezeThisOneIfNeeded); |
| 2993 | if (wtoken != null) { |
| 2994 | startAppFreezingScreenLocked(wtoken, |
| 2995 | ActivityInfo.CONFIG_ORIENTATION); |
| 2996 | } |
| 2997 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 2998 | return computeNewConfigurationLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2999 | } |
| 3000 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3001 | |
| 3002 | // No obvious action we need to take, but if our current |
| 3003 | // state mismatches the activity maanager's, update it |
| 3004 | if (appConfig != null) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 3005 | mTempConfiguration.setToDefaults(); |
| 3006 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3007 | if (appConfig.diff(mTempConfiguration) != 0) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 3008 | return new Configuration(mTempConfiguration); |
| 3009 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3010 | } |
| 3011 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3012 | } finally { |
| 3013 | Binder.restoreCallingIdentity(ident); |
| 3014 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3015 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3016 | return null; |
| 3017 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3018 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3019 | int computeForcedAppOrientationLocked() { |
| 3020 | int req = getOrientationFromWindowsLocked(); |
| 3021 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3022 | req = getOrientationFromAppTokensLocked(); |
| 3023 | } |
| 3024 | return req; |
| 3025 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3026 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3027 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3028 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3029 | "setAppOrientation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3030 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3031 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3032 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3033 | synchronized(mWindowMap) { |
| 3034 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3035 | if (wtoken == null) { |
| 3036 | Log.w(TAG, "Attempted to set orientation of non-existing app token: " + token); |
| 3037 | return; |
| 3038 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3039 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3040 | wtoken.requestedOrientation = requestedOrientation; |
| 3041 | } |
| 3042 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3043 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3044 | public int getAppOrientation(IApplicationToken token) { |
| 3045 | synchronized(mWindowMap) { |
| 3046 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3047 | if (wtoken == null) { |
| 3048 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3049 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3050 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3051 | return wtoken.requestedOrientation; |
| 3052 | } |
| 3053 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3054 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3055 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3056 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3057 | "setFocusedApp()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3058 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3059 | } |
| 3060 | |
| 3061 | synchronized(mWindowMap) { |
| 3062 | boolean changed = false; |
| 3063 | if (token == null) { |
| 3064 | if (DEBUG_FOCUS) Log.v(TAG, "Clearing focused app, was " + mFocusedApp); |
| 3065 | changed = mFocusedApp != null; |
| 3066 | mFocusedApp = null; |
| 3067 | mKeyWaiter.tickle(); |
| 3068 | } else { |
| 3069 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3070 | if (newFocus == null) { |
| 3071 | Log.w(TAG, "Attempted to set focus to non-existing app token: " + token); |
| 3072 | return; |
| 3073 | } |
| 3074 | changed = mFocusedApp != newFocus; |
| 3075 | mFocusedApp = newFocus; |
| 3076 | if (DEBUG_FOCUS) Log.v(TAG, "Set focused app to: " + mFocusedApp); |
| 3077 | mKeyWaiter.tickle(); |
| 3078 | } |
| 3079 | |
| 3080 | if (moveFocusNow && changed) { |
| 3081 | final long origId = Binder.clearCallingIdentity(); |
| 3082 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3083 | Binder.restoreCallingIdentity(origId); |
| 3084 | } |
| 3085 | } |
| 3086 | } |
| 3087 | |
| 3088 | public void prepareAppTransition(int transit) { |
| 3089 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3090 | "prepareAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3091 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3092 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3093 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3094 | synchronized(mWindowMap) { |
| 3095 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 3096 | TAG, "Prepare app transition: transit=" + transit |
| 3097 | + " mNextAppTransition=" + mNextAppTransition); |
| 3098 | if (!mDisplayFrozen) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3099 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3100 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3101 | mNextAppTransition = transit; |
Dianne Hackborn | d7cd29d | 2009-07-01 11:22:45 -0700 | [diff] [blame] | 3102 | } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3103 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3104 | // Opening a new task always supersedes a close for the anim. |
| 3105 | mNextAppTransition = transit; |
| 3106 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3107 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3108 | // Opening a new activity always supersedes a close for the anim. |
| 3109 | mNextAppTransition = transit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3110 | } |
| 3111 | mAppTransitionReady = false; |
| 3112 | mAppTransitionTimeout = false; |
| 3113 | mStartingIconInTransition = false; |
| 3114 | mSkipAppTransitionAnimation = false; |
| 3115 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3116 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3117 | 5000); |
| 3118 | } |
| 3119 | } |
| 3120 | } |
| 3121 | |
| 3122 | public int getPendingAppTransition() { |
| 3123 | return mNextAppTransition; |
| 3124 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3125 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3126 | public void overridePendingAppTransition(String packageName, |
| 3127 | int enterAnim, int exitAnim) { |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3128 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3129 | mNextAppTransitionPackage = packageName; |
| 3130 | mNextAppTransitionEnter = enterAnim; |
| 3131 | mNextAppTransitionExit = exitAnim; |
| 3132 | } |
| 3133 | } |
| 3134 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3135 | public void executeAppTransition() { |
| 3136 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3137 | "executeAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3138 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3139 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3141 | synchronized(mWindowMap) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3142 | if (DEBUG_APP_TRANSITIONS) { |
| 3143 | RuntimeException e = new RuntimeException("here"); |
| 3144 | e.fillInStackTrace(); |
| 3145 | Log.w(TAG, "Execute app transition: mNextAppTransition=" |
| 3146 | + mNextAppTransition, e); |
| 3147 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3148 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3149 | mAppTransitionReady = true; |
| 3150 | final long origId = Binder.clearCallingIdentity(); |
| 3151 | performLayoutAndPlaceSurfacesLocked(); |
| 3152 | Binder.restoreCallingIdentity(origId); |
| 3153 | } |
| 3154 | } |
| 3155 | } |
| 3156 | |
| 3157 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3158 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| 3159 | IBinder transferFrom, boolean createIfNeeded) { |
| 3160 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3161 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3162 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3163 | } |
| 3164 | |
| 3165 | synchronized(mWindowMap) { |
| 3166 | if (DEBUG_STARTING_WINDOW) Log.v( |
| 3167 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3168 | + " transferFrom=" + transferFrom); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3169 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3170 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3171 | if (wtoken == null) { |
| 3172 | Log.w(TAG, "Attempted to set icon of non-existing app token: " + token); |
| 3173 | return; |
| 3174 | } |
| 3175 | |
| 3176 | // If the display is frozen, we won't do anything until the |
| 3177 | // actual window is displayed so there is no reason to put in |
| 3178 | // the starting window. |
| 3179 | if (mDisplayFrozen) { |
| 3180 | return; |
| 3181 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3182 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3183 | if (wtoken.startingData != null) { |
| 3184 | return; |
| 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 (transferFrom != null) { |
| 3188 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3189 | if (ttoken != null) { |
| 3190 | WindowState startingWindow = ttoken.startingWindow; |
| 3191 | if (startingWindow != null) { |
| 3192 | if (mStartingIconInTransition) { |
| 3193 | // In this case, the starting icon has already |
| 3194 | // been displayed, so start letting windows get |
| 3195 | // shown immediately without any more transitions. |
| 3196 | mSkipAppTransitionAnimation = true; |
| 3197 | } |
| 3198 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 3199 | "Moving existing starting from " + ttoken |
| 3200 | + " to " + wtoken); |
| 3201 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3202 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3203 | // Transfer the starting window over to the new |
| 3204 | // token. |
| 3205 | wtoken.startingData = ttoken.startingData; |
| 3206 | wtoken.startingView = ttoken.startingView; |
| 3207 | wtoken.startingWindow = startingWindow; |
| 3208 | ttoken.startingData = null; |
| 3209 | ttoken.startingView = null; |
| 3210 | ttoken.startingWindow = null; |
| 3211 | ttoken.startingMoved = true; |
| 3212 | startingWindow.mToken = wtoken; |
Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3213 | startingWindow.mRootToken = wtoken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3214 | startingWindow.mAppToken = wtoken; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3215 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, |
| 3216 | "Removing starting window: " + startingWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3217 | mWindows.remove(startingWindow); |
| 3218 | ttoken.windows.remove(startingWindow); |
| 3219 | ttoken.allAppWindows.remove(startingWindow); |
| 3220 | addWindowToListInOrderLocked(startingWindow, true); |
| 3221 | wtoken.allAppWindows.add(startingWindow); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3222 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3223 | // Propagate other interesting state between the |
| 3224 | // tokens. If the old token is displayed, we should |
| 3225 | // immediately force the new one to be displayed. If |
| 3226 | // it is animating, we need to move that animation to |
| 3227 | // the new one. |
| 3228 | if (ttoken.allDrawn) { |
| 3229 | wtoken.allDrawn = true; |
| 3230 | } |
| 3231 | if (ttoken.firstWindowDrawn) { |
| 3232 | wtoken.firstWindowDrawn = true; |
| 3233 | } |
| 3234 | if (!ttoken.hidden) { |
| 3235 | wtoken.hidden = false; |
| 3236 | wtoken.hiddenRequested = false; |
| 3237 | wtoken.willBeHidden = false; |
| 3238 | } |
| 3239 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3240 | wtoken.clientHidden = ttoken.clientHidden; |
| 3241 | wtoken.sendAppVisibilityToClients(); |
| 3242 | } |
| 3243 | if (ttoken.animation != null) { |
| 3244 | wtoken.animation = ttoken.animation; |
| 3245 | wtoken.animating = ttoken.animating; |
| 3246 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3247 | ttoken.animation = null; |
| 3248 | ttoken.animLayerAdjustment = 0; |
| 3249 | wtoken.updateLayers(); |
| 3250 | ttoken.updateLayers(); |
| 3251 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3252 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3253 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3254 | mLayoutNeeded = true; |
| 3255 | performLayoutAndPlaceSurfacesLocked(); |
| 3256 | Binder.restoreCallingIdentity(origId); |
| 3257 | return; |
| 3258 | } else if (ttoken.startingData != null) { |
| 3259 | // The previous app was getting ready to show a |
| 3260 | // starting window, but hasn't yet done so. Steal it! |
| 3261 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 3262 | "Moving pending starting from " + ttoken |
| 3263 | + " to " + wtoken); |
| 3264 | wtoken.startingData = ttoken.startingData; |
| 3265 | ttoken.startingData = null; |
| 3266 | ttoken.startingMoved = true; |
| 3267 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3268 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3269 | // want to process the message ASAP, before any other queued |
| 3270 | // messages. |
| 3271 | mH.sendMessageAtFrontOfQueue(m); |
| 3272 | return; |
| 3273 | } |
| 3274 | } |
| 3275 | } |
| 3276 | |
| 3277 | // There is no existing starting window, and the caller doesn't |
| 3278 | // want us to create one, so that's it! |
| 3279 | if (!createIfNeeded) { |
| 3280 | return; |
| 3281 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3282 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3283 | // If this is a translucent or wallpaper window, then don't |
| 3284 | // show a starting window -- the current effect (a full-screen |
| 3285 | // opaque starting window that fades away to the real contents |
| 3286 | // when it is ready) does not work for this. |
| 3287 | if (theme != 0) { |
| 3288 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3289 | com.android.internal.R.styleable.Window); |
| 3290 | if (ent.array.getBoolean( |
| 3291 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3292 | return; |
| 3293 | } |
| 3294 | if (ent.array.getBoolean( |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3295 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3296 | return; |
| 3297 | } |
| 3298 | if (ent.array.getBoolean( |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3299 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3300 | return; |
| 3301 | } |
| 3302 | } |
| 3303 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3304 | mStartingIconInTransition = true; |
| 3305 | wtoken.startingData = new StartingData( |
| 3306 | pkg, theme, nonLocalizedLabel, |
| 3307 | labelRes, icon); |
| 3308 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3309 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3310 | // want to process the message ASAP, before any other queued |
| 3311 | // messages. |
| 3312 | mH.sendMessageAtFrontOfQueue(m); |
| 3313 | } |
| 3314 | } |
| 3315 | |
| 3316 | public void setAppWillBeHidden(IBinder token) { |
| 3317 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3318 | "setAppWillBeHidden()")) { |
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 | AppWindowToken wtoken; |
| 3323 | |
| 3324 | synchronized(mWindowMap) { |
| 3325 | wtoken = findAppWindowToken(token); |
| 3326 | if (wtoken == null) { |
| 3327 | Log.w(TAG, "Attempted to set will be hidden of non-existing app token: " + token); |
| 3328 | return; |
| 3329 | } |
| 3330 | wtoken.willBeHidden = true; |
| 3331 | } |
| 3332 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3333 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3334 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3335 | boolean visible, int transit, boolean performLayout) { |
| 3336 | boolean delayed = false; |
| 3337 | |
| 3338 | if (wtoken.clientHidden == visible) { |
| 3339 | wtoken.clientHidden = !visible; |
| 3340 | wtoken.sendAppVisibilityToClients(); |
| 3341 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3342 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3343 | wtoken.willBeHidden = false; |
| 3344 | if (wtoken.hidden == visible) { |
| 3345 | final int N = wtoken.allAppWindows.size(); |
| 3346 | boolean changed = false; |
| 3347 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 3348 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3349 | + " performLayout=" + performLayout); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3350 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3351 | boolean runningAppAnimation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3352 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3353 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3354 | if (wtoken.animation == sDummyAnimation) { |
| 3355 | wtoken.animation = null; |
| 3356 | } |
| 3357 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3358 | changed = true; |
| 3359 | if (wtoken.animation != null) { |
| 3360 | delayed = runningAppAnimation = true; |
| 3361 | } |
| 3362 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3363 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3364 | for (int i=0; i<N; i++) { |
| 3365 | WindowState win = wtoken.allAppWindows.get(i); |
| 3366 | if (win == wtoken.startingWindow) { |
| 3367 | continue; |
| 3368 | } |
| 3369 | |
| 3370 | if (win.isAnimating()) { |
| 3371 | delayed = true; |
| 3372 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3374 | //Log.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
| 3375 | //win.dump(" "); |
| 3376 | if (visible) { |
| 3377 | if (!win.isVisibleNow()) { |
| 3378 | if (!runningAppAnimation) { |
| 3379 | applyAnimationLocked(win, |
| 3380 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3381 | } |
| 3382 | changed = true; |
| 3383 | } |
| 3384 | } else if (win.isVisibleNow()) { |
| 3385 | if (!runningAppAnimation) { |
| 3386 | applyAnimationLocked(win, |
| 3387 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3388 | } |
| 3389 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 3390 | KeyWaiter.RETURN_NOTHING); |
| 3391 | changed = true; |
| 3392 | } |
| 3393 | } |
| 3394 | |
| 3395 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3396 | if (!visible) { |
| 3397 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3398 | } else { |
| 3399 | // If we are being set visible, and the starting window is |
| 3400 | // not yet displayed, then make sure it doesn't get displayed. |
| 3401 | WindowState swin = wtoken.startingWindow; |
| 3402 | if (swin != null && (swin.mDrawPending |
| 3403 | || swin.mCommitDrawPending)) { |
| 3404 | swin.mPolicyVisibility = false; |
| 3405 | swin.mPolicyVisibilityAfterAnim = false; |
| 3406 | } |
| 3407 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3408 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3409 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "setTokenVisibilityLocked: " + wtoken |
| 3410 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3411 | + wtoken.hiddenRequested); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3412 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3413 | if (changed && performLayout) { |
| 3414 | mLayoutNeeded = true; |
| 3415 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3416 | performLayoutAndPlaceSurfacesLocked(); |
| 3417 | } |
| 3418 | } |
| 3419 | |
| 3420 | if (wtoken.animation != null) { |
| 3421 | delayed = true; |
| 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 | return delayed; |
| 3425 | } |
| 3426 | |
| 3427 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3428 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3429 | "setAppVisibility()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3430 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3431 | } |
| 3432 | |
| 3433 | AppWindowToken wtoken; |
| 3434 | |
| 3435 | synchronized(mWindowMap) { |
| 3436 | wtoken = findAppWindowToken(token); |
| 3437 | if (wtoken == null) { |
| 3438 | Log.w(TAG, "Attempted to set visibility of non-existing app token: " + token); |
| 3439 | return; |
| 3440 | } |
| 3441 | |
| 3442 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
| 3443 | RuntimeException e = new RuntimeException(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3444 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3445 | Log.v(TAG, "setAppVisibility(" + token + ", " + visible |
| 3446 | + "): mNextAppTransition=" + mNextAppTransition |
| 3447 | + " hidden=" + wtoken.hidden |
| 3448 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3449 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3451 | // If we are preparing an app transition, then delay changing |
| 3452 | // the visibility of this token until we execute that transition. |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3453 | if (!mDisplayFrozen && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3454 | // Already in requested state, don't do anything more. |
| 3455 | if (wtoken.hiddenRequested != visible) { |
| 3456 | return; |
| 3457 | } |
| 3458 | wtoken.hiddenRequested = !visible; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3459 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3460 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 3461 | TAG, "Setting dummy animation on: " + wtoken); |
| 3462 | wtoken.setDummyAnimation(); |
| 3463 | mOpeningApps.remove(wtoken); |
| 3464 | mClosingApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3465 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3466 | wtoken.inPendingTransaction = true; |
| 3467 | if (visible) { |
| 3468 | mOpeningApps.add(wtoken); |
| 3469 | wtoken.allDrawn = false; |
| 3470 | wtoken.startingDisplayed = false; |
| 3471 | wtoken.startingMoved = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3472 | wtoken.waitingToShow = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3473 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3474 | if (wtoken.clientHidden) { |
| 3475 | // In the case where we are making an app visible |
| 3476 | // but holding off for a transition, we still need |
| 3477 | // to tell the client to make its windows visible so |
| 3478 | // they get drawn. Otherwise, we will wait on |
| 3479 | // performing the transition until all windows have |
| 3480 | // been drawn, they never will be, and we are sad. |
| 3481 | wtoken.clientHidden = false; |
| 3482 | wtoken.sendAppVisibilityToClients(); |
| 3483 | } |
| 3484 | } else { |
| 3485 | mClosingApps.add(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3486 | wtoken.waitingToHide = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3487 | } |
| 3488 | return; |
| 3489 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3490 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3491 | final long origId = Binder.clearCallingIdentity(); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3492 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3493 | wtoken.updateReportedVisibilityLocked(); |
| 3494 | Binder.restoreCallingIdentity(origId); |
| 3495 | } |
| 3496 | } |
| 3497 | |
| 3498 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3499 | boolean unfreezeSurfaceNow, boolean force) { |
| 3500 | if (wtoken.freezingScreen) { |
| 3501 | if (DEBUG_ORIENTATION) Log.v(TAG, "Clear freezing of " + wtoken |
| 3502 | + " force=" + force); |
| 3503 | final int N = wtoken.allAppWindows.size(); |
| 3504 | boolean unfrozeWindows = false; |
| 3505 | for (int i=0; i<N; i++) { |
| 3506 | WindowState w = wtoken.allAppWindows.get(i); |
| 3507 | if (w.mAppFreezing) { |
| 3508 | w.mAppFreezing = false; |
| 3509 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 3510 | w.mOrientationChanging = true; |
| 3511 | } |
| 3512 | unfrozeWindows = true; |
| 3513 | } |
| 3514 | } |
| 3515 | if (force || unfrozeWindows) { |
| 3516 | if (DEBUG_ORIENTATION) Log.v(TAG, "No longer freezing: " + wtoken); |
| 3517 | wtoken.freezingScreen = false; |
| 3518 | mAppsFreezingScreen--; |
| 3519 | } |
| 3520 | if (unfreezeSurfaceNow) { |
| 3521 | if (unfrozeWindows) { |
| 3522 | mLayoutNeeded = true; |
| 3523 | performLayoutAndPlaceSurfacesLocked(); |
| 3524 | } |
| 3525 | if (mAppsFreezingScreen == 0 && !mWindowsFreezingScreen) { |
| 3526 | stopFreezingDisplayLocked(); |
| 3527 | } |
| 3528 | } |
| 3529 | } |
| 3530 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3531 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3532 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3533 | int configChanges) { |
| 3534 | if (DEBUG_ORIENTATION) { |
| 3535 | RuntimeException e = new RuntimeException(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3536 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3537 | Log.i(TAG, "Set freezing of " + wtoken.appToken |
| 3538 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 3539 | + wtoken.freezingScreen, e); |
| 3540 | } |
| 3541 | if (!wtoken.hiddenRequested) { |
| 3542 | if (!wtoken.freezingScreen) { |
| 3543 | wtoken.freezingScreen = true; |
| 3544 | mAppsFreezingScreen++; |
| 3545 | if (mAppsFreezingScreen == 1) { |
| 3546 | startFreezingDisplayLocked(); |
| 3547 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 3548 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 3549 | 5000); |
| 3550 | } |
| 3551 | } |
| 3552 | final int N = wtoken.allAppWindows.size(); |
| 3553 | for (int i=0; i<N; i++) { |
| 3554 | WindowState w = wtoken.allAppWindows.get(i); |
| 3555 | w.mAppFreezing = true; |
| 3556 | } |
| 3557 | } |
| 3558 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3559 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3560 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 3561 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3562 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3563 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3564 | } |
| 3565 | |
| 3566 | synchronized(mWindowMap) { |
| 3567 | if (configChanges == 0 && !mDisplayFrozen) { |
| 3568 | if (DEBUG_ORIENTATION) Log.v(TAG, "Skipping set freeze of " + token); |
| 3569 | return; |
| 3570 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3571 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3572 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3573 | if (wtoken == null || wtoken.appToken == null) { |
| 3574 | Log.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken); |
| 3575 | return; |
| 3576 | } |
| 3577 | final long origId = Binder.clearCallingIdentity(); |
| 3578 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 3579 | Binder.restoreCallingIdentity(origId); |
| 3580 | } |
| 3581 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3582 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3583 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 3584 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3585 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3586 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3587 | } |
| 3588 | |
| 3589 | synchronized(mWindowMap) { |
| 3590 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3591 | if (wtoken == null || wtoken.appToken == null) { |
| 3592 | return; |
| 3593 | } |
| 3594 | final long origId = Binder.clearCallingIdentity(); |
| 3595 | if (DEBUG_ORIENTATION) Log.v(TAG, "Clear freezing of " + token |
| 3596 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 3597 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 3598 | Binder.restoreCallingIdentity(origId); |
| 3599 | } |
| 3600 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3601 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3602 | public void removeAppToken(IBinder token) { |
| 3603 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3604 | "removeAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3605 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3606 | } |
| 3607 | |
| 3608 | AppWindowToken wtoken = null; |
| 3609 | AppWindowToken startingToken = null; |
| 3610 | boolean delayed = false; |
| 3611 | |
| 3612 | final long origId = Binder.clearCallingIdentity(); |
| 3613 | synchronized(mWindowMap) { |
| 3614 | WindowToken basewtoken = mTokenMap.remove(token); |
| 3615 | mTokenList.remove(basewtoken); |
| 3616 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
| 3617 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "Removing app token: " + wtoken); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3618 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3619 | wtoken.inPendingTransaction = false; |
| 3620 | mOpeningApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3621 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3622 | if (mClosingApps.contains(wtoken)) { |
| 3623 | delayed = true; |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3624 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3625 | mClosingApps.add(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3626 | wtoken.waitingToHide = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3627 | delayed = true; |
| 3628 | } |
| 3629 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 3630 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 3631 | + " animation=" + wtoken.animation |
| 3632 | + " animating=" + wtoken.animating); |
| 3633 | if (delayed) { |
| 3634 | // set the token aside because it has an active animation to be finished |
| 3635 | mExitingAppTokens.add(wtoken); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3636 | } else { |
| 3637 | // Make sure there is no animation running on this token, |
| 3638 | // so any windows associated with it will be removed as |
| 3639 | // soon as their animations are complete |
| 3640 | wtoken.animation = null; |
| 3641 | wtoken.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3642 | } |
| 3643 | mAppTokens.remove(wtoken); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3644 | if (mLastEnterAnimToken == wtoken) { |
| 3645 | mLastEnterAnimToken = null; |
| 3646 | mLastEnterAnimParams = null; |
| 3647 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3648 | wtoken.removed = true; |
| 3649 | if (wtoken.startingData != null) { |
| 3650 | startingToken = wtoken; |
| 3651 | } |
| 3652 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3653 | if (mFocusedApp == wtoken) { |
| 3654 | if (DEBUG_FOCUS) Log.v(TAG, "Removing focused app token:" + wtoken); |
| 3655 | mFocusedApp = null; |
| 3656 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3657 | mKeyWaiter.tickle(); |
| 3658 | } |
| 3659 | } else { |
| 3660 | Log.w(TAG, "Attempted to remove non-existing app token: " + token); |
| 3661 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3662 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3663 | if (!delayed && wtoken != null) { |
| 3664 | wtoken.updateReportedVisibilityLocked(); |
| 3665 | } |
| 3666 | } |
| 3667 | Binder.restoreCallingIdentity(origId); |
| 3668 | |
| 3669 | if (startingToken != null) { |
| 3670 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Schedule remove starting " |
| 3671 | + startingToken + ": app token removed"); |
| 3672 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 3673 | mH.sendMessage(m); |
| 3674 | } |
| 3675 | } |
| 3676 | |
| 3677 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 3678 | final int NW = token.windows.size(); |
| 3679 | for (int i=0; i<NW; i++) { |
| 3680 | WindowState win = token.windows.get(i); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3681 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Tmp removing app window " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3682 | mWindows.remove(win); |
| 3683 | int j = win.mChildWindows.size(); |
| 3684 | while (j > 0) { |
| 3685 | j--; |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3686 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| 3687 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, |
| 3688 | "Tmp removing child window " + cwin); |
| 3689 | mWindows.remove(cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3690 | } |
| 3691 | } |
| 3692 | return NW > 0; |
| 3693 | } |
| 3694 | |
| 3695 | void dumpAppTokensLocked() { |
| 3696 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| 3697 | Log.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
| 3698 | } |
| 3699 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3700 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3701 | void dumpWindowsLocked() { |
| 3702 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 3703 | Log.v(TAG, " #" + i + ": " + mWindows.get(i)); |
| 3704 | } |
| 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 | private int findWindowOffsetLocked(int tokenPos) { |
| 3708 | final int NW = mWindows.size(); |
| 3709 | |
| 3710 | if (tokenPos >= mAppTokens.size()) { |
| 3711 | int i = NW; |
| 3712 | while (i > 0) { |
| 3713 | i--; |
| 3714 | WindowState win = (WindowState)mWindows.get(i); |
| 3715 | if (win.getAppToken() != null) { |
| 3716 | return i+1; |
| 3717 | } |
| 3718 | } |
| 3719 | } |
| 3720 | |
| 3721 | while (tokenPos > 0) { |
| 3722 | // Find the first app token below the new position that has |
| 3723 | // a window displayed. |
| 3724 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
| 3725 | if (DEBUG_REORDER) Log.v(TAG, "Looking for lower windows @ " |
| 3726 | + tokenPos + " -- " + wtoken.token); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3727 | if (wtoken.sendingToBottom) { |
| 3728 | if (DEBUG_REORDER) Log.v(TAG, |
| 3729 | "Skipping token -- currently sending to bottom"); |
| 3730 | tokenPos--; |
| 3731 | continue; |
| 3732 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3733 | int i = wtoken.windows.size(); |
| 3734 | while (i > 0) { |
| 3735 | i--; |
| 3736 | WindowState win = wtoken.windows.get(i); |
| 3737 | int j = win.mChildWindows.size(); |
| 3738 | while (j > 0) { |
| 3739 | j--; |
| 3740 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3741 | if (cwin.mSubLayer >= 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3742 | for (int pos=NW-1; pos>=0; pos--) { |
| 3743 | if (mWindows.get(pos) == cwin) { |
| 3744 | if (DEBUG_REORDER) Log.v(TAG, |
| 3745 | "Found child win @" + (pos+1)); |
| 3746 | return pos+1; |
| 3747 | } |
| 3748 | } |
| 3749 | } |
| 3750 | } |
| 3751 | for (int pos=NW-1; pos>=0; pos--) { |
| 3752 | if (mWindows.get(pos) == win) { |
| 3753 | if (DEBUG_REORDER) Log.v(TAG, "Found win @" + (pos+1)); |
| 3754 | return pos+1; |
| 3755 | } |
| 3756 | } |
| 3757 | } |
| 3758 | tokenPos--; |
| 3759 | } |
| 3760 | |
| 3761 | return 0; |
| 3762 | } |
| 3763 | |
| 3764 | private final int reAddWindowLocked(int index, WindowState win) { |
| 3765 | final int NCW = win.mChildWindows.size(); |
| 3766 | boolean added = false; |
| 3767 | for (int j=0; j<NCW; j++) { |
| 3768 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| 3769 | if (!added && cwin.mSubLayer >= 0) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3770 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Re-adding child window at " |
| 3771 | + index + ": " + cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3772 | mWindows.add(index, win); |
| 3773 | index++; |
| 3774 | added = true; |
| 3775 | } |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3776 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Re-adding window at " |
| 3777 | + index + ": " + cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3778 | mWindows.add(index, cwin); |
| 3779 | index++; |
| 3780 | } |
| 3781 | if (!added) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3782 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Re-adding window at " |
| 3783 | + index + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3784 | mWindows.add(index, win); |
| 3785 | index++; |
| 3786 | } |
| 3787 | return index; |
| 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 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 3791 | final int NW = token.windows.size(); |
| 3792 | for (int i=0; i<NW; i++) { |
| 3793 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 3794 | } |
| 3795 | return index; |
| 3796 | } |
| 3797 | |
| 3798 | public void moveAppToken(int index, IBinder token) { |
| 3799 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3800 | "moveAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3801 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3802 | } |
| 3803 | |
| 3804 | synchronized(mWindowMap) { |
| 3805 | if (DEBUG_REORDER) Log.v(TAG, "Initial app tokens:"); |
| 3806 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 3807 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 3808 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
| 3809 | Log.w(TAG, "Attempting to reorder token that doesn't exist: " |
| 3810 | + token + " (" + wtoken + ")"); |
| 3811 | return; |
| 3812 | } |
| 3813 | mAppTokens.add(index, wtoken); |
| 3814 | if (DEBUG_REORDER) Log.v(TAG, "Moved " + token + " to " + index + ":"); |
| 3815 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3816 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3817 | final long origId = Binder.clearCallingIdentity(); |
| 3818 | if (DEBUG_REORDER) Log.v(TAG, "Removing windows in " + token + ":"); |
| 3819 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3820 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
| 3821 | if (DEBUG_REORDER) Log.v(TAG, "Adding windows back in:"); |
| 3822 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3823 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
| 3824 | if (DEBUG_REORDER) Log.v(TAG, "Final window list:"); |
| 3825 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3826 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3827 | mLayoutNeeded = true; |
| 3828 | performLayoutAndPlaceSurfacesLocked(); |
| 3829 | } |
| 3830 | Binder.restoreCallingIdentity(origId); |
| 3831 | } |
| 3832 | } |
| 3833 | |
| 3834 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 3835 | // XXX This should be done more efficiently! |
| 3836 | // (take advantage of the fact that both lists should be |
| 3837 | // ordered in the same way.) |
| 3838 | int N = tokens.size(); |
| 3839 | for (int i=0; i<N; i++) { |
| 3840 | IBinder token = tokens.get(i); |
| 3841 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 3842 | if (!mAppTokens.remove(wtoken)) { |
| 3843 | Log.w(TAG, "Attempting to reorder token that doesn't exist: " |
| 3844 | + token + " (" + wtoken + ")"); |
| 3845 | i--; |
| 3846 | N--; |
| 3847 | } |
| 3848 | } |
| 3849 | } |
| 3850 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3851 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 3852 | boolean updateFocusAndLayout) { |
| 3853 | // First remove all of the windows from the list. |
| 3854 | tmpRemoveAppWindowsLocked(wtoken); |
| 3855 | |
| 3856 | // Where to start adding? |
| 3857 | int pos = findWindowOffsetLocked(tokenPos); |
| 3858 | |
| 3859 | // And now add them back at the correct place. |
| 3860 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 3861 | |
| 3862 | if (updateFocusAndLayout) { |
| 3863 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 3864 | assignLayersLocked(); |
| 3865 | } |
| 3866 | mLayoutNeeded = true; |
| 3867 | performLayoutAndPlaceSurfacesLocked(); |
| 3868 | } |
| 3869 | } |
| 3870 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3871 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 3872 | // First remove all of the windows from the list. |
| 3873 | final int N = tokens.size(); |
| 3874 | int i; |
| 3875 | for (i=0; i<N; i++) { |
| 3876 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 3877 | if (token != null) { |
| 3878 | tmpRemoveAppWindowsLocked(token); |
| 3879 | } |
| 3880 | } |
| 3881 | |
| 3882 | // Where to start adding? |
| 3883 | int pos = findWindowOffsetLocked(tokenPos); |
| 3884 | |
| 3885 | // And now add them back at the correct place. |
| 3886 | for (i=0; i<N; i++) { |
| 3887 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 3888 | if (token != null) { |
| 3889 | pos = reAddAppWindowsLocked(pos, token); |
| 3890 | } |
| 3891 | } |
| 3892 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3893 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 3894 | assignLayersLocked(); |
| 3895 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3896 | mLayoutNeeded = true; |
| 3897 | performLayoutAndPlaceSurfacesLocked(); |
| 3898 | |
| 3899 | //dump(); |
| 3900 | } |
| 3901 | |
| 3902 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 3903 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3904 | "moveAppTokensToTop()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3905 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3906 | } |
| 3907 | |
| 3908 | final long origId = Binder.clearCallingIdentity(); |
| 3909 | synchronized(mWindowMap) { |
| 3910 | removeAppTokensLocked(tokens); |
| 3911 | final int N = tokens.size(); |
| 3912 | for (int i=0; i<N; i++) { |
| 3913 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 3914 | if (wt != null) { |
| 3915 | mAppTokens.add(wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3916 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3917 | mToTopApps.remove(wt); |
| 3918 | mToBottomApps.remove(wt); |
| 3919 | mToTopApps.add(wt); |
| 3920 | wt.sendingToBottom = false; |
| 3921 | wt.sendingToTop = true; |
| 3922 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3923 | } |
| 3924 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3925 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3926 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3927 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 3928 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3929 | } |
| 3930 | Binder.restoreCallingIdentity(origId); |
| 3931 | } |
| 3932 | |
| 3933 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 3934 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3935 | "moveAppTokensToBottom()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3936 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3937 | } |
| 3938 | |
| 3939 | final long origId = Binder.clearCallingIdentity(); |
| 3940 | synchronized(mWindowMap) { |
| 3941 | removeAppTokensLocked(tokens); |
| 3942 | final int N = tokens.size(); |
| 3943 | int pos = 0; |
| 3944 | for (int i=0; i<N; i++) { |
| 3945 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 3946 | if (wt != null) { |
| 3947 | mAppTokens.add(pos, wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3948 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3949 | mToTopApps.remove(wt); |
| 3950 | mToBottomApps.remove(wt); |
| 3951 | mToBottomApps.add(i, wt); |
| 3952 | wt.sendingToTop = false; |
| 3953 | wt.sendingToBottom = true; |
| 3954 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3955 | pos++; |
| 3956 | } |
| 3957 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3958 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3959 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3960 | moveAppWindowsLocked(tokens, 0); |
| 3961 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3962 | } |
| 3963 | Binder.restoreCallingIdentity(origId); |
| 3964 | } |
| 3965 | |
| 3966 | // ------------------------------------------------------------- |
| 3967 | // Misc IWindowSession methods |
| 3968 | // ------------------------------------------------------------- |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3969 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3970 | public void disableKeyguard(IBinder token, String tag) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 3971 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3972 | != PackageManager.PERMISSION_GRANTED) { |
| 3973 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 3974 | } |
| 3975 | mKeyguardDisabled.acquire(token, tag); |
| 3976 | } |
| 3977 | |
| 3978 | public void reenableKeyguard(IBinder token) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 3979 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3980 | != PackageManager.PERMISSION_GRANTED) { |
| 3981 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 3982 | } |
| 3983 | synchronized (mKeyguardDisabled) { |
| 3984 | mKeyguardDisabled.release(token); |
| 3985 | |
| 3986 | if (!mKeyguardDisabled.isAcquired()) { |
| 3987 | // if we are the last one to reenable the keyguard wait until |
| 3988 | // we have actaully finished reenabling until returning |
| 3989 | mWaitingUntilKeyguardReenabled = true; |
| 3990 | while (mWaitingUntilKeyguardReenabled) { |
| 3991 | try { |
| 3992 | mKeyguardDisabled.wait(); |
| 3993 | } catch (InterruptedException e) { |
| 3994 | Thread.currentThread().interrupt(); |
| 3995 | } |
| 3996 | } |
| 3997 | } |
| 3998 | } |
| 3999 | } |
| 4000 | |
| 4001 | /** |
| 4002 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4003 | */ |
| 4004 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4005 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4006 | != PackageManager.PERMISSION_GRANTED) { |
| 4007 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4008 | } |
| 4009 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4010 | public void onKeyguardExitResult(boolean success) { |
| 4011 | try { |
| 4012 | callback.onKeyguardExitResult(success); |
| 4013 | } catch (RemoteException e) { |
| 4014 | // Client has died, we don't care. |
| 4015 | } |
| 4016 | } |
| 4017 | }); |
| 4018 | } |
| 4019 | |
| 4020 | public boolean inKeyguardRestrictedInputMode() { |
| 4021 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4022 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4023 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4024 | public void closeSystemDialogs(String reason) { |
| 4025 | synchronized(mWindowMap) { |
| 4026 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 4027 | WindowState w = (WindowState)mWindows.get(i); |
| 4028 | if (w.mSurface != null) { |
| 4029 | try { |
| 4030 | w.mClient.closeSystemDialogs(reason); |
| 4031 | } catch (RemoteException e) { |
| 4032 | } |
| 4033 | } |
| 4034 | } |
| 4035 | } |
| 4036 | } |
| 4037 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4038 | static float fixScale(float scale) { |
| 4039 | if (scale < 0) scale = 0; |
| 4040 | else if (scale > 20) scale = 20; |
| 4041 | return Math.abs(scale); |
| 4042 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4043 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4044 | public void setAnimationScale(int which, float scale) { |
| 4045 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4046 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4047 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4048 | } |
| 4049 | |
| 4050 | if (scale < 0) scale = 0; |
| 4051 | else if (scale > 20) scale = 20; |
| 4052 | scale = Math.abs(scale); |
| 4053 | switch (which) { |
| 4054 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4055 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4056 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4057 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4058 | // Persist setting |
| 4059 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4060 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4061 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4062 | public void setAnimationScales(float[] scales) { |
| 4063 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4064 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4065 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4066 | } |
| 4067 | |
| 4068 | if (scales != null) { |
| 4069 | if (scales.length >= 1) { |
| 4070 | mWindowAnimationScale = fixScale(scales[0]); |
| 4071 | } |
| 4072 | if (scales.length >= 2) { |
| 4073 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4074 | } |
| 4075 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4076 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4077 | // Persist setting |
| 4078 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4079 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4080 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4081 | public float getAnimationScale(int which) { |
| 4082 | switch (which) { |
| 4083 | case 0: return mWindowAnimationScale; |
| 4084 | case 1: return mTransitionAnimationScale; |
| 4085 | } |
| 4086 | return 0; |
| 4087 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4088 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4089 | public float[] getAnimationScales() { |
| 4090 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4091 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4092 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4093 | public int getSwitchState(int sw) { |
| 4094 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4095 | "getSwitchState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4096 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4097 | } |
| 4098 | return KeyInputQueue.getSwitchState(sw); |
| 4099 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4100 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4101 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4102 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4103 | "getSwitchStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4104 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4105 | } |
| 4106 | return KeyInputQueue.getSwitchState(devid, sw); |
| 4107 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4108 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4109 | public int getScancodeState(int sw) { |
| 4110 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4111 | "getScancodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4112 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4113 | } |
Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4114 | return mQueue.getScancodeState(sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4115 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4116 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4117 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4118 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4119 | "getScancodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4120 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4121 | } |
Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4122 | return mQueue.getScancodeState(devid, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4123 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4124 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4125 | public int getKeycodeState(int sw) { |
| 4126 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4127 | "getKeycodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4128 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4129 | } |
Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4130 | return mQueue.getKeycodeState(sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4131 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4132 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4133 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4134 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4135 | "getKeycodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4136 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4137 | } |
Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4138 | return mQueue.getKeycodeState(devid, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4139 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4141 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
| 4142 | return KeyInputQueue.hasKeys(keycodes, keyExists); |
| 4143 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4144 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4145 | public void enableScreenAfterBoot() { |
| 4146 | synchronized(mWindowMap) { |
| 4147 | if (mSystemBooted) { |
| 4148 | return; |
| 4149 | } |
| 4150 | mSystemBooted = true; |
| 4151 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4152 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4153 | performEnableScreen(); |
| 4154 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4155 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4156 | public void enableScreenIfNeededLocked() { |
| 4157 | if (mDisplayEnabled) { |
| 4158 | return; |
| 4159 | } |
| 4160 | if (!mSystemBooted) { |
| 4161 | return; |
| 4162 | } |
| 4163 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4164 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4165 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4166 | public void performEnableScreen() { |
| 4167 | synchronized(mWindowMap) { |
| 4168 | if (mDisplayEnabled) { |
| 4169 | return; |
| 4170 | } |
| 4171 | if (!mSystemBooted) { |
| 4172 | return; |
| 4173 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4174 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4175 | // Don't enable the screen until all existing windows |
| 4176 | // have been drawn. |
| 4177 | final int N = mWindows.size(); |
| 4178 | for (int i=0; i<N; i++) { |
| 4179 | WindowState w = (WindowState)mWindows.get(i); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 4180 | if (w.isVisibleLw() && !w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4181 | return; |
| 4182 | } |
| 4183 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4184 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4185 | mDisplayEnabled = true; |
| 4186 | if (false) { |
| 4187 | Log.i(TAG, "ENABLING SCREEN!"); |
| 4188 | StringWriter sw = new StringWriter(); |
| 4189 | PrintWriter pw = new PrintWriter(sw); |
| 4190 | this.dump(null, pw, null); |
| 4191 | Log.i(TAG, sw.toString()); |
| 4192 | } |
| 4193 | try { |
| 4194 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4195 | if (surfaceFlinger != null) { |
| 4196 | //Log.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
| 4197 | Parcel data = Parcel.obtain(); |
| 4198 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4199 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4200 | data, null, 0); |
| 4201 | data.recycle(); |
| 4202 | } |
| 4203 | } catch (RemoteException ex) { |
| 4204 | Log.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
| 4205 | } |
| 4206 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4207 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4208 | mPolicy.enableScreenAfterBoot(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4209 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4210 | // Make sure the last requested orientation has been applied. |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4211 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4212 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4213 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4214 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4215 | public void setInTouchMode(boolean mode) { |
| 4216 | synchronized(mWindowMap) { |
| 4217 | mInTouchMode = mode; |
| 4218 | } |
| 4219 | } |
| 4220 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4221 | public void setRotation(int rotation, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4222 | boolean alwaysSendConfiguration, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4223 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4224 | "setRotation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4225 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4226 | } |
| 4227 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4228 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4229 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4230 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4231 | public void setRotationUnchecked(int rotation, |
| 4232 | boolean alwaysSendConfiguration, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4233 | if(DEBUG_ORIENTATION) Log.v(TAG, |
| 4234 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4235 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4236 | long origId = Binder.clearCallingIdentity(); |
| 4237 | boolean changed; |
| 4238 | synchronized(mWindowMap) { |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4239 | changed = setRotationUncheckedLocked(rotation, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4240 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4241 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4242 | if (changed) { |
| 4243 | sendNewConfiguration(); |
| 4244 | synchronized(mWindowMap) { |
| 4245 | mLayoutNeeded = true; |
| 4246 | performLayoutAndPlaceSurfacesLocked(); |
| 4247 | } |
| 4248 | } else if (alwaysSendConfiguration) { |
| 4249 | //update configuration ignoring orientation change |
| 4250 | sendNewConfiguration(); |
| 4251 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4252 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4253 | Binder.restoreCallingIdentity(origId); |
| 4254 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4255 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4256 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4257 | boolean changed; |
| 4258 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4259 | rotation = mRequestedRotation; |
| 4260 | } else { |
| 4261 | mRequestedRotation = rotation; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4262 | mLastRotationFlags = animFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4263 | } |
| 4264 | 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] | 4265 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4266 | mRotation, mDisplayEnabled); |
| 4267 | if (DEBUG_ORIENTATION) Log.v(TAG, "new rotation is set to " + rotation); |
| 4268 | changed = mDisplayEnabled && mRotation != rotation; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4269 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4270 | if (changed) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4271 | if (DEBUG_ORIENTATION) Log.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4272 | "Rotation changed to " + rotation |
| 4273 | + " from " + mRotation |
| 4274 | + " (forceApp=" + mForcedAppOrientation |
| 4275 | + ", req=" + mRequestedRotation + ")"); |
| 4276 | mRotation = rotation; |
| 4277 | mWindowsFreezingScreen = true; |
| 4278 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 4279 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 4280 | 2000); |
| 4281 | startFreezingDisplayLocked(); |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4282 | Log.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4283 | mQueue.setOrientation(rotation); |
| 4284 | if (mDisplayEnabled) { |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4285 | Surface.setOrientation(0, rotation, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4286 | } |
| 4287 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 4288 | WindowState w = (WindowState)mWindows.get(i); |
| 4289 | if (w.mSurface != null) { |
| 4290 | w.mOrientationChanging = true; |
| 4291 | } |
| 4292 | } |
| 4293 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 4294 | try { |
| 4295 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 4296 | } catch (RemoteException e) { |
| 4297 | } |
| 4298 | } |
| 4299 | } //end if changed |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4300 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4301 | return changed; |
| 4302 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4303 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4304 | public int getRotation() { |
| 4305 | return mRotation; |
| 4306 | } |
| 4307 | |
| 4308 | public int watchRotation(IRotationWatcher watcher) { |
| 4309 | final IBinder watcherBinder = watcher.asBinder(); |
| 4310 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 4311 | public void binderDied() { |
| 4312 | synchronized (mWindowMap) { |
| 4313 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 4314 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 4315 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 4316 | if (removed != null) { |
| 4317 | removed.asBinder().unlinkToDeath(this, 0); |
| 4318 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4319 | i--; |
| 4320 | } |
| 4321 | } |
| 4322 | } |
| 4323 | } |
| 4324 | }; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4325 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4326 | synchronized (mWindowMap) { |
| 4327 | try { |
| 4328 | watcher.asBinder().linkToDeath(dr, 0); |
| 4329 | mRotationWatchers.add(watcher); |
| 4330 | } catch (RemoteException e) { |
| 4331 | // Client died, no cleanup needed. |
| 4332 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4333 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4334 | return mRotation; |
| 4335 | } |
| 4336 | } |
| 4337 | |
| 4338 | /** |
| 4339 | * Starts the view server on the specified port. |
| 4340 | * |
| 4341 | * @param port The port to listener to. |
| 4342 | * |
| 4343 | * @return True if the server was successfully started, false otherwise. |
| 4344 | * |
| 4345 | * @see com.android.server.ViewServer |
| 4346 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 4347 | */ |
| 4348 | public boolean startViewServer(int port) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4349 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4350 | return false; |
| 4351 | } |
| 4352 | |
| 4353 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 4354 | return false; |
| 4355 | } |
| 4356 | |
| 4357 | if (port < 1024) { |
| 4358 | return false; |
| 4359 | } |
| 4360 | |
| 4361 | if (mViewServer != null) { |
| 4362 | if (!mViewServer.isRunning()) { |
| 4363 | try { |
| 4364 | return mViewServer.start(); |
| 4365 | } catch (IOException e) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4366 | Log.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4367 | } |
| 4368 | } |
| 4369 | return false; |
| 4370 | } |
| 4371 | |
| 4372 | try { |
| 4373 | mViewServer = new ViewServer(this, port); |
| 4374 | return mViewServer.start(); |
| 4375 | } catch (IOException e) { |
| 4376 | Log.w(TAG, "View server did not start"); |
| 4377 | } |
| 4378 | return false; |
| 4379 | } |
| 4380 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4381 | private boolean isSystemSecure() { |
| 4382 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 4383 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 4384 | } |
| 4385 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4386 | /** |
| 4387 | * Stops the view server if it exists. |
| 4388 | * |
| 4389 | * @return True if the server stopped, false if it wasn't started or |
| 4390 | * couldn't be stopped. |
| 4391 | * |
| 4392 | * @see com.android.server.ViewServer |
| 4393 | */ |
| 4394 | public boolean stopViewServer() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4395 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4396 | return false; |
| 4397 | } |
| 4398 | |
| 4399 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 4400 | return false; |
| 4401 | } |
| 4402 | |
| 4403 | if (mViewServer != null) { |
| 4404 | return mViewServer.stop(); |
| 4405 | } |
| 4406 | return false; |
| 4407 | } |
| 4408 | |
| 4409 | /** |
| 4410 | * Indicates whether the view server is running. |
| 4411 | * |
| 4412 | * @return True if the server is running, false otherwise. |
| 4413 | * |
| 4414 | * @see com.android.server.ViewServer |
| 4415 | */ |
| 4416 | public boolean isViewServerRunning() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4417 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4418 | return false; |
| 4419 | } |
| 4420 | |
| 4421 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 4422 | return false; |
| 4423 | } |
| 4424 | |
| 4425 | return mViewServer != null && mViewServer.isRunning(); |
| 4426 | } |
| 4427 | |
| 4428 | /** |
| 4429 | * Lists all availble windows in the system. The listing is written in the |
| 4430 | * specified Socket's output stream with the following syntax: |
| 4431 | * windowHashCodeInHexadecimal windowName |
| 4432 | * Each line of the ouput represents a different window. |
| 4433 | * |
| 4434 | * @param client The remote client to send the listing to. |
| 4435 | * @return False if an error occured, true otherwise. |
| 4436 | */ |
| 4437 | boolean viewServerListWindows(Socket client) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4438 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4439 | return false; |
| 4440 | } |
| 4441 | |
| 4442 | boolean result = true; |
| 4443 | |
| 4444 | Object[] windows; |
| 4445 | synchronized (mWindowMap) { |
| 4446 | windows = new Object[mWindows.size()]; |
| 4447 | //noinspection unchecked |
| 4448 | windows = mWindows.toArray(windows); |
| 4449 | } |
| 4450 | |
| 4451 | BufferedWriter out = null; |
| 4452 | |
| 4453 | // Any uncaught exception will crash the system process |
| 4454 | try { |
| 4455 | OutputStream clientStream = client.getOutputStream(); |
| 4456 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 4457 | |
| 4458 | final int count = windows.length; |
| 4459 | for (int i = 0; i < count; i++) { |
| 4460 | final WindowState w = (WindowState) windows[i]; |
| 4461 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 4462 | out.write(' '); |
| 4463 | out.append(w.mAttrs.getTitle()); |
| 4464 | out.write('\n'); |
| 4465 | } |
| 4466 | |
| 4467 | out.write("DONE.\n"); |
| 4468 | out.flush(); |
| 4469 | } catch (Exception e) { |
| 4470 | result = false; |
| 4471 | } finally { |
| 4472 | if (out != null) { |
| 4473 | try { |
| 4474 | out.close(); |
| 4475 | } catch (IOException e) { |
| 4476 | result = false; |
| 4477 | } |
| 4478 | } |
| 4479 | } |
| 4480 | |
| 4481 | return result; |
| 4482 | } |
| 4483 | |
| 4484 | /** |
| 4485 | * Sends a command to a target window. The result of the command, if any, will be |
| 4486 | * written in the output stream of the specified socket. |
| 4487 | * |
| 4488 | * The parameters must follow this syntax: |
| 4489 | * windowHashcode extra |
| 4490 | * |
| 4491 | * Where XX is the length in characeters of the windowTitle. |
| 4492 | * |
| 4493 | * The first parameter is the target window. The window with the specified hashcode |
| 4494 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 4495 | * will be delivered to the target window and as parameters to the command itself. |
| 4496 | * |
| 4497 | * @param client The remote client to sent the result, if any, to. |
| 4498 | * @param command The command to execute. |
| 4499 | * @param parameters The command parameters. |
| 4500 | * |
| 4501 | * @return True if the command was successfully delivered, false otherwise. This does |
| 4502 | * not indicate whether the command itself was successful. |
| 4503 | */ |
| 4504 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4505 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4506 | return false; |
| 4507 | } |
| 4508 | |
| 4509 | boolean success = true; |
| 4510 | Parcel data = null; |
| 4511 | Parcel reply = null; |
| 4512 | |
| 4513 | // Any uncaught exception will crash the system process |
| 4514 | try { |
| 4515 | // Find the hashcode of the window |
| 4516 | int index = parameters.indexOf(' '); |
| 4517 | if (index == -1) { |
| 4518 | index = parameters.length(); |
| 4519 | } |
| 4520 | final String code = parameters.substring(0, index); |
| 4521 | int hashCode = "ffffffff".equals(code) ? -1 : Integer.parseInt(code, 16); |
| 4522 | |
| 4523 | // Extract the command's parameter after the window description |
| 4524 | if (index < parameters.length()) { |
| 4525 | parameters = parameters.substring(index + 1); |
| 4526 | } else { |
| 4527 | parameters = ""; |
| 4528 | } |
| 4529 | |
| 4530 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 4531 | if (window == null) { |
| 4532 | return false; |
| 4533 | } |
| 4534 | |
| 4535 | data = Parcel.obtain(); |
| 4536 | data.writeInterfaceToken("android.view.IWindow"); |
| 4537 | data.writeString(command); |
| 4538 | data.writeString(parameters); |
| 4539 | data.writeInt(1); |
| 4540 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 4541 | |
| 4542 | reply = Parcel.obtain(); |
| 4543 | |
| 4544 | final IBinder binder = window.mClient.asBinder(); |
| 4545 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 4546 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 4547 | |
| 4548 | reply.readException(); |
| 4549 | |
| 4550 | } catch (Exception e) { |
| 4551 | Log.w(TAG, "Could not send command " + command + " with parameters " + parameters, e); |
| 4552 | success = false; |
| 4553 | } finally { |
| 4554 | if (data != null) { |
| 4555 | data.recycle(); |
| 4556 | } |
| 4557 | if (reply != null) { |
| 4558 | reply.recycle(); |
| 4559 | } |
| 4560 | } |
| 4561 | |
| 4562 | return success; |
| 4563 | } |
| 4564 | |
| 4565 | private WindowState findWindow(int hashCode) { |
| 4566 | if (hashCode == -1) { |
| 4567 | return getFocusedWindow(); |
| 4568 | } |
| 4569 | |
| 4570 | synchronized (mWindowMap) { |
| 4571 | final ArrayList windows = mWindows; |
| 4572 | final int count = windows.size(); |
| 4573 | |
| 4574 | for (int i = 0; i < count; i++) { |
| 4575 | WindowState w = (WindowState) windows.get(i); |
| 4576 | if (System.identityHashCode(w) == hashCode) { |
| 4577 | return w; |
| 4578 | } |
| 4579 | } |
| 4580 | } |
| 4581 | |
| 4582 | return null; |
| 4583 | } |
| 4584 | |
| 4585 | /* |
| 4586 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 4587 | * that to config-changed listeners if appropriate. |
| 4588 | */ |
| 4589 | void sendNewConfiguration() { |
| 4590 | try { |
| 4591 | mActivityManager.updateConfiguration(null); |
| 4592 | } catch (RemoteException e) { |
| 4593 | } |
| 4594 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4595 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4596 | public Configuration computeNewConfiguration() { |
| 4597 | synchronized (mWindowMap) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4598 | return computeNewConfigurationLocked(); |
| 4599 | } |
| 4600 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4601 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4602 | Configuration computeNewConfigurationLocked() { |
| 4603 | Configuration config = new Configuration(); |
| 4604 | if (!computeNewConfigurationLocked(config)) { |
| 4605 | return null; |
| 4606 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4607 | return config; |
| 4608 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4609 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4610 | boolean computeNewConfigurationLocked(Configuration config) { |
| 4611 | if (mDisplay == null) { |
| 4612 | return false; |
| 4613 | } |
| 4614 | mQueue.getInputConfiguration(config); |
| 4615 | final int dw = mDisplay.getWidth(); |
| 4616 | final int dh = mDisplay.getHeight(); |
| 4617 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 4618 | if (dw < dh) { |
| 4619 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 4620 | } else if (dw > dh) { |
| 4621 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 4622 | } |
| 4623 | config.orientation = orientation; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4624 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4625 | DisplayMetrics dm = new DisplayMetrics(); |
| 4626 | mDisplay.getMetrics(dm); |
| 4627 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 4628 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4629 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4630 | // Note we only do this once because at this point we don't |
| 4631 | // expect the screen to change in this way at runtime, and want |
| 4632 | // to avoid all of this computation for every config change. |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4633 | int longSize = dw; |
| 4634 | int shortSize = dh; |
| 4635 | if (longSize < shortSize) { |
| 4636 | int tmp = longSize; |
| 4637 | longSize = shortSize; |
| 4638 | shortSize = tmp; |
| 4639 | } |
| 4640 | longSize = (int)(longSize/dm.density); |
| 4641 | shortSize = (int)(shortSize/dm.density); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4642 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4643 | // These semi-magic numbers define our compatibility modes for |
| 4644 | // applications with different screens. Don't change unless you |
| 4645 | // make sure to test lots and lots of apps! |
| 4646 | if (longSize < 470) { |
| 4647 | // This is shorter than an HVGA normal density screen (which |
| 4648 | // is 480 pixels on its long side). |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4649 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 4650 | | Configuration.SCREENLAYOUT_LONG_NO; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4651 | } else { |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4652 | // Is this a large screen? |
| 4653 | if (longSize > 640 && shortSize >= 480) { |
| 4654 | // VGA or larger screens at medium density are the point |
| 4655 | // at which we consider it to be a large screen. |
| 4656 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 4657 | } else { |
| 4658 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
| 4659 | |
| 4660 | // If this screen is wider than normal HVGA, or taller |
| 4661 | // than FWVGA, then for old apps we want to run in size |
| 4662 | // compatibility mode. |
| 4663 | if (shortSize > 321 || longSize > 570) { |
| 4664 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 4665 | } |
| 4666 | } |
| 4667 | |
| 4668 | // Is this a long screen? |
| 4669 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 4670 | // Anything wider than WVGA (5:3) is considering to be long. |
| 4671 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 4672 | } else { |
| 4673 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 4674 | } |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4675 | } |
| 4676 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4677 | config.screenLayout = mScreenLayout; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4678 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4679 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 4680 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 4681 | mPolicy.adjustConfigurationLw(config); |
| 4682 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4683 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4684 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4685 | // ------------------------------------------------------------- |
| 4686 | // Input Events and Focus Management |
| 4687 | // ------------------------------------------------------------- |
| 4688 | |
| 4689 | private final void wakeupIfNeeded(WindowState targetWin, int eventType) { |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4690 | long curTime = SystemClock.uptimeMillis(); |
| 4691 | |
Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 4692 | if (eventType == TOUCH_EVENT || eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) { |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4693 | if (mLastTouchEventType == eventType && |
| 4694 | (curTime - mLastUserActivityCallTime) < MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 4695 | return; |
| 4696 | } |
| 4697 | mLastUserActivityCallTime = curTime; |
| 4698 | mLastTouchEventType = eventType; |
| 4699 | } |
| 4700 | |
| 4701 | if (targetWin == null |
| 4702 | || targetWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) { |
| 4703 | mPowerManager.userActivity(curTime, false, eventType, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4704 | } |
| 4705 | } |
| 4706 | |
| 4707 | // tells if it's a cheek event or not -- this function is stateful |
| 4708 | private static final int EVENT_NONE = 0; |
| 4709 | private static final int EVENT_UNKNOWN = 0; |
| 4710 | private static final int EVENT_CHEEK = 0; |
| 4711 | private static final int EVENT_IGNORE_DURATION = 300; // ms |
| 4712 | private static final float CHEEK_THRESHOLD = 0.6f; |
| 4713 | private int mEventState = EVENT_NONE; |
| 4714 | private float mEventSize; |
Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4715 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4716 | private int eventType(MotionEvent ev) { |
| 4717 | float size = ev.getSize(); |
| 4718 | switch (ev.getAction()) { |
| 4719 | case MotionEvent.ACTION_DOWN: |
| 4720 | mEventSize = size; |
| 4721 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_EVENT; |
| 4722 | case MotionEvent.ACTION_UP: |
| 4723 | if (size > mEventSize) mEventSize = size; |
Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4724 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_UP_EVENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4725 | case MotionEvent.ACTION_MOVE: |
| 4726 | final int N = ev.getHistorySize(); |
| 4727 | if (size > mEventSize) mEventSize = size; |
| 4728 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 4729 | for (int i=0; i<N; i++) { |
| 4730 | size = ev.getHistoricalSize(i); |
| 4731 | if (size > mEventSize) mEventSize = size; |
| 4732 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 4733 | } |
| 4734 | if (ev.getEventTime() < ev.getDownTime() + EVENT_IGNORE_DURATION) { |
| 4735 | return TOUCH_EVENT; |
| 4736 | } else { |
Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4737 | return LONG_TOUCH_EVENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4738 | } |
| 4739 | default: |
| 4740 | // not good |
| 4741 | return OTHER_EVENT; |
| 4742 | } |
| 4743 | } |
| 4744 | |
| 4745 | /** |
| 4746 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4747 | */ |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4748 | 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] | 4749 | if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Log.v(TAG, |
| 4750 | "dispatchPointer " + ev); |
| 4751 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4752 | if (MEASURE_LATENCY) { |
| 4753 | lt.sample("3 Wait for last dispatch ", System.nanoTime() - qev.whenNano); |
| 4754 | } |
| 4755 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4756 | Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4757 | ev, true, false, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4758 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4759 | if (MEASURE_LATENCY) { |
| 4760 | lt.sample("3 Last dispatch finished ", System.nanoTime() - qev.whenNano); |
| 4761 | } |
| 4762 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4763 | int action = ev.getAction(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4764 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4765 | if (action == MotionEvent.ACTION_UP) { |
| 4766 | // let go of our target |
| 4767 | mKeyWaiter.mMotionTarget = null; |
| 4768 | mPowerManager.logPointerUpEvent(); |
| 4769 | } else if (action == MotionEvent.ACTION_DOWN) { |
| 4770 | mPowerManager.logPointerDownEvent(); |
| 4771 | } |
| 4772 | |
| 4773 | if (targetObj == null) { |
| 4774 | // In this case we are either dropping the event, or have received |
| 4775 | // a move or up without a down. It is common to receive move |
| 4776 | // events in such a way, since this means the user is moving the |
| 4777 | // pointer without actually pressing down. All other cases should |
| 4778 | // be atypical, so let's log them. |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4779 | if (action != MotionEvent.ACTION_MOVE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4780 | Log.w(TAG, "No window to dispatch pointer action " + ev.getAction()); |
| 4781 | } |
| 4782 | if (qev != null) { |
| 4783 | mQueue.recycleEvent(qev); |
| 4784 | } |
| 4785 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4786 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4787 | } |
| 4788 | if (targetObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| 4789 | if (qev != null) { |
| 4790 | mQueue.recycleEvent(qev); |
| 4791 | } |
| 4792 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4793 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4794 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4795 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4796 | WindowState target = (WindowState)targetObj; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4797 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4798 | final long eventTime = ev.getEventTime(); |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4799 | final long eventTimeNano = ev.getEventTimeNano(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4800 | |
| 4801 | //Log.i(TAG, "Sending " + ev + " to " + target); |
| 4802 | |
| 4803 | if (uid != 0 && uid != target.mSession.mUid) { |
| 4804 | if (mContext.checkPermission( |
| 4805 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 4806 | != PackageManager.PERMISSION_GRANTED) { |
| 4807 | Log.w(TAG, "Permission denied: injecting pointer event from pid " |
| 4808 | + pid + " uid " + uid + " to window " + target |
| 4809 | + " owned by uid " + target.mSession.mUid); |
| 4810 | if (qev != null) { |
| 4811 | mQueue.recycleEvent(qev); |
| 4812 | } |
| 4813 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4814 | return INJECT_NO_PERMISSION; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4815 | } |
| 4816 | } |
| 4817 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4818 | if (MEASURE_LATENCY) { |
| 4819 | lt.sample("4 in dispatchPointer ", System.nanoTime() - eventTimeNano); |
| 4820 | } |
| 4821 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4822 | if ((target.mAttrs.flags & |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4823 | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES) != 0) { |
| 4824 | //target wants to ignore fat touch events |
| 4825 | boolean cheekPress = mPolicy.isCheekPressedAgainstScreen(ev); |
| 4826 | //explicit flag to return without processing event further |
| 4827 | boolean returnFlag = false; |
| 4828 | if((action == MotionEvent.ACTION_DOWN)) { |
| 4829 | mFatTouch = false; |
| 4830 | if(cheekPress) { |
| 4831 | mFatTouch = true; |
| 4832 | returnFlag = true; |
| 4833 | } |
| 4834 | } else { |
| 4835 | if(action == MotionEvent.ACTION_UP) { |
| 4836 | if(mFatTouch) { |
| 4837 | //earlier even was invalid doesnt matter if current up is cheekpress or not |
| 4838 | mFatTouch = false; |
| 4839 | returnFlag = true; |
| 4840 | } else if(cheekPress) { |
| 4841 | //cancel the earlier event |
| 4842 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 4843 | action = MotionEvent.ACTION_CANCEL; |
| 4844 | } |
| 4845 | } else if(action == MotionEvent.ACTION_MOVE) { |
| 4846 | if(mFatTouch) { |
| 4847 | //two cases here |
| 4848 | //an invalid down followed by 0 or moves(valid or invalid) |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4849 | //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] | 4850 | returnFlag = true; |
| 4851 | } else if(cheekPress) { |
| 4852 | //valid down followed by invalid moves |
| 4853 | //an invalid move have to cancel earlier action |
| 4854 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 4855 | action = MotionEvent.ACTION_CANCEL; |
| 4856 | if (DEBUG_INPUT) Log.v(TAG, "Sending cancel for invalid ACTION_MOVE"); |
| 4857 | //note that the subsequent invalid moves will not get here |
| 4858 | mFatTouch = true; |
| 4859 | } |
| 4860 | } |
| 4861 | } //else if action |
| 4862 | if(returnFlag) { |
| 4863 | //recycle que, ev |
| 4864 | if (qev != null) { |
| 4865 | mQueue.recycleEvent(qev); |
| 4866 | } |
| 4867 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4868 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4869 | } |
| 4870 | } //end if target |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4871 | |
Michael Chan | 9f028e6 | 2009-08-04 17:37:46 -0700 | [diff] [blame] | 4872 | // Enable this for testing the "right" value |
| 4873 | if (false && action == MotionEvent.ACTION_DOWN) { |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4874 | int max_events_per_sec = 35; |
| 4875 | try { |
| 4876 | max_events_per_sec = Integer.parseInt(SystemProperties |
| 4877 | .get("windowsmgr.max_events_per_sec")); |
| 4878 | if (max_events_per_sec < 1) { |
| 4879 | max_events_per_sec = 35; |
| 4880 | } |
| 4881 | } catch (NumberFormatException e) { |
| 4882 | } |
| 4883 | mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec; |
| 4884 | } |
| 4885 | |
| 4886 | /* |
| 4887 | * Throttle events to minimize CPU usage when there's a flood of events |
| 4888 | * e.g. constant contact with the screen |
| 4889 | */ |
| 4890 | if (action == MotionEvent.ACTION_MOVE) { |
| 4891 | long nextEventTime = mLastTouchEventTime + mMinWaitTimeBetweenTouchEvents; |
| 4892 | long now = SystemClock.uptimeMillis(); |
| 4893 | if (now < nextEventTime) { |
| 4894 | try { |
| 4895 | Thread.sleep(nextEventTime - now); |
| 4896 | } catch (InterruptedException e) { |
| 4897 | } |
| 4898 | mLastTouchEventTime = nextEventTime; |
| 4899 | } else { |
| 4900 | mLastTouchEventTime = now; |
| 4901 | } |
| 4902 | } |
| 4903 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4904 | if (MEASURE_LATENCY) { |
| 4905 | lt.sample("5 in dispatchPointer ", System.nanoTime() - eventTimeNano); |
| 4906 | } |
| 4907 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4908 | synchronized(mWindowMap) { |
| 4909 | if (qev != null && action == MotionEvent.ACTION_MOVE) { |
| 4910 | mKeyWaiter.bindTargetWindowLocked(target, |
| 4911 | KeyWaiter.RETURN_PENDING_POINTER, qev); |
| 4912 | ev = null; |
| 4913 | } else { |
| 4914 | if (action == MotionEvent.ACTION_DOWN) { |
| 4915 | WindowState out = mKeyWaiter.mOutsideTouchTargets; |
| 4916 | if (out != null) { |
| 4917 | MotionEvent oev = MotionEvent.obtain(ev); |
| 4918 | oev.setAction(MotionEvent.ACTION_OUTSIDE); |
| 4919 | do { |
| 4920 | final Rect frame = out.mFrame; |
| 4921 | oev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 4922 | try { |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 4923 | out.mClient.dispatchPointer(oev, eventTime, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4924 | } catch (android.os.RemoteException e) { |
| 4925 | Log.i(TAG, "WINDOW DIED during outside motion dispatch: " + out); |
| 4926 | } |
| 4927 | oev.offsetLocation((float)frame.left, (float)frame.top); |
| 4928 | out = out.mNextOutsideTouch; |
| 4929 | } while (out != null); |
| 4930 | mKeyWaiter.mOutsideTouchTargets = null; |
| 4931 | } |
| 4932 | } |
| 4933 | final Rect frame = target.mFrame; |
| 4934 | ev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 4935 | mKeyWaiter.bindTargetWindowLocked(target); |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 4936 | |
| 4937 | // If we are on top of the wallpaper, then the wallpaper also |
| 4938 | // gets to see this movement. |
| 4939 | if (mWallpaperTarget == target) { |
| 4940 | sendPointerToWallpaperLocked(target, ev, eventTime); |
| 4941 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4942 | } |
| 4943 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4944 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4945 | // finally offset the event to the target's coordinate system and |
| 4946 | // dispatch the event. |
| 4947 | try { |
| 4948 | if (DEBUG_INPUT || DEBUG_FOCUS || WindowManagerPolicy.WATCH_POINTER) { |
| 4949 | Log.v(TAG, "Delivering pointer " + qev + " to " + target); |
| 4950 | } |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4951 | |
| 4952 | if (MEASURE_LATENCY) { |
| 4953 | lt.sample("6 before svr->client ipc ", System.nanoTime() - eventTimeNano); |
| 4954 | } |
| 4955 | |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 4956 | target.mClient.dispatchPointer(ev, eventTime, true); |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4957 | |
| 4958 | if (MEASURE_LATENCY) { |
| 4959 | lt.sample("7 after svr->client ipc ", System.nanoTime() - eventTimeNano); |
| 4960 | } |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4961 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4962 | } catch (android.os.RemoteException e) { |
| 4963 | Log.i(TAG, "WINDOW DIED during motion dispatch: " + target); |
| 4964 | mKeyWaiter.mMotionTarget = null; |
| 4965 | try { |
| 4966 | removeWindow(target.mSession, target.mClient); |
| 4967 | } catch (java.util.NoSuchElementException ex) { |
| 4968 | // This will happen if the window has already been |
| 4969 | // removed. |
| 4970 | } |
| 4971 | } |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4972 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4973 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4974 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4975 | /** |
| 4976 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4977 | */ |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4978 | 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] | 4979 | if (DEBUG_INPUT) Log.v( |
| 4980 | TAG, "dispatchTrackball [" + ev.getAction() +"] <" + ev.getX() + ", " + ev.getY() + ">"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4981 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4982 | Object focusObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4983 | ev, false, false, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4984 | if (focusObj == null) { |
| 4985 | Log.w(TAG, "No focus window, dropping trackball: " + ev); |
| 4986 | if (qev != null) { |
| 4987 | mQueue.recycleEvent(qev); |
| 4988 | } |
| 4989 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4990 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4991 | } |
| 4992 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| 4993 | if (qev != null) { |
| 4994 | mQueue.recycleEvent(qev); |
| 4995 | } |
| 4996 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4997 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4998 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4999 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5000 | WindowState focus = (WindowState)focusObj; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5001 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5002 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 5003 | if (mContext.checkPermission( |
| 5004 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 5005 | != PackageManager.PERMISSION_GRANTED) { |
| 5006 | Log.w(TAG, "Permission denied: injecting key event from pid " |
| 5007 | + pid + " uid " + uid + " to window " + focus |
| 5008 | + " owned by uid " + focus.mSession.mUid); |
| 5009 | if (qev != null) { |
| 5010 | mQueue.recycleEvent(qev); |
| 5011 | } |
| 5012 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5013 | return INJECT_NO_PERMISSION; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5014 | } |
| 5015 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5016 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5017 | final long eventTime = ev.getEventTime(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5018 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5019 | synchronized(mWindowMap) { |
| 5020 | if (qev != null && ev.getAction() == MotionEvent.ACTION_MOVE) { |
| 5021 | mKeyWaiter.bindTargetWindowLocked(focus, |
| 5022 | KeyWaiter.RETURN_PENDING_TRACKBALL, qev); |
| 5023 | // We don't deliver movement events to the client, we hold |
| 5024 | // them and wait for them to call back. |
| 5025 | ev = null; |
| 5026 | } else { |
| 5027 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 5028 | } |
| 5029 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5030 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5031 | try { |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5032 | focus.mClient.dispatchTrackball(ev, eventTime, true); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5033 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5034 | } catch (android.os.RemoteException e) { |
| 5035 | Log.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| 5036 | try { |
| 5037 | removeWindow(focus.mSession, focus.mClient); |
| 5038 | } catch (java.util.NoSuchElementException ex) { |
| 5039 | // This will happen if the window has already been |
| 5040 | // removed. |
| 5041 | } |
| 5042 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5043 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5044 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5045 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5046 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5047 | /** |
| 5048 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5049 | */ |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5050 | private int dispatchKey(KeyEvent event, int pid, int uid) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5051 | if (DEBUG_INPUT) Log.v(TAG, "Dispatch key: " + event); |
| 5052 | |
| 5053 | Object focusObj = mKeyWaiter.waitForNextEventTarget(event, null, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5054 | null, false, false, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5055 | if (focusObj == null) { |
| 5056 | Log.w(TAG, "No focus window, dropping: " + event); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5057 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5058 | } |
| 5059 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5060 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5061 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5062 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5063 | // Okay we have finished waiting for the last event to be processed. |
| 5064 | // First off, if this is a repeat event, check to see if there is |
| 5065 | // a corresponding up event in the queue. If there is, we will |
| 5066 | // just drop the repeat, because it makes no sense to repeat after |
| 5067 | // the user has released a key. (This is especially important for |
| 5068 | // long presses.) |
| 5069 | if (event.getRepeatCount() > 0 && mQueue.hasKeyUpEvent(event)) { |
| 5070 | return INJECT_SUCCEEDED; |
| 5071 | } |
| 5072 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5073 | WindowState focus = (WindowState)focusObj; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5074 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5075 | if (DEBUG_INPUT) Log.v( |
| 5076 | TAG, "Dispatching to " + focus + ": " + event); |
| 5077 | |
| 5078 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 5079 | if (mContext.checkPermission( |
| 5080 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 5081 | != PackageManager.PERMISSION_GRANTED) { |
| 5082 | Log.w(TAG, "Permission denied: injecting key event from pid " |
| 5083 | + pid + " uid " + uid + " to window " + focus |
| 5084 | + " owned by uid " + focus.mSession.mUid); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5085 | return INJECT_NO_PERMISSION; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5086 | } |
| 5087 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5088 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5089 | synchronized(mWindowMap) { |
| 5090 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 5091 | } |
| 5092 | |
| 5093 | // NOSHIP extra state logging |
| 5094 | mKeyWaiter.recordDispatchState(event, focus); |
| 5095 | // END NOSHIP |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5096 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5097 | try { |
| 5098 | if (DEBUG_INPUT || DEBUG_FOCUS) { |
| 5099 | Log.v(TAG, "Delivering key " + event.getKeyCode() |
| 5100 | + " to " + focus); |
| 5101 | } |
| 5102 | focus.mClient.dispatchKey(event); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5103 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5104 | } catch (android.os.RemoteException e) { |
| 5105 | Log.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| 5106 | try { |
| 5107 | removeWindow(focus.mSession, focus.mClient); |
| 5108 | } catch (java.util.NoSuchElementException ex) { |
| 5109 | // This will happen if the window has already been |
| 5110 | // removed. |
| 5111 | } |
| 5112 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5113 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5114 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5115 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5116 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5117 | public void pauseKeyDispatching(IBinder _token) { |
| 5118 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5119 | "pauseKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5120 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5121 | } |
| 5122 | |
| 5123 | synchronized (mWindowMap) { |
| 5124 | WindowToken token = mTokenMap.get(_token); |
| 5125 | if (token != null) { |
| 5126 | mKeyWaiter.pauseDispatchingLocked(token); |
| 5127 | } |
| 5128 | } |
| 5129 | } |
| 5130 | |
| 5131 | public void resumeKeyDispatching(IBinder _token) { |
| 5132 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5133 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5134 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5135 | } |
| 5136 | |
| 5137 | synchronized (mWindowMap) { |
| 5138 | WindowToken token = mTokenMap.get(_token); |
| 5139 | if (token != null) { |
| 5140 | mKeyWaiter.resumeDispatchingLocked(token); |
| 5141 | } |
| 5142 | } |
| 5143 | } |
| 5144 | |
| 5145 | public void setEventDispatching(boolean enabled) { |
| 5146 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5147 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5148 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5149 | } |
| 5150 | |
| 5151 | synchronized (mWindowMap) { |
| 5152 | mKeyWaiter.setEventDispatchingLocked(enabled); |
| 5153 | } |
| 5154 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5155 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5156 | /** |
| 5157 | * Injects a keystroke event into the UI. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5158 | * |
| 5159 | * @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] | 5160 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5161 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5162 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5163 | */ |
| 5164 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 5165 | long downTime = ev.getDownTime(); |
| 5166 | long eventTime = ev.getEventTime(); |
| 5167 | |
| 5168 | int action = ev.getAction(); |
| 5169 | int code = ev.getKeyCode(); |
| 5170 | int repeatCount = ev.getRepeatCount(); |
| 5171 | int metaState = ev.getMetaState(); |
| 5172 | int deviceId = ev.getDeviceId(); |
| 5173 | int scancode = ev.getScanCode(); |
| 5174 | |
| 5175 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 5176 | if (downTime == 0) downTime = eventTime; |
| 5177 | |
| 5178 | 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] | 5179 | deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5180 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5181 | final int pid = Binder.getCallingPid(); |
| 5182 | final int uid = Binder.getCallingUid(); |
| 5183 | final long ident = Binder.clearCallingIdentity(); |
| 5184 | final int result = dispatchKey(newEvent, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5185 | if (sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5186 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5187 | } |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5188 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5189 | switch (result) { |
| 5190 | case INJECT_NO_PERMISSION: |
| 5191 | throw new SecurityException( |
| 5192 | "Injecting to another application requires INJECT_EVENT permission"); |
| 5193 | case INJECT_SUCCEEDED: |
| 5194 | return true; |
| 5195 | } |
| 5196 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5197 | } |
| 5198 | |
| 5199 | /** |
| 5200 | * Inject a pointer (touch) event into the UI. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5201 | * |
| 5202 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 5203 | * {@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] | 5204 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5205 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5206 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5207 | */ |
| 5208 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5209 | final int pid = Binder.getCallingPid(); |
| 5210 | final int uid = Binder.getCallingUid(); |
| 5211 | final long ident = Binder.clearCallingIdentity(); |
| 5212 | final int result = dispatchPointer(null, ev, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5213 | if (sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5214 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5215 | } |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5216 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5217 | switch (result) { |
| 5218 | case INJECT_NO_PERMISSION: |
| 5219 | throw new SecurityException( |
| 5220 | "Injecting to another application requires INJECT_EVENT permission"); |
| 5221 | case INJECT_SUCCEEDED: |
| 5222 | return true; |
| 5223 | } |
| 5224 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5225 | } |
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 | /** |
| 5228 | * Inject a trackball (navigation device) event into the UI. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5229 | * |
| 5230 | * @param ev A motion event describing the trackball action. (As noted in |
| 5231 | * {@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] | 5232 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5233 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5234 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5235 | */ |
| 5236 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5237 | final int pid = Binder.getCallingPid(); |
| 5238 | final int uid = Binder.getCallingUid(); |
| 5239 | final long ident = Binder.clearCallingIdentity(); |
| 5240 | final int result = dispatchTrackball(null, ev, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5241 | if (sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5242 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5243 | } |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5244 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5245 | switch (result) { |
| 5246 | case INJECT_NO_PERMISSION: |
| 5247 | throw new SecurityException( |
| 5248 | "Injecting to another application requires INJECT_EVENT permission"); |
| 5249 | case INJECT_SUCCEEDED: |
| 5250 | return true; |
| 5251 | } |
| 5252 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5253 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5254 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5255 | private WindowState getFocusedWindow() { |
| 5256 | synchronized (mWindowMap) { |
| 5257 | return getFocusedWindowLocked(); |
| 5258 | } |
| 5259 | } |
| 5260 | |
| 5261 | private WindowState getFocusedWindowLocked() { |
| 5262 | return mCurrentFocus; |
| 5263 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5264 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5265 | /** |
| 5266 | * This class holds the state for dispatching key events. This state |
| 5267 | * is protected by the KeyWaiter instance, NOT by the window lock. You |
| 5268 | * can be holding the main window lock while acquire the KeyWaiter lock, |
| 5269 | * but not the other way around. |
| 5270 | */ |
| 5271 | final class KeyWaiter { |
| 5272 | // NOSHIP debugging |
| 5273 | public class DispatchState { |
| 5274 | private KeyEvent event; |
| 5275 | private WindowState focus; |
| 5276 | private long time; |
| 5277 | private WindowState lastWin; |
| 5278 | private IBinder lastBinder; |
| 5279 | private boolean finished; |
| 5280 | private boolean gotFirstWindow; |
| 5281 | private boolean eventDispatching; |
| 5282 | private long timeToSwitch; |
| 5283 | private boolean wasFrozen; |
| 5284 | private boolean focusPaused; |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5285 | private WindowState curFocus; |
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 | DispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 5288 | focus = theFocus; |
| 5289 | event = theEvent; |
| 5290 | time = System.currentTimeMillis(); |
| 5291 | // snapshot KeyWaiter state |
| 5292 | lastWin = mLastWin; |
| 5293 | lastBinder = mLastBinder; |
| 5294 | finished = mFinished; |
| 5295 | gotFirstWindow = mGotFirstWindow; |
| 5296 | eventDispatching = mEventDispatching; |
| 5297 | timeToSwitch = mTimeToSwitch; |
| 5298 | wasFrozen = mWasFrozen; |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5299 | curFocus = mCurrentFocus; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5300 | // cache the paused state at ctor time as well |
| 5301 | if (theFocus == null || theFocus.mToken == null) { |
| 5302 | Log.i(TAG, "focus " + theFocus + " mToken is null at event dispatch!"); |
| 5303 | focusPaused = false; |
| 5304 | } else { |
| 5305 | focusPaused = theFocus.mToken.paused; |
| 5306 | } |
| 5307 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5308 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5309 | public String toString() { |
| 5310 | return "{{" + event + " to " + focus + " @ " + time |
| 5311 | + " lw=" + lastWin + " lb=" + lastBinder |
| 5312 | + " fin=" + finished + " gfw=" + gotFirstWindow |
| 5313 | + " ed=" + eventDispatching + " tts=" + timeToSwitch |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5314 | + " wf=" + wasFrozen + " fp=" + focusPaused |
| 5315 | + " mcf=" + mCurrentFocus + "}}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5316 | } |
| 5317 | }; |
| 5318 | private DispatchState mDispatchState = null; |
| 5319 | public void recordDispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 5320 | mDispatchState = new DispatchState(theEvent, theFocus); |
| 5321 | } |
| 5322 | // END NOSHIP |
| 5323 | |
| 5324 | public static final int RETURN_NOTHING = 0; |
| 5325 | public static final int RETURN_PENDING_POINTER = 1; |
| 5326 | public static final int RETURN_PENDING_TRACKBALL = 2; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5327 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5328 | final Object SKIP_TARGET_TOKEN = new Object(); |
| 5329 | final Object CONSUMED_EVENT_TOKEN = new Object(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5330 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5331 | private WindowState mLastWin = null; |
| 5332 | private IBinder mLastBinder = null; |
| 5333 | private boolean mFinished = true; |
| 5334 | private boolean mGotFirstWindow = false; |
| 5335 | private boolean mEventDispatching = true; |
| 5336 | private long mTimeToSwitch = 0; |
| 5337 | /* package */ boolean mWasFrozen = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5338 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5339 | // Target of Motion events |
| 5340 | WindowState mMotionTarget; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5341 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5342 | // Windows above the target who would like to receive an "outside" |
| 5343 | // touch event for any down events outside of them. |
| 5344 | WindowState mOutsideTouchTargets; |
| 5345 | |
| 5346 | /** |
| 5347 | * Wait for the last event dispatch to complete, then find the next |
| 5348 | * target that should receive the given event and wait for that one |
| 5349 | * to be ready to receive it. |
| 5350 | */ |
| 5351 | Object waitForNextEventTarget(KeyEvent nextKey, QueuedEvent qev, |
| 5352 | MotionEvent nextMotion, boolean isPointerEvent, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5353 | boolean failIfTimeout, int callingPid, int callingUid) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5354 | long startTime = SystemClock.uptimeMillis(); |
| 5355 | long keyDispatchingTimeout = 5 * 1000; |
| 5356 | long waitedFor = 0; |
| 5357 | |
| 5358 | while (true) { |
| 5359 | // Figure out which window we care about. It is either the |
| 5360 | // last window we are waiting to have process the event or, |
| 5361 | // if none, then the next window we think the event should go |
| 5362 | // to. Note: we retrieve mLastWin outside of the lock, so |
| 5363 | // it may change before we lock. Thus we must check it again. |
| 5364 | WindowState targetWin = mLastWin; |
| 5365 | boolean targetIsNew = targetWin == null; |
| 5366 | if (DEBUG_INPUT) Log.v( |
| 5367 | TAG, "waitForLastKey: mFinished=" + mFinished + |
| 5368 | ", mLastWin=" + mLastWin); |
| 5369 | if (targetIsNew) { |
| 5370 | Object target = findTargetWindow(nextKey, qev, nextMotion, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5371 | isPointerEvent, callingPid, callingUid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5372 | if (target == SKIP_TARGET_TOKEN) { |
| 5373 | // The user has pressed a special key, and we are |
| 5374 | // dropping all pending events before it. |
| 5375 | if (DEBUG_INPUT) Log.v(TAG, "Skipping: " + nextKey |
| 5376 | + " " + nextMotion); |
| 5377 | return null; |
| 5378 | } |
| 5379 | if (target == CONSUMED_EVENT_TOKEN) { |
| 5380 | if (DEBUG_INPUT) Log.v(TAG, "Consumed: " + nextKey |
| 5381 | + " " + nextMotion); |
| 5382 | return target; |
| 5383 | } |
| 5384 | targetWin = (WindowState)target; |
| 5385 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5386 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5387 | AppWindowToken targetApp = null; |
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 | // Now: is it okay to send the next event to this window? |
| 5390 | synchronized (this) { |
| 5391 | // First: did we come here based on the last window not |
| 5392 | // being null, but it changed by the time we got here? |
| 5393 | // If so, try again. |
| 5394 | if (!targetIsNew && mLastWin == null) { |
| 5395 | continue; |
| 5396 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5397 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5398 | // We never dispatch events if not finished with the |
| 5399 | // last one, or the display is frozen. |
| 5400 | if (mFinished && !mDisplayFrozen) { |
| 5401 | // If event dispatching is disabled, then we |
| 5402 | // just consume the events. |
| 5403 | if (!mEventDispatching) { |
| 5404 | if (DEBUG_INPUT) Log.v(TAG, |
| 5405 | "Skipping event; dispatching disabled: " |
| 5406 | + nextKey + " " + nextMotion); |
| 5407 | return null; |
| 5408 | } |
| 5409 | if (targetWin != null) { |
| 5410 | // If this is a new target, and that target is not |
| 5411 | // paused or unresponsive, then all looks good to |
| 5412 | // handle the event. |
| 5413 | if (targetIsNew && !targetWin.mToken.paused) { |
| 5414 | return targetWin; |
| 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 | // If we didn't find a target window, and there is no |
| 5418 | // focused app window, then just eat the events. |
| 5419 | } else if (mFocusedApp == null) { |
| 5420 | if (DEBUG_INPUT) Log.v(TAG, |
| 5421 | "Skipping event; no focused app: " |
| 5422 | + nextKey + " " + nextMotion); |
| 5423 | return null; |
| 5424 | } |
| 5425 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5427 | if (DEBUG_INPUT) Log.v( |
| 5428 | TAG, "Waiting for last key in " + mLastBinder |
| 5429 | + " target=" + targetWin |
| 5430 | + " mFinished=" + mFinished |
| 5431 | + " mDisplayFrozen=" + mDisplayFrozen |
| 5432 | + " targetIsNew=" + targetIsNew |
| 5433 | + " paused=" |
| 5434 | + (targetWin != null ? targetWin.mToken.paused : false) |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5435 | + " mFocusedApp=" + mFocusedApp |
| 5436 | + " mCurrentFocus=" + mCurrentFocus); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5437 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5438 | targetApp = targetWin != null |
| 5439 | ? targetWin.mAppToken : mFocusedApp; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5440 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5441 | long curTimeout = keyDispatchingTimeout; |
| 5442 | if (mTimeToSwitch != 0) { |
| 5443 | long now = SystemClock.uptimeMillis(); |
| 5444 | if (mTimeToSwitch <= now) { |
| 5445 | // If an app switch key has been pressed, and we have |
| 5446 | // waited too long for the current app to finish |
| 5447 | // processing keys, then wait no more! |
| 5448 | doFinishedKeyLocked(true); |
| 5449 | continue; |
| 5450 | } |
| 5451 | long switchTimeout = mTimeToSwitch - now; |
| 5452 | if (curTimeout > switchTimeout) { |
| 5453 | curTimeout = switchTimeout; |
| 5454 | } |
| 5455 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5456 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5457 | try { |
| 5458 | // after that continue |
| 5459 | // processing keys, so we don't get stuck. |
| 5460 | if (DEBUG_INPUT) Log.v( |
| 5461 | TAG, "Waiting for key dispatch: " + curTimeout); |
| 5462 | wait(curTimeout); |
| 5463 | if (DEBUG_INPUT) Log.v(TAG, "Finished waiting @" |
| 5464 | + SystemClock.uptimeMillis() + " startTime=" |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5465 | + startTime + " switchTime=" + mTimeToSwitch |
| 5466 | + " target=" + targetWin + " mLW=" + mLastWin |
| 5467 | + " mLB=" + mLastBinder + " fin=" + mFinished |
| 5468 | + " mCurrentFocus=" + mCurrentFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5469 | } catch (InterruptedException e) { |
| 5470 | } |
| 5471 | } |
| 5472 | |
| 5473 | // If we were frozen during configuration change, restart the |
| 5474 | // timeout checks from now; otherwise look at whether we timed |
| 5475 | // out before awakening. |
| 5476 | if (mWasFrozen) { |
| 5477 | waitedFor = 0; |
| 5478 | mWasFrozen = false; |
| 5479 | } else { |
| 5480 | waitedFor = SystemClock.uptimeMillis() - startTime; |
| 5481 | } |
| 5482 | |
| 5483 | if (waitedFor >= keyDispatchingTimeout && mTimeToSwitch == 0) { |
| 5484 | IApplicationToken at = null; |
| 5485 | synchronized (this) { |
| 5486 | Log.w(TAG, "Key dispatching timed out sending to " + |
| 5487 | (targetWin != null ? targetWin.mAttrs.getTitle() |
| 5488 | : "<null>")); |
| 5489 | // NOSHIP debugging |
| 5490 | Log.w(TAG, "Dispatch state: " + mDispatchState); |
| 5491 | Log.w(TAG, "Current state: " + new DispatchState(nextKey, targetWin)); |
| 5492 | // END NOSHIP |
| 5493 | //dump(); |
| 5494 | if (targetWin != null) { |
| 5495 | at = targetWin.getAppToken(); |
| 5496 | } else if (targetApp != null) { |
| 5497 | at = targetApp.appToken; |
| 5498 | } |
| 5499 | } |
| 5500 | |
| 5501 | boolean abort = true; |
| 5502 | if (at != null) { |
| 5503 | try { |
| 5504 | long timeout = at.getKeyDispatchingTimeout(); |
| 5505 | if (timeout > waitedFor) { |
| 5506 | // we did not wait the proper amount of time for this application. |
| 5507 | // set the timeout to be the real timeout and wait again. |
| 5508 | keyDispatchingTimeout = timeout - waitedFor; |
| 5509 | continue; |
| 5510 | } else { |
| 5511 | abort = at.keyDispatchingTimedOut(); |
| 5512 | } |
| 5513 | } catch (RemoteException ex) { |
| 5514 | } |
| 5515 | } |
| 5516 | |
| 5517 | synchronized (this) { |
| 5518 | if (abort && (mLastWin == targetWin || targetWin == null)) { |
| 5519 | mFinished = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5520 | if (mLastWin != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5521 | if (DEBUG_INPUT) Log.v(TAG, |
| 5522 | "Window " + mLastWin + |
| 5523 | " timed out on key input"); |
| 5524 | if (mLastWin.mToken.paused) { |
| 5525 | Log.w(TAG, "Un-pausing dispatching to this window"); |
| 5526 | mLastWin.mToken.paused = false; |
| 5527 | } |
| 5528 | } |
| 5529 | if (mMotionTarget == targetWin) { |
| 5530 | mMotionTarget = null; |
| 5531 | } |
| 5532 | mLastWin = null; |
| 5533 | mLastBinder = null; |
| 5534 | if (failIfTimeout || targetWin == null) { |
| 5535 | return null; |
| 5536 | } |
| 5537 | } else { |
| 5538 | Log.w(TAG, "Continuing to wait for key to be dispatched"); |
| 5539 | startTime = SystemClock.uptimeMillis(); |
| 5540 | } |
| 5541 | } |
| 5542 | } |
| 5543 | } |
| 5544 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5545 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5546 | Object findTargetWindow(KeyEvent nextKey, QueuedEvent qev, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5547 | MotionEvent nextMotion, boolean isPointerEvent, |
| 5548 | int callingPid, int callingUid) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5549 | mOutsideTouchTargets = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5550 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5551 | if (nextKey != null) { |
| 5552 | // Find the target window for a normal key event. |
| 5553 | final int keycode = nextKey.getKeyCode(); |
| 5554 | final int repeatCount = nextKey.getRepeatCount(); |
| 5555 | final boolean down = nextKey.getAction() != KeyEvent.ACTION_UP; |
| 5556 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(keycode); |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5557 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5558 | if (!dispatch) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5559 | if (callingUid == 0 || |
| 5560 | mContext.checkPermission( |
| 5561 | android.Manifest.permission.INJECT_EVENTS, |
| 5562 | callingPid, callingUid) |
| 5563 | == PackageManager.PERMISSION_GRANTED) { |
| 5564 | mPolicy.interceptKeyTi(null, keycode, |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 5565 | nextKey.getMetaState(), down, repeatCount, |
| 5566 | nextKey.getFlags()); |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5567 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5568 | Log.w(TAG, "Event timeout during app switch: dropping " |
| 5569 | + nextKey); |
| 5570 | return SKIP_TARGET_TOKEN; |
| 5571 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5572 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5573 | // System.out.println("##### [" + SystemClock.uptimeMillis() + "] WindowManagerService.dispatchKey(" + keycode + ", " + down + ", " + repeatCount + ")"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5574 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5575 | WindowState focus = null; |
| 5576 | synchronized(mWindowMap) { |
| 5577 | focus = getFocusedWindowLocked(); |
| 5578 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5579 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5580 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5581 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5582 | if (callingUid == 0 || |
| 5583 | (focus != null && callingUid == focus.mSession.mUid) || |
| 5584 | mContext.checkPermission( |
| 5585 | android.Manifest.permission.INJECT_EVENTS, |
| 5586 | callingPid, callingUid) |
| 5587 | == PackageManager.PERMISSION_GRANTED) { |
| 5588 | if (mPolicy.interceptKeyTi(focus, |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 5589 | keycode, nextKey.getMetaState(), down, repeatCount, |
| 5590 | nextKey.getFlags())) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5591 | return CONSUMED_EVENT_TOKEN; |
| 5592 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5593 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5594 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5595 | return focus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5596 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5597 | } else if (!isPointerEvent) { |
| 5598 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(-1); |
| 5599 | if (!dispatch) { |
| 5600 | Log.w(TAG, "Event timeout during app switch: dropping trackball " |
| 5601 | + nextMotion); |
| 5602 | return SKIP_TARGET_TOKEN; |
| 5603 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5604 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5605 | WindowState focus = null; |
| 5606 | synchronized(mWindowMap) { |
| 5607 | focus = getFocusedWindowLocked(); |
| 5608 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5609 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5610 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
| 5611 | return focus; |
| 5612 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5613 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5614 | if (nextMotion == null) { |
| 5615 | return SKIP_TARGET_TOKEN; |
| 5616 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5617 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5618 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey( |
| 5619 | KeyEvent.KEYCODE_UNKNOWN); |
| 5620 | if (!dispatch) { |
| 5621 | Log.w(TAG, "Event timeout during app switch: dropping pointer " |
| 5622 | + nextMotion); |
| 5623 | return SKIP_TARGET_TOKEN; |
| 5624 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5625 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5626 | // Find the target window for a pointer event. |
| 5627 | int action = nextMotion.getAction(); |
| 5628 | final float xf = nextMotion.getX(); |
| 5629 | final float yf = nextMotion.getY(); |
| 5630 | final long eventTime = nextMotion.getEventTime(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5631 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5632 | final boolean screenWasOff = qev != null |
| 5633 | && (qev.flags&WindowManagerPolicy.FLAG_BRIGHT_HERE) != 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5634 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5635 | WindowState target = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5636 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5637 | synchronized(mWindowMap) { |
| 5638 | synchronized (this) { |
| 5639 | if (action == MotionEvent.ACTION_DOWN) { |
| 5640 | if (mMotionTarget != null) { |
| 5641 | // this is weird, we got a pen down, but we thought it was |
| 5642 | // already down! |
| 5643 | // XXX: We should probably send an ACTION_UP to the current |
| 5644 | // target. |
| 5645 | Log.w(TAG, "Pointer down received while already down in: " |
| 5646 | + mMotionTarget); |
| 5647 | mMotionTarget = null; |
| 5648 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5649 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5650 | // ACTION_DOWN is special, because we need to lock next events to |
| 5651 | // the window we'll land onto. |
| 5652 | final int x = (int)xf; |
| 5653 | final int y = (int)yf; |
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 | final ArrayList windows = mWindows; |
| 5656 | final int N = windows.size(); |
| 5657 | WindowState topErrWindow = null; |
| 5658 | final Rect tmpRect = mTempRect; |
| 5659 | for (int i=N-1; i>=0; i--) { |
| 5660 | WindowState child = (WindowState)windows.get(i); |
| 5661 | //Log.i(TAG, "Checking dispatch to: " + child); |
| 5662 | final int flags = child.mAttrs.flags; |
| 5663 | if ((flags & WindowManager.LayoutParams.FLAG_SYSTEM_ERROR) != 0) { |
| 5664 | if (topErrWindow == null) { |
| 5665 | topErrWindow = child; |
| 5666 | } |
| 5667 | } |
| 5668 | if (!child.isVisibleLw()) { |
| 5669 | //Log.i(TAG, "Not visible!"); |
| 5670 | continue; |
| 5671 | } |
| 5672 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 5673 | //Log.i(TAG, "Not touchable!"); |
| 5674 | if ((flags & WindowManager.LayoutParams |
| 5675 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 5676 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 5677 | mOutsideTouchTargets = child; |
| 5678 | } |
| 5679 | continue; |
| 5680 | } |
| 5681 | tmpRect.set(child.mFrame); |
| 5682 | if (child.mTouchableInsets == ViewTreeObserver |
| 5683 | .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) { |
| 5684 | // The touch is inside of the window if it is |
| 5685 | // inside the frame, AND the content part of that |
| 5686 | // frame that was given by the application. |
| 5687 | tmpRect.left += child.mGivenContentInsets.left; |
| 5688 | tmpRect.top += child.mGivenContentInsets.top; |
| 5689 | tmpRect.right -= child.mGivenContentInsets.right; |
| 5690 | tmpRect.bottom -= child.mGivenContentInsets.bottom; |
| 5691 | } else if (child.mTouchableInsets == ViewTreeObserver |
| 5692 | .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) { |
| 5693 | // The touch is inside of the window if it is |
| 5694 | // inside the frame, AND the visible part of that |
| 5695 | // frame that was given by the application. |
| 5696 | tmpRect.left += child.mGivenVisibleInsets.left; |
| 5697 | tmpRect.top += child.mGivenVisibleInsets.top; |
| 5698 | tmpRect.right -= child.mGivenVisibleInsets.right; |
| 5699 | tmpRect.bottom -= child.mGivenVisibleInsets.bottom; |
| 5700 | } |
| 5701 | final int touchFlags = flags & |
| 5702 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 5703 | |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 5704 | if (tmpRect.contains(x, y) || touchFlags == 0) { |
| 5705 | //Log.i(TAG, "Using this target!"); |
| 5706 | if (!screenWasOff || (flags & |
| 5707 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING) != 0) { |
| 5708 | mMotionTarget = child; |
| 5709 | } else { |
| 5710 | //Log.i(TAG, "Waking, skip!"); |
| 5711 | mMotionTarget = null; |
| 5712 | } |
| 5713 | break; |
| 5714 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5715 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5716 | if ((flags & WindowManager.LayoutParams |
| 5717 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 5718 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 5719 | mOutsideTouchTargets = child; |
| 5720 | //Log.i(TAG, "Adding to outside target list: " + child); |
| 5721 | } |
| 5722 | } |
| 5723 | |
| 5724 | // if there's an error window but it's not accepting |
| 5725 | // focus (typically because it is not yet visible) just |
| 5726 | // wait for it -- any other focused window may in fact |
| 5727 | // be in ANR state. |
| 5728 | if (topErrWindow != null && mMotionTarget != topErrWindow) { |
| 5729 | mMotionTarget = null; |
| 5730 | } |
| 5731 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5732 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5733 | target = mMotionTarget; |
| 5734 | } |
| 5735 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5736 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5737 | wakeupIfNeeded(target, eventType(nextMotion)); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5738 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5739 | // Pointer events are a little different -- if there isn't a |
| 5740 | // target found for any event, then just drop it. |
| 5741 | return target != null ? target : SKIP_TARGET_TOKEN; |
| 5742 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5743 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5744 | boolean checkShouldDispatchKey(int keycode) { |
| 5745 | synchronized (this) { |
| 5746 | if (mPolicy.isAppSwitchKeyTqTiLwLi(keycode)) { |
| 5747 | mTimeToSwitch = 0; |
| 5748 | return true; |
| 5749 | } |
| 5750 | if (mTimeToSwitch != 0 |
| 5751 | && mTimeToSwitch < SystemClock.uptimeMillis()) { |
| 5752 | return false; |
| 5753 | } |
| 5754 | return true; |
| 5755 | } |
| 5756 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5757 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5758 | void bindTargetWindowLocked(WindowState win, |
| 5759 | int pendingWhat, QueuedEvent pendingMotion) { |
| 5760 | synchronized (this) { |
| 5761 | bindTargetWindowLockedLocked(win, pendingWhat, pendingMotion); |
| 5762 | } |
| 5763 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5764 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5765 | void bindTargetWindowLocked(WindowState win) { |
| 5766 | synchronized (this) { |
| 5767 | bindTargetWindowLockedLocked(win, RETURN_NOTHING, null); |
| 5768 | } |
| 5769 | } |
| 5770 | |
| 5771 | void bindTargetWindowLockedLocked(WindowState win, |
| 5772 | int pendingWhat, QueuedEvent pendingMotion) { |
| 5773 | mLastWin = win; |
| 5774 | mLastBinder = win.mClient.asBinder(); |
| 5775 | mFinished = false; |
| 5776 | if (pendingMotion != null) { |
| 5777 | final Session s = win.mSession; |
| 5778 | if (pendingWhat == RETURN_PENDING_POINTER) { |
| 5779 | releasePendingPointerLocked(s); |
| 5780 | s.mPendingPointerMove = pendingMotion; |
| 5781 | s.mPendingPointerWindow = win; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5782 | if (DEBUG_INPUT) Log.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5783 | "bindTargetToWindow " + s.mPendingPointerMove); |
| 5784 | } else if (pendingWhat == RETURN_PENDING_TRACKBALL) { |
| 5785 | releasePendingTrackballLocked(s); |
| 5786 | s.mPendingTrackballMove = pendingMotion; |
| 5787 | s.mPendingTrackballWindow = win; |
| 5788 | } |
| 5789 | } |
| 5790 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5791 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5792 | void releasePendingPointerLocked(Session s) { |
| 5793 | if (DEBUG_INPUT) Log.v(TAG, |
| 5794 | "releasePendingPointer " + s.mPendingPointerMove); |
| 5795 | if (s.mPendingPointerMove != null) { |
| 5796 | mQueue.recycleEvent(s.mPendingPointerMove); |
| 5797 | s.mPendingPointerMove = null; |
| 5798 | } |
| 5799 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5800 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5801 | void releasePendingTrackballLocked(Session s) { |
| 5802 | if (s.mPendingTrackballMove != null) { |
| 5803 | mQueue.recycleEvent(s.mPendingTrackballMove); |
| 5804 | s.mPendingTrackballMove = null; |
| 5805 | } |
| 5806 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5807 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5808 | MotionEvent finishedKey(Session session, IWindow client, boolean force, |
| 5809 | int returnWhat) { |
| 5810 | if (DEBUG_INPUT) Log.v( |
| 5811 | TAG, "finishedKey: client=" + client + ", force=" + force); |
| 5812 | |
| 5813 | if (client == null) { |
| 5814 | return null; |
| 5815 | } |
| 5816 | |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5817 | MotionEvent res = null; |
| 5818 | QueuedEvent qev = null; |
| 5819 | WindowState win = null; |
| 5820 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5821 | synchronized (this) { |
| 5822 | if (DEBUG_INPUT) Log.v( |
| 5823 | TAG, "finishedKey: client=" + client.asBinder() |
| 5824 | + ", force=" + force + ", last=" + mLastBinder |
| 5825 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) + ")"); |
| 5826 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5827 | if (returnWhat == RETURN_PENDING_POINTER) { |
| 5828 | qev = session.mPendingPointerMove; |
| 5829 | win = session.mPendingPointerWindow; |
| 5830 | session.mPendingPointerMove = null; |
| 5831 | session.mPendingPointerWindow = null; |
| 5832 | } else if (returnWhat == RETURN_PENDING_TRACKBALL) { |
| 5833 | qev = session.mPendingTrackballMove; |
| 5834 | win = session.mPendingTrackballWindow; |
| 5835 | session.mPendingTrackballMove = null; |
| 5836 | session.mPendingTrackballWindow = null; |
| 5837 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5838 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5839 | if (mLastBinder == client.asBinder()) { |
| 5840 | if (DEBUG_INPUT) Log.v( |
| 5841 | TAG, "finishedKey: last paused=" |
| 5842 | + ((mLastWin != null) ? mLastWin.mToken.paused : "null")); |
| 5843 | if (mLastWin != null && (!mLastWin.mToken.paused || force |
| 5844 | || !mEventDispatching)) { |
| 5845 | doFinishedKeyLocked(false); |
| 5846 | } else { |
| 5847 | // Make sure to wake up anyone currently waiting to |
| 5848 | // dispatch a key, so they can re-evaluate their |
| 5849 | // current situation. |
| 5850 | mFinished = true; |
| 5851 | notifyAll(); |
| 5852 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5853 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5854 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5855 | if (qev != null) { |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5856 | res = (MotionEvent)qev.event; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5857 | if (DEBUG_INPUT) Log.v(TAG, |
| 5858 | "Returning pending motion: " + res); |
| 5859 | mQueue.recycleEvent(qev); |
| 5860 | if (win != null && returnWhat == RETURN_PENDING_POINTER) { |
| 5861 | res.offsetLocation(-win.mFrame.left, -win.mFrame.top); |
| 5862 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5863 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5864 | } |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5865 | |
| 5866 | if (res != null && returnWhat == RETURN_PENDING_POINTER) { |
| 5867 | synchronized (mWindowMap) { |
| 5868 | if (mWallpaperTarget == win) { |
| 5869 | sendPointerToWallpaperLocked(win, res, res.getEventTime()); |
| 5870 | } |
| 5871 | } |
| 5872 | } |
| 5873 | |
| 5874 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5875 | } |
| 5876 | |
| 5877 | void tickle() { |
| 5878 | synchronized (this) { |
| 5879 | notifyAll(); |
| 5880 | } |
| 5881 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5882 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5883 | void handleNewWindowLocked(WindowState newWindow) { |
| 5884 | if (!newWindow.canReceiveKeys()) { |
| 5885 | return; |
| 5886 | } |
| 5887 | synchronized (this) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5888 | if (DEBUG_INPUT) Log.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5889 | TAG, "New key dispatch window: win=" |
| 5890 | + newWindow.mClient.asBinder() |
| 5891 | + ", last=" + mLastBinder |
| 5892 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 5893 | + "), finished=" + mFinished + ", paused=" |
| 5894 | + newWindow.mToken.paused); |
| 5895 | |
| 5896 | // Displaying a window implicitly causes dispatching to |
| 5897 | // be unpaused. (This is to protect against bugs if someone |
| 5898 | // pauses dispatching but forgets to resume.) |
| 5899 | newWindow.mToken.paused = false; |
| 5900 | |
| 5901 | mGotFirstWindow = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5902 | |
| 5903 | if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) { |
| 5904 | if (DEBUG_INPUT) Log.v(TAG, |
| 5905 | "New SYSTEM_ERROR window; resetting state"); |
| 5906 | mLastWin = null; |
| 5907 | mLastBinder = null; |
| 5908 | mMotionTarget = null; |
| 5909 | mFinished = true; |
| 5910 | } else if (mLastWin != null) { |
| 5911 | // If the new window is above the window we are |
| 5912 | // waiting on, then stop waiting and let key dispatching |
| 5913 | // start on the new guy. |
| 5914 | if (DEBUG_INPUT) Log.v( |
| 5915 | TAG, "Last win layer=" + mLastWin.mLayer |
| 5916 | + ", new win layer=" + newWindow.mLayer); |
| 5917 | if (newWindow.mLayer >= mLastWin.mLayer) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5918 | // The new window is above the old; finish pending input to the last |
| 5919 | // window and start directing it to the new one. |
| 5920 | mLastWin.mToken.paused = false; |
| 5921 | doFinishedKeyLocked(true); // does a notifyAll() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5922 | } |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5923 | // Either the new window is lower, so there is no need to wake key waiters, |
| 5924 | // or we just finished key input to the previous window, which implicitly |
| 5925 | // notified the key waiters. In both cases, we don't need to issue the |
| 5926 | // notification here. |
| 5927 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5928 | } |
| 5929 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5930 | // Now that we've put a new window state in place, make the event waiter |
| 5931 | // take notice and retarget its attentions. |
| 5932 | notifyAll(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5933 | } |
| 5934 | } |
| 5935 | |
| 5936 | void pauseDispatchingLocked(WindowToken token) { |
| 5937 | synchronized (this) |
| 5938 | { |
| 5939 | if (DEBUG_INPUT) Log.v(TAG, "Pausing WindowToken " + token); |
| 5940 | token.paused = true; |
| 5941 | |
| 5942 | /* |
| 5943 | if (mLastWin != null && !mFinished && mLastWin.mBaseLayer <= layer) { |
| 5944 | mPaused = true; |
| 5945 | } else { |
| 5946 | if (mLastWin == null) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 5947 | 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] | 5948 | } else if (mFinished) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 5949 | 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] | 5950 | } else { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 5951 | 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] | 5952 | } |
| 5953 | } |
| 5954 | */ |
| 5955 | } |
| 5956 | } |
| 5957 | |
| 5958 | void resumeDispatchingLocked(WindowToken token) { |
| 5959 | synchronized (this) { |
| 5960 | if (token.paused) { |
| 5961 | if (DEBUG_INPUT) Log.v( |
| 5962 | TAG, "Resuming WindowToken " + token |
| 5963 | + ", last=" + mLastBinder |
| 5964 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 5965 | + "), finished=" + mFinished + ", paused=" |
| 5966 | + token.paused); |
| 5967 | token.paused = false; |
| 5968 | if (mLastWin != null && mLastWin.mToken == token && mFinished) { |
| 5969 | doFinishedKeyLocked(true); |
| 5970 | } else { |
| 5971 | notifyAll(); |
| 5972 | } |
| 5973 | } |
| 5974 | } |
| 5975 | } |
| 5976 | |
| 5977 | void setEventDispatchingLocked(boolean enabled) { |
| 5978 | synchronized (this) { |
| 5979 | mEventDispatching = enabled; |
| 5980 | notifyAll(); |
| 5981 | } |
| 5982 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5983 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5984 | void appSwitchComing() { |
| 5985 | synchronized (this) { |
| 5986 | // Don't wait for more than .5 seconds for app to finish |
| 5987 | // processing the pending events. |
| 5988 | long now = SystemClock.uptimeMillis() + 500; |
| 5989 | if (DEBUG_INPUT) Log.v(TAG, "appSwitchComing: " + now); |
| 5990 | if (mTimeToSwitch == 0 || now < mTimeToSwitch) { |
| 5991 | mTimeToSwitch = now; |
| 5992 | } |
| 5993 | notifyAll(); |
| 5994 | } |
| 5995 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5996 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5997 | private final void doFinishedKeyLocked(boolean doRecycle) { |
| 5998 | if (mLastWin != null) { |
| 5999 | releasePendingPointerLocked(mLastWin.mSession); |
| 6000 | releasePendingTrackballLocked(mLastWin.mSession); |
| 6001 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6002 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6003 | if (mLastWin == null || !mLastWin.mToken.paused |
| 6004 | || !mLastWin.isVisibleLw()) { |
| 6005 | // If the current window has been paused, we aren't -really- |
| 6006 | // finished... so let the waiters still wait. |
| 6007 | mLastWin = null; |
| 6008 | mLastBinder = null; |
| 6009 | } |
| 6010 | mFinished = true; |
| 6011 | notifyAll(); |
| 6012 | } |
| 6013 | } |
| 6014 | |
| 6015 | private class KeyQ extends KeyInputQueue |
| 6016 | implements KeyInputQueue.FilterCallback { |
| 6017 | PowerManager.WakeLock mHoldingScreen; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6018 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6019 | KeyQ() { |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 6020 | super(mContext, WindowManagerService.this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6021 | PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE); |
| 6022 | mHoldingScreen = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 6023 | "KEEP_SCREEN_ON_FLAG"); |
| 6024 | mHoldingScreen.setReferenceCounted(false); |
| 6025 | } |
| 6026 | |
| 6027 | @Override |
| 6028 | boolean preprocessEvent(InputDevice device, RawInputEvent event) { |
| 6029 | if (mPolicy.preprocessInputEventTq(event)) { |
| 6030 | return true; |
| 6031 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6032 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6033 | switch (event.type) { |
| 6034 | case RawInputEvent.EV_KEY: { |
| 6035 | // XXX begin hack |
| 6036 | if (DEBUG) { |
| 6037 | if (event.keycode == KeyEvent.KEYCODE_G) { |
| 6038 | if (event.value != 0) { |
| 6039 | // G down |
| 6040 | mPolicy.screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 6041 | } |
| 6042 | return false; |
| 6043 | } |
| 6044 | if (event.keycode == KeyEvent.KEYCODE_D) { |
| 6045 | if (event.value != 0) { |
| 6046 | //dump(); |
| 6047 | } |
| 6048 | return false; |
| 6049 | } |
| 6050 | } |
| 6051 | // XXX end hack |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6052 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6053 | boolean screenIsOff = !mPowerManager.screenIsOn(); |
| 6054 | boolean screenIsDim = !mPowerManager.screenIsBright(); |
| 6055 | int actions = mPolicy.interceptKeyTq(event, !screenIsOff); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6056 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6057 | if ((actions & WindowManagerPolicy.ACTION_GO_TO_SLEEP) != 0) { |
| 6058 | mPowerManager.goToSleep(event.when); |
| 6059 | } |
| 6060 | |
| 6061 | if (screenIsOff) { |
| 6062 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6063 | } |
| 6064 | if (screenIsDim) { |
| 6065 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6066 | } |
| 6067 | if ((actions & WindowManagerPolicy.ACTION_POKE_USER_ACTIVITY) != 0) { |
| 6068 | mPowerManager.userActivity(event.when, false, |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6069 | LocalPowerManager.BUTTON_EVENT, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6070 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6071 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6072 | if ((actions & WindowManagerPolicy.ACTION_PASS_TO_USER) != 0) { |
| 6073 | if (event.value != 0 && mPolicy.isAppSwitchKeyTqTiLwLi(event.keycode)) { |
| 6074 | filterQueue(this); |
| 6075 | mKeyWaiter.appSwitchComing(); |
| 6076 | } |
| 6077 | return true; |
| 6078 | } else { |
| 6079 | return false; |
| 6080 | } |
| 6081 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6082 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6083 | case RawInputEvent.EV_REL: { |
| 6084 | boolean screenIsOff = !mPowerManager.screenIsOn(); |
| 6085 | boolean screenIsDim = !mPowerManager.screenIsBright(); |
| 6086 | if (screenIsOff) { |
| 6087 | if (!mPolicy.isWakeRelMovementTq(event.deviceId, |
| 6088 | device.classes, event)) { |
| 6089 | //Log.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| 6090 | return false; |
| 6091 | } |
| 6092 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6093 | } |
| 6094 | if (screenIsDim) { |
| 6095 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6096 | } |
| 6097 | return true; |
| 6098 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6099 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6100 | case RawInputEvent.EV_ABS: { |
| 6101 | boolean screenIsOff = !mPowerManager.screenIsOn(); |
| 6102 | boolean screenIsDim = !mPowerManager.screenIsBright(); |
| 6103 | if (screenIsOff) { |
| 6104 | if (!mPolicy.isWakeAbsMovementTq(event.deviceId, |
| 6105 | device.classes, event)) { |
| 6106 | //Log.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| 6107 | return false; |
| 6108 | } |
| 6109 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6110 | } |
| 6111 | if (screenIsDim) { |
| 6112 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6113 | } |
| 6114 | return true; |
| 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 | default: |
| 6118 | return true; |
| 6119 | } |
| 6120 | } |
| 6121 | |
| 6122 | public int filterEvent(QueuedEvent ev) { |
| 6123 | switch (ev.classType) { |
| 6124 | case RawInputEvent.CLASS_KEYBOARD: |
| 6125 | KeyEvent ke = (KeyEvent)ev.event; |
| 6126 | if (mPolicy.isMovementKeyTi(ke.getKeyCode())) { |
| 6127 | Log.w(TAG, "Dropping movement key during app switch: " |
| 6128 | + ke.getKeyCode() + ", action=" + ke.getAction()); |
| 6129 | return FILTER_REMOVE; |
| 6130 | } |
| 6131 | return FILTER_ABORT; |
| 6132 | default: |
| 6133 | return FILTER_KEEP; |
| 6134 | } |
| 6135 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6136 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6137 | /** |
| 6138 | * Must be called with the main window manager lock held. |
| 6139 | */ |
| 6140 | void setHoldScreenLocked(boolean holding) { |
| 6141 | boolean state = mHoldingScreen.isHeld(); |
| 6142 | if (holding != state) { |
| 6143 | if (holding) { |
| 6144 | mHoldingScreen.acquire(); |
| 6145 | } else { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6146 | mPolicy.screenOnStoppedLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6147 | mHoldingScreen.release(); |
| 6148 | } |
| 6149 | } |
| 6150 | } |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6151 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6152 | |
| 6153 | public boolean detectSafeMode() { |
| 6154 | mSafeMode = mPolicy.detectSafeMode(); |
| 6155 | return mSafeMode; |
| 6156 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6157 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6158 | public void systemReady() { |
| 6159 | mPolicy.systemReady(); |
| 6160 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6161 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6162 | private final class InputDispatcherThread extends Thread { |
| 6163 | // Time to wait when there is nothing to do: 9999 seconds. |
| 6164 | static final int LONG_WAIT=9999*1000; |
| 6165 | |
| 6166 | public InputDispatcherThread() { |
| 6167 | super("InputDispatcher"); |
| 6168 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6169 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6170 | @Override |
| 6171 | public void run() { |
| 6172 | while (true) { |
| 6173 | try { |
| 6174 | process(); |
| 6175 | } catch (Exception e) { |
| 6176 | Log.e(TAG, "Exception in input dispatcher", e); |
| 6177 | } |
| 6178 | } |
| 6179 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6180 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6181 | private void process() { |
| 6182 | android.os.Process.setThreadPriority( |
| 6183 | android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6184 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6185 | // The last key event we saw |
| 6186 | KeyEvent lastKey = null; |
| 6187 | |
| 6188 | // Last keydown time for auto-repeating keys |
| 6189 | long lastKeyTime = SystemClock.uptimeMillis(); |
| 6190 | long nextKeyTime = lastKeyTime+LONG_WAIT; |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6191 | long downTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6192 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6193 | // How many successive repeats we generated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6194 | int keyRepeatCount = 0; |
| 6195 | |
| 6196 | // Need to report that configuration has changed? |
| 6197 | boolean configChanged = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6198 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6199 | while (true) { |
| 6200 | long curTime = SystemClock.uptimeMillis(); |
| 6201 | |
| 6202 | if (DEBUG_INPUT) Log.v( |
| 6203 | TAG, "Waiting for next key: now=" + curTime |
| 6204 | + ", repeat @ " + nextKeyTime); |
| 6205 | |
| 6206 | // Retrieve next event, waiting only as long as the next |
| 6207 | // repeat timeout. If the configuration has changed, then |
| 6208 | // don't wait at all -- we'll report the change as soon as |
| 6209 | // we have processed all events. |
| 6210 | QueuedEvent ev = mQueue.getEvent( |
| 6211 | (int)((!configChanged && curTime < nextKeyTime) |
| 6212 | ? (nextKeyTime-curTime) : 0)); |
| 6213 | |
| 6214 | if (DEBUG_INPUT && ev != null) Log.v( |
| 6215 | TAG, "Event: type=" + ev.classType + " data=" + ev.event); |
| 6216 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6217 | if (MEASURE_LATENCY) { |
| 6218 | lt.sample("2 got event ", System.nanoTime() - ev.whenNano); |
| 6219 | } |
| 6220 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6221 | try { |
| 6222 | if (ev != null) { |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6223 | curTime = SystemClock.uptimeMillis(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6224 | int eventType; |
| 6225 | if (ev.classType == RawInputEvent.CLASS_TOUCHSCREEN) { |
| 6226 | eventType = eventType((MotionEvent)ev.event); |
| 6227 | } else if (ev.classType == RawInputEvent.CLASS_KEYBOARD || |
| 6228 | ev.classType == RawInputEvent.CLASS_TRACKBALL) { |
| 6229 | eventType = LocalPowerManager.BUTTON_EVENT; |
| 6230 | } else { |
| 6231 | eventType = LocalPowerManager.OTHER_EVENT; |
| 6232 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6233 | try { |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6234 | if ((curTime - mLastBatteryStatsCallTime) |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6235 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6236 | mLastBatteryStatsCallTime = curTime; |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6237 | mBatteryStats.noteInputEvent(); |
| 6238 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6239 | } catch (RemoteException e) { |
| 6240 | // Ignore |
| 6241 | } |
Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 6242 | |
| 6243 | if (eventType != TOUCH_EVENT |
| 6244 | && eventType != LONG_TOUCH_EVENT |
| 6245 | && eventType != CHEEK_EVENT) { |
| 6246 | mPowerManager.userActivity(curTime, false, |
| 6247 | eventType, false); |
| 6248 | } else if (mLastTouchEventType != eventType |
| 6249 | || (curTime - mLastUserActivityCallTime) |
| 6250 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 6251 | mLastUserActivityCallTime = curTime; |
| 6252 | mLastTouchEventType = eventType; |
| 6253 | mPowerManager.userActivity(curTime, false, |
| 6254 | eventType, false); |
| 6255 | } |
| 6256 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6257 | switch (ev.classType) { |
| 6258 | case RawInputEvent.CLASS_KEYBOARD: |
| 6259 | KeyEvent ke = (KeyEvent)ev.event; |
| 6260 | if (ke.isDown()) { |
| 6261 | lastKey = ke; |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6262 | downTime = curTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6263 | keyRepeatCount = 0; |
| 6264 | lastKeyTime = curTime; |
| 6265 | nextKeyTime = lastKeyTime |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6266 | + ViewConfiguration.getLongPressTimeout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6267 | if (DEBUG_INPUT) Log.v( |
| 6268 | TAG, "Received key down: first repeat @ " |
| 6269 | + nextKeyTime); |
| 6270 | } else { |
| 6271 | lastKey = null; |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6272 | downTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6273 | // Arbitrary long timeout. |
| 6274 | lastKeyTime = curTime; |
| 6275 | nextKeyTime = curTime + LONG_WAIT; |
| 6276 | if (DEBUG_INPUT) Log.v( |
| 6277 | TAG, "Received key up: ignore repeat @ " |
| 6278 | + nextKeyTime); |
| 6279 | } |
| 6280 | dispatchKey((KeyEvent)ev.event, 0, 0); |
| 6281 | mQueue.recycleEvent(ev); |
| 6282 | break; |
| 6283 | case RawInputEvent.CLASS_TOUCHSCREEN: |
| 6284 | //Log.i(TAG, "Read next event " + ev); |
| 6285 | dispatchPointer(ev, (MotionEvent)ev.event, 0, 0); |
| 6286 | break; |
| 6287 | case RawInputEvent.CLASS_TRACKBALL: |
| 6288 | dispatchTrackball(ev, (MotionEvent)ev.event, 0, 0); |
| 6289 | break; |
| 6290 | case RawInputEvent.CLASS_CONFIGURATION_CHANGED: |
| 6291 | configChanged = true; |
| 6292 | break; |
| 6293 | default: |
| 6294 | mQueue.recycleEvent(ev); |
| 6295 | break; |
| 6296 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6297 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6298 | } else if (configChanged) { |
| 6299 | configChanged = false; |
| 6300 | sendNewConfiguration(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6301 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6302 | } else if (lastKey != null) { |
| 6303 | curTime = SystemClock.uptimeMillis(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6304 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6305 | // Timeout occurred while key was down. If it is at or |
| 6306 | // past the key repeat time, dispatch the repeat. |
| 6307 | if (DEBUG_INPUT) Log.v( |
| 6308 | TAG, "Key timeout: repeat=" + nextKeyTime |
| 6309 | + ", now=" + curTime); |
| 6310 | if (curTime < nextKeyTime) { |
| 6311 | continue; |
| 6312 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6313 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6314 | lastKeyTime = nextKeyTime; |
| 6315 | nextKeyTime = nextKeyTime + KEY_REPEAT_DELAY; |
| 6316 | keyRepeatCount++; |
| 6317 | if (DEBUG_INPUT) Log.v( |
| 6318 | TAG, "Key repeat: count=" + keyRepeatCount |
| 6319 | + ", next @ " + nextKeyTime); |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6320 | KeyEvent newEvent; |
| 6321 | if (downTime != 0 && (downTime |
| 6322 | + ViewConfiguration.getLongPressTimeout()) |
| 6323 | <= curTime) { |
| 6324 | newEvent = KeyEvent.changeTimeRepeat(lastKey, |
| 6325 | curTime, keyRepeatCount, |
| 6326 | lastKey.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 6327 | downTime = 0; |
| 6328 | } else { |
| 6329 | newEvent = KeyEvent.changeTimeRepeat(lastKey, |
| 6330 | curTime, keyRepeatCount); |
| 6331 | } |
| 6332 | dispatchKey(newEvent, 0, 0); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6333 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6334 | } else { |
| 6335 | curTime = SystemClock.uptimeMillis(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6336 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6337 | lastKeyTime = curTime; |
| 6338 | nextKeyTime = curTime + LONG_WAIT; |
| 6339 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6340 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6341 | } catch (Exception e) { |
| 6342 | Log.e(TAG, |
| 6343 | "Input thread received uncaught exception: " + e, e); |
| 6344 | } |
| 6345 | } |
| 6346 | } |
| 6347 | } |
| 6348 | |
| 6349 | // ------------------------------------------------------------- |
| 6350 | // Client Session State |
| 6351 | // ------------------------------------------------------------- |
| 6352 | |
| 6353 | private final class Session extends IWindowSession.Stub |
| 6354 | implements IBinder.DeathRecipient { |
| 6355 | final IInputMethodClient mClient; |
| 6356 | final IInputContext mInputContext; |
| 6357 | final int mUid; |
| 6358 | final int mPid; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6359 | final String mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6360 | SurfaceSession mSurfaceSession; |
| 6361 | int mNumWindow = 0; |
| 6362 | boolean mClientDead = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6363 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6364 | /** |
| 6365 | * Current pointer move event being dispatched to client window... must |
| 6366 | * hold key lock to access. |
| 6367 | */ |
| 6368 | QueuedEvent mPendingPointerMove; |
| 6369 | WindowState mPendingPointerWindow; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6370 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6371 | /** |
| 6372 | * Current trackball move event being dispatched to client window... must |
| 6373 | * hold key lock to access. |
| 6374 | */ |
| 6375 | QueuedEvent mPendingTrackballMove; |
| 6376 | WindowState mPendingTrackballWindow; |
| 6377 | |
| 6378 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 6379 | mClient = client; |
| 6380 | mInputContext = inputContext; |
| 6381 | mUid = Binder.getCallingUid(); |
| 6382 | mPid = Binder.getCallingPid(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6383 | StringBuilder sb = new StringBuilder(); |
| 6384 | sb.append("Session{"); |
| 6385 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 6386 | sb.append(" uid "); |
| 6387 | sb.append(mUid); |
| 6388 | sb.append("}"); |
| 6389 | mStringName = sb.toString(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6390 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6391 | synchronized (mWindowMap) { |
| 6392 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 6393 | IBinder b = ServiceManager.getService( |
| 6394 | Context.INPUT_METHOD_SERVICE); |
| 6395 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 6396 | } |
| 6397 | } |
| 6398 | long ident = Binder.clearCallingIdentity(); |
| 6399 | try { |
| 6400 | // Note: it is safe to call in to the input method manager |
| 6401 | // here because we are not holding our lock. |
| 6402 | if (mInputMethodManager != null) { |
| 6403 | mInputMethodManager.addClient(client, inputContext, |
| 6404 | mUid, mPid); |
| 6405 | } else { |
| 6406 | client.setUsingInputMethod(false); |
| 6407 | } |
| 6408 | client.asBinder().linkToDeath(this, 0); |
| 6409 | } catch (RemoteException e) { |
| 6410 | // The caller has died, so we can just forget about this. |
| 6411 | try { |
| 6412 | if (mInputMethodManager != null) { |
| 6413 | mInputMethodManager.removeClient(client); |
| 6414 | } |
| 6415 | } catch (RemoteException ee) { |
| 6416 | } |
| 6417 | } finally { |
| 6418 | Binder.restoreCallingIdentity(ident); |
| 6419 | } |
| 6420 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6421 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6422 | @Override |
| 6423 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 6424 | throws RemoteException { |
| 6425 | try { |
| 6426 | return super.onTransact(code, data, reply, flags); |
| 6427 | } catch (RuntimeException e) { |
| 6428 | // Log all 'real' exceptions thrown to the caller |
| 6429 | if (!(e instanceof SecurityException)) { |
| 6430 | Log.e(TAG, "Window Session Crash", e); |
| 6431 | } |
| 6432 | throw e; |
| 6433 | } |
| 6434 | } |
| 6435 | |
| 6436 | public void binderDied() { |
| 6437 | // Note: it is safe to call in to the input method manager |
| 6438 | // here because we are not holding our lock. |
| 6439 | try { |
| 6440 | if (mInputMethodManager != null) { |
| 6441 | mInputMethodManager.removeClient(mClient); |
| 6442 | } |
| 6443 | } catch (RemoteException e) { |
| 6444 | } |
| 6445 | synchronized(mWindowMap) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 6446 | mClient.asBinder().unlinkToDeath(this, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6447 | mClientDead = true; |
| 6448 | killSessionLocked(); |
| 6449 | } |
| 6450 | } |
| 6451 | |
| 6452 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
| 6453 | int viewVisibility, Rect outContentInsets) { |
| 6454 | return addWindow(this, window, attrs, viewVisibility, outContentInsets); |
| 6455 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6456 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6457 | public void remove(IWindow window) { |
| 6458 | removeWindow(this, window); |
| 6459 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6460 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6461 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 6462 | int requestedWidth, int requestedHeight, int viewFlags, |
| 6463 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
| 6464 | Rect outVisibleInsets, Surface outSurface) { |
| 6465 | return relayoutWindow(this, window, attrs, |
| 6466 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
| 6467 | outFrame, outContentInsets, outVisibleInsets, outSurface); |
| 6468 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6469 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6470 | public void setTransparentRegion(IWindow window, Region region) { |
| 6471 | setTransparentRegionWindow(this, window, region); |
| 6472 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6473 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6474 | public void setInsets(IWindow window, int touchableInsets, |
| 6475 | Rect contentInsets, Rect visibleInsets) { |
| 6476 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 6477 | visibleInsets); |
| 6478 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6479 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6480 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 6481 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 6482 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6483 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6484 | public void finishDrawing(IWindow window) { |
| 6485 | if (localLOGV) Log.v( |
| 6486 | TAG, "IWindow finishDrawing called for " + window); |
| 6487 | finishDrawingWindow(this, window); |
| 6488 | } |
| 6489 | |
| 6490 | public void finishKey(IWindow window) { |
| 6491 | if (localLOGV) Log.v( |
| 6492 | TAG, "IWindow finishKey called for " + window); |
| 6493 | mKeyWaiter.finishedKey(this, window, false, |
| 6494 | KeyWaiter.RETURN_NOTHING); |
| 6495 | } |
| 6496 | |
| 6497 | public MotionEvent getPendingPointerMove(IWindow window) { |
| 6498 | if (localLOGV) Log.v( |
| 6499 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 6500 | return mKeyWaiter.finishedKey(this, window, false, |
| 6501 | KeyWaiter.RETURN_PENDING_POINTER); |
| 6502 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6503 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6504 | public MotionEvent getPendingTrackballMove(IWindow window) { |
| 6505 | if (localLOGV) Log.v( |
| 6506 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 6507 | return mKeyWaiter.finishedKey(this, window, false, |
| 6508 | KeyWaiter.RETURN_PENDING_TRACKBALL); |
| 6509 | } |
| 6510 | |
| 6511 | public void setInTouchMode(boolean mode) { |
| 6512 | synchronized(mWindowMap) { |
| 6513 | mInTouchMode = mode; |
| 6514 | } |
| 6515 | } |
| 6516 | |
| 6517 | public boolean getInTouchMode() { |
| 6518 | synchronized(mWindowMap) { |
| 6519 | return mInTouchMode; |
| 6520 | } |
| 6521 | } |
| 6522 | |
| 6523 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 6524 | boolean always) { |
| 6525 | synchronized(mWindowMap) { |
| 6526 | long ident = Binder.clearCallingIdentity(); |
| 6527 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6528 | return mPolicy.performHapticFeedbackLw( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6529 | windowForClientLocked(this, window), effectId, always); |
| 6530 | } finally { |
| 6531 | Binder.restoreCallingIdentity(ident); |
| 6532 | } |
| 6533 | } |
| 6534 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6535 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6536 | public void setWallpaperPosition(IBinder window, float x, float y) { |
| 6537 | synchronized(mWindowMap) { |
| 6538 | long ident = Binder.clearCallingIdentity(); |
| 6539 | try { |
| 6540 | setWindowWallpaperPositionLocked(windowForClientLocked(this, window), |
| 6541 | x, y); |
| 6542 | } finally { |
| 6543 | Binder.restoreCallingIdentity(ident); |
| 6544 | } |
| 6545 | } |
| 6546 | } |
| 6547 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6548 | public void wallpaperOffsetsComplete(IBinder window) { |
| 6549 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 6550 | } |
| 6551 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6552 | void windowAddedLocked() { |
| 6553 | if (mSurfaceSession == null) { |
| 6554 | if (localLOGV) Log.v( |
| 6555 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 6556 | mSurfaceSession = new SurfaceSession(); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6557 | if (SHOW_TRANSACTIONS) Log.i( |
| 6558 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6559 | mSessions.add(this); |
| 6560 | } |
| 6561 | mNumWindow++; |
| 6562 | } |
| 6563 | |
| 6564 | void windowRemovedLocked() { |
| 6565 | mNumWindow--; |
| 6566 | killSessionLocked(); |
| 6567 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6568 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6569 | void killSessionLocked() { |
| 6570 | if (mNumWindow <= 0 && mClientDead) { |
| 6571 | mSessions.remove(this); |
| 6572 | if (mSurfaceSession != null) { |
| 6573 | if (localLOGV) Log.v( |
| 6574 | TAG, "Last window removed from " + this |
| 6575 | + ", destroying " + mSurfaceSession); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6576 | if (SHOW_TRANSACTIONS) Log.i( |
| 6577 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6578 | try { |
| 6579 | mSurfaceSession.kill(); |
| 6580 | } catch (Exception e) { |
| 6581 | Log.w(TAG, "Exception thrown when killing surface session " |
| 6582 | + mSurfaceSession + " in session " + this |
| 6583 | + ": " + e.toString()); |
| 6584 | } |
| 6585 | mSurfaceSession = null; |
| 6586 | } |
| 6587 | } |
| 6588 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6589 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6590 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6591 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 6592 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 6593 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
| 6594 | if (mPendingPointerWindow != null || mPendingPointerMove != null) { |
| 6595 | pw.print(prefix); |
| 6596 | pw.print("mPendingPointerWindow="); pw.print(mPendingPointerWindow); |
| 6597 | pw.print(" mPendingPointerMove="); pw.println(mPendingPointerMove); |
| 6598 | } |
| 6599 | if (mPendingTrackballWindow != null || mPendingTrackballMove != null) { |
| 6600 | pw.print(prefix); |
| 6601 | pw.print("mPendingTrackballWindow="); pw.print(mPendingTrackballWindow); |
| 6602 | pw.print(" mPendingTrackballMove="); pw.println(mPendingTrackballMove); |
| 6603 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6604 | } |
| 6605 | |
| 6606 | @Override |
| 6607 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6608 | return mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6609 | } |
| 6610 | } |
| 6611 | |
| 6612 | // ------------------------------------------------------------- |
| 6613 | // Client Window State |
| 6614 | // ------------------------------------------------------------- |
| 6615 | |
| 6616 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 6617 | final Session mSession; |
| 6618 | final IWindow mClient; |
| 6619 | WindowToken mToken; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6620 | WindowToken mRootToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6621 | AppWindowToken mAppToken; |
| 6622 | AppWindowToken mTargetAppToken; |
| 6623 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 6624 | final DeathRecipient mDeathRecipient; |
| 6625 | final WindowState mAttachedWindow; |
| 6626 | final ArrayList mChildWindows = new ArrayList(); |
| 6627 | final int mBaseLayer; |
| 6628 | final int mSubLayer; |
| 6629 | final boolean mLayoutAttached; |
| 6630 | final boolean mIsImWindow; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6631 | final boolean mIsWallpaper; |
| 6632 | final boolean mIsFloatingLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6633 | int mViewVisibility; |
| 6634 | boolean mPolicyVisibility = true; |
| 6635 | boolean mPolicyVisibilityAfterAnim = true; |
| 6636 | boolean mAppFreezing; |
| 6637 | Surface mSurface; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6638 | boolean mReportDestroySurface; |
| 6639 | boolean mSurfacePendingDestroy; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6640 | boolean mAttachedHidden; // is our parent window hidden? |
| 6641 | boolean mLastHidden; // was this window last hidden? |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6642 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6643 | int mRequestedWidth; |
| 6644 | int mRequestedHeight; |
| 6645 | int mLastRequestedWidth; |
| 6646 | int mLastRequestedHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6647 | int mLayer; |
| 6648 | int mAnimLayer; |
| 6649 | int mLastLayer; |
| 6650 | boolean mHaveFrame; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6651 | boolean mObscured; |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 6652 | boolean mTurnOnScreen; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6653 | |
| 6654 | WindowState mNextOutsideTouch; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6655 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6656 | // Actual frame shown on-screen (may be modified by animation) |
| 6657 | final Rect mShownFrame = new Rect(); |
| 6658 | final Rect mLastShownFrame = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6659 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6660 | /** |
| 6661 | * Insets that determine the actually visible area |
| 6662 | */ |
| 6663 | final Rect mVisibleInsets = new Rect(); |
| 6664 | final Rect mLastVisibleInsets = new Rect(); |
| 6665 | boolean mVisibleInsetsChanged; |
| 6666 | |
| 6667 | /** |
| 6668 | * Insets that are covered by system windows |
| 6669 | */ |
| 6670 | final Rect mContentInsets = new Rect(); |
| 6671 | final Rect mLastContentInsets = new Rect(); |
| 6672 | boolean mContentInsetsChanged; |
| 6673 | |
| 6674 | /** |
| 6675 | * Set to true if we are waiting for this window to receive its |
| 6676 | * given internal insets before laying out other windows based on it. |
| 6677 | */ |
| 6678 | boolean mGivenInsetsPending; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6679 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6680 | /** |
| 6681 | * These are the content insets that were given during layout for |
| 6682 | * this window, to be applied to windows behind it. |
| 6683 | */ |
| 6684 | final Rect mGivenContentInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6685 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6686 | /** |
| 6687 | * These are the visible insets that were given during layout for |
| 6688 | * this window, to be applied to windows behind it. |
| 6689 | */ |
| 6690 | final Rect mGivenVisibleInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6691 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6692 | /** |
| 6693 | * Flag indicating whether the touchable region should be adjusted by |
| 6694 | * the visible insets; if false the area outside the visible insets is |
| 6695 | * NOT touchable, so we must use those to adjust the frame during hit |
| 6696 | * tests. |
| 6697 | */ |
| 6698 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6699 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6700 | // Current transformation being applied. |
| 6701 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 6702 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 6703 | float mHScale=1, mVScale=1; |
| 6704 | float mLastHScale=1, mLastVScale=1; |
| 6705 | final Matrix mTmpMatrix = new Matrix(); |
| 6706 | |
| 6707 | // "Real" frame that the application sees. |
| 6708 | final Rect mFrame = new Rect(); |
| 6709 | final Rect mLastFrame = new Rect(); |
| 6710 | |
| 6711 | final Rect mContainingFrame = new Rect(); |
| 6712 | final Rect mDisplayFrame = new Rect(); |
| 6713 | final Rect mContentFrame = new Rect(); |
| 6714 | final Rect mVisibleFrame = new Rect(); |
| 6715 | |
| 6716 | float mShownAlpha = 1; |
| 6717 | float mAlpha = 1; |
| 6718 | float mLastAlpha = 1; |
| 6719 | |
| 6720 | // Set to true if, when the window gets displayed, it should perform |
| 6721 | // an enter animation. |
| 6722 | boolean mEnterAnimationPending; |
| 6723 | |
| 6724 | // Currently running animation. |
| 6725 | boolean mAnimating; |
| 6726 | boolean mLocalAnimating; |
| 6727 | Animation mAnimation; |
| 6728 | boolean mAnimationIsEntrance; |
| 6729 | boolean mHasTransformation; |
| 6730 | boolean mHasLocalTransformation; |
| 6731 | final Transformation mTransformation = new Transformation(); |
| 6732 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6733 | // If a window showing a wallpaper: the requested offset for the |
| 6734 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 6735 | float mWallpaperX = -1; |
| 6736 | float mWallpaperY = -1; |
| 6737 | |
| 6738 | // Wallpaper windows: pixels offset based on above variables. |
| 6739 | int mXOffset; |
| 6740 | int mYOffset; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6741 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6742 | // This is set after IWindowSession.relayout() has been called at |
| 6743 | // least once for the window. It allows us to detect the situation |
| 6744 | // where we don't yet have a surface, but should have one soon, so |
| 6745 | // we can give the window focus before waiting for the relayout. |
| 6746 | boolean mRelayoutCalled; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6747 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6748 | // This is set after the Surface has been created but before the |
| 6749 | // window has been drawn. During this time the surface is hidden. |
| 6750 | boolean mDrawPending; |
| 6751 | |
| 6752 | // This is set after the window has finished drawing for the first |
| 6753 | // time but before its surface is shown. The surface will be |
| 6754 | // displayed when the next layout is run. |
| 6755 | boolean mCommitDrawPending; |
| 6756 | |
| 6757 | // This is set during the time after the window's drawing has been |
| 6758 | // committed, and before its surface is actually shown. It is used |
| 6759 | // to delay showing the surface until all windows in a token are ready |
| 6760 | // to be shown. |
| 6761 | boolean mReadyToShow; |
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 | // Set when the window has been shown in the screen the first time. |
| 6764 | boolean mHasDrawn; |
| 6765 | |
| 6766 | // Currently running an exit animation? |
| 6767 | boolean mExiting; |
| 6768 | |
| 6769 | // Currently on the mDestroySurface list? |
| 6770 | boolean mDestroying; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6771 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6772 | // Completely remove from window manager after exit animation? |
| 6773 | boolean mRemoveOnExit; |
| 6774 | |
| 6775 | // Set when the orientation is changing and this window has not yet |
| 6776 | // been updated for the new orientation. |
| 6777 | boolean mOrientationChanging; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6778 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6779 | // Is this window now (or just being) removed? |
| 6780 | boolean mRemoved; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6781 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6782 | WindowState(Session s, IWindow c, WindowToken token, |
| 6783 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 6784 | int viewVisibility) { |
| 6785 | mSession = s; |
| 6786 | mClient = c; |
| 6787 | mToken = token; |
| 6788 | mAttrs.copyFrom(a); |
| 6789 | mViewVisibility = viewVisibility; |
| 6790 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 6791 | mAlpha = a.alpha; |
| 6792 | if (localLOGV) Log.v( |
| 6793 | TAG, "Window " + this + " client=" + c.asBinder() |
| 6794 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 6795 | try { |
| 6796 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 6797 | } catch (RemoteException e) { |
| 6798 | mDeathRecipient = null; |
| 6799 | mAttachedWindow = null; |
| 6800 | mLayoutAttached = false; |
| 6801 | mIsImWindow = false; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6802 | mIsWallpaper = false; |
| 6803 | mIsFloatingLayer = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6804 | mBaseLayer = 0; |
| 6805 | mSubLayer = 0; |
| 6806 | return; |
| 6807 | } |
| 6808 | mDeathRecipient = deathRecipient; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6809 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6810 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 6811 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 6812 | // The multiplier here is to reserve space for multiple |
| 6813 | // windows in the same type layer. |
| 6814 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 6815 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 6816 | + TYPE_LAYER_OFFSET; |
| 6817 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 6818 | mAttachedWindow = attachedWindow; |
| 6819 | mAttachedWindow.mChildWindows.add(this); |
| 6820 | mLayoutAttached = mAttrs.type != |
| 6821 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 6822 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 6823 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6824 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 6825 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6826 | } else { |
| 6827 | // The multiplier here is to reserve space for multiple |
| 6828 | // windows in the same type layer. |
| 6829 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 6830 | * TYPE_LAYER_MULTIPLIER |
| 6831 | + TYPE_LAYER_OFFSET; |
| 6832 | mSubLayer = 0; |
| 6833 | mAttachedWindow = null; |
| 6834 | mLayoutAttached = false; |
| 6835 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 6836 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6837 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 6838 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6839 | } |
| 6840 | |
| 6841 | WindowState appWin = this; |
| 6842 | while (appWin.mAttachedWindow != null) { |
| 6843 | appWin = mAttachedWindow; |
| 6844 | } |
| 6845 | WindowToken appToken = appWin.mToken; |
| 6846 | while (appToken.appWindowToken == null) { |
| 6847 | WindowToken parent = mTokenMap.get(appToken.token); |
| 6848 | if (parent == null || appToken == parent) { |
| 6849 | break; |
| 6850 | } |
| 6851 | appToken = parent; |
| 6852 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6853 | mRootToken = appToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6854 | mAppToken = appToken.appWindowToken; |
| 6855 | |
| 6856 | mSurface = null; |
| 6857 | mRequestedWidth = 0; |
| 6858 | mRequestedHeight = 0; |
| 6859 | mLastRequestedWidth = 0; |
| 6860 | mLastRequestedHeight = 0; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6861 | mXOffset = 0; |
| 6862 | mYOffset = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6863 | mLayer = 0; |
| 6864 | mAnimLayer = 0; |
| 6865 | mLastLayer = 0; |
| 6866 | } |
| 6867 | |
| 6868 | void attach() { |
| 6869 | if (localLOGV) Log.v( |
| 6870 | TAG, "Attaching " + this + " token=" + mToken |
| 6871 | + ", list=" + mToken.windows); |
| 6872 | mSession.windowAddedLocked(); |
| 6873 | } |
| 6874 | |
| 6875 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 6876 | mHaveFrame = true; |
| 6877 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6878 | final Rect container = mContainingFrame; |
| 6879 | container.set(pf); |
| 6880 | |
| 6881 | final Rect display = mDisplayFrame; |
| 6882 | display.set(df); |
| 6883 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6884 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6885 | container.intersect(mCompatibleScreenFrame); |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6886 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 6887 | display.intersect(mCompatibleScreenFrame); |
| 6888 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6889 | } |
| 6890 | |
| 6891 | final int pw = container.right - container.left; |
| 6892 | final int ph = container.bottom - container.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6893 | |
| 6894 | int w,h; |
| 6895 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 6896 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 6897 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 6898 | } else { |
| 6899 | w = mAttrs.width == mAttrs.FILL_PARENT ? pw : mRequestedWidth; |
| 6900 | h = mAttrs.height== mAttrs.FILL_PARENT ? ph : mRequestedHeight; |
| 6901 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6902 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6903 | final Rect content = mContentFrame; |
| 6904 | content.set(cf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6905 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6906 | final Rect visible = mVisibleFrame; |
| 6907 | visible.set(vf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6908 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6909 | final Rect frame = mFrame; |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6910 | final int fw = frame.width(); |
| 6911 | final int fh = frame.height(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6912 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6913 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 6914 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 6915 | |
| 6916 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 6917 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 6918 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 6919 | |
| 6920 | //System.out.println("Out: " + mFrame); |
| 6921 | |
| 6922 | // Now make sure the window fits in the overall display. |
| 6923 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6924 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6925 | // Make sure the content and visible frames are inside of the |
| 6926 | // final window frame. |
| 6927 | if (content.left < frame.left) content.left = frame.left; |
| 6928 | if (content.top < frame.top) content.top = frame.top; |
| 6929 | if (content.right > frame.right) content.right = frame.right; |
| 6930 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 6931 | if (visible.left < frame.left) visible.left = frame.left; |
| 6932 | if (visible.top < frame.top) visible.top = frame.top; |
| 6933 | if (visible.right > frame.right) visible.right = frame.right; |
| 6934 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6935 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6936 | final Rect contentInsets = mContentInsets; |
| 6937 | contentInsets.left = content.left-frame.left; |
| 6938 | contentInsets.top = content.top-frame.top; |
| 6939 | contentInsets.right = frame.right-content.right; |
| 6940 | contentInsets.bottom = frame.bottom-content.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6941 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6942 | final Rect visibleInsets = mVisibleInsets; |
| 6943 | visibleInsets.left = visible.left-frame.left; |
| 6944 | visibleInsets.top = visible.top-frame.top; |
| 6945 | visibleInsets.right = frame.right-visible.right; |
| 6946 | visibleInsets.bottom = frame.bottom-visible.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6947 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 6948 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 6949 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6950 | mDisplay.getHeight(), false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6951 | } |
| 6952 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6953 | if (localLOGV) { |
| 6954 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 6955 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
| 6956 | Log.v(TAG, "Resolving (mRequestedWidth=" |
| 6957 | + mRequestedWidth + ", mRequestedheight=" |
| 6958 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 6959 | + "): frame=" + mFrame.toShortString() |
| 6960 | + " ci=" + contentInsets.toShortString() |
| 6961 | + " vi=" + visibleInsets.toShortString()); |
| 6962 | //} |
| 6963 | } |
| 6964 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6965 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6966 | public Rect getFrameLw() { |
| 6967 | return mFrame; |
| 6968 | } |
| 6969 | |
| 6970 | public Rect getShownFrameLw() { |
| 6971 | return mShownFrame; |
| 6972 | } |
| 6973 | |
| 6974 | public Rect getDisplayFrameLw() { |
| 6975 | return mDisplayFrame; |
| 6976 | } |
| 6977 | |
| 6978 | public Rect getContentFrameLw() { |
| 6979 | return mContentFrame; |
| 6980 | } |
| 6981 | |
| 6982 | public Rect getVisibleFrameLw() { |
| 6983 | return mVisibleFrame; |
| 6984 | } |
| 6985 | |
| 6986 | public boolean getGivenInsetsPendingLw() { |
| 6987 | return mGivenInsetsPending; |
| 6988 | } |
| 6989 | |
| 6990 | public Rect getGivenContentInsetsLw() { |
| 6991 | return mGivenContentInsets; |
| 6992 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6993 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6994 | public Rect getGivenVisibleInsetsLw() { |
| 6995 | return mGivenVisibleInsets; |
| 6996 | } |
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 | public WindowManager.LayoutParams getAttrs() { |
| 6999 | return mAttrs; |
| 7000 | } |
| 7001 | |
| 7002 | public int getSurfaceLayer() { |
| 7003 | return mLayer; |
| 7004 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7005 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7006 | public IApplicationToken getAppToken() { |
| 7007 | return mAppToken != null ? mAppToken.appToken : null; |
| 7008 | } |
| 7009 | |
| 7010 | public boolean hasAppShownWindows() { |
| 7011 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 7012 | } |
| 7013 | |
| 7014 | public boolean hasAppStartingIcon() { |
| 7015 | return mAppToken != null ? (mAppToken.startingData != null) : false; |
| 7016 | } |
| 7017 | |
| 7018 | public WindowManagerPolicy.WindowState getAppStartingWindow() { |
| 7019 | return mAppToken != null ? mAppToken.startingWindow : null; |
| 7020 | } |
| 7021 | |
| 7022 | public void setAnimation(Animation anim) { |
| 7023 | if (localLOGV) Log.v( |
| 7024 | TAG, "Setting animation in " + this + ": " + anim); |
| 7025 | mAnimating = false; |
| 7026 | mLocalAnimating = false; |
| 7027 | mAnimation = anim; |
| 7028 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 7029 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 7030 | } |
| 7031 | |
| 7032 | public void clearAnimation() { |
| 7033 | if (mAnimation != null) { |
| 7034 | mAnimating = true; |
| 7035 | mLocalAnimating = false; |
| 7036 | mAnimation = null; |
| 7037 | } |
| 7038 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7039 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7040 | Surface createSurfaceLocked() { |
| 7041 | if (mSurface == null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7042 | mReportDestroySurface = false; |
| 7043 | mSurfacePendingDestroy = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7044 | mDrawPending = true; |
| 7045 | mCommitDrawPending = false; |
| 7046 | mReadyToShow = false; |
| 7047 | if (mAppToken != null) { |
| 7048 | mAppToken.allDrawn = false; |
| 7049 | } |
| 7050 | |
| 7051 | int flags = 0; |
Mathias Agopian | 317a628 | 2009-08-13 17:29:02 -0700 | [diff] [blame] | 7052 | if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7053 | flags |= Surface.PUSH_BUFFERS; |
| 7054 | } |
| 7055 | |
| 7056 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 7057 | flags |= Surface.SECURE; |
| 7058 | } |
| 7059 | if (DEBUG_VISIBILITY) Log.v( |
| 7060 | TAG, "Creating surface in session " |
| 7061 | + mSession.mSurfaceSession + " window " + this |
| 7062 | + " w=" + mFrame.width() |
| 7063 | + " h=" + mFrame.height() + " format=" |
| 7064 | + mAttrs.format + " flags=" + flags); |
| 7065 | |
| 7066 | int w = mFrame.width(); |
| 7067 | int h = mFrame.height(); |
| 7068 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 7069 | // for a scaled surface, we always want the requested |
| 7070 | // size. |
| 7071 | w = mRequestedWidth; |
| 7072 | h = mRequestedHeight; |
| 7073 | } |
| 7074 | |
| 7075 | try { |
| 7076 | mSurface = new Surface( |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7077 | mSession.mSurfaceSession, mSession.mPid, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7078 | 0, w, h, mAttrs.format, flags); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7079 | if (SHOW_TRANSACTIONS) Log.i(TAG, " CREATE SURFACE " |
| 7080 | + mSurface + " IN SESSION " |
| 7081 | + mSession.mSurfaceSession |
| 7082 | + ": pid=" + mSession.mPid + " format=" |
| 7083 | + mAttrs.format + " flags=0x" |
| 7084 | + Integer.toHexString(flags)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7085 | } catch (Surface.OutOfResourcesException e) { |
| 7086 | Log.w(TAG, "OutOfResourcesException creating surface"); |
| 7087 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 7088 | return null; |
| 7089 | } catch (Exception e) { |
| 7090 | Log.e(TAG, "Exception creating surface", e); |
| 7091 | return null; |
| 7092 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7093 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7094 | if (localLOGV) Log.v( |
| 7095 | TAG, "Got surface: " + mSurface |
| 7096 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 7097 | + ", animLayer=" + mAnimLayer); |
| 7098 | if (SHOW_TRANSACTIONS) { |
| 7099 | Log.i(TAG, ">>> OPEN TRANSACTION"); |
| 7100 | Log.i(TAG, " SURFACE " + mSurface + ": CREATE (" |
| 7101 | + mAttrs.getTitle() + ") pos=(" + |
| 7102 | mFrame.left + "," + mFrame.top + ") (" + |
| 7103 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 7104 | mAnimLayer + " HIDE"); |
| 7105 | } |
| 7106 | Surface.openTransaction(); |
| 7107 | try { |
| 7108 | try { |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7109 | mSurface.setPosition(mFrame.left + mXOffset, |
| 7110 | mFrame.top + mYOffset); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7111 | mSurface.setLayer(mAnimLayer); |
| 7112 | mSurface.hide(); |
| 7113 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7114 | if (SHOW_TRANSACTIONS) Log.i(TAG, " SURFACE " |
| 7115 | + mSurface + ": DITHER"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7116 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 7117 | Surface.SURFACE_DITHER); |
| 7118 | } |
| 7119 | } catch (RuntimeException e) { |
| 7120 | Log.w(TAG, "Error creating surface in " + w, e); |
| 7121 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 7122 | } |
| 7123 | mLastHidden = true; |
| 7124 | } finally { |
| 7125 | if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION"); |
| 7126 | Surface.closeTransaction(); |
| 7127 | } |
| 7128 | if (localLOGV) Log.v( |
| 7129 | TAG, "Created surface " + this); |
| 7130 | } |
| 7131 | return mSurface; |
| 7132 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7133 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7134 | void destroySurfaceLocked() { |
| 7135 | // Window is no longer on-screen, so can no longer receive |
| 7136 | // key events... if we were waiting for it to finish |
| 7137 | // handling a key event, the wait is over! |
| 7138 | mKeyWaiter.finishedKey(mSession, mClient, true, |
| 7139 | KeyWaiter.RETURN_NOTHING); |
| 7140 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 7141 | mKeyWaiter.releasePendingTrackballLocked(mSession); |
| 7142 | |
| 7143 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 7144 | mAppToken.startingDisplayed = false; |
| 7145 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7146 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7147 | if (mSurface != null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7148 | mDrawPending = false; |
| 7149 | mCommitDrawPending = false; |
| 7150 | mReadyToShow = false; |
| 7151 | |
| 7152 | int i = mChildWindows.size(); |
| 7153 | while (i > 0) { |
| 7154 | i--; |
| 7155 | WindowState c = (WindowState)mChildWindows.get(i); |
| 7156 | c.mAttachedHidden = true; |
| 7157 | } |
| 7158 | |
| 7159 | if (mReportDestroySurface) { |
| 7160 | mReportDestroySurface = false; |
| 7161 | mSurfacePendingDestroy = true; |
| 7162 | try { |
| 7163 | mClient.dispatchGetNewSurface(); |
| 7164 | // We'll really destroy on the next time around. |
| 7165 | return; |
| 7166 | } catch (RemoteException e) { |
| 7167 | } |
| 7168 | } |
| 7169 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7170 | try { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7171 | if (DEBUG_VISIBILITY) { |
| 7172 | RuntimeException e = new RuntimeException(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7173 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7174 | Log.w(TAG, "Window " + this + " destroying surface " |
| 7175 | + mSurface + ", session " + mSession, e); |
| 7176 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7177 | if (SHOW_TRANSACTIONS) { |
| 7178 | RuntimeException ex = new RuntimeException(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7179 | if (!HIDE_STACK_CRAWLS) ex.fillInStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7180 | Log.i(TAG, " SURFACE " + mSurface + ": DESTROY (" |
| 7181 | + mAttrs.getTitle() + ")", ex); |
| 7182 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7183 | mSurface.destroy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7184 | } catch (RuntimeException e) { |
| 7185 | Log.w(TAG, "Exception thrown when destroying Window " + this |
| 7186 | + " surface " + mSurface + " session " + mSession |
| 7187 | + ": " + e.toString()); |
| 7188 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7189 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7190 | mSurface = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7191 | } |
| 7192 | } |
| 7193 | |
| 7194 | boolean finishDrawingLocked() { |
| 7195 | if (mDrawPending) { |
| 7196 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Log.v( |
| 7197 | TAG, "finishDrawingLocked: " + mSurface); |
| 7198 | mCommitDrawPending = true; |
| 7199 | mDrawPending = false; |
| 7200 | return true; |
| 7201 | } |
| 7202 | return false; |
| 7203 | } |
| 7204 | |
| 7205 | // This must be called while inside a transaction. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7206 | boolean commitFinishDrawingLocked(long currentTime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7207 | //Log.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
| 7208 | if (!mCommitDrawPending) { |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7209 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7210 | } |
| 7211 | mCommitDrawPending = false; |
| 7212 | mReadyToShow = true; |
| 7213 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 7214 | final AppWindowToken atoken = mAppToken; |
| 7215 | if (atoken == null || atoken.allDrawn || starting) { |
| 7216 | performShowLocked(); |
| 7217 | } |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7218 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7219 | } |
| 7220 | |
| 7221 | // This must be called while inside a transaction. |
| 7222 | boolean performShowLocked() { |
| 7223 | if (DEBUG_VISIBILITY) { |
| 7224 | RuntimeException e = new RuntimeException(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7225 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7226 | Log.v(TAG, "performShow on " + this |
| 7227 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 7228 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 7229 | } |
| 7230 | if (mReadyToShow && isReadyForDisplay()) { |
| 7231 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Log.i( |
| 7232 | TAG, " SURFACE " + mSurface + ": SHOW (performShowLocked)"); |
| 7233 | if (DEBUG_VISIBILITY) Log.v(TAG, "Showing " + this |
| 7234 | + " during animation: policyVis=" + mPolicyVisibility |
| 7235 | + " attHidden=" + mAttachedHidden |
| 7236 | + " tok.hiddenRequested=" |
| 7237 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7238 | + " tok.hidden=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7239 | + (mAppToken != null ? mAppToken.hidden : false) |
| 7240 | + " animating=" + mAnimating |
| 7241 | + " tok animating=" |
| 7242 | + (mAppToken != null ? mAppToken.animating : false)); |
| 7243 | if (!showSurfaceRobustlyLocked(this)) { |
| 7244 | return false; |
| 7245 | } |
| 7246 | mLastAlpha = -1; |
| 7247 | mHasDrawn = true; |
| 7248 | mLastHidden = false; |
| 7249 | mReadyToShow = false; |
| 7250 | enableScreenIfNeededLocked(); |
| 7251 | |
| 7252 | applyEnterAnimationLocked(this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7253 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7254 | int i = mChildWindows.size(); |
| 7255 | while (i > 0) { |
| 7256 | i--; |
| 7257 | WindowState c = (WindowState)mChildWindows.get(i); |
| 7258 | if (c.mSurface != null && c.mAttachedHidden) { |
| 7259 | c.mAttachedHidden = false; |
| 7260 | c.performShowLocked(); |
| 7261 | } |
| 7262 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7263 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7264 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 7265 | && mAppToken != null) { |
| 7266 | mAppToken.firstWindowDrawn = true; |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7267 | |
| 7268 | if (mAppToken.startingData != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7269 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Log.v(TAG, |
| 7270 | "Finish starting " + mToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7271 | + ": first real window is shown, no animation"); |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7272 | // If this initial window is animating, stop it -- we |
| 7273 | // will do an animation to reveal it from behind the |
| 7274 | // starting window, so there is no need for it to also |
| 7275 | // be doing its own stuff. |
| 7276 | if (mAnimation != null) { |
| 7277 | mAnimation = null; |
| 7278 | // Make sure we clean up the animation. |
| 7279 | mAnimating = true; |
| 7280 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7281 | mFinishedStarting.add(mAppToken); |
| 7282 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7283 | } |
| 7284 | mAppToken.updateReportedVisibilityLocked(); |
| 7285 | } |
| 7286 | } |
| 7287 | return true; |
| 7288 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7289 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7290 | // This must be called while inside a transaction. Returns true if |
| 7291 | // there is more animation to run. |
| 7292 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| 7293 | if (!mDisplayFrozen) { |
| 7294 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7295 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7296 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 7297 | mHasTransformation = true; |
| 7298 | mHasLocalTransformation = true; |
| 7299 | if (!mLocalAnimating) { |
| 7300 | if (DEBUG_ANIM) Log.v( |
| 7301 | TAG, "Starting animation in " + this + |
| 7302 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 7303 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 7304 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 7305 | mAnimation.setStartTime(currentTime); |
| 7306 | mLocalAnimating = true; |
| 7307 | mAnimating = true; |
| 7308 | } |
| 7309 | mTransformation.clear(); |
| 7310 | final boolean more = mAnimation.getTransformation( |
| 7311 | currentTime, mTransformation); |
| 7312 | if (DEBUG_ANIM) Log.v( |
| 7313 | TAG, "Stepped animation in " + this + |
| 7314 | ": more=" + more + ", xform=" + mTransformation); |
| 7315 | if (more) { |
| 7316 | // we're not done! |
| 7317 | return true; |
| 7318 | } |
| 7319 | if (DEBUG_ANIM) Log.v( |
| 7320 | TAG, "Finished animation in " + this + |
| 7321 | " @ " + currentTime); |
| 7322 | mAnimation = null; |
| 7323 | //WindowManagerService.this.dump(); |
| 7324 | } |
| 7325 | mHasLocalTransformation = false; |
| 7326 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7327 | && mAppToken.animation != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7328 | // When our app token is animating, we kind-of pretend like |
| 7329 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 7330 | // part of this check means that we will only do this if |
| 7331 | // our window is not currently exiting, or it is not |
| 7332 | // locally animating itself. The idea being that one that |
| 7333 | // is exiting and doing a local animation should be removed |
| 7334 | // once that animation is done. |
| 7335 | mAnimating = true; |
| 7336 | mHasTransformation = true; |
| 7337 | mTransformation.clear(); |
| 7338 | return false; |
| 7339 | } else if (mHasTransformation) { |
| 7340 | // Little trick to get through the path below to act like |
| 7341 | // we have finished an animation. |
| 7342 | mAnimating = true; |
| 7343 | } else if (isAnimating()) { |
| 7344 | mAnimating = true; |
| 7345 | } |
| 7346 | } else if (mAnimation != null) { |
| 7347 | // If the display is frozen, and there is a pending animation, |
| 7348 | // clear it and make sure we run the cleanup code. |
| 7349 | mAnimating = true; |
| 7350 | mLocalAnimating = true; |
| 7351 | mAnimation = null; |
| 7352 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7353 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7354 | if (!mAnimating && !mLocalAnimating) { |
| 7355 | return false; |
| 7356 | } |
| 7357 | |
| 7358 | if (DEBUG_ANIM) Log.v( |
| 7359 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 7360 | + ", reportedVisible=" |
| 7361 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7362 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7363 | mAnimating = false; |
| 7364 | mLocalAnimating = false; |
| 7365 | mAnimation = null; |
| 7366 | mAnimLayer = mLayer; |
| 7367 | if (mIsImWindow) { |
| 7368 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7369 | } else if (mIsWallpaper) { |
| 7370 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7371 | } |
| 7372 | if (DEBUG_LAYERS) Log.v(TAG, "Stepping win " + this |
| 7373 | + " anim layer: " + mAnimLayer); |
| 7374 | mHasTransformation = false; |
| 7375 | mHasLocalTransformation = false; |
| 7376 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 7377 | mTransformation.clear(); |
| 7378 | if (mHasDrawn |
| 7379 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 7380 | && mAppToken != null |
| 7381 | && mAppToken.firstWindowDrawn |
| 7382 | && mAppToken.startingData != null) { |
| 7383 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Finish starting " |
| 7384 | + mToken + ": first real window done animating"); |
| 7385 | mFinishedStarting.add(mAppToken); |
| 7386 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7387 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7388 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7389 | finishExit(); |
| 7390 | |
| 7391 | if (mAppToken != null) { |
| 7392 | mAppToken.updateReportedVisibilityLocked(); |
| 7393 | } |
| 7394 | |
| 7395 | return false; |
| 7396 | } |
| 7397 | |
| 7398 | void finishExit() { |
| 7399 | if (DEBUG_ANIM) Log.v( |
| 7400 | TAG, "finishExit in " + this |
| 7401 | + ": exiting=" + mExiting |
| 7402 | + " remove=" + mRemoveOnExit |
| 7403 | + " windowAnimating=" + isWindowAnimating()); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7404 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7405 | final int N = mChildWindows.size(); |
| 7406 | for (int i=0; i<N; i++) { |
| 7407 | ((WindowState)mChildWindows.get(i)).finishExit(); |
| 7408 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7409 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7410 | if (!mExiting) { |
| 7411 | return; |
| 7412 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7414 | if (isWindowAnimating()) { |
| 7415 | return; |
| 7416 | } |
| 7417 | |
| 7418 | if (localLOGV) Log.v( |
| 7419 | TAG, "Exit animation finished in " + this |
| 7420 | + ": remove=" + mRemoveOnExit); |
| 7421 | if (mSurface != null) { |
| 7422 | mDestroySurface.add(this); |
| 7423 | mDestroying = true; |
| 7424 | if (SHOW_TRANSACTIONS) Log.i( |
| 7425 | TAG, " SURFACE " + mSurface + ": HIDE (finishExit)"); |
| 7426 | try { |
| 7427 | mSurface.hide(); |
| 7428 | } catch (RuntimeException e) { |
| 7429 | Log.w(TAG, "Error hiding surface in " + this, e); |
| 7430 | } |
| 7431 | mLastHidden = true; |
| 7432 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 7433 | } |
| 7434 | mExiting = false; |
| 7435 | if (mRemoveOnExit) { |
| 7436 | mPendingRemove.add(this); |
| 7437 | mRemoveOnExit = false; |
| 7438 | } |
| 7439 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7440 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7441 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 7442 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 7443 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 7444 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 7445 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 7446 | return true; |
| 7447 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7448 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7449 | void computeShownFrameLocked() { |
| 7450 | final boolean selfTransformation = mHasLocalTransformation; |
| 7451 | Transformation attachedTransformation = |
| 7452 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 7453 | ? mAttachedWindow.mTransformation : null; |
| 7454 | Transformation appTransformation = |
| 7455 | (mAppToken != null && mAppToken.hasTransformation) |
| 7456 | ? mAppToken.transformation : null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7457 | |
| 7458 | // Wallpapers are animated based on the "real" window they |
| 7459 | // are currently targeting. |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7460 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7461 | && mWallpaperTarget != null) { |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7462 | if (mWallpaperTarget.mHasLocalTransformation && |
| 7463 | mWallpaperTarget.mAnimation != null && |
| 7464 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7465 | attachedTransformation = mWallpaperTarget.mTransformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7466 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
| 7467 | Log.v(TAG, "WP target attached xform: " + attachedTransformation); |
| 7468 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7469 | } |
| 7470 | if (mWallpaperTarget.mAppToken != null && |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7471 | mWallpaperTarget.mAppToken.hasTransformation && |
| 7472 | mWallpaperTarget.mAppToken.animation != null && |
| 7473 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7474 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7475 | if (DEBUG_WALLPAPER && appTransformation != null) { |
| 7476 | Log.v(TAG, "WP target app xform: " + appTransformation); |
| 7477 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7478 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7479 | } |
| 7480 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7481 | if (selfTransformation || attachedTransformation != null |
| 7482 | || appTransformation != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7483 | // cache often used attributes locally |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7484 | final Rect frame = mFrame; |
| 7485 | final float tmpFloats[] = mTmpFloats; |
| 7486 | final Matrix tmpMatrix = mTmpMatrix; |
| 7487 | |
| 7488 | // Compute the desired transformation. |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7489 | tmpMatrix.setTranslate(0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7490 | if (selfTransformation) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7491 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7492 | } |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7493 | tmpMatrix.postTranslate(frame.left, frame.top); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7494 | if (attachedTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7495 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7496 | } |
| 7497 | if (appTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7498 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7499 | } |
| 7500 | |
| 7501 | // "convert" it into SurfaceFlinger's format |
| 7502 | // (a 2x2 matrix + an offset) |
| 7503 | // Here we must not transform the position of the surface |
| 7504 | // since it is already included in the transformation. |
| 7505 | //Log.i(TAG, "Transform: " + matrix); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7506 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7507 | tmpMatrix.getValues(tmpFloats); |
| 7508 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 7509 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 7510 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 7511 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7512 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 7513 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7514 | int w = frame.width(); |
| 7515 | int h = frame.height(); |
| 7516 | mShownFrame.set(x, y, x+w, y+h); |
| 7517 | |
| 7518 | // Now set the alpha... but because our current hardware |
| 7519 | // can't do alpha transformation on a non-opaque surface, |
| 7520 | // turn it off if we are running an animation that is also |
| 7521 | // transforming since it is more important to have that |
| 7522 | // animation be smooth. |
| 7523 | mShownAlpha = mAlpha; |
| 7524 | if (!mLimitedAlphaCompositing |
| 7525 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 7526 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 7527 | && x == frame.left && y == frame.top))) { |
| 7528 | //Log.i(TAG, "Applying alpha transform"); |
| 7529 | if (selfTransformation) { |
| 7530 | mShownAlpha *= mTransformation.getAlpha(); |
| 7531 | } |
| 7532 | if (attachedTransformation != null) { |
| 7533 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 7534 | } |
| 7535 | if (appTransformation != null) { |
| 7536 | mShownAlpha *= appTransformation.getAlpha(); |
| 7537 | } |
| 7538 | } else { |
| 7539 | //Log.i(TAG, "Not applying alpha transform"); |
| 7540 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7541 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7542 | if (localLOGV) Log.v( |
| 7543 | TAG, "Continuing animation in " + this + |
| 7544 | ": " + mShownFrame + |
| 7545 | ", alpha=" + mTransformation.getAlpha()); |
| 7546 | return; |
| 7547 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7548 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7549 | mShownFrame.set(mFrame); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7550 | if (mXOffset != 0 || mYOffset != 0) { |
| 7551 | mShownFrame.offset(mXOffset, mYOffset); |
| 7552 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7553 | mShownAlpha = mAlpha; |
| 7554 | mDsDx = 1; |
| 7555 | mDtDx = 0; |
| 7556 | mDsDy = 0; |
| 7557 | mDtDy = 1; |
| 7558 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7559 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7560 | /** |
| 7561 | * Is this window visible? It is not visible if there is no |
| 7562 | * surface, or we are in the process of running an exit animation |
| 7563 | * that will remove the surface, or its app token has been hidden. |
| 7564 | */ |
| 7565 | public boolean isVisibleLw() { |
| 7566 | final AppWindowToken atoken = mAppToken; |
| 7567 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7568 | && (atoken == null || !atoken.hiddenRequested) |
| 7569 | && !mExiting && !mDestroying; |
| 7570 | } |
| 7571 | |
| 7572 | /** |
| 7573 | * Is this window visible, ignoring its app token? It is not visible |
| 7574 | * if there is no surface, or we are in the process of running an exit animation |
| 7575 | * that will remove the surface. |
| 7576 | */ |
| 7577 | public boolean isWinVisibleLw() { |
| 7578 | final AppWindowToken atoken = mAppToken; |
| 7579 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7580 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 7581 | && !mExiting && !mDestroying; |
| 7582 | } |
| 7583 | |
| 7584 | /** |
| 7585 | * The same as isVisible(), but follows the current hidden state of |
| 7586 | * the associated app token, not the pending requested hidden state. |
| 7587 | */ |
| 7588 | boolean isVisibleNow() { |
| 7589 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7590 | && !mRootToken.hidden && !mExiting && !mDestroying; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7591 | } |
| 7592 | |
| 7593 | /** |
| 7594 | * Same as isVisible(), but we also count it as visible between the |
| 7595 | * call to IWindowSession.add() and the first relayout(). |
| 7596 | */ |
| 7597 | boolean isVisibleOrAdding() { |
| 7598 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7599 | return ((mSurface != null && !mReportDestroySurface) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7600 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 7601 | && mPolicyVisibility && !mAttachedHidden |
| 7602 | && (atoken == null || !atoken.hiddenRequested) |
| 7603 | && !mExiting && !mDestroying; |
| 7604 | } |
| 7605 | |
| 7606 | /** |
| 7607 | * Is this window currently on-screen? It is on-screen either if it |
| 7608 | * is visible or it is currently running an animation before no longer |
| 7609 | * being visible. |
| 7610 | */ |
| 7611 | boolean isOnScreen() { |
| 7612 | final AppWindowToken atoken = mAppToken; |
| 7613 | if (atoken != null) { |
| 7614 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7615 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7616 | || mAnimation != null || atoken.animation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7617 | } else { |
| 7618 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7619 | && (!mAttachedHidden || mAnimation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7620 | } |
| 7621 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7622 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7623 | /** |
| 7624 | * Like isOnScreen(), but we don't return true if the window is part |
| 7625 | * of a transition that has not yet been started. |
| 7626 | */ |
| 7627 | boolean isReadyForDisplay() { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7628 | if (mRootToken.waitingToShow && |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7629 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7630 | return false; |
| 7631 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7632 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7633 | final boolean animating = atoken != null |
| 7634 | ? (atoken.animation != null) : false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7635 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7636 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 7637 | && !mRootToken.hidden) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7638 | || mAnimation != null || animating); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7639 | } |
| 7640 | |
| 7641 | /** Is the window or its container currently animating? */ |
| 7642 | boolean isAnimating() { |
| 7643 | final WindowState attached = mAttachedWindow; |
| 7644 | final AppWindowToken atoken = mAppToken; |
| 7645 | return mAnimation != null |
| 7646 | || (attached != null && attached.mAnimation != null) |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7647 | || (atoken != null && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7648 | (atoken.animation != null |
| 7649 | || atoken.inPendingTransaction)); |
| 7650 | } |
| 7651 | |
| 7652 | /** Is this window currently animating? */ |
| 7653 | boolean isWindowAnimating() { |
| 7654 | return mAnimation != null; |
| 7655 | } |
| 7656 | |
| 7657 | /** |
| 7658 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 7659 | * been drawn. |
| 7660 | */ |
| 7661 | public boolean isDisplayedLw() { |
| 7662 | final AppWindowToken atoken = mAppToken; |
| 7663 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7664 | && !mDrawPending && !mCommitDrawPending |
| 7665 | && ((!mAttachedHidden && |
| 7666 | (atoken == null || !atoken.hiddenRequested)) |
| 7667 | || mAnimating); |
| 7668 | } |
| 7669 | |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7670 | /** |
| 7671 | * Returns true if the window has a surface that it has drawn a |
| 7672 | * complete UI in to. |
| 7673 | */ |
| 7674 | public boolean isDrawnLw() { |
| 7675 | final AppWindowToken atoken = mAppToken; |
| 7676 | return mSurface != null && !mDestroying |
| 7677 | && !mDrawPending && !mCommitDrawPending; |
| 7678 | } |
| 7679 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7680 | public boolean fillsScreenLw(int screenWidth, int screenHeight, |
| 7681 | boolean shownFrame, boolean onlyOpaque) { |
| 7682 | if (mSurface == null) { |
| 7683 | return false; |
| 7684 | } |
| 7685 | if (mAppToken != null && !mAppToken.appFullscreen) { |
| 7686 | return false; |
| 7687 | } |
| 7688 | if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) { |
| 7689 | return false; |
| 7690 | } |
| 7691 | final Rect frame = shownFrame ? mShownFrame : mFrame; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7692 | |
| 7693 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| 7694 | return frame.left <= mCompatibleScreenFrame.left && |
| 7695 | frame.top <= mCompatibleScreenFrame.top && |
| 7696 | frame.right >= mCompatibleScreenFrame.right && |
| 7697 | frame.bottom >= mCompatibleScreenFrame.bottom; |
| 7698 | } else { |
| 7699 | return frame.left <= 0 && frame.top <= 0 |
| 7700 | && frame.right >= screenWidth |
| 7701 | && frame.bottom >= screenHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7702 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7703 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7704 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7705 | /** |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7706 | * Return true if the window is opaque and fully drawn. This indicates |
| 7707 | * it may obscure windows behind it. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7708 | */ |
| 7709 | boolean isOpaqueDrawn() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7710 | return (mAttrs.format == PixelFormat.OPAQUE |
| 7711 | || mAttrs.type == TYPE_WALLPAPER) |
| 7712 | && mSurface != null && mAnimation == null |
| 7713 | && (mAppToken == null || mAppToken.animation == null) |
| 7714 | && !mDrawPending && !mCommitDrawPending; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7715 | } |
| 7716 | |
| 7717 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 7718 | return |
| 7719 | // only if the application is requesting compatible window |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7720 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 7721 | // only if it's visible |
| 7722 | mHasDrawn && mViewVisibility == View.VISIBLE && |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7723 | // and only if the application fills the compatible screen |
| 7724 | mFrame.left <= mCompatibleScreenFrame.left && |
| 7725 | mFrame.top <= mCompatibleScreenFrame.top && |
| 7726 | mFrame.right >= mCompatibleScreenFrame.right && |
| 7727 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7728 | // and starting window do not need background filler |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7729 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7730 | } |
| 7731 | |
| 7732 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 7733 | return mFrame.left <= 0 && mFrame.top <= 0 && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7734 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7735 | } |
| 7736 | |
| 7737 | void removeLocked() { |
| 7738 | if (mAttachedWindow != null) { |
| 7739 | mAttachedWindow.mChildWindows.remove(this); |
| 7740 | } |
| 7741 | destroySurfaceLocked(); |
| 7742 | mSession.windowRemovedLocked(); |
| 7743 | try { |
| 7744 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 7745 | } catch (RuntimeException e) { |
| 7746 | // Ignore if it has already been removed (usually because |
| 7747 | // we are doing this as part of processing a death note.) |
| 7748 | } |
| 7749 | } |
| 7750 | |
| 7751 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 7752 | public void binderDied() { |
| 7753 | try { |
| 7754 | synchronized(mWindowMap) { |
| 7755 | WindowState win = windowForClientLocked(mSession, mClient); |
| 7756 | Log.i(TAG, "WIN DEATH: " + win); |
| 7757 | if (win != null) { |
| 7758 | removeWindowLocked(mSession, win); |
| 7759 | } |
| 7760 | } |
| 7761 | } catch (IllegalArgumentException ex) { |
| 7762 | // This will happen if the window has already been |
| 7763 | // removed. |
| 7764 | } |
| 7765 | } |
| 7766 | } |
| 7767 | |
| 7768 | /** Returns true if this window desires key events. */ |
| 7769 | public final boolean canReceiveKeys() { |
| 7770 | return isVisibleOrAdding() |
| 7771 | && (mViewVisibility == View.VISIBLE) |
| 7772 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 7773 | } |
| 7774 | |
| 7775 | public boolean hasDrawnLw() { |
| 7776 | return mHasDrawn; |
| 7777 | } |
| 7778 | |
| 7779 | public boolean showLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7780 | return showLw(doAnimation, true); |
| 7781 | } |
| 7782 | |
| 7783 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 7784 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 7785 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7786 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7787 | mPolicyVisibility = true; |
| 7788 | mPolicyVisibilityAfterAnim = true; |
| 7789 | if (doAnimation) { |
| 7790 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 7791 | } |
| 7792 | if (requestAnim) { |
| 7793 | requestAnimationLocked(0); |
| 7794 | } |
| 7795 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7796 | } |
| 7797 | |
| 7798 | public boolean hideLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7799 | return hideLw(doAnimation, true); |
| 7800 | } |
| 7801 | |
| 7802 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7803 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 7804 | : mPolicyVisibility; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7805 | if (!current) { |
| 7806 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7807 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7808 | if (doAnimation) { |
| 7809 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 7810 | if (mAnimation == null) { |
| 7811 | doAnimation = false; |
| 7812 | } |
| 7813 | } |
| 7814 | if (doAnimation) { |
| 7815 | mPolicyVisibilityAfterAnim = false; |
| 7816 | } else { |
| 7817 | mPolicyVisibilityAfterAnim = false; |
| 7818 | mPolicyVisibility = false; |
| 7819 | } |
| 7820 | if (requestAnim) { |
| 7821 | requestAnimationLocked(0); |
| 7822 | } |
| 7823 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7824 | } |
| 7825 | |
| 7826 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7827 | StringBuilder sb = new StringBuilder(64); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7828 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7829 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 7830 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 7831 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 7832 | if (mAttachedWindow != null || mLayoutAttached) { |
| 7833 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 7834 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 7835 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7836 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 7837 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 7838 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7839 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 7840 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7841 | } |
| 7842 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 7843 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 7844 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 7845 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 7846 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 7847 | pw.print("="); pw.print(mAnimLayer); |
| 7848 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 7849 | if (mSurface != null) { |
| 7850 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
| 7851 | } |
| 7852 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 7853 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 7854 | if (mAppToken != null) { |
| 7855 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 7856 | } |
| 7857 | if (mTargetAppToken != null) { |
| 7858 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 7859 | } |
| 7860 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 7861 | pw.print(Integer.toHexString(mViewVisibility)); |
| 7862 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7863 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 7864 | pw.print(" mObscured="); pw.println(mObscured); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7865 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 7866 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 7867 | pw.print(mPolicyVisibility); |
| 7868 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 7869 | pw.print(mPolicyVisibilityAfterAnim); |
| 7870 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 7871 | } |
| 7872 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7873 | pw.print(" h="); pw.println(mRequestedHeight); |
| 7874 | if (mXOffset != 0 || mYOffset != 0) { |
| 7875 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 7876 | pw.print(" y="); pw.println(mYOffset); |
| 7877 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7878 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 7879 | mGivenContentInsets.printShortString(pw); |
| 7880 | pw.print(" mGivenVisibleInsets="); |
| 7881 | mGivenVisibleInsets.printShortString(pw); |
| 7882 | pw.println(); |
| 7883 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 7884 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 7885 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 7886 | } |
| 7887 | pw.print(prefix); pw.print("mShownFrame="); |
| 7888 | mShownFrame.printShortString(pw); |
| 7889 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 7890 | pw.println(); |
| 7891 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 7892 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 7893 | pw.println(); |
| 7894 | pw.print(prefix); pw.print("mContainingFrame="); |
| 7895 | mContainingFrame.printShortString(pw); |
| 7896 | pw.print(" mDisplayFrame="); |
| 7897 | mDisplayFrame.printShortString(pw); |
| 7898 | pw.println(); |
| 7899 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 7900 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 7901 | pw.println(); |
| 7902 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 7903 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 7904 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 7905 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 7906 | pw.println(); |
| 7907 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 7908 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 7909 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 7910 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 7911 | } |
| 7912 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 7913 | || mAnimation != null) { |
| 7914 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 7915 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 7916 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 7917 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 7918 | } |
| 7919 | if (mHasTransformation || mHasLocalTransformation) { |
| 7920 | pw.print(prefix); pw.print("XForm: has="); |
| 7921 | pw.print(mHasTransformation); |
| 7922 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 7923 | pw.print(" "); mTransformation.printShortString(pw); |
| 7924 | pw.println(); |
| 7925 | } |
| 7926 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 7927 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 7928 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 7929 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 7930 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 7931 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 7932 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 7933 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 7934 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 7935 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7936 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7937 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 7938 | pw.print(mOrientationChanging); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7939 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 7940 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7941 | } |
Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 7942 | if (mHScale != 1 || mVScale != 1) { |
| 7943 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 7944 | pw.print(" mVScale="); pw.println(mVScale); |
| 7945 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7946 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7947 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 7948 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 7949 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7950 | } |
| 7951 | |
| 7952 | @Override |
| 7953 | public String toString() { |
| 7954 | return "Window{" |
| 7955 | + Integer.toHexString(System.identityHashCode(this)) |
| 7956 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 7957 | } |
| 7958 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7959 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7960 | // ------------------------------------------------------------- |
| 7961 | // Window Token State |
| 7962 | // ------------------------------------------------------------- |
| 7963 | |
| 7964 | class WindowToken { |
| 7965 | // The actual token. |
| 7966 | final IBinder token; |
| 7967 | |
| 7968 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 7969 | final int windowType; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7970 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7971 | // Set if this token was explicitly added by a client, so should |
| 7972 | // not be removed when all windows are removed. |
| 7973 | final boolean explicit; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7974 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7975 | // For printing. |
| 7976 | String stringName; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7977 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7978 | // If this is an AppWindowToken, this is non-null. |
| 7979 | AppWindowToken appWindowToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7980 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7981 | // All of the windows associated with this token. |
| 7982 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 7983 | |
| 7984 | // Is key dispatching paused for this token? |
| 7985 | boolean paused = false; |
| 7986 | |
| 7987 | // Should this token's windows be hidden? |
| 7988 | boolean hidden; |
| 7989 | |
| 7990 | // Temporary for finding which tokens no longer have visible windows. |
| 7991 | boolean hasVisible; |
| 7992 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7993 | // Set to true when this token is in a pending transaction where it |
| 7994 | // will be shown. |
| 7995 | boolean waitingToShow; |
| 7996 | |
| 7997 | // Set to true when this token is in a pending transaction where it |
| 7998 | // will be hidden. |
| 7999 | boolean waitingToHide; |
| 8000 | |
| 8001 | // Set to true when this token is in a pending transaction where its |
| 8002 | // windows will be put to the bottom of the list. |
| 8003 | boolean sendingToBottom; |
| 8004 | |
| 8005 | // Set to true when this token is in a pending transaction where its |
| 8006 | // windows will be put to the top of the list. |
| 8007 | boolean sendingToTop; |
| 8008 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8009 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 8010 | token = _token; |
| 8011 | windowType = type; |
| 8012 | explicit = _explicit; |
| 8013 | } |
| 8014 | |
| 8015 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8016 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 8017 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 8018 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 8019 | pw.print(" hidden="); pw.print(hidden); |
| 8020 | pw.print(" hasVisible="); pw.println(hasVisible); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8021 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 8022 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 8023 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 8024 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 8025 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 8026 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8027 | } |
| 8028 | |
| 8029 | @Override |
| 8030 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8031 | if (stringName == null) { |
| 8032 | StringBuilder sb = new StringBuilder(); |
| 8033 | sb.append("WindowToken{"); |
| 8034 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8035 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8036 | stringName = sb.toString(); |
| 8037 | } |
| 8038 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8039 | } |
| 8040 | }; |
| 8041 | |
| 8042 | class AppWindowToken extends WindowToken { |
| 8043 | // Non-null only for application tokens. |
| 8044 | final IApplicationToken appToken; |
| 8045 | |
| 8046 | // All of the windows and child windows that are included in this |
| 8047 | // application token. Note this list is NOT sorted! |
| 8048 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 8049 | |
| 8050 | int groupId = -1; |
| 8051 | boolean appFullscreen; |
| 8052 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8053 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8054 | // These are used for determining when all windows associated with |
| 8055 | // an activity have been drawn, so they can be made visible together |
| 8056 | // at the same time. |
| 8057 | int lastTransactionSequence = mTransactionSequence-1; |
| 8058 | int numInterestingWindows; |
| 8059 | int numDrawnWindows; |
| 8060 | boolean inPendingTransaction; |
| 8061 | boolean allDrawn; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8062 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8063 | // Is this token going to be hidden in a little while? If so, it |
| 8064 | // won't be taken into account for setting the screen orientation. |
| 8065 | boolean willBeHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8066 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8067 | // Is this window's surface needed? This is almost like hidden, except |
| 8068 | // it will sometimes be true a little earlier: when the token has |
| 8069 | // been shown, but is still waiting for its app transition to execute |
| 8070 | // before making its windows shown. |
| 8071 | boolean hiddenRequested; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8072 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8073 | // Have we told the window clients to hide themselves? |
| 8074 | boolean clientHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8075 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8076 | // Last visibility state we reported to the app token. |
| 8077 | boolean reportedVisible; |
| 8078 | |
| 8079 | // Set to true when the token has been removed from the window mgr. |
| 8080 | boolean removed; |
| 8081 | |
| 8082 | // Have we been asked to have this token keep the screen frozen? |
| 8083 | boolean freezingScreen; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8084 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8085 | boolean animating; |
| 8086 | Animation animation; |
| 8087 | boolean hasTransformation; |
| 8088 | final Transformation transformation = new Transformation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8089 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8090 | // Offset to the window of all layers in the token, for use by |
| 8091 | // AppWindowToken animations. |
| 8092 | int animLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8093 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8094 | // Information about an application starting window if displayed. |
| 8095 | StartingData startingData; |
| 8096 | WindowState startingWindow; |
| 8097 | View startingView; |
| 8098 | boolean startingDisplayed; |
| 8099 | boolean startingMoved; |
| 8100 | boolean firstWindowDrawn; |
| 8101 | |
| 8102 | AppWindowToken(IApplicationToken _token) { |
| 8103 | super(_token.asBinder(), |
| 8104 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 8105 | appWindowToken = this; |
| 8106 | appToken = _token; |
| 8107 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8108 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8109 | public void setAnimation(Animation anim) { |
| 8110 | if (localLOGV) Log.v( |
| 8111 | TAG, "Setting animation in " + this + ": " + anim); |
| 8112 | animation = anim; |
| 8113 | animating = false; |
| 8114 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 8115 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 8116 | int zorder = anim.getZAdjustment(); |
| 8117 | int adj = 0; |
| 8118 | if (zorder == Animation.ZORDER_TOP) { |
| 8119 | adj = TYPE_LAYER_OFFSET; |
| 8120 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 8121 | adj = -TYPE_LAYER_OFFSET; |
| 8122 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8123 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8124 | if (animLayerAdjustment != adj) { |
| 8125 | animLayerAdjustment = adj; |
| 8126 | updateLayers(); |
| 8127 | } |
| 8128 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8129 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8130 | public void setDummyAnimation() { |
| 8131 | if (animation == null) { |
| 8132 | if (localLOGV) Log.v( |
| 8133 | TAG, "Setting dummy animation in " + this); |
| 8134 | animation = sDummyAnimation; |
| 8135 | } |
| 8136 | } |
| 8137 | |
| 8138 | public void clearAnimation() { |
| 8139 | if (animation != null) { |
| 8140 | animation = null; |
| 8141 | animating = true; |
| 8142 | } |
| 8143 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8144 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8145 | void updateLayers() { |
| 8146 | final int N = allAppWindows.size(); |
| 8147 | final int adj = animLayerAdjustment; |
| 8148 | for (int i=0; i<N; i++) { |
| 8149 | WindowState w = allAppWindows.get(i); |
| 8150 | w.mAnimLayer = w.mLayer + adj; |
| 8151 | if (DEBUG_LAYERS) Log.v(TAG, "Updating layer " + w + ": " |
| 8152 | + w.mAnimLayer); |
| 8153 | if (w == mInputMethodTarget) { |
| 8154 | setInputMethodAnimLayerAdjustment(adj); |
| 8155 | } |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8156 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8157 | setWallpaperAnimLayerAdjustmentLocked(adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8158 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8159 | } |
| 8160 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8161 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8162 | void sendAppVisibilityToClients() { |
| 8163 | final int N = allAppWindows.size(); |
| 8164 | for (int i=0; i<N; i++) { |
| 8165 | WindowState win = allAppWindows.get(i); |
| 8166 | if (win == startingWindow && clientHidden) { |
| 8167 | // Don't hide the starting window. |
| 8168 | continue; |
| 8169 | } |
| 8170 | try { |
| 8171 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 8172 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 8173 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 8174 | } catch (RemoteException e) { |
| 8175 | } |
| 8176 | } |
| 8177 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8178 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8179 | void showAllWindowsLocked() { |
| 8180 | final int NW = allAppWindows.size(); |
| 8181 | for (int i=0; i<NW; i++) { |
| 8182 | WindowState w = allAppWindows.get(i); |
| 8183 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 8184 | "performing show on: " + w); |
| 8185 | w.performShowLocked(); |
| 8186 | } |
| 8187 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8188 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8189 | // This must be called while inside a transaction. |
| 8190 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| 8191 | if (!mDisplayFrozen) { |
| 8192 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8193 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8194 | if (animation == sDummyAnimation) { |
| 8195 | // This guy is going to animate, but not yet. For now count |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8196 | // it as not animating for purposes of scheduling transactions; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8197 | // when it is really time to animate, this will be set to |
| 8198 | // a real animation and the next call will execute normally. |
| 8199 | return false; |
| 8200 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8201 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8202 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 8203 | if (!animating) { |
| 8204 | if (DEBUG_ANIM) Log.v( |
| 8205 | TAG, "Starting animation in " + this + |
| 8206 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 8207 | + " scale=" + mTransitionAnimationScale |
| 8208 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 8209 | animation.initialize(dw, dh, dw, dh); |
| 8210 | animation.setStartTime(currentTime); |
| 8211 | animating = true; |
| 8212 | } |
| 8213 | transformation.clear(); |
| 8214 | final boolean more = animation.getTransformation( |
| 8215 | currentTime, transformation); |
| 8216 | if (DEBUG_ANIM) Log.v( |
| 8217 | TAG, "Stepped animation in " + this + |
| 8218 | ": more=" + more + ", xform=" + transformation); |
| 8219 | if (more) { |
| 8220 | // we're done! |
| 8221 | hasTransformation = true; |
| 8222 | return true; |
| 8223 | } |
| 8224 | if (DEBUG_ANIM) Log.v( |
| 8225 | TAG, "Finished animation in " + this + |
| 8226 | " @ " + currentTime); |
| 8227 | animation = null; |
| 8228 | } |
| 8229 | } else if (animation != null) { |
| 8230 | // If the display is frozen, and there is a pending animation, |
| 8231 | // clear it and make sure we run the cleanup code. |
| 8232 | animating = true; |
| 8233 | animation = null; |
| 8234 | } |
| 8235 | |
| 8236 | hasTransformation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8237 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8238 | if (!animating) { |
| 8239 | return false; |
| 8240 | } |
| 8241 | |
| 8242 | clearAnimation(); |
| 8243 | animating = false; |
| 8244 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 8245 | moveInputMethodWindowsIfNeededLocked(true); |
| 8246 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8247 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8248 | if (DEBUG_ANIM) Log.v( |
| 8249 | TAG, "Animation done in " + this |
| 8250 | + ": reportedVisible=" + reportedVisible); |
| 8251 | |
| 8252 | transformation.clear(); |
| 8253 | if (animLayerAdjustment != 0) { |
| 8254 | animLayerAdjustment = 0; |
| 8255 | updateLayers(); |
| 8256 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8257 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8258 | final int N = windows.size(); |
| 8259 | for (int i=0; i<N; i++) { |
| 8260 | ((WindowState)windows.get(i)).finishExit(); |
| 8261 | } |
| 8262 | updateReportedVisibilityLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8263 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8264 | return false; |
| 8265 | } |
| 8266 | |
| 8267 | void updateReportedVisibilityLocked() { |
| 8268 | if (appToken == null) { |
| 8269 | return; |
| 8270 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8271 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8272 | int numInteresting = 0; |
| 8273 | int numVisible = 0; |
| 8274 | boolean nowGone = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8275 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8276 | if (DEBUG_VISIBILITY) Log.v(TAG, "Update reported visibility: " + this); |
| 8277 | final int N = allAppWindows.size(); |
| 8278 | for (int i=0; i<N; i++) { |
| 8279 | WindowState win = allAppWindows.get(i); |
| 8280 | if (win == startingWindow || win.mAppFreezing) { |
| 8281 | continue; |
| 8282 | } |
| 8283 | if (DEBUG_VISIBILITY) { |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8284 | Log.v(TAG, "Win " + win + ": isDrawn=" |
| 8285 | + win.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8286 | + ", isAnimating=" + win.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8287 | if (!win.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8288 | Log.v(TAG, "Not displayed: s=" + win.mSurface |
| 8289 | + " pv=" + win.mPolicyVisibility |
| 8290 | + " dp=" + win.mDrawPending |
| 8291 | + " cdp=" + win.mCommitDrawPending |
| 8292 | + " ah=" + win.mAttachedHidden |
| 8293 | + " th=" |
| 8294 | + (win.mAppToken != null |
| 8295 | ? win.mAppToken.hiddenRequested : false) |
| 8296 | + " a=" + win.mAnimating); |
| 8297 | } |
| 8298 | } |
| 8299 | numInteresting++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8300 | if (win.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8301 | if (!win.isAnimating()) { |
| 8302 | numVisible++; |
| 8303 | } |
| 8304 | nowGone = false; |
| 8305 | } else if (win.isAnimating()) { |
| 8306 | nowGone = false; |
| 8307 | } |
| 8308 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8309 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8310 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
| 8311 | if (DEBUG_VISIBILITY) Log.v(TAG, "VIS " + this + ": interesting=" |
| 8312 | + numInteresting + " visible=" + numVisible); |
| 8313 | if (nowVisible != reportedVisible) { |
| 8314 | if (DEBUG_VISIBILITY) Log.v( |
| 8315 | TAG, "Visibility changed in " + this |
| 8316 | + ": vis=" + nowVisible); |
| 8317 | reportedVisible = nowVisible; |
| 8318 | Message m = mH.obtainMessage( |
| 8319 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 8320 | nowVisible ? 1 : 0, |
| 8321 | nowGone ? 1 : 0, |
| 8322 | this); |
| 8323 | mH.sendMessage(m); |
| 8324 | } |
| 8325 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8326 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8327 | WindowState findMainWindow() { |
| 8328 | int j = windows.size(); |
| 8329 | while (j > 0) { |
| 8330 | j--; |
| 8331 | WindowState win = windows.get(j); |
| 8332 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 8333 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 8334 | return win; |
| 8335 | } |
| 8336 | } |
| 8337 | return null; |
| 8338 | } |
| 8339 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8340 | void dump(PrintWriter pw, String prefix) { |
| 8341 | super.dump(pw, prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8342 | if (appToken != null) { |
| 8343 | pw.print(prefix); pw.println("app=true"); |
| 8344 | } |
| 8345 | if (allAppWindows.size() > 0) { |
| 8346 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 8347 | } |
| 8348 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8349 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8350 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 8351 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 8352 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 8353 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 8354 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 8355 | if (paused || freezingScreen) { |
| 8356 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 8357 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 8358 | } |
| 8359 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 8360 | || inPendingTransaction || allDrawn) { |
| 8361 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 8362 | pw.print(numInterestingWindows); |
| 8363 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 8364 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 8365 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 8366 | } |
| 8367 | if (animating || animation != null) { |
| 8368 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 8369 | pw.print(" animation="); pw.println(animation); |
| 8370 | } |
| 8371 | if (animLayerAdjustment != 0) { |
| 8372 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 8373 | } |
| 8374 | if (hasTransformation) { |
| 8375 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 8376 | pw.print(" transformation="); transformation.printShortString(pw); |
| 8377 | pw.println(); |
| 8378 | } |
| 8379 | if (startingData != null || removed || firstWindowDrawn) { |
| 8380 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 8381 | pw.print(" removed="); pw.print(removed); |
| 8382 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 8383 | } |
| 8384 | if (startingWindow != null || startingView != null |
| 8385 | || startingDisplayed || startingMoved) { |
| 8386 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 8387 | pw.print(" startingView="); pw.print(startingView); |
| 8388 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 8389 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 8390 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8391 | } |
| 8392 | |
| 8393 | @Override |
| 8394 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8395 | if (stringName == null) { |
| 8396 | StringBuilder sb = new StringBuilder(); |
| 8397 | sb.append("AppWindowToken{"); |
| 8398 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8399 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8400 | stringName = sb.toString(); |
| 8401 | } |
| 8402 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8403 | } |
| 8404 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8405 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8406 | // ------------------------------------------------------------- |
| 8407 | // DummyAnimation |
| 8408 | // ------------------------------------------------------------- |
| 8409 | |
| 8410 | // This is an animation that does nothing: it just immediately finishes |
| 8411 | // itself every time it is called. It is used as a stub animation in cases |
| 8412 | // where we want to synchronize multiple things that may be animating. |
| 8413 | static final class DummyAnimation extends Animation { |
| 8414 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 8415 | return false; |
| 8416 | } |
| 8417 | } |
| 8418 | static final Animation sDummyAnimation = new DummyAnimation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8419 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8420 | // ------------------------------------------------------------- |
| 8421 | // Async Handler |
| 8422 | // ------------------------------------------------------------- |
| 8423 | |
| 8424 | static final class StartingData { |
| 8425 | final String pkg; |
| 8426 | final int theme; |
| 8427 | final CharSequence nonLocalizedLabel; |
| 8428 | final int labelRes; |
| 8429 | final int icon; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8430 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8431 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 8432 | int _labelRes, int _icon) { |
| 8433 | pkg = _pkg; |
| 8434 | theme = _theme; |
| 8435 | nonLocalizedLabel = _nonLocalizedLabel; |
| 8436 | labelRes = _labelRes; |
| 8437 | icon = _icon; |
| 8438 | } |
| 8439 | } |
| 8440 | |
| 8441 | private final class H extends Handler { |
| 8442 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 8443 | public static final int REPORT_LOSING_FOCUS = 3; |
| 8444 | public static final int ANIMATE = 4; |
| 8445 | public static final int ADD_STARTING = 5; |
| 8446 | public static final int REMOVE_STARTING = 6; |
| 8447 | public static final int FINISHED_STARTING = 7; |
| 8448 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8449 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 8450 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 8451 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 8452 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 8453 | public static final int FORCE_GC = 15; |
| 8454 | public static final int ENABLE_SCREEN = 16; |
| 8455 | public static final int APP_FREEZE_TIMEOUT = 17; |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8456 | public static final int COMPUTE_AND_SEND_NEW_CONFIGURATION = 18; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8457 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8458 | private Session mLastReportedHold; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8459 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8460 | public H() { |
| 8461 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8462 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8463 | @Override |
| 8464 | public void handleMessage(Message msg) { |
| 8465 | switch (msg.what) { |
| 8466 | case REPORT_FOCUS_CHANGE: { |
| 8467 | WindowState lastFocus; |
| 8468 | WindowState newFocus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8469 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8470 | synchronized(mWindowMap) { |
| 8471 | lastFocus = mLastFocus; |
| 8472 | newFocus = mCurrentFocus; |
| 8473 | if (lastFocus == newFocus) { |
| 8474 | // Focus is not changing, so nothing to do. |
| 8475 | return; |
| 8476 | } |
| 8477 | mLastFocus = newFocus; |
| 8478 | //Log.i(TAG, "Focus moving from " + lastFocus |
| 8479 | // + " to " + newFocus); |
| 8480 | if (newFocus != null && lastFocus != null |
| 8481 | && !newFocus.isDisplayedLw()) { |
| 8482 | //Log.i(TAG, "Delaying loss of focus..."); |
| 8483 | mLosingFocus.add(lastFocus); |
| 8484 | lastFocus = null; |
| 8485 | } |
| 8486 | } |
| 8487 | |
| 8488 | if (lastFocus != newFocus) { |
| 8489 | //System.out.println("Changing focus from " + lastFocus |
| 8490 | // + " to " + newFocus); |
| 8491 | if (newFocus != null) { |
| 8492 | try { |
| 8493 | //Log.i(TAG, "Gaining focus: " + newFocus); |
| 8494 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 8495 | } catch (RemoteException e) { |
| 8496 | // Ignore if process has died. |
| 8497 | } |
| 8498 | } |
| 8499 | |
| 8500 | if (lastFocus != null) { |
| 8501 | try { |
| 8502 | //Log.i(TAG, "Losing focus: " + lastFocus); |
| 8503 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 8504 | } catch (RemoteException e) { |
| 8505 | // Ignore if process has died. |
| 8506 | } |
| 8507 | } |
| 8508 | } |
| 8509 | } break; |
| 8510 | |
| 8511 | case REPORT_LOSING_FOCUS: { |
| 8512 | ArrayList<WindowState> losers; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8513 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8514 | synchronized(mWindowMap) { |
| 8515 | losers = mLosingFocus; |
| 8516 | mLosingFocus = new ArrayList<WindowState>(); |
| 8517 | } |
| 8518 | |
| 8519 | final int N = losers.size(); |
| 8520 | for (int i=0; i<N; i++) { |
| 8521 | try { |
| 8522 | //Log.i(TAG, "Losing delayed focus: " + losers.get(i)); |
| 8523 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 8524 | } catch (RemoteException e) { |
| 8525 | // Ignore if process has died. |
| 8526 | } |
| 8527 | } |
| 8528 | } break; |
| 8529 | |
| 8530 | case ANIMATE: { |
| 8531 | synchronized(mWindowMap) { |
| 8532 | mAnimationPending = false; |
| 8533 | performLayoutAndPlaceSurfacesLocked(); |
| 8534 | } |
| 8535 | } break; |
| 8536 | |
| 8537 | case ADD_STARTING: { |
| 8538 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8539 | final StartingData sd = wtoken.startingData; |
| 8540 | |
| 8541 | if (sd == null) { |
| 8542 | // Animation has been canceled... do nothing. |
| 8543 | return; |
| 8544 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8545 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8546 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Add starting " |
| 8547 | + wtoken + ": pkg=" + sd.pkg); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8548 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8549 | View view = null; |
| 8550 | try { |
| 8551 | view = mPolicy.addStartingWindow( |
| 8552 | wtoken.token, sd.pkg, |
| 8553 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 8554 | sd.icon); |
| 8555 | } catch (Exception e) { |
| 8556 | Log.w(TAG, "Exception when adding starting window", e); |
| 8557 | } |
| 8558 | |
| 8559 | if (view != null) { |
| 8560 | boolean abort = false; |
| 8561 | |
| 8562 | synchronized(mWindowMap) { |
| 8563 | if (wtoken.removed || wtoken.startingData == null) { |
| 8564 | // If the window was successfully added, then |
| 8565 | // we need to remove it. |
| 8566 | if (wtoken.startingWindow != null) { |
| 8567 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 8568 | "Aborted starting " + wtoken |
| 8569 | + ": removed=" + wtoken.removed |
| 8570 | + " startingData=" + wtoken.startingData); |
| 8571 | wtoken.startingWindow = null; |
| 8572 | wtoken.startingData = null; |
| 8573 | abort = true; |
| 8574 | } |
| 8575 | } else { |
| 8576 | wtoken.startingView = view; |
| 8577 | } |
| 8578 | if (DEBUG_STARTING_WINDOW && !abort) Log.v(TAG, |
| 8579 | "Added starting " + wtoken |
| 8580 | + ": startingWindow=" |
| 8581 | + wtoken.startingWindow + " startingView=" |
| 8582 | + wtoken.startingView); |
| 8583 | } |
| 8584 | |
| 8585 | if (abort) { |
| 8586 | try { |
| 8587 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 8588 | } catch (Exception e) { |
| 8589 | Log.w(TAG, "Exception when removing starting window", e); |
| 8590 | } |
| 8591 | } |
| 8592 | } |
| 8593 | } break; |
| 8594 | |
| 8595 | case REMOVE_STARTING: { |
| 8596 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8597 | IBinder token = null; |
| 8598 | View view = null; |
| 8599 | synchronized (mWindowMap) { |
| 8600 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Remove starting " |
| 8601 | + wtoken + ": startingWindow=" |
| 8602 | + wtoken.startingWindow + " startingView=" |
| 8603 | + wtoken.startingView); |
| 8604 | if (wtoken.startingWindow != null) { |
| 8605 | view = wtoken.startingView; |
| 8606 | token = wtoken.token; |
| 8607 | wtoken.startingData = null; |
| 8608 | wtoken.startingView = null; |
| 8609 | wtoken.startingWindow = null; |
| 8610 | } |
| 8611 | } |
| 8612 | if (view != null) { |
| 8613 | try { |
| 8614 | mPolicy.removeStartingWindow(token, view); |
| 8615 | } catch (Exception e) { |
| 8616 | Log.w(TAG, "Exception when removing starting window", e); |
| 8617 | } |
| 8618 | } |
| 8619 | } break; |
| 8620 | |
| 8621 | case FINISHED_STARTING: { |
| 8622 | IBinder token = null; |
| 8623 | View view = null; |
| 8624 | while (true) { |
| 8625 | synchronized (mWindowMap) { |
| 8626 | final int N = mFinishedStarting.size(); |
| 8627 | if (N <= 0) { |
| 8628 | break; |
| 8629 | } |
| 8630 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 8631 | |
| 8632 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 8633 | "Finished starting " + wtoken |
| 8634 | + ": startingWindow=" + wtoken.startingWindow |
| 8635 | + " startingView=" + wtoken.startingView); |
| 8636 | |
| 8637 | if (wtoken.startingWindow == null) { |
| 8638 | continue; |
| 8639 | } |
| 8640 | |
| 8641 | view = wtoken.startingView; |
| 8642 | token = wtoken.token; |
| 8643 | wtoken.startingData = null; |
| 8644 | wtoken.startingView = null; |
| 8645 | wtoken.startingWindow = null; |
| 8646 | } |
| 8647 | |
| 8648 | try { |
| 8649 | mPolicy.removeStartingWindow(token, view); |
| 8650 | } catch (Exception e) { |
| 8651 | Log.w(TAG, "Exception when removing starting window", e); |
| 8652 | } |
| 8653 | } |
| 8654 | } break; |
| 8655 | |
| 8656 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 8657 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8658 | |
| 8659 | boolean nowVisible = msg.arg1 != 0; |
| 8660 | boolean nowGone = msg.arg2 != 0; |
| 8661 | |
| 8662 | try { |
| 8663 | if (DEBUG_VISIBILITY) Log.v( |
| 8664 | TAG, "Reporting visible in " + wtoken |
| 8665 | + " visible=" + nowVisible |
| 8666 | + " gone=" + nowGone); |
| 8667 | if (nowVisible) { |
| 8668 | wtoken.appToken.windowsVisible(); |
| 8669 | } else { |
| 8670 | wtoken.appToken.windowsGone(); |
| 8671 | } |
| 8672 | } catch (RemoteException ex) { |
| 8673 | } |
| 8674 | } break; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8675 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8676 | case WINDOW_FREEZE_TIMEOUT: { |
| 8677 | synchronized (mWindowMap) { |
| 8678 | Log.w(TAG, "Window freeze timeout expired."); |
| 8679 | int i = mWindows.size(); |
| 8680 | while (i > 0) { |
| 8681 | i--; |
| 8682 | WindowState w = (WindowState)mWindows.get(i); |
| 8683 | if (w.mOrientationChanging) { |
| 8684 | w.mOrientationChanging = false; |
| 8685 | Log.w(TAG, "Force clearing orientation change: " + w); |
| 8686 | } |
| 8687 | } |
| 8688 | performLayoutAndPlaceSurfacesLocked(); |
| 8689 | } |
| 8690 | break; |
| 8691 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8692 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8693 | case HOLD_SCREEN_CHANGED: { |
| 8694 | Session oldHold; |
| 8695 | Session newHold; |
| 8696 | synchronized (mWindowMap) { |
| 8697 | oldHold = mLastReportedHold; |
| 8698 | newHold = (Session)msg.obj; |
| 8699 | mLastReportedHold = newHold; |
| 8700 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8701 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8702 | if (oldHold != newHold) { |
| 8703 | try { |
| 8704 | if (oldHold != null) { |
| 8705 | mBatteryStats.noteStopWakelock(oldHold.mUid, |
| 8706 | "window", |
| 8707 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8708 | } |
| 8709 | if (newHold != null) { |
| 8710 | mBatteryStats.noteStartWakelock(newHold.mUid, |
| 8711 | "window", |
| 8712 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8713 | } |
| 8714 | } catch (RemoteException e) { |
| 8715 | } |
| 8716 | } |
| 8717 | break; |
| 8718 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8719 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8720 | case APP_TRANSITION_TIMEOUT: { |
| 8721 | synchronized (mWindowMap) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8722 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8723 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 8724 | "*** APP TRANSITION TIMEOUT"); |
| 8725 | mAppTransitionReady = true; |
| 8726 | mAppTransitionTimeout = true; |
| 8727 | performLayoutAndPlaceSurfacesLocked(); |
| 8728 | } |
| 8729 | } |
| 8730 | break; |
| 8731 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8732 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8733 | case PERSIST_ANIMATION_SCALE: { |
| 8734 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8735 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 8736 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8737 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 8738 | break; |
| 8739 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8740 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8741 | case FORCE_GC: { |
| 8742 | synchronized(mWindowMap) { |
| 8743 | if (mAnimationPending) { |
| 8744 | // If we are animating, don't do the gc now but |
| 8745 | // delay a bit so we don't interrupt the animation. |
| 8746 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 8747 | 2000); |
| 8748 | return; |
| 8749 | } |
| 8750 | // If we are currently rotating the display, it will |
| 8751 | // schedule a new message when done. |
| 8752 | if (mDisplayFrozen) { |
| 8753 | return; |
| 8754 | } |
| 8755 | mFreezeGcPending = 0; |
| 8756 | } |
| 8757 | Runtime.getRuntime().gc(); |
| 8758 | break; |
| 8759 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8760 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8761 | case ENABLE_SCREEN: { |
| 8762 | performEnableScreen(); |
| 8763 | break; |
| 8764 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8765 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8766 | case APP_FREEZE_TIMEOUT: { |
| 8767 | synchronized (mWindowMap) { |
| 8768 | Log.w(TAG, "App freeze timeout expired."); |
| 8769 | int i = mAppTokens.size(); |
| 8770 | while (i > 0) { |
| 8771 | i--; |
| 8772 | AppWindowToken tok = mAppTokens.get(i); |
| 8773 | if (tok.freezingScreen) { |
| 8774 | Log.w(TAG, "Force clearing freeze: " + tok); |
| 8775 | unsetAppFreezingScreenLocked(tok, true, true); |
| 8776 | } |
| 8777 | } |
| 8778 | } |
| 8779 | break; |
| 8780 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8781 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8782 | case COMPUTE_AND_SEND_NEW_CONFIGURATION: { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 8783 | if (updateOrientationFromAppTokensUnchecked(null, null) != null) { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8784 | sendNewConfiguration(); |
| 8785 | } |
| 8786 | break; |
| 8787 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8788 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8789 | } |
| 8790 | } |
| 8791 | } |
| 8792 | |
| 8793 | // ------------------------------------------------------------- |
| 8794 | // IWindowManager API |
| 8795 | // ------------------------------------------------------------- |
| 8796 | |
| 8797 | public IWindowSession openSession(IInputMethodClient client, |
| 8798 | IInputContext inputContext) { |
| 8799 | if (client == null) throw new IllegalArgumentException("null client"); |
| 8800 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
| 8801 | return new Session(client, inputContext); |
| 8802 | } |
| 8803 | |
| 8804 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 8805 | synchronized (mWindowMap) { |
| 8806 | // The focus for the client is the window immediately below |
| 8807 | // where we would place the input method window. |
| 8808 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 8809 | WindowState imFocus; |
| 8810 | if (idx > 0) { |
| 8811 | imFocus = (WindowState)mWindows.get(idx-1); |
| 8812 | if (imFocus != null) { |
| 8813 | if (imFocus.mSession.mClient != null && |
| 8814 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 8815 | return true; |
| 8816 | } |
| 8817 | } |
| 8818 | } |
| 8819 | } |
| 8820 | return false; |
| 8821 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8822 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8823 | // ------------------------------------------------------------- |
| 8824 | // Internals |
| 8825 | // ------------------------------------------------------------- |
| 8826 | |
| 8827 | final WindowState windowForClientLocked(Session session, IWindow client) { |
| 8828 | return windowForClientLocked(session, client.asBinder()); |
| 8829 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8830 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8831 | final WindowState windowForClientLocked(Session session, IBinder client) { |
| 8832 | WindowState win = mWindowMap.get(client); |
| 8833 | if (localLOGV) Log.v( |
| 8834 | TAG, "Looking up client " + client + ": " + win); |
| 8835 | if (win == null) { |
| 8836 | RuntimeException ex = new RuntimeException(); |
| 8837 | Log.w(TAG, "Requested window " + client + " does not exist", ex); |
| 8838 | return null; |
| 8839 | } |
| 8840 | if (session != null && win.mSession != session) { |
| 8841 | RuntimeException ex = new RuntimeException(); |
| 8842 | Log.w(TAG, "Requested window " + client + " is in session " + |
| 8843 | win.mSession + ", not " + session, ex); |
| 8844 | return null; |
| 8845 | } |
| 8846 | |
| 8847 | return win; |
| 8848 | } |
| 8849 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8850 | final void rebuildAppWindowListLocked() { |
| 8851 | int NW = mWindows.size(); |
| 8852 | int i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8853 | int lastWallpaper = -1; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8854 | int numRemoved = 0; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8855 | |
| 8856 | // First remove all existing app windows. |
| 8857 | i=0; |
| 8858 | while (i < NW) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8859 | WindowState w = (WindowState)mWindows.get(i); |
| 8860 | if (w.mAppToken != null) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8861 | WindowState win = (WindowState)mWindows.remove(i); |
| 8862 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, |
| 8863 | "Rebuild removing window: " + win); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8864 | NW--; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8865 | numRemoved++; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8866 | continue; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8867 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 8868 | && lastWallpaper == i-1) { |
| 8869 | lastWallpaper = i; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8870 | } |
| 8871 | i++; |
| 8872 | } |
| 8873 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8874 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 8875 | // so skip them before adding app tokens. |
| 8876 | lastWallpaper++; |
| 8877 | i = lastWallpaper; |
| 8878 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8879 | // First add all of the exiting app tokens... these are no longer |
| 8880 | // in the main app list, but still have windows shown. We put them |
| 8881 | // in the back because now that the animation is over we no longer |
| 8882 | // will care about them. |
| 8883 | int NT = mExitingAppTokens.size(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8884 | for (int j=0; j<NT; j++) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8885 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 8886 | } |
| 8887 | |
| 8888 | // And add in the still active app tokens in Z order. |
| 8889 | NT = mAppTokens.size(); |
| 8890 | for (int j=0; j<NT; j++) { |
| 8891 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8892 | } |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8893 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8894 | i -= lastWallpaper; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8895 | if (i != numRemoved) { |
| 8896 | Log.w(TAG, "Rebuild removed " + numRemoved |
| 8897 | + " windows but added " + i); |
| 8898 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8899 | } |
| 8900 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8901 | private final void assignLayersLocked() { |
| 8902 | int N = mWindows.size(); |
| 8903 | int curBaseLayer = 0; |
| 8904 | int curLayer = 0; |
| 8905 | int i; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8906 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8907 | for (i=0; i<N; i++) { |
| 8908 | WindowState w = (WindowState)mWindows.get(i); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8909 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 8910 | || (i > 0 && w.mIsWallpaper)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8911 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 8912 | w.mLayer = curLayer; |
| 8913 | } else { |
| 8914 | curBaseLayer = curLayer = w.mBaseLayer; |
| 8915 | w.mLayer = curLayer; |
| 8916 | } |
| 8917 | if (w.mTargetAppToken != null) { |
| 8918 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 8919 | } else if (w.mAppToken != null) { |
| 8920 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 8921 | } else { |
| 8922 | w.mAnimLayer = w.mLayer; |
| 8923 | } |
| 8924 | if (w.mIsImWindow) { |
| 8925 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8926 | } else if (w.mIsWallpaper) { |
| 8927 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8928 | } |
| 8929 | if (DEBUG_LAYERS) Log.v(TAG, "Assign layer " + w + ": " |
| 8930 | + w.mAnimLayer); |
| 8931 | //System.out.println( |
| 8932 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 8933 | } |
| 8934 | } |
| 8935 | |
| 8936 | private boolean mInLayout = false; |
| 8937 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 8938 | if (mInLayout) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 8939 | if (DEBUG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8940 | throw new RuntimeException("Recursive call!"); |
| 8941 | } |
| 8942 | Log.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
| 8943 | return; |
| 8944 | } |
| 8945 | |
| 8946 | boolean recoveringMemory = false; |
| 8947 | if (mForceRemoves != null) { |
| 8948 | recoveringMemory = true; |
| 8949 | // Wait a little it for things to settle down, and off we go. |
| 8950 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 8951 | WindowState ws = mForceRemoves.get(i); |
| 8952 | Log.i(TAG, "Force removing: " + ws); |
| 8953 | removeWindowInnerLocked(ws.mSession, ws); |
| 8954 | } |
| 8955 | mForceRemoves = null; |
| 8956 | Log.w(TAG, "Due to memory failure, waiting a bit for next layout"); |
| 8957 | Object tmp = new Object(); |
| 8958 | synchronized (tmp) { |
| 8959 | try { |
| 8960 | tmp.wait(250); |
| 8961 | } catch (InterruptedException e) { |
| 8962 | } |
| 8963 | } |
| 8964 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8965 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8966 | mInLayout = true; |
| 8967 | try { |
| 8968 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8969 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8970 | int i = mPendingRemove.size()-1; |
| 8971 | if (i >= 0) { |
| 8972 | while (i >= 0) { |
| 8973 | WindowState w = mPendingRemove.get(i); |
| 8974 | removeWindowInnerLocked(w.mSession, w); |
| 8975 | i--; |
| 8976 | } |
| 8977 | mPendingRemove.clear(); |
| 8978 | |
| 8979 | mInLayout = false; |
| 8980 | assignLayersLocked(); |
| 8981 | mLayoutNeeded = true; |
| 8982 | performLayoutAndPlaceSurfacesLocked(); |
| 8983 | |
| 8984 | } else { |
| 8985 | mInLayout = false; |
| 8986 | if (mLayoutNeeded) { |
| 8987 | requestAnimationLocked(0); |
| 8988 | } |
| 8989 | } |
| 8990 | } catch (RuntimeException e) { |
| 8991 | mInLayout = false; |
| 8992 | Log.e(TAG, "Unhandled exception while layout out windows", e); |
| 8993 | } |
| 8994 | } |
| 8995 | |
| 8996 | private final void performLayoutLockedInner() { |
| 8997 | final int dw = mDisplay.getWidth(); |
| 8998 | final int dh = mDisplay.getHeight(); |
| 8999 | |
| 9000 | final int N = mWindows.size(); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9001 | int repeats = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9002 | int i; |
| 9003 | |
| 9004 | // FIRST LOOP: Perform a layout, if needed. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9005 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9006 | while (mLayoutNeeded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9007 | mPolicy.beginLayoutLw(dw, dh); |
| 9008 | |
| 9009 | // First perform layout of any root windows (not attached |
| 9010 | // to another window). |
| 9011 | int topAttached = -1; |
| 9012 | for (i = N-1; i >= 0; i--) { |
| 9013 | WindowState win = (WindowState) mWindows.get(i); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9014 | |
| 9015 | // Don't do layout of a window if it is not visible, or |
| 9016 | // soon won't be visible, to avoid wasting time and funky |
| 9017 | // changes while a window is animating away. |
| 9018 | final AppWindowToken atoken = win.mAppToken; |
| 9019 | final boolean gone = win.mViewVisibility == View.GONE |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9020 | || !win.mRelayoutCalled |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9021 | || win.mRootToken.hidden |
| 9022 | || (atoken != null && atoken.hiddenRequested) |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9023 | || win.mAttachedHidden |
| 9024 | || win.mExiting || win.mDestroying; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9025 | |
| 9026 | // If this view is GONE, then skip it -- keep the current |
| 9027 | // frame, and let the caller know so they can ignore it |
| 9028 | // if they want. (We do the normal layout for INVISIBLE |
| 9029 | // windows, since that means "perform layout as normal, |
| 9030 | // just don't display"). |
| 9031 | if (!gone || !win.mHaveFrame) { |
| 9032 | if (!win.mLayoutAttached) { |
| 9033 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 9034 | } else { |
| 9035 | if (topAttached < 0) topAttached = i; |
| 9036 | } |
| 9037 | } |
| 9038 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9039 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9040 | // Now perform layout of attached windows, which usually |
| 9041 | // depend on the position of the window they are attached to. |
| 9042 | // XXX does not deal with windows that are attached to windows |
| 9043 | // that are themselves attached. |
| 9044 | for (i = topAttached; i >= 0; i--) { |
| 9045 | WindowState win = (WindowState) mWindows.get(i); |
| 9046 | |
| 9047 | // If this view is GONE, then skip it -- keep the current |
| 9048 | // frame, and let the caller know so they can ignore it |
| 9049 | // if they want. (We do the normal layout for INVISIBLE |
| 9050 | // windows, since that means "perform layout as normal, |
| 9051 | // just don't display"). |
| 9052 | if (win.mLayoutAttached) { |
| 9053 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 9054 | || !win.mHaveFrame) { |
| 9055 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 9056 | } |
| 9057 | } |
| 9058 | } |
| 9059 | |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9060 | int changes = mPolicy.finishLayoutLw(); |
| 9061 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 9062 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9063 | assignLayersLocked(); |
| 9064 | } |
| 9065 | } |
| 9066 | if (changes == 0) { |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9067 | mLayoutNeeded = false; |
| 9068 | } else if (repeats > 2) { |
| 9069 | Log.w(TAG, "Layout repeat aborted after too many iterations"); |
| 9070 | mLayoutNeeded = false; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9071 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 9072 | Configuration newConfig = updateOrientationFromAppTokensLocked( |
| 9073 | null, null); |
| 9074 | if (newConfig != null) { |
| 9075 | mLayoutNeeded = true; |
| 9076 | mH.sendEmptyMessage(H.COMPUTE_AND_SEND_NEW_CONFIGURATION); |
| 9077 | } |
| 9078 | } |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9079 | } else { |
| 9080 | repeats++; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9081 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 9082 | Configuration newConfig = updateOrientationFromAppTokensLocked( |
| 9083 | null, null); |
| 9084 | if (newConfig != null) { |
| 9085 | mH.sendEmptyMessage(H.COMPUTE_AND_SEND_NEW_CONFIGURATION); |
| 9086 | } |
| 9087 | } |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9088 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9089 | } |
| 9090 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9091 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9092 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 9093 | boolean recoveringMemory) { |
| 9094 | final long currentTime = SystemClock.uptimeMillis(); |
| 9095 | final int dw = mDisplay.getWidth(); |
| 9096 | final int dh = mDisplay.getHeight(); |
| 9097 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9098 | int i; |
| 9099 | |
| 9100 | // FIRST LOOP: Perform a layout, if needed. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9101 | performLayoutLockedInner(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9102 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9103 | if (mFxSession == null) { |
| 9104 | mFxSession = new SurfaceSession(); |
| 9105 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9106 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9107 | if (SHOW_TRANSACTIONS) Log.i(TAG, ">>> OPEN TRANSACTION"); |
| 9108 | |
| 9109 | // Initialize state of exiting tokens. |
| 9110 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9111 | mExitingTokens.get(i).hasVisible = false; |
| 9112 | } |
| 9113 | |
| 9114 | // Initialize state of exiting applications. |
| 9115 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9116 | mExitingAppTokens.get(i).hasVisible = false; |
| 9117 | } |
| 9118 | |
| 9119 | // SECOND LOOP: Execute animations and update visibility of windows. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9120 | boolean orientationChangeComplete = true; |
| 9121 | Session holdScreen = null; |
| 9122 | float screenBrightness = -1; |
| 9123 | boolean focusDisplayed = false; |
| 9124 | boolean animating = false; |
| 9125 | |
| 9126 | Surface.openTransaction(); |
| 9127 | try { |
| 9128 | boolean restart; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9129 | boolean forceHiding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9130 | |
| 9131 | do { |
| 9132 | final int transactionSequence = ++mTransactionSequence; |
| 9133 | |
| 9134 | // Update animations of all applications, including those |
| 9135 | // associated with exiting/removed apps |
| 9136 | boolean tokensAnimating = false; |
| 9137 | final int NAT = mAppTokens.size(); |
| 9138 | for (i=0; i<NAT; i++) { |
| 9139 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9140 | tokensAnimating = true; |
| 9141 | } |
| 9142 | } |
| 9143 | final int NEAT = mExitingAppTokens.size(); |
| 9144 | for (i=0; i<NEAT; i++) { |
| 9145 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9146 | tokensAnimating = true; |
| 9147 | } |
| 9148 | } |
| 9149 | |
| 9150 | animating = tokensAnimating; |
| 9151 | restart = false; |
| 9152 | |
| 9153 | boolean tokenMayBeDrawn = false; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9154 | boolean wallpaperMayChange = false; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9155 | boolean focusMayChange = false; |
| 9156 | boolean wallpaperForceHidingChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9157 | |
| 9158 | mPolicy.beginAnimationLw(dw, dh); |
| 9159 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9160 | final int N = mWindows.size(); |
| 9161 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9162 | for (i=N-1; i>=0; i--) { |
| 9163 | WindowState w = (WindowState)mWindows.get(i); |
| 9164 | |
| 9165 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9166 | |
| 9167 | if (w.mSurface != null) { |
| 9168 | // Execute animation. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9169 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 9170 | if ((w.mAttrs.flags |
| 9171 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9172 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 9173 | "First draw done in potential wallpaper target " + w); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9174 | wallpaperMayChange = true; |
| 9175 | } |
| 9176 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9177 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9178 | boolean wasAnimating = w.mAnimating; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9179 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 9180 | animating = true; |
| 9181 | //w.dump(" "); |
| 9182 | } |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9183 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 9184 | wallpaperMayChange = true; |
| 9185 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9186 | |
| 9187 | if (mPolicy.doesForceHide(w, attrs)) { |
| 9188 | if (!wasAnimating && animating) { |
| 9189 | wallpaperForceHidingChanged = true; |
| 9190 | focusMayChange = true; |
| 9191 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 9192 | forceHiding = true; |
| 9193 | } |
| 9194 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9195 | boolean changed; |
| 9196 | if (forceHiding) { |
| 9197 | changed = w.hideLw(false, false); |
| 9198 | } else { |
| 9199 | changed = w.showLw(false, false); |
| 9200 | if (changed && wallpaperForceHidingChanged |
| 9201 | && w.isReadyForDisplay()) { |
| 9202 | // Assume we will need to animate. If |
| 9203 | // we don't (because the wallpaper will |
| 9204 | // stay with the lock screen), then we will |
| 9205 | // clean up later. |
| 9206 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 9207 | if (a != null) { |
| 9208 | w.setAnimation(a); |
| 9209 | } |
| 9210 | } |
| 9211 | } |
| 9212 | if (changed && (attrs.flags |
| 9213 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 9214 | wallpaperMayChange = true; |
| 9215 | } |
| 9216 | } |
| 9217 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9218 | mPolicy.animatingWindowLw(w, attrs); |
| 9219 | } |
| 9220 | |
| 9221 | final AppWindowToken atoken = w.mAppToken; |
| 9222 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 9223 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 9224 | atoken.lastTransactionSequence = transactionSequence; |
| 9225 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 9226 | atoken.startingDisplayed = false; |
| 9227 | } |
| 9228 | if ((w.isOnScreen() || w.mAttrs.type |
| 9229 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 9230 | && !w.mExiting && !w.mDestroying) { |
| 9231 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9232 | Log.v(TAG, "Eval win " + w + ": isDrawn=" |
| 9233 | + w.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9234 | + ", isAnimating=" + w.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9235 | if (!w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9236 | Log.v(TAG, "Not displayed: s=" + w.mSurface |
| 9237 | + " pv=" + w.mPolicyVisibility |
| 9238 | + " dp=" + w.mDrawPending |
| 9239 | + " cdp=" + w.mCommitDrawPending |
| 9240 | + " ah=" + w.mAttachedHidden |
| 9241 | + " th=" + atoken.hiddenRequested |
| 9242 | + " a=" + w.mAnimating); |
| 9243 | } |
| 9244 | } |
| 9245 | if (w != atoken.startingWindow) { |
| 9246 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 9247 | atoken.numInterestingWindows++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9248 | if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9249 | atoken.numDrawnWindows++; |
| 9250 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Log.v(TAG, |
| 9251 | "tokenMayBeDrawn: " + atoken |
| 9252 | + " freezingScreen=" + atoken.freezingScreen |
| 9253 | + " mAppFreezing=" + w.mAppFreezing); |
| 9254 | tokenMayBeDrawn = true; |
| 9255 | } |
| 9256 | } |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9257 | } else if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9258 | atoken.startingDisplayed = true; |
| 9259 | } |
| 9260 | } |
| 9261 | } else if (w.mReadyToShow) { |
| 9262 | w.performShowLocked(); |
| 9263 | } |
| 9264 | } |
| 9265 | |
| 9266 | if (mPolicy.finishAnimationLw()) { |
| 9267 | restart = true; |
| 9268 | } |
| 9269 | |
| 9270 | if (tokenMayBeDrawn) { |
| 9271 | // See if any windows have been drawn, so they (and others |
| 9272 | // associated with them) can now be shown. |
| 9273 | final int NT = mTokenList.size(); |
| 9274 | for (i=0; i<NT; i++) { |
| 9275 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 9276 | if (wtoken == null) { |
| 9277 | continue; |
| 9278 | } |
| 9279 | if (wtoken.freezingScreen) { |
| 9280 | int numInteresting = wtoken.numInterestingWindows; |
| 9281 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| 9282 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 9283 | "allDrawn: " + wtoken |
| 9284 | + " interesting=" + numInteresting |
| 9285 | + " drawn=" + wtoken.numDrawnWindows); |
| 9286 | wtoken.showAllWindowsLocked(); |
| 9287 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 9288 | orientationChangeComplete = true; |
| 9289 | } |
| 9290 | } else if (!wtoken.allDrawn) { |
| 9291 | int numInteresting = wtoken.numInterestingWindows; |
| 9292 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| 9293 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 9294 | "allDrawn: " + wtoken |
| 9295 | + " interesting=" + numInteresting |
| 9296 | + " drawn=" + wtoken.numDrawnWindows); |
| 9297 | wtoken.allDrawn = true; |
| 9298 | restart = true; |
| 9299 | |
| 9300 | // We can now show all of the drawn windows! |
| 9301 | if (!mOpeningApps.contains(wtoken)) { |
| 9302 | wtoken.showAllWindowsLocked(); |
| 9303 | } |
| 9304 | } |
| 9305 | } |
| 9306 | } |
| 9307 | } |
| 9308 | |
| 9309 | // If we are ready to perform an app transition, check through |
| 9310 | // all of the app tokens to be shown and see if they are ready |
| 9311 | // to go. |
| 9312 | if (mAppTransitionReady) { |
| 9313 | int NN = mOpeningApps.size(); |
| 9314 | boolean goodToGo = true; |
| 9315 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9316 | "Checking " + NN + " opening apps (frozen=" |
| 9317 | + mDisplayFrozen + " timeout=" |
| 9318 | + mAppTransitionTimeout + ")..."); |
| 9319 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 9320 | // If the display isn't frozen, wait to do anything until |
| 9321 | // all of the apps are ready. Otherwise just go because |
| 9322 | // we'll unfreeze the display when everyone is ready. |
| 9323 | for (i=0; i<NN && goodToGo; i++) { |
| 9324 | AppWindowToken wtoken = mOpeningApps.get(i); |
| 9325 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9326 | "Check opening app" + wtoken + ": allDrawn=" |
| 9327 | + wtoken.allDrawn + " startingDisplayed=" |
| 9328 | + wtoken.startingDisplayed); |
| 9329 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 9330 | && !wtoken.startingMoved) { |
| 9331 | goodToGo = false; |
| 9332 | } |
| 9333 | } |
| 9334 | } |
| 9335 | if (goodToGo) { |
| 9336 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "**** GOOD TO GO"); |
| 9337 | int transit = mNextAppTransition; |
| 9338 | if (mSkipAppTransitionAnimation) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9339 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9340 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9341 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9342 | mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9343 | mAppTransitionRunning = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9344 | mAppTransitionTimeout = false; |
| 9345 | mStartingIconInTransition = false; |
| 9346 | mSkipAppTransitionAnimation = false; |
| 9347 | |
| 9348 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 9349 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9350 | // If there are applications waiting to come to the |
| 9351 | // top of the stack, now is the time to move their windows. |
| 9352 | // (Note that we don't do apps going to the bottom |
| 9353 | // here -- we want to keep their windows in the old |
| 9354 | // Z-order until the animation completes.) |
| 9355 | if (mToTopApps.size() > 0) { |
| 9356 | NN = mAppTokens.size(); |
| 9357 | for (i=0; i<NN; i++) { |
| 9358 | AppWindowToken wtoken = mAppTokens.get(i); |
| 9359 | if (wtoken.sendingToTop) { |
| 9360 | wtoken.sendingToTop = false; |
| 9361 | moveAppWindowsLocked(wtoken, NN, false); |
| 9362 | } |
| 9363 | } |
| 9364 | mToTopApps.clear(); |
| 9365 | } |
| 9366 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9367 | WindowState oldWallpaper = mWallpaperTarget; |
| 9368 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9369 | adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9370 | wallpaperMayChange = false; |
| 9371 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9372 | // The top-most window will supply the layout params, |
| 9373 | // and we will determine it below. |
| 9374 | LayoutParams animLp = null; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9375 | AppWindowToken animToken = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9376 | int bestAnimLayer = -1; |
| 9377 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9378 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9379 | "New wallpaper target=" + mWallpaperTarget |
| 9380 | + ", lower target=" + mLowerWallpaperTarget |
| 9381 | + ", upper target=" + mUpperWallpaperTarget); |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9382 | int foundWallpapers = 0; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9383 | // Do a first pass through the tokens for two |
| 9384 | // things: |
| 9385 | // (1) Determine if both the closing and opening |
| 9386 | // app token sets are wallpaper targets, in which |
| 9387 | // case special animations are needed |
| 9388 | // (since the wallpaper needs to stay static |
| 9389 | // behind them). |
| 9390 | // (2) Find the layout params of the top-most |
| 9391 | // application window in the tokens, which is |
| 9392 | // what will control the animation theme. |
| 9393 | final int NC = mClosingApps.size(); |
| 9394 | NN = NC + mOpeningApps.size(); |
| 9395 | for (i=0; i<NN; i++) { |
| 9396 | AppWindowToken wtoken; |
| 9397 | int mode; |
| 9398 | if (i < NC) { |
| 9399 | wtoken = mClosingApps.get(i); |
| 9400 | mode = 1; |
| 9401 | } else { |
| 9402 | wtoken = mOpeningApps.get(i-NC); |
| 9403 | mode = 2; |
| 9404 | } |
| 9405 | if (mLowerWallpaperTarget != null) { |
| 9406 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 9407 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 9408 | foundWallpapers |= mode; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9409 | } |
| 9410 | } |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9411 | if (wtoken.appFullscreen) { |
| 9412 | WindowState ws = wtoken.findMainWindow(); |
| 9413 | if (ws != null) { |
| 9414 | // If this is a compatibility mode |
| 9415 | // window, we will always use its anim. |
| 9416 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 9417 | animLp = ws.mAttrs; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9418 | animToken = ws.mAppToken; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9419 | bestAnimLayer = Integer.MAX_VALUE; |
| 9420 | } else if (ws.mLayer > bestAnimLayer) { |
| 9421 | animLp = ws.mAttrs; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9422 | animToken = ws.mAppToken; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9423 | bestAnimLayer = ws.mLayer; |
| 9424 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9425 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9426 | } |
| 9427 | } |
| 9428 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9429 | if (foundWallpapers == 3) { |
| 9430 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9431 | "Wallpaper animation!"); |
| 9432 | switch (transit) { |
| 9433 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 9434 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 9435 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 9436 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 9437 | break; |
| 9438 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 9439 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 9440 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 9441 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 9442 | break; |
| 9443 | } |
| 9444 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9445 | "New transit: " + transit); |
| 9446 | } else if (oldWallpaper != null) { |
| 9447 | // We are transitioning from an activity with |
| 9448 | // a wallpaper to one without. |
| 9449 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
| 9450 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9451 | "New transit away from wallpaper: " + transit); |
| 9452 | } else if (mWallpaperTarget != null) { |
| 9453 | // We are transitioning from an activity without |
| 9454 | // a wallpaper to now showing the wallpaper |
| 9455 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
| 9456 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9457 | "New transit into wallpaper: " + transit); |
| 9458 | } |
| 9459 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9460 | if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) { |
| 9461 | mLastEnterAnimToken = animToken; |
| 9462 | mLastEnterAnimParams = animLp; |
| 9463 | } else if (mLastEnterAnimParams != null) { |
| 9464 | animLp = mLastEnterAnimParams; |
| 9465 | mLastEnterAnimToken = null; |
| 9466 | mLastEnterAnimParams = null; |
| 9467 | } |
| 9468 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9469 | NN = mOpeningApps.size(); |
| 9470 | for (i=0; i<NN; i++) { |
| 9471 | AppWindowToken wtoken = mOpeningApps.get(i); |
| 9472 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9473 | "Now opening app" + wtoken); |
| 9474 | wtoken.reportedVisible = false; |
| 9475 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9476 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9477 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9478 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9479 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9480 | wtoken.showAllWindowsLocked(); |
| 9481 | } |
| 9482 | NN = mClosingApps.size(); |
| 9483 | for (i=0; i<NN; i++) { |
| 9484 | AppWindowToken wtoken = mClosingApps.get(i); |
| 9485 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9486 | "Now closing app" + wtoken); |
| 9487 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9488 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9489 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9490 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9491 | wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9492 | // Force the allDrawn flag, because we want to start |
| 9493 | // this guy's animations regardless of whether it's |
| 9494 | // gotten drawn. |
| 9495 | wtoken.allDrawn = true; |
| 9496 | } |
| 9497 | |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 9498 | mNextAppTransitionPackage = null; |
| 9499 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9500 | mOpeningApps.clear(); |
| 9501 | mClosingApps.clear(); |
| 9502 | |
| 9503 | // This has changed the visibility of windows, so perform |
| 9504 | // a new layout to get them all up-to-date. |
| 9505 | mLayoutNeeded = true; |
Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 9506 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 9507 | assignLayersLocked(); |
| 9508 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9509 | performLayoutLockedInner(); |
| 9510 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9511 | focusMayChange = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9512 | |
| 9513 | restart = true; |
| 9514 | } |
| 9515 | } |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9516 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9517 | if (!animating && mAppTransitionRunning) { |
| 9518 | // We have finished the animation of an app transition. To do |
| 9519 | // this, we have delayed a lot of operations like showing and |
| 9520 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 9521 | // reflects the correct Z-order, but the window list may now |
| 9522 | // be out of sync with it. So here we will just rebuild the |
| 9523 | // entire app window list. Fun! |
| 9524 | mAppTransitionRunning = false; |
| 9525 | // Clear information about apps that were moving. |
| 9526 | mToBottomApps.clear(); |
| 9527 | |
| 9528 | rebuildAppWindowListLocked(); |
| 9529 | restart = true; |
| 9530 | moveInputMethodWindowsIfNeededLocked(false); |
| 9531 | wallpaperMayChange = true; |
| 9532 | mLayoutNeeded = true; |
| 9533 | } |
| 9534 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9535 | int adjResult = 0; |
| 9536 | |
| 9537 | if (wallpaperForceHidingChanged) { |
| 9538 | // At this point, there was a window with a wallpaper that |
| 9539 | // was force hiding other windows behind it, but now it |
| 9540 | // is going away. This may be simple -- just animate |
| 9541 | // away the wallpaper and its window -- or it may be |
| 9542 | // hard -- the wallpaper now needs to be shown behind |
| 9543 | // something that was hidden. |
| 9544 | WindowState oldWallpaper = mWallpaperTarget; |
| 9545 | adjResult = adjustWallpaperWindowsLocked(); |
| 9546 | wallpaperMayChange = false; |
| 9547 | if (false) Log.v(TAG, "****** OLD: " + oldWallpaper |
| 9548 | + " NEW: " + mWallpaperTarget); |
| 9549 | if (mLowerWallpaperTarget == null) { |
| 9550 | // Whoops, we don't need a special wallpaper animation. |
| 9551 | // Clear them out. |
| 9552 | forceHiding = false; |
| 9553 | for (i=N-1; i>=0; i--) { |
| 9554 | WindowState w = (WindowState)mWindows.get(i); |
| 9555 | if (w.mSurface != null) { |
| 9556 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9557 | if (mPolicy.doesForceHide(w, attrs)) { |
| 9558 | forceHiding = true; |
| 9559 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9560 | if (!w.mAnimating) { |
| 9561 | // We set the animation above so it |
| 9562 | // is not yet running. |
| 9563 | w.clearAnimation(); |
| 9564 | } |
| 9565 | } |
| 9566 | } |
| 9567 | } |
| 9568 | } |
| 9569 | } |
| 9570 | |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9571 | if (wallpaperMayChange) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9572 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 9573 | "Wallpaper may change! Adjusting"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9574 | adjResult = adjustWallpaperWindowsLocked(); |
| 9575 | } |
| 9576 | |
| 9577 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9578 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 9579 | "Wallpaper layer changed: assigning layers + relayout"); |
| 9580 | restart = true; |
| 9581 | mLayoutNeeded = true; |
| 9582 | assignLayersLocked(); |
| 9583 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
| 9584 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 9585 | "Wallpaper visibility changed: relayout"); |
| 9586 | restart = true; |
| 9587 | mLayoutNeeded = true; |
| 9588 | } |
| 9589 | |
| 9590 | if (focusMayChange) { |
| 9591 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9592 | restart = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9593 | adjResult = 0; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9594 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9595 | } |
| 9596 | |
| 9597 | if (mLayoutNeeded) { |
| 9598 | restart = true; |
| 9599 | performLayoutLockedInner(); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9600 | } |
| 9601 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9602 | } while (restart); |
| 9603 | |
| 9604 | // THIRD LOOP: Update the surfaces of all windows. |
| 9605 | |
| 9606 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 9607 | |
| 9608 | boolean obscured = false; |
| 9609 | boolean blurring = false; |
| 9610 | boolean dimming = false; |
| 9611 | boolean covered = false; |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9612 | boolean syswin = false; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9613 | boolean backgroundFillerShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9614 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9615 | final int N = mWindows.size(); |
| 9616 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9617 | for (i=N-1; i>=0; i--) { |
| 9618 | WindowState w = (WindowState)mWindows.get(i); |
| 9619 | |
| 9620 | boolean displayed = false; |
| 9621 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9622 | final int attrFlags = attrs.flags; |
| 9623 | |
| 9624 | if (w.mSurface != null) { |
| 9625 | w.computeShownFrameLocked(); |
| 9626 | if (localLOGV) Log.v( |
| 9627 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 9628 | + ": new=" + w.mShownFrame + ", old=" |
| 9629 | + w.mLastShownFrame); |
| 9630 | |
| 9631 | boolean resize; |
| 9632 | int width, height; |
| 9633 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 9634 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 9635 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 9636 | // for a scaled surface, we just want to use |
| 9637 | // the requested size. |
| 9638 | width = w.mRequestedWidth; |
| 9639 | height = w.mRequestedHeight; |
| 9640 | w.mLastRequestedWidth = width; |
| 9641 | w.mLastRequestedHeight = height; |
| 9642 | w.mLastShownFrame.set(w.mShownFrame); |
| 9643 | try { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9644 | if (SHOW_TRANSACTIONS) Log.i( |
| 9645 | TAG, " SURFACE " + w.mSurface |
| 9646 | + ": POS " + w.mShownFrame.left |
| 9647 | + ", " + w.mShownFrame.top); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9648 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 9649 | } catch (RuntimeException e) { |
| 9650 | Log.w(TAG, "Error positioning surface in " + w, e); |
| 9651 | if (!recoveringMemory) { |
| 9652 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 9653 | } |
| 9654 | } |
| 9655 | } else { |
| 9656 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 9657 | width = w.mShownFrame.width(); |
| 9658 | height = w.mShownFrame.height(); |
| 9659 | w.mLastShownFrame.set(w.mShownFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9660 | } |
| 9661 | |
| 9662 | if (resize) { |
| 9663 | if (width < 1) width = 1; |
| 9664 | if (height < 1) height = 1; |
| 9665 | if (w.mSurface != null) { |
| 9666 | try { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9667 | if (SHOW_TRANSACTIONS) Log.i( |
| 9668 | TAG, " SURFACE " + w.mSurface + ": POS " |
| 9669 | + w.mShownFrame.left + "," |
| 9670 | + w.mShownFrame.top + " SIZE " |
| 9671 | + w.mShownFrame.width() + "x" |
| 9672 | + w.mShownFrame.height()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9673 | w.mSurface.setSize(width, height); |
| 9674 | w.mSurface.setPosition(w.mShownFrame.left, |
| 9675 | w.mShownFrame.top); |
| 9676 | } catch (RuntimeException e) { |
| 9677 | // If something goes wrong with the surface (such |
| 9678 | // as running out of memory), don't take down the |
| 9679 | // entire system. |
| 9680 | Log.e(TAG, "Failure updating surface of " + w |
| 9681 | + "size=(" + width + "x" + height |
| 9682 | + "), pos=(" + w.mShownFrame.left |
| 9683 | + "," + w.mShownFrame.top + ")", e); |
| 9684 | if (!recoveringMemory) { |
| 9685 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 9686 | } |
| 9687 | } |
| 9688 | } |
| 9689 | } |
| 9690 | if (!w.mAppFreezing) { |
| 9691 | w.mContentInsetsChanged = |
| 9692 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 9693 | w.mVisibleInsetsChanged = |
| 9694 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9695 | if (!w.mLastFrame.equals(w.mFrame) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9696 | || w.mContentInsetsChanged |
| 9697 | || w.mVisibleInsetsChanged) { |
| 9698 | w.mLastFrame.set(w.mFrame); |
| 9699 | w.mLastContentInsets.set(w.mContentInsets); |
| 9700 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9701 | // If the screen is currently frozen, then keep |
| 9702 | // it frozen until this window draws at its new |
| 9703 | // orientation. |
| 9704 | if (mDisplayFrozen) { |
| 9705 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 9706 | "Resizing while display frozen: " + w); |
| 9707 | w.mOrientationChanging = true; |
| 9708 | if (mWindowsFreezingScreen) { |
| 9709 | mWindowsFreezingScreen = true; |
| 9710 | // XXX should probably keep timeout from |
| 9711 | // when we first froze the display. |
| 9712 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 9713 | mH.sendMessageDelayed(mH.obtainMessage( |
| 9714 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 9715 | } |
| 9716 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9717 | // If the orientation is changing, then we need to |
| 9718 | // hold off on unfreezing the display until this |
| 9719 | // window has been redrawn; to do that, we need |
| 9720 | // to go through the process of getting informed |
| 9721 | // by the application when it has finished drawing. |
| 9722 | if (w.mOrientationChanging) { |
| 9723 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 9724 | "Orientation start waiting for draw in " |
| 9725 | + w + ", surface " + w.mSurface); |
| 9726 | w.mDrawPending = true; |
| 9727 | w.mCommitDrawPending = false; |
| 9728 | w.mReadyToShow = false; |
| 9729 | if (w.mAppToken != null) { |
| 9730 | w.mAppToken.allDrawn = false; |
| 9731 | } |
| 9732 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9733 | if (DEBUG_ORIENTATION) Log.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9734 | "Resizing window " + w + " to " + w.mFrame); |
| 9735 | mResizingWindows.add(w); |
| 9736 | } else if (w.mOrientationChanging) { |
| 9737 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
| 9738 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 9739 | "Orientation not waiting for draw in " |
| 9740 | + w + ", surface " + w.mSurface); |
| 9741 | w.mOrientationChanging = false; |
| 9742 | } |
| 9743 | } |
| 9744 | } |
| 9745 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9746 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9747 | if (!w.mLastHidden) { |
| 9748 | //dump(); |
| 9749 | w.mLastHidden = true; |
| 9750 | if (SHOW_TRANSACTIONS) Log.i( |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9751 | TAG, " SURFACE " + w.mSurface + ": HIDE (performLayout)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9752 | if (w.mSurface != null) { |
| 9753 | try { |
| 9754 | w.mSurface.hide(); |
| 9755 | } catch (RuntimeException e) { |
| 9756 | Log.w(TAG, "Exception hiding surface in " + w); |
| 9757 | } |
| 9758 | } |
| 9759 | mKeyWaiter.releasePendingPointerLocked(w.mSession); |
| 9760 | } |
| 9761 | // If we are waiting for this window to handle an |
| 9762 | // orientation change, well, it is hidden, so |
| 9763 | // doesn't really matter. Note that this does |
| 9764 | // introduce a potential glitch if the window |
| 9765 | // becomes unhidden before it has drawn for the |
| 9766 | // new orientation. |
| 9767 | if (w.mOrientationChanging) { |
| 9768 | w.mOrientationChanging = false; |
| 9769 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 9770 | "Orientation change skips hidden " + w); |
| 9771 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9772 | } else if (w.mLastLayer != w.mAnimLayer |
| 9773 | || w.mLastAlpha != w.mShownAlpha |
| 9774 | || w.mLastDsDx != w.mDsDx |
| 9775 | || w.mLastDtDx != w.mDtDx |
| 9776 | || w.mLastDsDy != w.mDsDy |
| 9777 | || w.mLastDtDy != w.mDtDy |
| 9778 | || w.mLastHScale != w.mHScale |
| 9779 | || w.mLastVScale != w.mVScale |
| 9780 | || w.mLastHidden) { |
| 9781 | displayed = true; |
| 9782 | w.mLastAlpha = w.mShownAlpha; |
| 9783 | w.mLastLayer = w.mAnimLayer; |
| 9784 | w.mLastDsDx = w.mDsDx; |
| 9785 | w.mLastDtDx = w.mDtDx; |
| 9786 | w.mLastDsDy = w.mDsDy; |
| 9787 | w.mLastDtDy = w.mDtDy; |
| 9788 | w.mLastHScale = w.mHScale; |
| 9789 | w.mLastVScale = w.mVScale; |
| 9790 | if (SHOW_TRANSACTIONS) Log.i( |
| 9791 | TAG, " SURFACE " + w.mSurface + ": alpha=" |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9792 | + w.mShownAlpha + " layer=" + w.mAnimLayer |
| 9793 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 9794 | + "," + (w.mDtDx*w.mVScale) |
| 9795 | + "][" + (w.mDsDy*w.mHScale) |
| 9796 | + "," + (w.mDtDy*w.mVScale) + "]"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9797 | if (w.mSurface != null) { |
| 9798 | try { |
| 9799 | w.mSurface.setAlpha(w.mShownAlpha); |
| 9800 | w.mSurface.setLayer(w.mAnimLayer); |
| 9801 | w.mSurface.setMatrix( |
| 9802 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 9803 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 9804 | } catch (RuntimeException e) { |
| 9805 | Log.w(TAG, "Error updating surface in " + w, e); |
| 9806 | if (!recoveringMemory) { |
| 9807 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 9808 | } |
| 9809 | } |
| 9810 | } |
| 9811 | |
| 9812 | if (w.mLastHidden && !w.mDrawPending |
| 9813 | && !w.mCommitDrawPending |
| 9814 | && !w.mReadyToShow) { |
| 9815 | if (SHOW_TRANSACTIONS) Log.i( |
| 9816 | TAG, " SURFACE " + w.mSurface + ": SHOW (performLayout)"); |
| 9817 | if (DEBUG_VISIBILITY) Log.v(TAG, "Showing " + w |
| 9818 | + " during relayout"); |
| 9819 | if (showSurfaceRobustlyLocked(w)) { |
| 9820 | w.mHasDrawn = true; |
| 9821 | w.mLastHidden = false; |
| 9822 | } else { |
| 9823 | w.mOrientationChanging = false; |
| 9824 | } |
| 9825 | } |
| 9826 | if (w.mSurface != null) { |
| 9827 | w.mToken.hasVisible = true; |
| 9828 | } |
| 9829 | } else { |
| 9830 | displayed = true; |
| 9831 | } |
| 9832 | |
| 9833 | if (displayed) { |
| 9834 | if (!covered) { |
| 9835 | if (attrs.width == LayoutParams.FILL_PARENT |
| 9836 | && attrs.height == LayoutParams.FILL_PARENT) { |
| 9837 | covered = true; |
| 9838 | } |
| 9839 | } |
| 9840 | if (w.mOrientationChanging) { |
| 9841 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 9842 | orientationChangeComplete = false; |
| 9843 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 9844 | "Orientation continue waiting for draw in " + w); |
| 9845 | } else { |
| 9846 | w.mOrientationChanging = false; |
| 9847 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 9848 | "Orientation change complete in " + w); |
| 9849 | } |
| 9850 | } |
| 9851 | w.mToken.hasVisible = true; |
| 9852 | } |
| 9853 | } else if (w.mOrientationChanging) { |
| 9854 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 9855 | "Orientation change skips hidden " + w); |
| 9856 | w.mOrientationChanging = false; |
| 9857 | } |
| 9858 | |
| 9859 | final boolean canBeSeen = w.isDisplayedLw(); |
| 9860 | |
| 9861 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 9862 | focusDisplayed = true; |
| 9863 | } |
| 9864 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 9865 | final boolean obscuredChanged = w.mObscured != obscured; |
| 9866 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9867 | // Update effect. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9868 | if (!(w.mObscured=obscured)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9869 | if (w.mSurface != null) { |
| 9870 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 9871 | holdScreen = w.mSession; |
| 9872 | } |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9873 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 9874 | && screenBrightness < 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9875 | screenBrightness = w.mAttrs.screenBrightness; |
| 9876 | } |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9877 | if (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 9878 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 9879 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR) { |
| 9880 | syswin = true; |
| 9881 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9882 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9883 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9884 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 9885 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9886 | // This window completely covers everything behind it, |
| 9887 | // so we want to leave all of them as unblurred (for |
| 9888 | // performance reasons). |
| 9889 | obscured = true; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9890 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
| 9891 | if (SHOW_TRANSACTIONS) Log.d(TAG, "showing background filler"); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9892 | // This window is in compatibility mode, and needs background filler. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9893 | obscured = true; |
| 9894 | if (mBackgroundFillerSurface == null) { |
| 9895 | try { |
| 9896 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
| 9897 | 0, dw, dh, |
| 9898 | PixelFormat.OPAQUE, |
| 9899 | Surface.FX_SURFACE_NORMAL); |
| 9900 | } catch (Exception e) { |
| 9901 | Log.e(TAG, "Exception creating filler surface", e); |
| 9902 | } |
| 9903 | } |
| 9904 | try { |
| 9905 | mBackgroundFillerSurface.setPosition(0, 0); |
| 9906 | mBackgroundFillerSurface.setSize(dw, dh); |
| 9907 | // Using the same layer as Dim because they will never be shown at the |
| 9908 | // same time. |
| 9909 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 9910 | mBackgroundFillerSurface.show(); |
| 9911 | } catch (RuntimeException e) { |
| 9912 | Log.e(TAG, "Exception showing filler surface"); |
| 9913 | } |
| 9914 | backgroundFillerShown = true; |
| 9915 | mBackgroundFillerShown = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9916 | } else if (canBeSeen && !obscured && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9917 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
| 9918 | if (localLOGV) Log.v(TAG, "Win " + w |
| 9919 | + ": blurring=" + blurring |
| 9920 | + " obscured=" + obscured |
| 9921 | + " displayed=" + displayed); |
| 9922 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 9923 | if (!dimming) { |
| 9924 | //Log.i(TAG, "DIM BEHIND: " + w); |
| 9925 | dimming = true; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9926 | if (mDimAnimator == null) { |
| 9927 | mDimAnimator = new DimAnimator(mFxSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9928 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9929 | mDimAnimator.show(dw, dh); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9930 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9931 | mDimAnimator.updateParameters(w, currentTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9932 | } |
| 9933 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 9934 | if (!blurring) { |
| 9935 | //Log.i(TAG, "BLUR BEHIND: " + w); |
| 9936 | blurring = true; |
| 9937 | mBlurShown = true; |
| 9938 | if (mBlurSurface == null) { |
| 9939 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " |
| 9940 | + mBlurSurface + ": CREATE"); |
| 9941 | try { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9942 | mBlurSurface = new Surface(mFxSession, 0, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9943 | -1, 16, 16, |
| 9944 | PixelFormat.OPAQUE, |
| 9945 | Surface.FX_SURFACE_BLUR); |
| 9946 | } catch (Exception e) { |
| 9947 | Log.e(TAG, "Exception creating Blur surface", e); |
| 9948 | } |
| 9949 | } |
| 9950 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " |
| 9951 | + mBlurSurface + ": SHOW pos=(0,0) (" + |
| 9952 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
| 9953 | if (mBlurSurface != null) { |
| 9954 | mBlurSurface.setPosition(0, 0); |
| 9955 | mBlurSurface.setSize(dw, dh); |
| 9956 | try { |
| 9957 | mBlurSurface.show(); |
| 9958 | } catch (RuntimeException e) { |
| 9959 | Log.w(TAG, "Failure showing blur surface", e); |
| 9960 | } |
| 9961 | } |
| 9962 | } |
| 9963 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 9964 | } |
| 9965 | } |
| 9966 | } |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 9967 | |
| 9968 | if (obscuredChanged && mWallpaperTarget == w) { |
| 9969 | // This is the wallpaper target and its obscured state |
| 9970 | // changed... make sure the current wallaper's visibility |
| 9971 | // has been updated accordingly. |
| 9972 | updateWallpaperVisibilityLocked(); |
| 9973 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9974 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9975 | |
| 9976 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 9977 | mBackgroundFillerShown = false; |
| 9978 | if (SHOW_TRANSACTIONS) Log.d(TAG, "hiding background filler"); |
| 9979 | try { |
| 9980 | mBackgroundFillerSurface.hide(); |
| 9981 | } catch (RuntimeException e) { |
| 9982 | Log.e(TAG, "Exception hiding filler surface", e); |
| 9983 | } |
| 9984 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9985 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9986 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
| 9987 | animating |= mDimAnimator.updateSurface(dimming, currentTime, mDisplayFrozen); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9988 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9989 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9990 | if (!blurring && mBlurShown) { |
| 9991 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " + mBlurSurface |
| 9992 | + ": HIDE"); |
| 9993 | try { |
| 9994 | mBlurSurface.hide(); |
| 9995 | } catch (IllegalArgumentException e) { |
| 9996 | Log.w(TAG, "Illegal argument exception hiding blur surface"); |
| 9997 | } |
| 9998 | mBlurShown = false; |
| 9999 | } |
| 10000 | |
| 10001 | if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION"); |
| 10002 | } catch (RuntimeException e) { |
| 10003 | Log.e(TAG, "Unhandled exception in Window Manager", e); |
| 10004 | } |
| 10005 | |
| 10006 | Surface.closeTransaction(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10007 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10008 | if (DEBUG_ORIENTATION && mDisplayFrozen) Log.v(TAG, |
| 10009 | "With display frozen, orientationChangeComplete=" |
| 10010 | + orientationChangeComplete); |
| 10011 | if (orientationChangeComplete) { |
| 10012 | if (mWindowsFreezingScreen) { |
| 10013 | mWindowsFreezingScreen = false; |
| 10014 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10015 | } |
| 10016 | if (mAppsFreezingScreen == 0) { |
| 10017 | stopFreezingDisplayLocked(); |
| 10018 | } |
| 10019 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10020 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10021 | i = mResizingWindows.size(); |
| 10022 | if (i > 0) { |
| 10023 | do { |
| 10024 | i--; |
| 10025 | WindowState win = mResizingWindows.get(i); |
| 10026 | try { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10027 | if (DEBUG_ORIENTATION) Log.v(TAG, "Reporting new frame to " |
| 10028 | + win + ": " + win.mFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10029 | win.mClient.resized(win.mFrame.width(), |
| 10030 | win.mFrame.height(), win.mLastContentInsets, |
| 10031 | win.mLastVisibleInsets, win.mDrawPending); |
| 10032 | win.mContentInsetsChanged = false; |
| 10033 | win.mVisibleInsetsChanged = false; |
| 10034 | } catch (RemoteException e) { |
| 10035 | win.mOrientationChanging = false; |
| 10036 | } |
| 10037 | } while (i > 0); |
| 10038 | mResizingWindows.clear(); |
| 10039 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10040 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10041 | // Destroy the surface of any windows that are no longer visible. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10042 | boolean wallpaperDestroyed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10043 | i = mDestroySurface.size(); |
| 10044 | if (i > 0) { |
| 10045 | do { |
| 10046 | i--; |
| 10047 | WindowState win = mDestroySurface.get(i); |
| 10048 | win.mDestroying = false; |
| 10049 | if (mInputMethodWindow == win) { |
| 10050 | mInputMethodWindow = null; |
| 10051 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10052 | if (win == mWallpaperTarget) { |
| 10053 | wallpaperDestroyed = true; |
| 10054 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10055 | win.destroySurfaceLocked(); |
| 10056 | } while (i > 0); |
| 10057 | mDestroySurface.clear(); |
| 10058 | } |
| 10059 | |
| 10060 | // Time to remove any exiting tokens? |
| 10061 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 10062 | WindowToken token = mExitingTokens.get(i); |
| 10063 | if (!token.hasVisible) { |
| 10064 | mExitingTokens.remove(i); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10065 | if (token.windowType == TYPE_WALLPAPER) { |
| 10066 | mWallpaperTokens.remove(token); |
| 10067 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10068 | } |
| 10069 | } |
| 10070 | |
| 10071 | // Time to remove any exiting applications? |
| 10072 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10073 | AppWindowToken token = mExitingAppTokens.get(i); |
| 10074 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 10075 | // Make sure there is no animation running on this token, |
| 10076 | // so any windows associated with it will be removed as |
| 10077 | // soon as their animations are complete |
| 10078 | token.animation = null; |
| 10079 | token.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10080 | mAppTokens.remove(token); |
| 10081 | mExitingAppTokens.remove(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10082 | if (mLastEnterAnimToken == token) { |
| 10083 | mLastEnterAnimToken = null; |
| 10084 | mLastEnterAnimParams = null; |
| 10085 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10086 | } |
| 10087 | } |
| 10088 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10089 | boolean needRelayout = false; |
| 10090 | |
| 10091 | if (!animating && mAppTransitionRunning) { |
| 10092 | // We have finished the animation of an app transition. To do |
| 10093 | // this, we have delayed a lot of operations like showing and |
| 10094 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10095 | // reflects the correct Z-order, but the window list may now |
| 10096 | // be out of sync with it. So here we will just rebuild the |
| 10097 | // entire app window list. Fun! |
| 10098 | mAppTransitionRunning = false; |
| 10099 | needRelayout = true; |
| 10100 | rebuildAppWindowListLocked(); |
| 10101 | // Clear information about apps that were moving. |
| 10102 | mToBottomApps.clear(); |
| 10103 | } |
| 10104 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10105 | if (focusDisplayed) { |
| 10106 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 10107 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10108 | if (wallpaperDestroyed) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10109 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10110 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10111 | if (needRelayout) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10112 | requestAnimationLocked(0); |
| 10113 | } else if (animating) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10114 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 10115 | } |
| 10116 | mQueue.setHoldScreenLocked(holdScreen != null); |
| 10117 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 10118 | mPowerManager.setScreenBrightnessOverride(-1); |
| 10119 | } else { |
| 10120 | mPowerManager.setScreenBrightnessOverride((int) |
| 10121 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 10122 | } |
| 10123 | if (holdScreen != mHoldingScreenOn) { |
| 10124 | mHoldingScreenOn = holdScreen; |
| 10125 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 10126 | mH.sendMessage(m); |
| 10127 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10128 | |
| 10129 | if (mTurnOnScreen) { |
| 10130 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 10131 | LocalPowerManager.BUTTON_EVENT, true); |
| 10132 | mTurnOnScreen = false; |
| 10133 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10134 | } |
| 10135 | |
| 10136 | void requestAnimationLocked(long delay) { |
| 10137 | if (!mAnimationPending) { |
| 10138 | mAnimationPending = true; |
| 10139 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 10140 | } |
| 10141 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10142 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10143 | /** |
| 10144 | * Have the surface flinger show a surface, robustly dealing with |
| 10145 | * error conditions. In particular, if there is not enough memory |
| 10146 | * to show the surface, then we will try to get rid of other surfaces |
| 10147 | * in order to succeed. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10148 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10149 | * @return Returns true if the surface was successfully shown. |
| 10150 | */ |
| 10151 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 10152 | try { |
| 10153 | if (win.mSurface != null) { |
| 10154 | win.mSurface.show(); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10155 | if (win.mTurnOnScreen) { |
| 10156 | win.mTurnOnScreen = false; |
| 10157 | mTurnOnScreen = true; |
| 10158 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10159 | } |
| 10160 | return true; |
| 10161 | } catch (RuntimeException e) { |
| 10162 | Log.w(TAG, "Failure showing surface " + win.mSurface + " in " + win); |
| 10163 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10164 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10165 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10166 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10167 | return false; |
| 10168 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10169 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10170 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 10171 | final Surface surface = win.mSurface; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10172 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10173 | EventLog.writeEvent(LOG_WM_NO_SURFACE_MEMORY, win.toString(), |
| 10174 | win.mSession.mPid, operation); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10175 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10176 | if (mForceRemoves == null) { |
| 10177 | mForceRemoves = new ArrayList<WindowState>(); |
| 10178 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10179 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10180 | long callingIdentity = Binder.clearCallingIdentity(); |
| 10181 | try { |
| 10182 | // There was some problem... first, do a sanity check of the |
| 10183 | // window list to make sure we haven't left any dangling surfaces |
| 10184 | // around. |
| 10185 | int N = mWindows.size(); |
| 10186 | boolean leakedSurface = false; |
| 10187 | Log.i(TAG, "Out of memory for surface! Looking for leaks..."); |
| 10188 | for (int i=0; i<N; i++) { |
| 10189 | WindowState ws = (WindowState)mWindows.get(i); |
| 10190 | if (ws.mSurface != null) { |
| 10191 | if (!mSessions.contains(ws.mSession)) { |
| 10192 | Log.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
| 10193 | + ws + " surface=" + ws.mSurface |
| 10194 | + " token=" + win.mToken |
| 10195 | + " pid=" + ws.mSession.mPid |
| 10196 | + " uid=" + ws.mSession.mUid); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10197 | ws.mSurface.destroy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10198 | ws.mSurface = null; |
| 10199 | mForceRemoves.add(ws); |
| 10200 | i--; |
| 10201 | N--; |
| 10202 | leakedSurface = true; |
| 10203 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
| 10204 | Log.w(TAG, "LEAKED SURFACE (app token hidden): " |
| 10205 | + ws + " surface=" + ws.mSurface |
| 10206 | + " token=" + win.mAppToken); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10207 | ws.mSurface.destroy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10208 | ws.mSurface = null; |
| 10209 | leakedSurface = true; |
| 10210 | } |
| 10211 | } |
| 10212 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10213 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10214 | boolean killedApps = false; |
| 10215 | if (!leakedSurface) { |
| 10216 | Log.w(TAG, "No leaked surfaces; killing applicatons!"); |
| 10217 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 10218 | for (int i=0; i<N; i++) { |
| 10219 | WindowState ws = (WindowState)mWindows.get(i); |
| 10220 | if (ws.mSurface != null) { |
| 10221 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 10222 | } |
| 10223 | } |
| 10224 | if (pidCandidates.size() > 0) { |
| 10225 | int[] pids = new int[pidCandidates.size()]; |
| 10226 | for (int i=0; i<pids.length; i++) { |
| 10227 | pids[i] = pidCandidates.keyAt(i); |
| 10228 | } |
| 10229 | try { |
| 10230 | if (mActivityManager.killPidsForMemory(pids)) { |
| 10231 | killedApps = true; |
| 10232 | } |
| 10233 | } catch (RemoteException e) { |
| 10234 | } |
| 10235 | } |
| 10236 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10237 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10238 | if (leakedSurface || killedApps) { |
| 10239 | // We managed to reclaim some memory, so get rid of the trouble |
| 10240 | // surface and ask the app to request another one. |
| 10241 | Log.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry."); |
| 10242 | if (surface != null) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10243 | surface.destroy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10244 | win.mSurface = null; |
| 10245 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10246 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10247 | try { |
| 10248 | win.mClient.dispatchGetNewSurface(); |
| 10249 | } catch (RemoteException e) { |
| 10250 | } |
| 10251 | } |
| 10252 | } finally { |
| 10253 | Binder.restoreCallingIdentity(callingIdentity); |
| 10254 | } |
| 10255 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10256 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10257 | private boolean updateFocusedWindowLocked(int mode) { |
| 10258 | WindowState newFocus = computeFocusedWindowLocked(); |
| 10259 | if (mCurrentFocus != newFocus) { |
| 10260 | // This check makes sure that we don't already have the focus |
| 10261 | // change message pending. |
| 10262 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 10263 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
| 10264 | if (localLOGV) Log.v( |
| 10265 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 10266 | final WindowState oldFocus = mCurrentFocus; |
| 10267 | mCurrentFocus = newFocus; |
| 10268 | mLosingFocus.remove(newFocus); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10269 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10270 | final WindowState imWindow = mInputMethodWindow; |
| 10271 | if (newFocus != imWindow && oldFocus != imWindow) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10272 | if (moveInputMethodWindowsIfNeededLocked( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10273 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10274 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 10275 | mLayoutNeeded = true; |
| 10276 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10277 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 10278 | performLayoutLockedInner(); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10279 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 10280 | // Client will do the layout, but we need to assign layers |
| 10281 | // for handleNewWindowLocked() below. |
| 10282 | assignLayersLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10283 | } |
| 10284 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10285 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10286 | if (newFocus != null && mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 10287 | mKeyWaiter.handleNewWindowLocked(newFocus); |
| 10288 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10289 | return true; |
| 10290 | } |
| 10291 | return false; |
| 10292 | } |
| 10293 | |
| 10294 | private WindowState computeFocusedWindowLocked() { |
| 10295 | WindowState result = null; |
| 10296 | WindowState win; |
| 10297 | |
| 10298 | int i = mWindows.size() - 1; |
| 10299 | int nextAppIndex = mAppTokens.size()-1; |
| 10300 | WindowToken nextApp = nextAppIndex >= 0 |
| 10301 | ? mAppTokens.get(nextAppIndex) : null; |
| 10302 | |
| 10303 | while (i >= 0) { |
| 10304 | win = (WindowState)mWindows.get(i); |
| 10305 | |
| 10306 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 10307 | TAG, "Looking for focus: " + i |
| 10308 | + " = " + win |
| 10309 | + ", flags=" + win.mAttrs.flags |
| 10310 | + ", canReceive=" + win.canReceiveKeys()); |
| 10311 | |
| 10312 | AppWindowToken thisApp = win.mAppToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10313 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10314 | // If this window's application has been removed, just skip it. |
| 10315 | if (thisApp != null && thisApp.removed) { |
| 10316 | i--; |
| 10317 | continue; |
| 10318 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10319 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10320 | // If there is a focused app, don't allow focus to go to any |
| 10321 | // windows below it. If this is an application window, step |
| 10322 | // through the app tokens until we find its app. |
| 10323 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 10324 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 10325 | int origAppIndex = nextAppIndex; |
| 10326 | while (nextAppIndex > 0) { |
| 10327 | if (nextApp == mFocusedApp) { |
| 10328 | // Whoops, we are below the focused app... no focus |
| 10329 | // for you! |
| 10330 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 10331 | TAG, "Reached focused app: " + mFocusedApp); |
| 10332 | return null; |
| 10333 | } |
| 10334 | nextAppIndex--; |
| 10335 | nextApp = mAppTokens.get(nextAppIndex); |
| 10336 | if (nextApp == thisApp) { |
| 10337 | break; |
| 10338 | } |
| 10339 | } |
| 10340 | if (thisApp != nextApp) { |
| 10341 | // Uh oh, the app token doesn't exist! This shouldn't |
| 10342 | // happen, but if it does we can get totally hosed... |
| 10343 | // so restart at the original app. |
| 10344 | nextAppIndex = origAppIndex; |
| 10345 | nextApp = mAppTokens.get(nextAppIndex); |
| 10346 | } |
| 10347 | } |
| 10348 | |
| 10349 | // Dispatch to this window if it is wants key events. |
| 10350 | if (win.canReceiveKeys()) { |
| 10351 | if (DEBUG_FOCUS) Log.v( |
| 10352 | TAG, "Found focus @ " + i + " = " + win); |
| 10353 | result = win; |
| 10354 | break; |
| 10355 | } |
| 10356 | |
| 10357 | i--; |
| 10358 | } |
| 10359 | |
| 10360 | return result; |
| 10361 | } |
| 10362 | |
| 10363 | private void startFreezingDisplayLocked() { |
| 10364 | if (mDisplayFrozen) { |
Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 10365 | // Freezing the display also suspends key event delivery, to |
| 10366 | // keep events from going astray while the display is reconfigured. |
| 10367 | // If someone has changed orientation again while the screen is |
| 10368 | // still frozen, the events will continue to be blocked while the |
| 10369 | // successive orientation change is processed. To prevent spurious |
| 10370 | // ANRs, we reset the event dispatch timeout in this case. |
| 10371 | synchronized (mKeyWaiter) { |
| 10372 | mKeyWaiter.mWasFrozen = true; |
| 10373 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10374 | return; |
| 10375 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10376 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10377 | mScreenFrozenLock.acquire(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10378 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10379 | long now = SystemClock.uptimeMillis(); |
| 10380 | //Log.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
| 10381 | if (mFreezeGcPending != 0) { |
| 10382 | if (now > (mFreezeGcPending+1000)) { |
| 10383 | //Log.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| 10384 | mH.removeMessages(H.FORCE_GC); |
| 10385 | Runtime.getRuntime().gc(); |
| 10386 | mFreezeGcPending = now; |
| 10387 | } |
| 10388 | } else { |
| 10389 | mFreezeGcPending = now; |
| 10390 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10391 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10392 | mDisplayFrozen = true; |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 10393 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 10394 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10395 | mNextAppTransitionPackage = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10396 | mAppTransitionReady = true; |
| 10397 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10398 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10399 | if (PROFILE_ORIENTATION) { |
| 10400 | File file = new File("/data/system/frozen"); |
| 10401 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 10402 | } |
| 10403 | Surface.freezeDisplay(0); |
| 10404 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10405 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10406 | private void stopFreezingDisplayLocked() { |
| 10407 | if (!mDisplayFrozen) { |
| 10408 | return; |
| 10409 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10410 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10411 | mDisplayFrozen = false; |
| 10412 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 10413 | if (PROFILE_ORIENTATION) { |
| 10414 | Debug.stopMethodTracing(); |
| 10415 | } |
| 10416 | Surface.unfreezeDisplay(0); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10417 | |
Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 10418 | // Reset the key delivery timeout on unfreeze, too. We force a wakeup here |
| 10419 | // too because regular key delivery processing should resume immediately. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10420 | synchronized (mKeyWaiter) { |
| 10421 | mKeyWaiter.mWasFrozen = true; |
| 10422 | mKeyWaiter.notifyAll(); |
| 10423 | } |
| 10424 | |
| 10425 | // A little kludge: a lot could have happened while the |
| 10426 | // display was frozen, so now that we are coming back we |
| 10427 | // do a gc so that any remote references the system |
| 10428 | // processes holds on others can be released if they are |
| 10429 | // no longer needed. |
| 10430 | mH.removeMessages(H.FORCE_GC); |
| 10431 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 10432 | 2000); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10433 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10434 | mScreenFrozenLock.release(); |
| 10435 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10436 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10437 | @Override |
| 10438 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 10439 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 10440 | != PackageManager.PERMISSION_GRANTED) { |
| 10441 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 10442 | + Binder.getCallingPid() |
| 10443 | + ", uid=" + Binder.getCallingUid()); |
| 10444 | return; |
| 10445 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10446 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10447 | synchronized(mWindowMap) { |
| 10448 | pw.println("Current Window Manager state:"); |
| 10449 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 10450 | WindowState w = (WindowState)mWindows.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10451 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 10452 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10453 | w.dump(pw, " "); |
| 10454 | } |
| 10455 | if (mInputMethodDialogs.size() > 0) { |
| 10456 | pw.println(" "); |
| 10457 | pw.println(" Input method dialogs:"); |
| 10458 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 10459 | WindowState w = mInputMethodDialogs.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10460 | 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] | 10461 | } |
| 10462 | } |
| 10463 | if (mPendingRemove.size() > 0) { |
| 10464 | pw.println(" "); |
| 10465 | pw.println(" Remove pending for:"); |
| 10466 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 10467 | WindowState w = mPendingRemove.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10468 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 10469 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10470 | w.dump(pw, " "); |
| 10471 | } |
| 10472 | } |
| 10473 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 10474 | pw.println(" "); |
| 10475 | pw.println(" Windows force removing:"); |
| 10476 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 10477 | WindowState w = mForceRemoves.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10478 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 10479 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10480 | w.dump(pw, " "); |
| 10481 | } |
| 10482 | } |
| 10483 | if (mDestroySurface.size() > 0) { |
| 10484 | pw.println(" "); |
| 10485 | pw.println(" Windows waiting to destroy their surface:"); |
| 10486 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 10487 | WindowState w = mDestroySurface.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10488 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 10489 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10490 | w.dump(pw, " "); |
| 10491 | } |
| 10492 | } |
| 10493 | if (mLosingFocus.size() > 0) { |
| 10494 | pw.println(" "); |
| 10495 | pw.println(" Windows losing focus:"); |
| 10496 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 10497 | WindowState w = mLosingFocus.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10498 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 10499 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10500 | w.dump(pw, " "); |
| 10501 | } |
| 10502 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10503 | if (mResizingWindows.size() > 0) { |
| 10504 | pw.println(" "); |
| 10505 | pw.println(" Windows waiting to resize:"); |
| 10506 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 10507 | WindowState w = mResizingWindows.get(i); |
| 10508 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 10509 | pw.print(w); pw.println(":"); |
| 10510 | w.dump(pw, " "); |
| 10511 | } |
| 10512 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10513 | if (mSessions.size() > 0) { |
| 10514 | pw.println(" "); |
| 10515 | pw.println(" All active sessions:"); |
| 10516 | Iterator<Session> it = mSessions.iterator(); |
| 10517 | while (it.hasNext()) { |
| 10518 | Session s = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10519 | pw.print(" Session "); pw.print(s); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10520 | s.dump(pw, " "); |
| 10521 | } |
| 10522 | } |
| 10523 | if (mTokenMap.size() > 0) { |
| 10524 | pw.println(" "); |
| 10525 | pw.println(" All tokens:"); |
| 10526 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 10527 | while (it.hasNext()) { |
| 10528 | WindowToken token = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10529 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10530 | token.dump(pw, " "); |
| 10531 | } |
| 10532 | } |
| 10533 | if (mTokenList.size() > 0) { |
| 10534 | pw.println(" "); |
| 10535 | pw.println(" Window token list:"); |
| 10536 | for (int i=0; i<mTokenList.size(); i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10537 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 10538 | pw.println(mTokenList.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10539 | } |
| 10540 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10541 | if (mWallpaperTokens.size() > 0) { |
| 10542 | pw.println(" "); |
| 10543 | pw.println(" Wallpaper tokens:"); |
| 10544 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 10545 | WindowToken token = mWallpaperTokens.get(i); |
| 10546 | pw.print(" Wallpaper #"); pw.print(i); |
| 10547 | pw.print(' '); pw.print(token); pw.println(':'); |
| 10548 | token.dump(pw, " "); |
| 10549 | } |
| 10550 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10551 | if (mAppTokens.size() > 0) { |
| 10552 | pw.println(" "); |
| 10553 | pw.println(" Application tokens in Z order:"); |
| 10554 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10555 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 10556 | pw.println(mAppTokens.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10557 | } |
| 10558 | } |
| 10559 | if (mFinishedStarting.size() > 0) { |
| 10560 | pw.println(" "); |
| 10561 | pw.println(" Finishing start of application tokens:"); |
| 10562 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 10563 | WindowToken token = mFinishedStarting.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10564 | pw.print(" Finished Starting #"); pw.print(i); |
| 10565 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10566 | token.dump(pw, " "); |
| 10567 | } |
| 10568 | } |
| 10569 | if (mExitingTokens.size() > 0) { |
| 10570 | pw.println(" "); |
| 10571 | pw.println(" Exiting tokens:"); |
| 10572 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 10573 | WindowToken token = mExitingTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10574 | pw.print(" Exiting #"); pw.print(i); |
| 10575 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10576 | token.dump(pw, " "); |
| 10577 | } |
| 10578 | } |
| 10579 | if (mExitingAppTokens.size() > 0) { |
| 10580 | pw.println(" "); |
| 10581 | pw.println(" Exiting application tokens:"); |
| 10582 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10583 | WindowToken token = mExitingAppTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10584 | pw.print(" Exiting App #"); pw.print(i); |
| 10585 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10586 | token.dump(pw, " "); |
| 10587 | } |
| 10588 | } |
| 10589 | pw.println(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10590 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 10591 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 10592 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 10593 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 10594 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 10595 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10596 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 10597 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 10598 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 10599 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10600 | pw.print(" mInTouchMode="); pw.println(mInTouchMode); |
| 10601 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 10602 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 10603 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 10604 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10605 | if (mDimAnimator != null) { |
| 10606 | mDimAnimator.printTo(pw); |
| 10607 | } else { |
| 10608 | pw.print( " no DimAnimator "); |
| 10609 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10610 | pw.print(" mInputMethodAnimLayerAdjustment="); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 10611 | pw.print(mInputMethodAnimLayerAdjustment); |
| 10612 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 10613 | pw.println(mWallpaperAnimLayerAdjustment); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10614 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 10615 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10616 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 10617 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
| 10618 | pw.print(" mAppsFreezingScreen="); pw.println(mAppsFreezingScreen); |
| 10619 | pw.print(" mRotation="); pw.print(mRotation); |
| 10620 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 10621 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 10622 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 10623 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 10624 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 10625 | pw.print(" mNextAppTransition=0x"); |
| 10626 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 10627 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10628 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10629 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10630 | if (mNextAppTransitionPackage != null) { |
| 10631 | pw.print(" mNextAppTransitionPackage="); |
| 10632 | pw.print(mNextAppTransitionPackage); |
| 10633 | pw.print(", mNextAppTransitionEnter=0x"); |
| 10634 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 10635 | pw.print(", mNextAppTransitionExit=0x"); |
| 10636 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 10637 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10638 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 10639 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10640 | if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) { |
| 10641 | pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken); |
| 10642 | pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams); |
| 10643 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10644 | if (mOpeningApps.size() > 0) { |
| 10645 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 10646 | } |
| 10647 | if (mClosingApps.size() > 0) { |
| 10648 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 10649 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10650 | if (mToTopApps.size() > 0) { |
| 10651 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 10652 | } |
| 10653 | if (mToBottomApps.size() > 0) { |
| 10654 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 10655 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10656 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 10657 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10658 | pw.println(" KeyWaiter state:"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10659 | pw.print(" mLastWin="); pw.print(mKeyWaiter.mLastWin); |
| 10660 | pw.print(" mLastBinder="); pw.println(mKeyWaiter.mLastBinder); |
| 10661 | pw.print(" mFinished="); pw.print(mKeyWaiter.mFinished); |
| 10662 | pw.print(" mGotFirstWindow="); pw.print(mKeyWaiter.mGotFirstWindow); |
| 10663 | pw.print(" mEventDispatching="); pw.print(mKeyWaiter.mEventDispatching); |
| 10664 | pw.print(" mTimeToSwitch="); pw.println(mKeyWaiter.mTimeToSwitch); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10665 | } |
| 10666 | } |
| 10667 | |
| 10668 | public void monitor() { |
| 10669 | synchronized (mWindowMap) { } |
| 10670 | synchronized (mKeyguardDisabled) { } |
| 10671 | synchronized (mKeyWaiter) { } |
| 10672 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10673 | |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 10674 | public void virtualKeyFeedback(KeyEvent event) { |
| 10675 | mPolicy.keyFeedbackFromInput(event); |
| 10676 | } |
| 10677 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10678 | /** |
| 10679 | * DimAnimator class that controls the dim animation. This holds the surface and |
| 10680 | * all state used for dim animation. |
| 10681 | */ |
| 10682 | private static class DimAnimator { |
| 10683 | Surface mDimSurface; |
| 10684 | boolean mDimShown = false; |
| 10685 | float mDimCurrentAlpha; |
| 10686 | float mDimTargetAlpha; |
| 10687 | float mDimDeltaPerMs; |
| 10688 | long mLastDimAnimTime; |
| 10689 | |
| 10690 | DimAnimator (SurfaceSession session) { |
| 10691 | if (mDimSurface == null) { |
| 10692 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 10693 | + mDimSurface + ": CREATE"); |
| 10694 | try { |
| 10695 | mDimSurface = new Surface(session, 0, -1, 16, 16, PixelFormat.OPAQUE, |
| 10696 | Surface.FX_SURFACE_DIM); |
| 10697 | } catch (Exception e) { |
| 10698 | Log.e(TAG, "Exception creating Dim surface", e); |
| 10699 | } |
| 10700 | } |
| 10701 | } |
| 10702 | |
| 10703 | /** |
| 10704 | * Show the dim surface. |
| 10705 | */ |
| 10706 | void show(int dw, int dh) { |
| 10707 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 10708 | dw + "x" + dh + ")"); |
| 10709 | mDimShown = true; |
| 10710 | try { |
| 10711 | mDimSurface.setPosition(0, 0); |
| 10712 | mDimSurface.setSize(dw, dh); |
| 10713 | mDimSurface.show(); |
| 10714 | } catch (RuntimeException e) { |
| 10715 | Log.w(TAG, "Failure showing dim surface", e); |
| 10716 | } |
| 10717 | } |
| 10718 | |
| 10719 | /** |
| 10720 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 10721 | * {@link updateSurface} after all windows are examined. |
| 10722 | */ |
| 10723 | void updateParameters(WindowState w, long currentTime) { |
| 10724 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 10725 | |
| 10726 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10727 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface |
| 10728 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10729 | if (mDimTargetAlpha != target) { |
| 10730 | // If the desired dim level has changed, then |
| 10731 | // start an animation to it. |
| 10732 | mLastDimAnimTime = currentTime; |
| 10733 | long duration = (w.mAnimating && w.mAnimation != null) |
| 10734 | ? w.mAnimation.computeDurationHint() |
| 10735 | : DEFAULT_DIM_DURATION; |
| 10736 | if (target > mDimTargetAlpha) { |
| 10737 | // This is happening behind the activity UI, |
| 10738 | // so we can make it run a little longer to |
| 10739 | // give a stronger impression without disrupting |
| 10740 | // the user. |
| 10741 | duration *= DIM_DURATION_MULTIPLIER; |
| 10742 | } |
| 10743 | if (duration < 1) { |
| 10744 | // Don't divide by zero |
| 10745 | duration = 1; |
| 10746 | } |
| 10747 | mDimTargetAlpha = target; |
| 10748 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 10749 | } |
| 10750 | } |
| 10751 | |
| 10752 | /** |
| 10753 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 10754 | * false when the animation is finished and the dim surface is hidden. |
| 10755 | */ |
| 10756 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 10757 | if (!dimming) { |
| 10758 | if (mDimTargetAlpha != 0) { |
| 10759 | mLastDimAnimTime = currentTime; |
| 10760 | mDimTargetAlpha = 0; |
| 10761 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 10762 | } |
| 10763 | } |
| 10764 | |
| 10765 | boolean animating = false; |
| 10766 | if (mLastDimAnimTime != 0) { |
| 10767 | mDimCurrentAlpha += mDimDeltaPerMs |
| 10768 | * (currentTime-mLastDimAnimTime); |
| 10769 | boolean more = true; |
| 10770 | if (displayFrozen) { |
| 10771 | // If the display is frozen, there is no reason to animate. |
| 10772 | more = false; |
| 10773 | } else if (mDimDeltaPerMs > 0) { |
| 10774 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 10775 | more = false; |
| 10776 | } |
| 10777 | } else if (mDimDeltaPerMs < 0) { |
| 10778 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 10779 | more = false; |
| 10780 | } |
| 10781 | } else { |
| 10782 | more = false; |
| 10783 | } |
| 10784 | |
| 10785 | // Do we need to continue animating? |
| 10786 | if (more) { |
| 10787 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 10788 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 10789 | mLastDimAnimTime = currentTime; |
| 10790 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 10791 | animating = true; |
| 10792 | } else { |
| 10793 | mDimCurrentAlpha = mDimTargetAlpha; |
| 10794 | mLastDimAnimTime = 0; |
| 10795 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 10796 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 10797 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 10798 | if (!dimming) { |
| 10799 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface |
| 10800 | + ": HIDE"); |
| 10801 | try { |
| 10802 | mDimSurface.hide(); |
| 10803 | } catch (RuntimeException e) { |
| 10804 | Log.w(TAG, "Illegal argument exception hiding dim surface"); |
| 10805 | } |
| 10806 | mDimShown = false; |
| 10807 | } |
| 10808 | } |
| 10809 | } |
| 10810 | return animating; |
| 10811 | } |
| 10812 | |
| 10813 | public void printTo(PrintWriter pw) { |
| 10814 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 10815 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 10816 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 10817 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 10818 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 10819 | } |
| 10820 | } |
| 10821 | |
| 10822 | /** |
| 10823 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 10824 | * This is used for opening/closing transition for apps in compatible mode. |
| 10825 | */ |
| 10826 | private static class FadeInOutAnimation extends Animation { |
| 10827 | int mWidth; |
| 10828 | boolean mFadeIn; |
| 10829 | |
| 10830 | public FadeInOutAnimation(boolean fadeIn) { |
| 10831 | setInterpolator(new AccelerateInterpolator()); |
| 10832 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 10833 | mFadeIn = fadeIn; |
| 10834 | } |
| 10835 | |
| 10836 | @Override |
| 10837 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 10838 | float x = interpolatedTime; |
| 10839 | if (!mFadeIn) { |
| 10840 | x = 1.0f - x; // reverse the interpolation for fade out |
| 10841 | } |
| 10842 | if (x < 0.5) { |
| 10843 | // move the window out of the screen. |
| 10844 | t.getMatrix().setTranslate(mWidth, 0); |
| 10845 | } else { |
| 10846 | t.getMatrix().setTranslate(0, 0);// show |
| 10847 | t.setAlpha((x - 0.5f) * 2); |
| 10848 | } |
| 10849 | } |
| 10850 | |
| 10851 | @Override |
| 10852 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 10853 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 10854 | mWidth = width; |
| 10855 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10856 | |
| 10857 | @Override |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 10858 | public int getZAdjustment() { |
| 10859 | return Animation.ZORDER_TOP; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10860 | } |
| 10861 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10862 | } |