| 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); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3221 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3222 | // Propagate other interesting state between the |
| 3223 | // tokens. If the old token is displayed, we should |
| 3224 | // immediately force the new one to be displayed. If |
| 3225 | // it is animating, we need to move that animation to |
| 3226 | // the new one. |
| 3227 | if (ttoken.allDrawn) { |
| 3228 | wtoken.allDrawn = true; |
| 3229 | } |
| 3230 | if (ttoken.firstWindowDrawn) { |
| 3231 | wtoken.firstWindowDrawn = true; |
| 3232 | } |
| 3233 | if (!ttoken.hidden) { |
| 3234 | wtoken.hidden = false; |
| 3235 | wtoken.hiddenRequested = false; |
| 3236 | wtoken.willBeHidden = false; |
| 3237 | } |
| 3238 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3239 | wtoken.clientHidden = ttoken.clientHidden; |
| 3240 | wtoken.sendAppVisibilityToClients(); |
| 3241 | } |
| 3242 | if (ttoken.animation != null) { |
| 3243 | wtoken.animation = ttoken.animation; |
| 3244 | wtoken.animating = ttoken.animating; |
| 3245 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3246 | ttoken.animation = null; |
| 3247 | ttoken.animLayerAdjustment = 0; |
| 3248 | wtoken.updateLayers(); |
| 3249 | ttoken.updateLayers(); |
| 3250 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3251 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3252 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3253 | mLayoutNeeded = true; |
| 3254 | performLayoutAndPlaceSurfacesLocked(); |
| 3255 | Binder.restoreCallingIdentity(origId); |
| 3256 | return; |
| 3257 | } else if (ttoken.startingData != null) { |
| 3258 | // The previous app was getting ready to show a |
| 3259 | // starting window, but hasn't yet done so. Steal it! |
| 3260 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 3261 | "Moving pending starting from " + ttoken |
| 3262 | + " to " + wtoken); |
| 3263 | wtoken.startingData = ttoken.startingData; |
| 3264 | ttoken.startingData = null; |
| 3265 | ttoken.startingMoved = true; |
| 3266 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3267 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3268 | // want to process the message ASAP, before any other queued |
| 3269 | // messages. |
| 3270 | mH.sendMessageAtFrontOfQueue(m); |
| 3271 | return; |
| 3272 | } |
| 3273 | } |
| 3274 | } |
| 3275 | |
| 3276 | // There is no existing starting window, and the caller doesn't |
| 3277 | // want us to create one, so that's it! |
| 3278 | if (!createIfNeeded) { |
| 3279 | return; |
| 3280 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3281 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3282 | // If this is a translucent or wallpaper window, then don't |
| 3283 | // show a starting window -- the current effect (a full-screen |
| 3284 | // opaque starting window that fades away to the real contents |
| 3285 | // when it is ready) does not work for this. |
| 3286 | if (theme != 0) { |
| 3287 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3288 | com.android.internal.R.styleable.Window); |
| 3289 | if (ent.array.getBoolean( |
| 3290 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3291 | return; |
| 3292 | } |
| 3293 | if (ent.array.getBoolean( |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3294 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3295 | return; |
| 3296 | } |
| 3297 | if (ent.array.getBoolean( |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3298 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3299 | return; |
| 3300 | } |
| 3301 | } |
| 3302 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3303 | mStartingIconInTransition = true; |
| 3304 | wtoken.startingData = new StartingData( |
| 3305 | pkg, theme, nonLocalizedLabel, |
| 3306 | labelRes, icon); |
| 3307 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3308 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3309 | // want to process the message ASAP, before any other queued |
| 3310 | // messages. |
| 3311 | mH.sendMessageAtFrontOfQueue(m); |
| 3312 | } |
| 3313 | } |
| 3314 | |
| 3315 | public void setAppWillBeHidden(IBinder token) { |
| 3316 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3317 | "setAppWillBeHidden()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3318 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3319 | } |
| 3320 | |
| 3321 | AppWindowToken wtoken; |
| 3322 | |
| 3323 | synchronized(mWindowMap) { |
| 3324 | wtoken = findAppWindowToken(token); |
| 3325 | if (wtoken == null) { |
| 3326 | Log.w(TAG, "Attempted to set will be hidden of non-existing app token: " + token); |
| 3327 | return; |
| 3328 | } |
| 3329 | wtoken.willBeHidden = true; |
| 3330 | } |
| 3331 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3332 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3333 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3334 | boolean visible, int transit, boolean performLayout) { |
| 3335 | boolean delayed = false; |
| 3336 | |
| 3337 | if (wtoken.clientHidden == visible) { |
| 3338 | wtoken.clientHidden = !visible; |
| 3339 | wtoken.sendAppVisibilityToClients(); |
| 3340 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3341 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3342 | wtoken.willBeHidden = false; |
| 3343 | if (wtoken.hidden == visible) { |
| 3344 | final int N = wtoken.allAppWindows.size(); |
| 3345 | boolean changed = false; |
| 3346 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 3347 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3348 | + " performLayout=" + performLayout); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3349 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3350 | boolean runningAppAnimation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3351 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3352 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3353 | if (wtoken.animation == sDummyAnimation) { |
| 3354 | wtoken.animation = null; |
| 3355 | } |
| 3356 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3357 | changed = true; |
| 3358 | if (wtoken.animation != null) { |
| 3359 | delayed = runningAppAnimation = true; |
| 3360 | } |
| 3361 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3362 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3363 | for (int i=0; i<N; i++) { |
| 3364 | WindowState win = wtoken.allAppWindows.get(i); |
| 3365 | if (win == wtoken.startingWindow) { |
| 3366 | continue; |
| 3367 | } |
| 3368 | |
| 3369 | if (win.isAnimating()) { |
| 3370 | delayed = true; |
| 3371 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3372 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3373 | //Log.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
| 3374 | //win.dump(" "); |
| 3375 | if (visible) { |
| 3376 | if (!win.isVisibleNow()) { |
| 3377 | if (!runningAppAnimation) { |
| 3378 | applyAnimationLocked(win, |
| 3379 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3380 | } |
| 3381 | changed = true; |
| 3382 | } |
| 3383 | } else if (win.isVisibleNow()) { |
| 3384 | if (!runningAppAnimation) { |
| 3385 | applyAnimationLocked(win, |
| 3386 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3387 | } |
| 3388 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 3389 | KeyWaiter.RETURN_NOTHING); |
| 3390 | changed = true; |
| 3391 | } |
| 3392 | } |
| 3393 | |
| 3394 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3395 | if (!visible) { |
| 3396 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3397 | } else { |
| 3398 | // If we are being set visible, and the starting window is |
| 3399 | // not yet displayed, then make sure it doesn't get displayed. |
| 3400 | WindowState swin = wtoken.startingWindow; |
| 3401 | if (swin != null && (swin.mDrawPending |
| 3402 | || swin.mCommitDrawPending)) { |
| 3403 | swin.mPolicyVisibility = false; |
| 3404 | swin.mPolicyVisibilityAfterAnim = false; |
| 3405 | } |
| 3406 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3407 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3408 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "setTokenVisibilityLocked: " + wtoken |
| 3409 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3410 | + wtoken.hiddenRequested); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3411 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3412 | if (changed && performLayout) { |
| 3413 | mLayoutNeeded = true; |
| 3414 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3415 | performLayoutAndPlaceSurfacesLocked(); |
| 3416 | } |
| 3417 | } |
| 3418 | |
| 3419 | if (wtoken.animation != null) { |
| 3420 | delayed = true; |
| 3421 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3422 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3423 | return delayed; |
| 3424 | } |
| 3425 | |
| 3426 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3427 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3428 | "setAppVisibility()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3429 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3430 | } |
| 3431 | |
| 3432 | AppWindowToken wtoken; |
| 3433 | |
| 3434 | synchronized(mWindowMap) { |
| 3435 | wtoken = findAppWindowToken(token); |
| 3436 | if (wtoken == null) { |
| 3437 | Log.w(TAG, "Attempted to set visibility of non-existing app token: " + token); |
| 3438 | return; |
| 3439 | } |
| 3440 | |
| 3441 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
| 3442 | RuntimeException e = new RuntimeException(); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3443 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3444 | Log.v(TAG, "setAppVisibility(" + token + ", " + visible |
| 3445 | + "): mNextAppTransition=" + mNextAppTransition |
| 3446 | + " hidden=" + wtoken.hidden |
| 3447 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3448 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3449 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3450 | // If we are preparing an app transition, then delay changing |
| 3451 | // the visibility of this token until we execute that transition. |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3452 | if (!mDisplayFrozen && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3453 | // Already in requested state, don't do anything more. |
| 3454 | if (wtoken.hiddenRequested != visible) { |
| 3455 | return; |
| 3456 | } |
| 3457 | wtoken.hiddenRequested = !visible; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3458 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3459 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 3460 | TAG, "Setting dummy animation on: " + wtoken); |
| 3461 | wtoken.setDummyAnimation(); |
| 3462 | mOpeningApps.remove(wtoken); |
| 3463 | mClosingApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3464 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3465 | wtoken.inPendingTransaction = true; |
| 3466 | if (visible) { |
| 3467 | mOpeningApps.add(wtoken); |
| 3468 | wtoken.allDrawn = false; |
| 3469 | wtoken.startingDisplayed = false; |
| 3470 | wtoken.startingMoved = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3471 | wtoken.waitingToShow = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3472 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3473 | if (wtoken.clientHidden) { |
| 3474 | // In the case where we are making an app visible |
| 3475 | // but holding off for a transition, we still need |
| 3476 | // to tell the client to make its windows visible so |
| 3477 | // they get drawn. Otherwise, we will wait on |
| 3478 | // performing the transition until all windows have |
| 3479 | // been drawn, they never will be, and we are sad. |
| 3480 | wtoken.clientHidden = false; |
| 3481 | wtoken.sendAppVisibilityToClients(); |
| 3482 | } |
| 3483 | } else { |
| 3484 | mClosingApps.add(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3485 | wtoken.waitingToHide = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3486 | } |
| 3487 | return; |
| 3488 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3489 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3490 | final long origId = Binder.clearCallingIdentity(); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3491 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3492 | wtoken.updateReportedVisibilityLocked(); |
| 3493 | Binder.restoreCallingIdentity(origId); |
| 3494 | } |
| 3495 | } |
| 3496 | |
| 3497 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3498 | boolean unfreezeSurfaceNow, boolean force) { |
| 3499 | if (wtoken.freezingScreen) { |
| 3500 | if (DEBUG_ORIENTATION) Log.v(TAG, "Clear freezing of " + wtoken |
| 3501 | + " force=" + force); |
| 3502 | final int N = wtoken.allAppWindows.size(); |
| 3503 | boolean unfrozeWindows = false; |
| 3504 | for (int i=0; i<N; i++) { |
| 3505 | WindowState w = wtoken.allAppWindows.get(i); |
| 3506 | if (w.mAppFreezing) { |
| 3507 | w.mAppFreezing = false; |
| 3508 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 3509 | w.mOrientationChanging = true; |
| 3510 | } |
| 3511 | unfrozeWindows = true; |
| 3512 | } |
| 3513 | } |
| 3514 | if (force || unfrozeWindows) { |
| 3515 | if (DEBUG_ORIENTATION) Log.v(TAG, "No longer freezing: " + wtoken); |
| 3516 | wtoken.freezingScreen = false; |
| 3517 | mAppsFreezingScreen--; |
| 3518 | } |
| 3519 | if (unfreezeSurfaceNow) { |
| 3520 | if (unfrozeWindows) { |
| 3521 | mLayoutNeeded = true; |
| 3522 | performLayoutAndPlaceSurfacesLocked(); |
| 3523 | } |
| 3524 | if (mAppsFreezingScreen == 0 && !mWindowsFreezingScreen) { |
| 3525 | stopFreezingDisplayLocked(); |
| 3526 | } |
| 3527 | } |
| 3528 | } |
| 3529 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3530 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3531 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3532 | int configChanges) { |
| 3533 | if (DEBUG_ORIENTATION) { |
| 3534 | RuntimeException e = new RuntimeException(); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3535 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3536 | Log.i(TAG, "Set freezing of " + wtoken.appToken |
| 3537 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 3538 | + wtoken.freezingScreen, e); |
| 3539 | } |
| 3540 | if (!wtoken.hiddenRequested) { |
| 3541 | if (!wtoken.freezingScreen) { |
| 3542 | wtoken.freezingScreen = true; |
| 3543 | mAppsFreezingScreen++; |
| 3544 | if (mAppsFreezingScreen == 1) { |
| 3545 | startFreezingDisplayLocked(); |
| 3546 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 3547 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 3548 | 5000); |
| 3549 | } |
| 3550 | } |
| 3551 | final int N = wtoken.allAppWindows.size(); |
| 3552 | for (int i=0; i<N; i++) { |
| 3553 | WindowState w = wtoken.allAppWindows.get(i); |
| 3554 | w.mAppFreezing = true; |
| 3555 | } |
| 3556 | } |
| 3557 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3558 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3559 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 3560 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3561 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3562 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3563 | } |
| 3564 | |
| 3565 | synchronized(mWindowMap) { |
| 3566 | if (configChanges == 0 && !mDisplayFrozen) { |
| 3567 | if (DEBUG_ORIENTATION) Log.v(TAG, "Skipping set freeze of " + token); |
| 3568 | return; |
| 3569 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3570 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3571 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3572 | if (wtoken == null || wtoken.appToken == null) { |
| 3573 | Log.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken); |
| 3574 | return; |
| 3575 | } |
| 3576 | final long origId = Binder.clearCallingIdentity(); |
| 3577 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 3578 | Binder.restoreCallingIdentity(origId); |
| 3579 | } |
| 3580 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3581 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3582 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 3583 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3584 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3585 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3586 | } |
| 3587 | |
| 3588 | synchronized(mWindowMap) { |
| 3589 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3590 | if (wtoken == null || wtoken.appToken == null) { |
| 3591 | return; |
| 3592 | } |
| 3593 | final long origId = Binder.clearCallingIdentity(); |
| 3594 | if (DEBUG_ORIENTATION) Log.v(TAG, "Clear freezing of " + token |
| 3595 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 3596 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 3597 | Binder.restoreCallingIdentity(origId); |
| 3598 | } |
| 3599 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3600 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3601 | public void removeAppToken(IBinder token) { |
| 3602 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3603 | "removeAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3604 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3605 | } |
| 3606 | |
| 3607 | AppWindowToken wtoken = null; |
| 3608 | AppWindowToken startingToken = null; |
| 3609 | boolean delayed = false; |
| 3610 | |
| 3611 | final long origId = Binder.clearCallingIdentity(); |
| 3612 | synchronized(mWindowMap) { |
| 3613 | WindowToken basewtoken = mTokenMap.remove(token); |
| 3614 | mTokenList.remove(basewtoken); |
| 3615 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
| 3616 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "Removing app token: " + wtoken); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3617 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3618 | wtoken.inPendingTransaction = false; |
| 3619 | mOpeningApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3620 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3621 | if (mClosingApps.contains(wtoken)) { |
| 3622 | delayed = true; |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3623 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3624 | mClosingApps.add(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3625 | wtoken.waitingToHide = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3626 | delayed = true; |
| 3627 | } |
| 3628 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 3629 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 3630 | + " animation=" + wtoken.animation |
| 3631 | + " animating=" + wtoken.animating); |
| 3632 | if (delayed) { |
| 3633 | // set the token aside because it has an active animation to be finished |
| 3634 | mExitingAppTokens.add(wtoken); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3635 | } else { |
| 3636 | // Make sure there is no animation running on this token, |
| 3637 | // so any windows associated with it will be removed as |
| 3638 | // soon as their animations are complete |
| 3639 | wtoken.animation = null; |
| 3640 | wtoken.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3641 | } |
| 3642 | mAppTokens.remove(wtoken); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3643 | if (mLastEnterAnimToken == wtoken) { |
| 3644 | mLastEnterAnimToken = null; |
| 3645 | mLastEnterAnimParams = null; |
| 3646 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3647 | wtoken.removed = true; |
| 3648 | if (wtoken.startingData != null) { |
| 3649 | startingToken = wtoken; |
| 3650 | } |
| 3651 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3652 | if (mFocusedApp == wtoken) { |
| 3653 | if (DEBUG_FOCUS) Log.v(TAG, "Removing focused app token:" + wtoken); |
| 3654 | mFocusedApp = null; |
| 3655 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3656 | mKeyWaiter.tickle(); |
| 3657 | } |
| 3658 | } else { |
| 3659 | Log.w(TAG, "Attempted to remove non-existing app token: " + token); |
| 3660 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3661 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3662 | if (!delayed && wtoken != null) { |
| 3663 | wtoken.updateReportedVisibilityLocked(); |
| 3664 | } |
| 3665 | } |
| 3666 | Binder.restoreCallingIdentity(origId); |
| 3667 | |
| 3668 | if (startingToken != null) { |
| 3669 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Schedule remove starting " |
| 3670 | + startingToken + ": app token removed"); |
| 3671 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 3672 | mH.sendMessage(m); |
| 3673 | } |
| 3674 | } |
| 3675 | |
| 3676 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 3677 | final int NW = token.windows.size(); |
| 3678 | for (int i=0; i<NW; i++) { |
| 3679 | WindowState win = token.windows.get(i); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3680 | 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] | 3681 | mWindows.remove(win); |
| 3682 | int j = win.mChildWindows.size(); |
| 3683 | while (j > 0) { |
| 3684 | j--; |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3685 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| 3686 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, |
| 3687 | "Tmp removing child window " + cwin); |
| 3688 | mWindows.remove(cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3689 | } |
| 3690 | } |
| 3691 | return NW > 0; |
| 3692 | } |
| 3693 | |
| 3694 | void dumpAppTokensLocked() { |
| 3695 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| 3696 | Log.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
| 3697 | } |
| 3698 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3699 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3700 | void dumpWindowsLocked() { |
| 3701 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 3702 | Log.v(TAG, " #" + i + ": " + mWindows.get(i)); |
| 3703 | } |
| 3704 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3705 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3706 | private int findWindowOffsetLocked(int tokenPos) { |
| 3707 | final int NW = mWindows.size(); |
| 3708 | |
| 3709 | if (tokenPos >= mAppTokens.size()) { |
| 3710 | int i = NW; |
| 3711 | while (i > 0) { |
| 3712 | i--; |
| 3713 | WindowState win = (WindowState)mWindows.get(i); |
| 3714 | if (win.getAppToken() != null) { |
| 3715 | return i+1; |
| 3716 | } |
| 3717 | } |
| 3718 | } |
| 3719 | |
| 3720 | while (tokenPos > 0) { |
| 3721 | // Find the first app token below the new position that has |
| 3722 | // a window displayed. |
| 3723 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
| 3724 | if (DEBUG_REORDER) Log.v(TAG, "Looking for lower windows @ " |
| 3725 | + tokenPos + " -- " + wtoken.token); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3726 | if (wtoken.sendingToBottom) { |
| 3727 | if (DEBUG_REORDER) Log.v(TAG, |
| 3728 | "Skipping token -- currently sending to bottom"); |
| 3729 | tokenPos--; |
| 3730 | continue; |
| 3731 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3732 | int i = wtoken.windows.size(); |
| 3733 | while (i > 0) { |
| 3734 | i--; |
| 3735 | WindowState win = wtoken.windows.get(i); |
| 3736 | int j = win.mChildWindows.size(); |
| 3737 | while (j > 0) { |
| 3738 | j--; |
| 3739 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3740 | if (cwin.mSubLayer >= 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3741 | for (int pos=NW-1; pos>=0; pos--) { |
| 3742 | if (mWindows.get(pos) == cwin) { |
| 3743 | if (DEBUG_REORDER) Log.v(TAG, |
| 3744 | "Found child win @" + (pos+1)); |
| 3745 | return pos+1; |
| 3746 | } |
| 3747 | } |
| 3748 | } |
| 3749 | } |
| 3750 | for (int pos=NW-1; pos>=0; pos--) { |
| 3751 | if (mWindows.get(pos) == win) { |
| 3752 | if (DEBUG_REORDER) Log.v(TAG, "Found win @" + (pos+1)); |
| 3753 | return pos+1; |
| 3754 | } |
| 3755 | } |
| 3756 | } |
| 3757 | tokenPos--; |
| 3758 | } |
| 3759 | |
| 3760 | return 0; |
| 3761 | } |
| 3762 | |
| 3763 | private final int reAddWindowLocked(int index, WindowState win) { |
| 3764 | final int NCW = win.mChildWindows.size(); |
| 3765 | boolean added = false; |
| 3766 | for (int j=0; j<NCW; j++) { |
| 3767 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| 3768 | if (!added && cwin.mSubLayer >= 0) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3769 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Re-adding child window at " |
| 3770 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3771 | mWindows.add(index, win); |
| 3772 | index++; |
| 3773 | added = true; |
| 3774 | } |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3775 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Re-adding window at " |
| 3776 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3777 | mWindows.add(index, cwin); |
| 3778 | index++; |
| 3779 | } |
| 3780 | if (!added) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3781 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Re-adding window at " |
| 3782 | + index + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3783 | mWindows.add(index, win); |
| 3784 | index++; |
| 3785 | } |
| 3786 | return index; |
| 3787 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3788 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3789 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 3790 | final int NW = token.windows.size(); |
| 3791 | for (int i=0; i<NW; i++) { |
| 3792 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 3793 | } |
| 3794 | return index; |
| 3795 | } |
| 3796 | |
| 3797 | public void moveAppToken(int index, IBinder token) { |
| 3798 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3799 | "moveAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3800 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3801 | } |
| 3802 | |
| 3803 | synchronized(mWindowMap) { |
| 3804 | if (DEBUG_REORDER) Log.v(TAG, "Initial app tokens:"); |
| 3805 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 3806 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 3807 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
| 3808 | Log.w(TAG, "Attempting to reorder token that doesn't exist: " |
| 3809 | + token + " (" + wtoken + ")"); |
| 3810 | return; |
| 3811 | } |
| 3812 | mAppTokens.add(index, wtoken); |
| 3813 | if (DEBUG_REORDER) Log.v(TAG, "Moved " + token + " to " + index + ":"); |
| 3814 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3815 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3816 | final long origId = Binder.clearCallingIdentity(); |
| 3817 | if (DEBUG_REORDER) Log.v(TAG, "Removing windows in " + token + ":"); |
| 3818 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3819 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
| 3820 | if (DEBUG_REORDER) Log.v(TAG, "Adding windows back in:"); |
| 3821 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3822 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
| 3823 | if (DEBUG_REORDER) Log.v(TAG, "Final window list:"); |
| 3824 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3825 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3826 | mLayoutNeeded = true; |
| 3827 | performLayoutAndPlaceSurfacesLocked(); |
| 3828 | } |
| 3829 | Binder.restoreCallingIdentity(origId); |
| 3830 | } |
| 3831 | } |
| 3832 | |
| 3833 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 3834 | // XXX This should be done more efficiently! |
| 3835 | // (take advantage of the fact that both lists should be |
| 3836 | // ordered in the same way.) |
| 3837 | int N = tokens.size(); |
| 3838 | for (int i=0; i<N; i++) { |
| 3839 | IBinder token = tokens.get(i); |
| 3840 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 3841 | if (!mAppTokens.remove(wtoken)) { |
| 3842 | Log.w(TAG, "Attempting to reorder token that doesn't exist: " |
| 3843 | + token + " (" + wtoken + ")"); |
| 3844 | i--; |
| 3845 | N--; |
| 3846 | } |
| 3847 | } |
| 3848 | } |
| 3849 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3850 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 3851 | boolean updateFocusAndLayout) { |
| 3852 | // First remove all of the windows from the list. |
| 3853 | tmpRemoveAppWindowsLocked(wtoken); |
| 3854 | |
| 3855 | // Where to start adding? |
| 3856 | int pos = findWindowOffsetLocked(tokenPos); |
| 3857 | |
| 3858 | // And now add them back at the correct place. |
| 3859 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 3860 | |
| 3861 | if (updateFocusAndLayout) { |
| 3862 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 3863 | assignLayersLocked(); |
| 3864 | } |
| 3865 | mLayoutNeeded = true; |
| 3866 | performLayoutAndPlaceSurfacesLocked(); |
| 3867 | } |
| 3868 | } |
| 3869 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3870 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 3871 | // First remove all of the windows from the list. |
| 3872 | final int N = tokens.size(); |
| 3873 | int i; |
| 3874 | for (i=0; i<N; i++) { |
| 3875 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 3876 | if (token != null) { |
| 3877 | tmpRemoveAppWindowsLocked(token); |
| 3878 | } |
| 3879 | } |
| 3880 | |
| 3881 | // Where to start adding? |
| 3882 | int pos = findWindowOffsetLocked(tokenPos); |
| 3883 | |
| 3884 | // And now add them back at the correct place. |
| 3885 | for (i=0; i<N; i++) { |
| 3886 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 3887 | if (token != null) { |
| 3888 | pos = reAddAppWindowsLocked(pos, token); |
| 3889 | } |
| 3890 | } |
| 3891 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3892 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 3893 | assignLayersLocked(); |
| 3894 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3895 | mLayoutNeeded = true; |
| 3896 | performLayoutAndPlaceSurfacesLocked(); |
| 3897 | |
| 3898 | //dump(); |
| 3899 | } |
| 3900 | |
| 3901 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 3902 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3903 | "moveAppTokensToTop()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3904 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3905 | } |
| 3906 | |
| 3907 | final long origId = Binder.clearCallingIdentity(); |
| 3908 | synchronized(mWindowMap) { |
| 3909 | removeAppTokensLocked(tokens); |
| 3910 | final int N = tokens.size(); |
| 3911 | for (int i=0; i<N; i++) { |
| 3912 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 3913 | if (wt != null) { |
| 3914 | mAppTokens.add(wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3915 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3916 | mToTopApps.remove(wt); |
| 3917 | mToBottomApps.remove(wt); |
| 3918 | mToTopApps.add(wt); |
| 3919 | wt.sendingToBottom = false; |
| 3920 | wt.sendingToTop = true; |
| 3921 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3922 | } |
| 3923 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3924 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3925 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3926 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 3927 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3928 | } |
| 3929 | Binder.restoreCallingIdentity(origId); |
| 3930 | } |
| 3931 | |
| 3932 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 3933 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3934 | "moveAppTokensToBottom()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3935 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3936 | } |
| 3937 | |
| 3938 | final long origId = Binder.clearCallingIdentity(); |
| 3939 | synchronized(mWindowMap) { |
| 3940 | removeAppTokensLocked(tokens); |
| 3941 | final int N = tokens.size(); |
| 3942 | int pos = 0; |
| 3943 | for (int i=0; i<N; i++) { |
| 3944 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 3945 | if (wt != null) { |
| 3946 | mAppTokens.add(pos, wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3947 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3948 | mToTopApps.remove(wt); |
| 3949 | mToBottomApps.remove(wt); |
| 3950 | mToBottomApps.add(i, wt); |
| 3951 | wt.sendingToTop = false; |
| 3952 | wt.sendingToBottom = true; |
| 3953 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3954 | pos++; |
| 3955 | } |
| 3956 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3957 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3958 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3959 | moveAppWindowsLocked(tokens, 0); |
| 3960 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3961 | } |
| 3962 | Binder.restoreCallingIdentity(origId); |
| 3963 | } |
| 3964 | |
| 3965 | // ------------------------------------------------------------- |
| 3966 | // Misc IWindowSession methods |
| 3967 | // ------------------------------------------------------------- |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3968 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3969 | public void disableKeyguard(IBinder token, String tag) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 3970 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3971 | != PackageManager.PERMISSION_GRANTED) { |
| 3972 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 3973 | } |
| 3974 | mKeyguardDisabled.acquire(token, tag); |
| 3975 | } |
| 3976 | |
| 3977 | public void reenableKeyguard(IBinder token) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 3978 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3979 | != PackageManager.PERMISSION_GRANTED) { |
| 3980 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 3981 | } |
| 3982 | synchronized (mKeyguardDisabled) { |
| 3983 | mKeyguardDisabled.release(token); |
| 3984 | |
| 3985 | if (!mKeyguardDisabled.isAcquired()) { |
| 3986 | // if we are the last one to reenable the keyguard wait until |
| 3987 | // we have actaully finished reenabling until returning |
| 3988 | mWaitingUntilKeyguardReenabled = true; |
| 3989 | while (mWaitingUntilKeyguardReenabled) { |
| 3990 | try { |
| 3991 | mKeyguardDisabled.wait(); |
| 3992 | } catch (InterruptedException e) { |
| 3993 | Thread.currentThread().interrupt(); |
| 3994 | } |
| 3995 | } |
| 3996 | } |
| 3997 | } |
| 3998 | } |
| 3999 | |
| 4000 | /** |
| 4001 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4002 | */ |
| 4003 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4004 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4005 | != PackageManager.PERMISSION_GRANTED) { |
| 4006 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4007 | } |
| 4008 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4009 | public void onKeyguardExitResult(boolean success) { |
| 4010 | try { |
| 4011 | callback.onKeyguardExitResult(success); |
| 4012 | } catch (RemoteException e) { |
| 4013 | // Client has died, we don't care. |
| 4014 | } |
| 4015 | } |
| 4016 | }); |
| 4017 | } |
| 4018 | |
| 4019 | public boolean inKeyguardRestrictedInputMode() { |
| 4020 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4021 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4022 | |
| Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4023 | public void closeSystemDialogs(String reason) { |
| 4024 | synchronized(mWindowMap) { |
| 4025 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 4026 | WindowState w = (WindowState)mWindows.get(i); |
| 4027 | if (w.mSurface != null) { |
| 4028 | try { |
| 4029 | w.mClient.closeSystemDialogs(reason); |
| 4030 | } catch (RemoteException e) { |
| 4031 | } |
| 4032 | } |
| 4033 | } |
| 4034 | } |
| 4035 | } |
| 4036 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4037 | static float fixScale(float scale) { |
| 4038 | if (scale < 0) scale = 0; |
| 4039 | else if (scale > 20) scale = 20; |
| 4040 | return Math.abs(scale); |
| 4041 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4042 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4043 | public void setAnimationScale(int which, float scale) { |
| 4044 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4045 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4046 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4047 | } |
| 4048 | |
| 4049 | if (scale < 0) scale = 0; |
| 4050 | else if (scale > 20) scale = 20; |
| 4051 | scale = Math.abs(scale); |
| 4052 | switch (which) { |
| 4053 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4054 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4055 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4056 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4057 | // Persist setting |
| 4058 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4059 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4060 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4061 | public void setAnimationScales(float[] scales) { |
| 4062 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4063 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4064 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4065 | } |
| 4066 | |
| 4067 | if (scales != null) { |
| 4068 | if (scales.length >= 1) { |
| 4069 | mWindowAnimationScale = fixScale(scales[0]); |
| 4070 | } |
| 4071 | if (scales.length >= 2) { |
| 4072 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4073 | } |
| 4074 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4075 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4076 | // Persist setting |
| 4077 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4078 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4079 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4080 | public float getAnimationScale(int which) { |
| 4081 | switch (which) { |
| 4082 | case 0: return mWindowAnimationScale; |
| 4083 | case 1: return mTransitionAnimationScale; |
| 4084 | } |
| 4085 | return 0; |
| 4086 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4087 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4088 | public float[] getAnimationScales() { |
| 4089 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4090 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4091 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4092 | public int getSwitchState(int sw) { |
| 4093 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4094 | "getSwitchState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4095 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4096 | } |
| 4097 | return KeyInputQueue.getSwitchState(sw); |
| 4098 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4099 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4100 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4101 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4102 | "getSwitchStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4103 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4104 | } |
| 4105 | return KeyInputQueue.getSwitchState(devid, sw); |
| 4106 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4107 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4108 | public int getScancodeState(int sw) { |
| 4109 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4110 | "getScancodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4111 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4112 | } |
| Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4113 | return mQueue.getScancodeState(sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4114 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4115 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4116 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4117 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4118 | "getScancodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4119 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4120 | } |
| Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4121 | return mQueue.getScancodeState(devid, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4122 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4123 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4124 | public int getKeycodeState(int sw) { |
| 4125 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4126 | "getKeycodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4127 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4128 | } |
| Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4129 | return mQueue.getKeycodeState(sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4130 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4131 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4132 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4133 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4134 | "getKeycodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4135 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4136 | } |
| Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4137 | return mQueue.getKeycodeState(devid, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4138 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4139 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4140 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
| 4141 | return KeyInputQueue.hasKeys(keycodes, keyExists); |
| 4142 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4143 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4144 | public void enableScreenAfterBoot() { |
| 4145 | synchronized(mWindowMap) { |
| 4146 | if (mSystemBooted) { |
| 4147 | return; |
| 4148 | } |
| 4149 | mSystemBooted = true; |
| 4150 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4151 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4152 | performEnableScreen(); |
| 4153 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4154 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4155 | public void enableScreenIfNeededLocked() { |
| 4156 | if (mDisplayEnabled) { |
| 4157 | return; |
| 4158 | } |
| 4159 | if (!mSystemBooted) { |
| 4160 | return; |
| 4161 | } |
| 4162 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4163 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4164 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4165 | public void performEnableScreen() { |
| 4166 | synchronized(mWindowMap) { |
| 4167 | if (mDisplayEnabled) { |
| 4168 | return; |
| 4169 | } |
| 4170 | if (!mSystemBooted) { |
| 4171 | return; |
| 4172 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4173 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4174 | // Don't enable the screen until all existing windows |
| 4175 | // have been drawn. |
| 4176 | final int N = mWindows.size(); |
| 4177 | for (int i=0; i<N; i++) { |
| 4178 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 4179 | if (w.isVisibleLw() && !w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4180 | return; |
| 4181 | } |
| 4182 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4183 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4184 | mDisplayEnabled = true; |
| 4185 | if (false) { |
| 4186 | Log.i(TAG, "ENABLING SCREEN!"); |
| 4187 | StringWriter sw = new StringWriter(); |
| 4188 | PrintWriter pw = new PrintWriter(sw); |
| 4189 | this.dump(null, pw, null); |
| 4190 | Log.i(TAG, sw.toString()); |
| 4191 | } |
| 4192 | try { |
| 4193 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4194 | if (surfaceFlinger != null) { |
| 4195 | //Log.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
| 4196 | Parcel data = Parcel.obtain(); |
| 4197 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4198 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4199 | data, null, 0); |
| 4200 | data.recycle(); |
| 4201 | } |
| 4202 | } catch (RemoteException ex) { |
| 4203 | Log.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
| 4204 | } |
| 4205 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4206 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4207 | mPolicy.enableScreenAfterBoot(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4208 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4209 | // Make sure the last requested orientation has been applied. |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4210 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4211 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4212 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4213 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4214 | public void setInTouchMode(boolean mode) { |
| 4215 | synchronized(mWindowMap) { |
| 4216 | mInTouchMode = mode; |
| 4217 | } |
| 4218 | } |
| 4219 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4220 | public void setRotation(int rotation, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4221 | boolean alwaysSendConfiguration, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4222 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4223 | "setRotation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4224 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4225 | } |
| 4226 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4227 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4228 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4229 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4230 | public void setRotationUnchecked(int rotation, |
| 4231 | boolean alwaysSendConfiguration, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4232 | if(DEBUG_ORIENTATION) Log.v(TAG, |
| 4233 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4234 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4235 | long origId = Binder.clearCallingIdentity(); |
| 4236 | boolean changed; |
| 4237 | synchronized(mWindowMap) { |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4238 | changed = setRotationUncheckedLocked(rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4239 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4240 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4241 | if (changed) { |
| 4242 | sendNewConfiguration(); |
| 4243 | synchronized(mWindowMap) { |
| 4244 | mLayoutNeeded = true; |
| 4245 | performLayoutAndPlaceSurfacesLocked(); |
| 4246 | } |
| 4247 | } else if (alwaysSendConfiguration) { |
| 4248 | //update configuration ignoring orientation change |
| 4249 | sendNewConfiguration(); |
| 4250 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4251 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4252 | Binder.restoreCallingIdentity(origId); |
| 4253 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4254 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4255 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4256 | boolean changed; |
| 4257 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4258 | rotation = mRequestedRotation; |
| 4259 | } else { |
| 4260 | mRequestedRotation = rotation; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4261 | mLastRotationFlags = animFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4262 | } |
| 4263 | 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] | 4264 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4265 | mRotation, mDisplayEnabled); |
| 4266 | if (DEBUG_ORIENTATION) Log.v(TAG, "new rotation is set to " + rotation); |
| 4267 | changed = mDisplayEnabled && mRotation != rotation; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4268 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4269 | if (changed) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4270 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4271 | "Rotation changed to " + rotation |
| 4272 | + " from " + mRotation |
| 4273 | + " (forceApp=" + mForcedAppOrientation |
| 4274 | + ", req=" + mRequestedRotation + ")"); |
| 4275 | mRotation = rotation; |
| 4276 | mWindowsFreezingScreen = true; |
| 4277 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 4278 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 4279 | 2000); |
| 4280 | startFreezingDisplayLocked(); |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4281 | Log.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4282 | mQueue.setOrientation(rotation); |
| 4283 | if (mDisplayEnabled) { |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4284 | Surface.setOrientation(0, rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4285 | } |
| 4286 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 4287 | WindowState w = (WindowState)mWindows.get(i); |
| 4288 | if (w.mSurface != null) { |
| 4289 | w.mOrientationChanging = true; |
| 4290 | } |
| 4291 | } |
| 4292 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 4293 | try { |
| 4294 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 4295 | } catch (RemoteException e) { |
| 4296 | } |
| 4297 | } |
| 4298 | } //end if changed |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4299 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4300 | return changed; |
| 4301 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4302 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4303 | public int getRotation() { |
| 4304 | return mRotation; |
| 4305 | } |
| 4306 | |
| 4307 | public int watchRotation(IRotationWatcher watcher) { |
| 4308 | final IBinder watcherBinder = watcher.asBinder(); |
| 4309 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 4310 | public void binderDied() { |
| 4311 | synchronized (mWindowMap) { |
| 4312 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 4313 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 4314 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 4315 | if (removed != null) { |
| 4316 | removed.asBinder().unlinkToDeath(this, 0); |
| 4317 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4318 | i--; |
| 4319 | } |
| 4320 | } |
| 4321 | } |
| 4322 | } |
| 4323 | }; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4324 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4325 | synchronized (mWindowMap) { |
| 4326 | try { |
| 4327 | watcher.asBinder().linkToDeath(dr, 0); |
| 4328 | mRotationWatchers.add(watcher); |
| 4329 | } catch (RemoteException e) { |
| 4330 | // Client died, no cleanup needed. |
| 4331 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4332 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4333 | return mRotation; |
| 4334 | } |
| 4335 | } |
| 4336 | |
| 4337 | /** |
| 4338 | * Starts the view server on the specified port. |
| 4339 | * |
| 4340 | * @param port The port to listener to. |
| 4341 | * |
| 4342 | * @return True if the server was successfully started, false otherwise. |
| 4343 | * |
| 4344 | * @see com.android.server.ViewServer |
| 4345 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 4346 | */ |
| 4347 | public boolean startViewServer(int port) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4348 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4349 | return false; |
| 4350 | } |
| 4351 | |
| 4352 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 4353 | return false; |
| 4354 | } |
| 4355 | |
| 4356 | if (port < 1024) { |
| 4357 | return false; |
| 4358 | } |
| 4359 | |
| 4360 | if (mViewServer != null) { |
| 4361 | if (!mViewServer.isRunning()) { |
| 4362 | try { |
| 4363 | return mViewServer.start(); |
| 4364 | } catch (IOException e) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4365 | Log.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4366 | } |
| 4367 | } |
| 4368 | return false; |
| 4369 | } |
| 4370 | |
| 4371 | try { |
| 4372 | mViewServer = new ViewServer(this, port); |
| 4373 | return mViewServer.start(); |
| 4374 | } catch (IOException e) { |
| 4375 | Log.w(TAG, "View server did not start"); |
| 4376 | } |
| 4377 | return false; |
| 4378 | } |
| 4379 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4380 | private boolean isSystemSecure() { |
| 4381 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 4382 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 4383 | } |
| 4384 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4385 | /** |
| 4386 | * Stops the view server if it exists. |
| 4387 | * |
| 4388 | * @return True if the server stopped, false if it wasn't started or |
| 4389 | * couldn't be stopped. |
| 4390 | * |
| 4391 | * @see com.android.server.ViewServer |
| 4392 | */ |
| 4393 | public boolean stopViewServer() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4394 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4395 | return false; |
| 4396 | } |
| 4397 | |
| 4398 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 4399 | return false; |
| 4400 | } |
| 4401 | |
| 4402 | if (mViewServer != null) { |
| 4403 | return mViewServer.stop(); |
| 4404 | } |
| 4405 | return false; |
| 4406 | } |
| 4407 | |
| 4408 | /** |
| 4409 | * Indicates whether the view server is running. |
| 4410 | * |
| 4411 | * @return True if the server is running, false otherwise. |
| 4412 | * |
| 4413 | * @see com.android.server.ViewServer |
| 4414 | */ |
| 4415 | public boolean isViewServerRunning() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4416 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4417 | return false; |
| 4418 | } |
| 4419 | |
| 4420 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 4421 | return false; |
| 4422 | } |
| 4423 | |
| 4424 | return mViewServer != null && mViewServer.isRunning(); |
| 4425 | } |
| 4426 | |
| 4427 | /** |
| 4428 | * Lists all availble windows in the system. The listing is written in the |
| 4429 | * specified Socket's output stream with the following syntax: |
| 4430 | * windowHashCodeInHexadecimal windowName |
| 4431 | * Each line of the ouput represents a different window. |
| 4432 | * |
| 4433 | * @param client The remote client to send the listing to. |
| 4434 | * @return False if an error occured, true otherwise. |
| 4435 | */ |
| 4436 | boolean viewServerListWindows(Socket client) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4437 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4438 | return false; |
| 4439 | } |
| 4440 | |
| 4441 | boolean result = true; |
| 4442 | |
| 4443 | Object[] windows; |
| 4444 | synchronized (mWindowMap) { |
| 4445 | windows = new Object[mWindows.size()]; |
| 4446 | //noinspection unchecked |
| 4447 | windows = mWindows.toArray(windows); |
| 4448 | } |
| 4449 | |
| 4450 | BufferedWriter out = null; |
| 4451 | |
| 4452 | // Any uncaught exception will crash the system process |
| 4453 | try { |
| 4454 | OutputStream clientStream = client.getOutputStream(); |
| 4455 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 4456 | |
| 4457 | final int count = windows.length; |
| 4458 | for (int i = 0; i < count; i++) { |
| 4459 | final WindowState w = (WindowState) windows[i]; |
| 4460 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 4461 | out.write(' '); |
| 4462 | out.append(w.mAttrs.getTitle()); |
| 4463 | out.write('\n'); |
| 4464 | } |
| 4465 | |
| 4466 | out.write("DONE.\n"); |
| 4467 | out.flush(); |
| 4468 | } catch (Exception e) { |
| 4469 | result = false; |
| 4470 | } finally { |
| 4471 | if (out != null) { |
| 4472 | try { |
| 4473 | out.close(); |
| 4474 | } catch (IOException e) { |
| 4475 | result = false; |
| 4476 | } |
| 4477 | } |
| 4478 | } |
| 4479 | |
| 4480 | return result; |
| 4481 | } |
| 4482 | |
| 4483 | /** |
| 4484 | * Sends a command to a target window. The result of the command, if any, will be |
| 4485 | * written in the output stream of the specified socket. |
| 4486 | * |
| 4487 | * The parameters must follow this syntax: |
| 4488 | * windowHashcode extra |
| 4489 | * |
| 4490 | * Where XX is the length in characeters of the windowTitle. |
| 4491 | * |
| 4492 | * The first parameter is the target window. The window with the specified hashcode |
| 4493 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 4494 | * will be delivered to the target window and as parameters to the command itself. |
| 4495 | * |
| 4496 | * @param client The remote client to sent the result, if any, to. |
| 4497 | * @param command The command to execute. |
| 4498 | * @param parameters The command parameters. |
| 4499 | * |
| 4500 | * @return True if the command was successfully delivered, false otherwise. This does |
| 4501 | * not indicate whether the command itself was successful. |
| 4502 | */ |
| 4503 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4504 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4505 | return false; |
| 4506 | } |
| 4507 | |
| 4508 | boolean success = true; |
| 4509 | Parcel data = null; |
| 4510 | Parcel reply = null; |
| 4511 | |
| 4512 | // Any uncaught exception will crash the system process |
| 4513 | try { |
| 4514 | // Find the hashcode of the window |
| 4515 | int index = parameters.indexOf(' '); |
| 4516 | if (index == -1) { |
| 4517 | index = parameters.length(); |
| 4518 | } |
| 4519 | final String code = parameters.substring(0, index); |
| 4520 | int hashCode = "ffffffff".equals(code) ? -1 : Integer.parseInt(code, 16); |
| 4521 | |
| 4522 | // Extract the command's parameter after the window description |
| 4523 | if (index < parameters.length()) { |
| 4524 | parameters = parameters.substring(index + 1); |
| 4525 | } else { |
| 4526 | parameters = ""; |
| 4527 | } |
| 4528 | |
| 4529 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 4530 | if (window == null) { |
| 4531 | return false; |
| 4532 | } |
| 4533 | |
| 4534 | data = Parcel.obtain(); |
| 4535 | data.writeInterfaceToken("android.view.IWindow"); |
| 4536 | data.writeString(command); |
| 4537 | data.writeString(parameters); |
| 4538 | data.writeInt(1); |
| 4539 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 4540 | |
| 4541 | reply = Parcel.obtain(); |
| 4542 | |
| 4543 | final IBinder binder = window.mClient.asBinder(); |
| 4544 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 4545 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 4546 | |
| 4547 | reply.readException(); |
| 4548 | |
| 4549 | } catch (Exception e) { |
| 4550 | Log.w(TAG, "Could not send command " + command + " with parameters " + parameters, e); |
| 4551 | success = false; |
| 4552 | } finally { |
| 4553 | if (data != null) { |
| 4554 | data.recycle(); |
| 4555 | } |
| 4556 | if (reply != null) { |
| 4557 | reply.recycle(); |
| 4558 | } |
| 4559 | } |
| 4560 | |
| 4561 | return success; |
| 4562 | } |
| 4563 | |
| 4564 | private WindowState findWindow(int hashCode) { |
| 4565 | if (hashCode == -1) { |
| 4566 | return getFocusedWindow(); |
| 4567 | } |
| 4568 | |
| 4569 | synchronized (mWindowMap) { |
| 4570 | final ArrayList windows = mWindows; |
| 4571 | final int count = windows.size(); |
| 4572 | |
| 4573 | for (int i = 0; i < count; i++) { |
| 4574 | WindowState w = (WindowState) windows.get(i); |
| 4575 | if (System.identityHashCode(w) == hashCode) { |
| 4576 | return w; |
| 4577 | } |
| 4578 | } |
| 4579 | } |
| 4580 | |
| 4581 | return null; |
| 4582 | } |
| 4583 | |
| 4584 | /* |
| 4585 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 4586 | * that to config-changed listeners if appropriate. |
| 4587 | */ |
| 4588 | void sendNewConfiguration() { |
| 4589 | try { |
| 4590 | mActivityManager.updateConfiguration(null); |
| 4591 | } catch (RemoteException e) { |
| 4592 | } |
| 4593 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4594 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4595 | public Configuration computeNewConfiguration() { |
| 4596 | synchronized (mWindowMap) { |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4597 | return computeNewConfigurationLocked(); |
| 4598 | } |
| 4599 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4600 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4601 | Configuration computeNewConfigurationLocked() { |
| 4602 | Configuration config = new Configuration(); |
| 4603 | if (!computeNewConfigurationLocked(config)) { |
| 4604 | return null; |
| 4605 | } |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4606 | return config; |
| 4607 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4608 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4609 | boolean computeNewConfigurationLocked(Configuration config) { |
| 4610 | if (mDisplay == null) { |
| 4611 | return false; |
| 4612 | } |
| 4613 | mQueue.getInputConfiguration(config); |
| 4614 | final int dw = mDisplay.getWidth(); |
| 4615 | final int dh = mDisplay.getHeight(); |
| 4616 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 4617 | if (dw < dh) { |
| 4618 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 4619 | } else if (dw > dh) { |
| 4620 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 4621 | } |
| 4622 | config.orientation = orientation; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4623 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4624 | DisplayMetrics dm = new DisplayMetrics(); |
| 4625 | mDisplay.getMetrics(dm); |
| 4626 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 4627 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4628 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4629 | // Note we only do this once because at this point we don't |
| 4630 | // expect the screen to change in this way at runtime, and want |
| 4631 | // to avoid all of this computation for every config change. |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4632 | int longSize = dw; |
| 4633 | int shortSize = dh; |
| 4634 | if (longSize < shortSize) { |
| 4635 | int tmp = longSize; |
| 4636 | longSize = shortSize; |
| 4637 | shortSize = tmp; |
| 4638 | } |
| 4639 | longSize = (int)(longSize/dm.density); |
| 4640 | shortSize = (int)(shortSize/dm.density); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4641 | |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4642 | // These semi-magic numbers define our compatibility modes for |
| 4643 | // applications with different screens. Don't change unless you |
| 4644 | // make sure to test lots and lots of apps! |
| 4645 | if (longSize < 470) { |
| 4646 | // This is shorter than an HVGA normal density screen (which |
| 4647 | // is 480 pixels on its long side). |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4648 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 4649 | | Configuration.SCREENLAYOUT_LONG_NO; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4650 | } else { |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4651 | // Is this a large screen? |
| 4652 | if (longSize > 640 && shortSize >= 480) { |
| 4653 | // VGA or larger screens at medium density are the point |
| 4654 | // at which we consider it to be a large screen. |
| 4655 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 4656 | } else { |
| 4657 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
| 4658 | |
| 4659 | // If this screen is wider than normal HVGA, or taller |
| 4660 | // than FWVGA, then for old apps we want to run in size |
| 4661 | // compatibility mode. |
| 4662 | if (shortSize > 321 || longSize > 570) { |
| 4663 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 4664 | } |
| 4665 | } |
| 4666 | |
| 4667 | // Is this a long screen? |
| 4668 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 4669 | // Anything wider than WVGA (5:3) is considering to be long. |
| 4670 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 4671 | } else { |
| 4672 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 4673 | } |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4674 | } |
| 4675 | } |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4676 | config.screenLayout = mScreenLayout; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4677 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4678 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 4679 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 4680 | mPolicy.adjustConfigurationLw(config); |
| 4681 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4682 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4683 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4684 | // ------------------------------------------------------------- |
| 4685 | // Input Events and Focus Management |
| 4686 | // ------------------------------------------------------------- |
| 4687 | |
| 4688 | private final void wakeupIfNeeded(WindowState targetWin, int eventType) { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4689 | long curTime = SystemClock.uptimeMillis(); |
| 4690 | |
| Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 4691 | if (eventType == TOUCH_EVENT || eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4692 | if (mLastTouchEventType == eventType && |
| 4693 | (curTime - mLastUserActivityCallTime) < MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 4694 | return; |
| 4695 | } |
| 4696 | mLastUserActivityCallTime = curTime; |
| 4697 | mLastTouchEventType = eventType; |
| 4698 | } |
| 4699 | |
| 4700 | if (targetWin == null |
| 4701 | || targetWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) { |
| 4702 | mPowerManager.userActivity(curTime, false, eventType, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4703 | } |
| 4704 | } |
| 4705 | |
| 4706 | // tells if it's a cheek event or not -- this function is stateful |
| 4707 | private static final int EVENT_NONE = 0; |
| 4708 | private static final int EVENT_UNKNOWN = 0; |
| 4709 | private static final int EVENT_CHEEK = 0; |
| 4710 | private static final int EVENT_IGNORE_DURATION = 300; // ms |
| 4711 | private static final float CHEEK_THRESHOLD = 0.6f; |
| 4712 | private int mEventState = EVENT_NONE; |
| 4713 | private float mEventSize; |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4714 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4715 | private int eventType(MotionEvent ev) { |
| 4716 | float size = ev.getSize(); |
| 4717 | switch (ev.getAction()) { |
| 4718 | case MotionEvent.ACTION_DOWN: |
| 4719 | mEventSize = size; |
| 4720 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_EVENT; |
| 4721 | case MotionEvent.ACTION_UP: |
| 4722 | if (size > mEventSize) mEventSize = size; |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4723 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_UP_EVENT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4724 | case MotionEvent.ACTION_MOVE: |
| 4725 | final int N = ev.getHistorySize(); |
| 4726 | if (size > mEventSize) mEventSize = size; |
| 4727 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 4728 | for (int i=0; i<N; i++) { |
| 4729 | size = ev.getHistoricalSize(i); |
| 4730 | if (size > mEventSize) mEventSize = size; |
| 4731 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 4732 | } |
| 4733 | if (ev.getEventTime() < ev.getDownTime() + EVENT_IGNORE_DURATION) { |
| 4734 | return TOUCH_EVENT; |
| 4735 | } else { |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4736 | return LONG_TOUCH_EVENT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4737 | } |
| 4738 | default: |
| 4739 | // not good |
| 4740 | return OTHER_EVENT; |
| 4741 | } |
| 4742 | } |
| 4743 | |
| 4744 | /** |
| 4745 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4746 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4747 | 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] | 4748 | if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Log.v(TAG, |
| 4749 | "dispatchPointer " + ev); |
| 4750 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4751 | if (MEASURE_LATENCY) { |
| 4752 | lt.sample("3 Wait for last dispatch ", System.nanoTime() - qev.whenNano); |
| 4753 | } |
| 4754 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4755 | Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4756 | ev, true, false, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4757 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4758 | if (MEASURE_LATENCY) { |
| 4759 | lt.sample("3 Last dispatch finished ", System.nanoTime() - qev.whenNano); |
| 4760 | } |
| 4761 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4762 | int action = ev.getAction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4763 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4764 | if (action == MotionEvent.ACTION_UP) { |
| 4765 | // let go of our target |
| 4766 | mKeyWaiter.mMotionTarget = null; |
| 4767 | mPowerManager.logPointerUpEvent(); |
| 4768 | } else if (action == MotionEvent.ACTION_DOWN) { |
| 4769 | mPowerManager.logPointerDownEvent(); |
| 4770 | } |
| 4771 | |
| 4772 | if (targetObj == null) { |
| 4773 | // In this case we are either dropping the event, or have received |
| 4774 | // a move or up without a down. It is common to receive move |
| 4775 | // events in such a way, since this means the user is moving the |
| 4776 | // pointer without actually pressing down. All other cases should |
| 4777 | // be atypical, so let's log them. |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4778 | if (action != MotionEvent.ACTION_MOVE) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4779 | Log.w(TAG, "No window to dispatch pointer action " + ev.getAction()); |
| 4780 | } |
| 4781 | if (qev != null) { |
| 4782 | mQueue.recycleEvent(qev); |
| 4783 | } |
| 4784 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4785 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4786 | } |
| 4787 | if (targetObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| 4788 | if (qev != null) { |
| 4789 | mQueue.recycleEvent(qev); |
| 4790 | } |
| 4791 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4792 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4793 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4794 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4795 | WindowState target = (WindowState)targetObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4796 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4797 | final long eventTime = ev.getEventTime(); |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4798 | final long eventTimeNano = ev.getEventTimeNano(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4799 | |
| 4800 | //Log.i(TAG, "Sending " + ev + " to " + target); |
| 4801 | |
| 4802 | if (uid != 0 && uid != target.mSession.mUid) { |
| 4803 | if (mContext.checkPermission( |
| 4804 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 4805 | != PackageManager.PERMISSION_GRANTED) { |
| 4806 | Log.w(TAG, "Permission denied: injecting pointer event from pid " |
| 4807 | + pid + " uid " + uid + " to window " + target |
| 4808 | + " owned by uid " + target.mSession.mUid); |
| 4809 | if (qev != null) { |
| 4810 | mQueue.recycleEvent(qev); |
| 4811 | } |
| 4812 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4813 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4814 | } |
| 4815 | } |
| 4816 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4817 | if (MEASURE_LATENCY) { |
| 4818 | lt.sample("4 in dispatchPointer ", System.nanoTime() - eventTimeNano); |
| 4819 | } |
| 4820 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4821 | if ((target.mAttrs.flags & |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4822 | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES) != 0) { |
| 4823 | //target wants to ignore fat touch events |
| 4824 | boolean cheekPress = mPolicy.isCheekPressedAgainstScreen(ev); |
| 4825 | //explicit flag to return without processing event further |
| 4826 | boolean returnFlag = false; |
| 4827 | if((action == MotionEvent.ACTION_DOWN)) { |
| 4828 | mFatTouch = false; |
| 4829 | if(cheekPress) { |
| 4830 | mFatTouch = true; |
| 4831 | returnFlag = true; |
| 4832 | } |
| 4833 | } else { |
| 4834 | if(action == MotionEvent.ACTION_UP) { |
| 4835 | if(mFatTouch) { |
| 4836 | //earlier even was invalid doesnt matter if current up is cheekpress or not |
| 4837 | mFatTouch = false; |
| 4838 | returnFlag = true; |
| 4839 | } else if(cheekPress) { |
| 4840 | //cancel the earlier event |
| 4841 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 4842 | action = MotionEvent.ACTION_CANCEL; |
| 4843 | } |
| 4844 | } else if(action == MotionEvent.ACTION_MOVE) { |
| 4845 | if(mFatTouch) { |
| 4846 | //two cases here |
| 4847 | //an invalid down followed by 0 or moves(valid or invalid) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4848 | //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] | 4849 | returnFlag = true; |
| 4850 | } else if(cheekPress) { |
| 4851 | //valid down followed by invalid moves |
| 4852 | //an invalid move have to cancel earlier action |
| 4853 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 4854 | action = MotionEvent.ACTION_CANCEL; |
| 4855 | if (DEBUG_INPUT) Log.v(TAG, "Sending cancel for invalid ACTION_MOVE"); |
| 4856 | //note that the subsequent invalid moves will not get here |
| 4857 | mFatTouch = true; |
| 4858 | } |
| 4859 | } |
| 4860 | } //else if action |
| 4861 | if(returnFlag) { |
| 4862 | //recycle que, ev |
| 4863 | if (qev != null) { |
| 4864 | mQueue.recycleEvent(qev); |
| 4865 | } |
| 4866 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4867 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4868 | } |
| 4869 | } //end if target |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4870 | |
| Michael Chan | 9f028e6 | 2009-08-04 17:37:46 -0700 | [diff] [blame] | 4871 | // Enable this for testing the "right" value |
| 4872 | if (false && action == MotionEvent.ACTION_DOWN) { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4873 | int max_events_per_sec = 35; |
| 4874 | try { |
| 4875 | max_events_per_sec = Integer.parseInt(SystemProperties |
| 4876 | .get("windowsmgr.max_events_per_sec")); |
| 4877 | if (max_events_per_sec < 1) { |
| 4878 | max_events_per_sec = 35; |
| 4879 | } |
| 4880 | } catch (NumberFormatException e) { |
| 4881 | } |
| 4882 | mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec; |
| 4883 | } |
| 4884 | |
| 4885 | /* |
| 4886 | * Throttle events to minimize CPU usage when there's a flood of events |
| 4887 | * e.g. constant contact with the screen |
| 4888 | */ |
| 4889 | if (action == MotionEvent.ACTION_MOVE) { |
| 4890 | long nextEventTime = mLastTouchEventTime + mMinWaitTimeBetweenTouchEvents; |
| 4891 | long now = SystemClock.uptimeMillis(); |
| 4892 | if (now < nextEventTime) { |
| 4893 | try { |
| 4894 | Thread.sleep(nextEventTime - now); |
| 4895 | } catch (InterruptedException e) { |
| 4896 | } |
| 4897 | mLastTouchEventTime = nextEventTime; |
| 4898 | } else { |
| 4899 | mLastTouchEventTime = now; |
| 4900 | } |
| 4901 | } |
| 4902 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4903 | if (MEASURE_LATENCY) { |
| 4904 | lt.sample("5 in dispatchPointer ", System.nanoTime() - eventTimeNano); |
| 4905 | } |
| 4906 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4907 | synchronized(mWindowMap) { |
| 4908 | if (qev != null && action == MotionEvent.ACTION_MOVE) { |
| 4909 | mKeyWaiter.bindTargetWindowLocked(target, |
| 4910 | KeyWaiter.RETURN_PENDING_POINTER, qev); |
| 4911 | ev = null; |
| 4912 | } else { |
| 4913 | if (action == MotionEvent.ACTION_DOWN) { |
| 4914 | WindowState out = mKeyWaiter.mOutsideTouchTargets; |
| 4915 | if (out != null) { |
| 4916 | MotionEvent oev = MotionEvent.obtain(ev); |
| 4917 | oev.setAction(MotionEvent.ACTION_OUTSIDE); |
| 4918 | do { |
| 4919 | final Rect frame = out.mFrame; |
| 4920 | oev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 4921 | try { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 4922 | out.mClient.dispatchPointer(oev, eventTime, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4923 | } catch (android.os.RemoteException e) { |
| 4924 | Log.i(TAG, "WINDOW DIED during outside motion dispatch: " + out); |
| 4925 | } |
| 4926 | oev.offsetLocation((float)frame.left, (float)frame.top); |
| 4927 | out = out.mNextOutsideTouch; |
| 4928 | } while (out != null); |
| 4929 | mKeyWaiter.mOutsideTouchTargets = null; |
| 4930 | } |
| 4931 | } |
| 4932 | final Rect frame = target.mFrame; |
| 4933 | ev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 4934 | mKeyWaiter.bindTargetWindowLocked(target); |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 4935 | |
| 4936 | // If we are on top of the wallpaper, then the wallpaper also |
| 4937 | // gets to see this movement. |
| 4938 | if (mWallpaperTarget == target) { |
| 4939 | sendPointerToWallpaperLocked(target, ev, eventTime); |
| 4940 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4941 | } |
| 4942 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4943 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4944 | // finally offset the event to the target's coordinate system and |
| 4945 | // dispatch the event. |
| 4946 | try { |
| 4947 | if (DEBUG_INPUT || DEBUG_FOCUS || WindowManagerPolicy.WATCH_POINTER) { |
| 4948 | Log.v(TAG, "Delivering pointer " + qev + " to " + target); |
| 4949 | } |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4950 | |
| 4951 | if (MEASURE_LATENCY) { |
| 4952 | lt.sample("6 before svr->client ipc ", System.nanoTime() - eventTimeNano); |
| 4953 | } |
| 4954 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 4955 | target.mClient.dispatchPointer(ev, eventTime, true); |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4956 | |
| 4957 | if (MEASURE_LATENCY) { |
| 4958 | lt.sample("7 after svr->client ipc ", System.nanoTime() - eventTimeNano); |
| 4959 | } |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4960 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4961 | } catch (android.os.RemoteException e) { |
| 4962 | Log.i(TAG, "WINDOW DIED during motion dispatch: " + target); |
| 4963 | mKeyWaiter.mMotionTarget = null; |
| 4964 | try { |
| 4965 | removeWindow(target.mSession, target.mClient); |
| 4966 | } catch (java.util.NoSuchElementException ex) { |
| 4967 | // This will happen if the window has already been |
| 4968 | // removed. |
| 4969 | } |
| 4970 | } |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4971 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4972 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4973 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4974 | /** |
| 4975 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4976 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4977 | 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] | 4978 | if (DEBUG_INPUT) Log.v( |
| 4979 | TAG, "dispatchTrackball [" + ev.getAction() +"] <" + ev.getX() + ", " + ev.getY() + ">"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4980 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4981 | Object focusObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4982 | ev, false, false, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4983 | if (focusObj == null) { |
| 4984 | Log.w(TAG, "No focus window, dropping trackball: " + ev); |
| 4985 | if (qev != null) { |
| 4986 | mQueue.recycleEvent(qev); |
| 4987 | } |
| 4988 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4989 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4990 | } |
| 4991 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| 4992 | if (qev != null) { |
| 4993 | mQueue.recycleEvent(qev); |
| 4994 | } |
| 4995 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4996 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4997 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4998 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4999 | WindowState focus = (WindowState)focusObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5000 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5001 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 5002 | if (mContext.checkPermission( |
| 5003 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 5004 | != PackageManager.PERMISSION_GRANTED) { |
| 5005 | Log.w(TAG, "Permission denied: injecting key event from pid " |
| 5006 | + pid + " uid " + uid + " to window " + focus |
| 5007 | + " owned by uid " + focus.mSession.mUid); |
| 5008 | if (qev != null) { |
| 5009 | mQueue.recycleEvent(qev); |
| 5010 | } |
| 5011 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5012 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5013 | } |
| 5014 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5015 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5016 | final long eventTime = ev.getEventTime(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5017 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5018 | synchronized(mWindowMap) { |
| 5019 | if (qev != null && ev.getAction() == MotionEvent.ACTION_MOVE) { |
| 5020 | mKeyWaiter.bindTargetWindowLocked(focus, |
| 5021 | KeyWaiter.RETURN_PENDING_TRACKBALL, qev); |
| 5022 | // We don't deliver movement events to the client, we hold |
| 5023 | // them and wait for them to call back. |
| 5024 | ev = null; |
| 5025 | } else { |
| 5026 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 5027 | } |
| 5028 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5029 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5030 | try { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5031 | focus.mClient.dispatchTrackball(ev, eventTime, true); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5032 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5033 | } catch (android.os.RemoteException e) { |
| 5034 | Log.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| 5035 | try { |
| 5036 | removeWindow(focus.mSession, focus.mClient); |
| 5037 | } catch (java.util.NoSuchElementException ex) { |
| 5038 | // This will happen if the window has already been |
| 5039 | // removed. |
| 5040 | } |
| 5041 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5042 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5043 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5044 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5045 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5046 | /** |
| 5047 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5048 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5049 | private int dispatchKey(KeyEvent event, int pid, int uid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5050 | if (DEBUG_INPUT) Log.v(TAG, "Dispatch key: " + event); |
| 5051 | |
| 5052 | Object focusObj = mKeyWaiter.waitForNextEventTarget(event, null, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5053 | null, false, false, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5054 | if (focusObj == null) { |
| 5055 | Log.w(TAG, "No focus window, dropping: " + event); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5056 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5057 | } |
| 5058 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5059 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5060 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5061 | |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5062 | // Okay we have finished waiting for the last event to be processed. |
| 5063 | // First off, if this is a repeat event, check to see if there is |
| 5064 | // a corresponding up event in the queue. If there is, we will |
| 5065 | // just drop the repeat, because it makes no sense to repeat after |
| 5066 | // the user has released a key. (This is especially important for |
| 5067 | // long presses.) |
| 5068 | if (event.getRepeatCount() > 0 && mQueue.hasKeyUpEvent(event)) { |
| 5069 | return INJECT_SUCCEEDED; |
| 5070 | } |
| 5071 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5072 | WindowState focus = (WindowState)focusObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5073 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5074 | if (DEBUG_INPUT) Log.v( |
| 5075 | TAG, "Dispatching to " + focus + ": " + event); |
| 5076 | |
| 5077 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 5078 | if (mContext.checkPermission( |
| 5079 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 5080 | != PackageManager.PERMISSION_GRANTED) { |
| 5081 | Log.w(TAG, "Permission denied: injecting key event from pid " |
| 5082 | + pid + " uid " + uid + " to window " + focus |
| 5083 | + " owned by uid " + focus.mSession.mUid); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5084 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5085 | } |
| 5086 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5087 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5088 | synchronized(mWindowMap) { |
| 5089 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 5090 | } |
| 5091 | |
| 5092 | // NOSHIP extra state logging |
| 5093 | mKeyWaiter.recordDispatchState(event, focus); |
| 5094 | // END NOSHIP |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5095 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5096 | try { |
| 5097 | if (DEBUG_INPUT || DEBUG_FOCUS) { |
| 5098 | Log.v(TAG, "Delivering key " + event.getKeyCode() |
| 5099 | + " to " + focus); |
| 5100 | } |
| 5101 | focus.mClient.dispatchKey(event); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5102 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5103 | } catch (android.os.RemoteException e) { |
| 5104 | Log.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| 5105 | try { |
| 5106 | removeWindow(focus.mSession, focus.mClient); |
| 5107 | } catch (java.util.NoSuchElementException ex) { |
| 5108 | // This will happen if the window has already been |
| 5109 | // removed. |
| 5110 | } |
| 5111 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5112 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5113 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5114 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5115 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5116 | public void pauseKeyDispatching(IBinder _token) { |
| 5117 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5118 | "pauseKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5119 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5120 | } |
| 5121 | |
| 5122 | synchronized (mWindowMap) { |
| 5123 | WindowToken token = mTokenMap.get(_token); |
| 5124 | if (token != null) { |
| 5125 | mKeyWaiter.pauseDispatchingLocked(token); |
| 5126 | } |
| 5127 | } |
| 5128 | } |
| 5129 | |
| 5130 | public void resumeKeyDispatching(IBinder _token) { |
| 5131 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5132 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5133 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5134 | } |
| 5135 | |
| 5136 | synchronized (mWindowMap) { |
| 5137 | WindowToken token = mTokenMap.get(_token); |
| 5138 | if (token != null) { |
| 5139 | mKeyWaiter.resumeDispatchingLocked(token); |
| 5140 | } |
| 5141 | } |
| 5142 | } |
| 5143 | |
| 5144 | public void setEventDispatching(boolean enabled) { |
| 5145 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5146 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5147 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5148 | } |
| 5149 | |
| 5150 | synchronized (mWindowMap) { |
| 5151 | mKeyWaiter.setEventDispatchingLocked(enabled); |
| 5152 | } |
| 5153 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5154 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5155 | /** |
| 5156 | * Injects a keystroke event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5157 | * |
| 5158 | * @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] | 5159 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5160 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5161 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5162 | */ |
| 5163 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 5164 | long downTime = ev.getDownTime(); |
| 5165 | long eventTime = ev.getEventTime(); |
| 5166 | |
| 5167 | int action = ev.getAction(); |
| 5168 | int code = ev.getKeyCode(); |
| 5169 | int repeatCount = ev.getRepeatCount(); |
| 5170 | int metaState = ev.getMetaState(); |
| 5171 | int deviceId = ev.getDeviceId(); |
| 5172 | int scancode = ev.getScanCode(); |
| 5173 | |
| 5174 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 5175 | if (downTime == 0) downTime = eventTime; |
| 5176 | |
| 5177 | 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] | 5178 | deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5179 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5180 | final int pid = Binder.getCallingPid(); |
| 5181 | final int uid = Binder.getCallingUid(); |
| 5182 | final long ident = Binder.clearCallingIdentity(); |
| 5183 | final int result = dispatchKey(newEvent, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5184 | if (sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5185 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5186 | } |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5187 | Binder.restoreCallingIdentity(ident); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5188 | switch (result) { |
| 5189 | case INJECT_NO_PERMISSION: |
| 5190 | throw new SecurityException( |
| 5191 | "Injecting to another application requires INJECT_EVENT permission"); |
| 5192 | case INJECT_SUCCEEDED: |
| 5193 | return true; |
| 5194 | } |
| 5195 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5196 | } |
| 5197 | |
| 5198 | /** |
| 5199 | * Inject a pointer (touch) event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5200 | * |
| 5201 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 5202 | * {@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] | 5203 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5204 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5205 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5206 | */ |
| 5207 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5208 | final int pid = Binder.getCallingPid(); |
| 5209 | final int uid = Binder.getCallingUid(); |
| 5210 | final long ident = Binder.clearCallingIdentity(); |
| 5211 | final int result = dispatchPointer(null, ev, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5212 | if (sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5213 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5214 | } |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5215 | Binder.restoreCallingIdentity(ident); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5216 | switch (result) { |
| 5217 | case INJECT_NO_PERMISSION: |
| 5218 | throw new SecurityException( |
| 5219 | "Injecting to another application requires INJECT_EVENT permission"); |
| 5220 | case INJECT_SUCCEEDED: |
| 5221 | return true; |
| 5222 | } |
| 5223 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5224 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5225 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5226 | /** |
| 5227 | * Inject a trackball (navigation device) event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5228 | * |
| 5229 | * @param ev A motion event describing the trackball action. (As noted in |
| 5230 | * {@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] | 5231 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5232 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5233 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5234 | */ |
| 5235 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5236 | final int pid = Binder.getCallingPid(); |
| 5237 | final int uid = Binder.getCallingUid(); |
| 5238 | final long ident = Binder.clearCallingIdentity(); |
| 5239 | final int result = dispatchTrackball(null, ev, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5240 | if (sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5241 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5242 | } |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5243 | Binder.restoreCallingIdentity(ident); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5244 | switch (result) { |
| 5245 | case INJECT_NO_PERMISSION: |
| 5246 | throw new SecurityException( |
| 5247 | "Injecting to another application requires INJECT_EVENT permission"); |
| 5248 | case INJECT_SUCCEEDED: |
| 5249 | return true; |
| 5250 | } |
| 5251 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5252 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5253 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5254 | private WindowState getFocusedWindow() { |
| 5255 | synchronized (mWindowMap) { |
| 5256 | return getFocusedWindowLocked(); |
| 5257 | } |
| 5258 | } |
| 5259 | |
| 5260 | private WindowState getFocusedWindowLocked() { |
| 5261 | return mCurrentFocus; |
| 5262 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5263 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5264 | /** |
| 5265 | * This class holds the state for dispatching key events. This state |
| 5266 | * is protected by the KeyWaiter instance, NOT by the window lock. You |
| 5267 | * can be holding the main window lock while acquire the KeyWaiter lock, |
| 5268 | * but not the other way around. |
| 5269 | */ |
| 5270 | final class KeyWaiter { |
| 5271 | // NOSHIP debugging |
| 5272 | public class DispatchState { |
| 5273 | private KeyEvent event; |
| 5274 | private WindowState focus; |
| 5275 | private long time; |
| 5276 | private WindowState lastWin; |
| 5277 | private IBinder lastBinder; |
| 5278 | private boolean finished; |
| 5279 | private boolean gotFirstWindow; |
| 5280 | private boolean eventDispatching; |
| 5281 | private long timeToSwitch; |
| 5282 | private boolean wasFrozen; |
| 5283 | private boolean focusPaused; |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5284 | private WindowState curFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5285 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5286 | DispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 5287 | focus = theFocus; |
| 5288 | event = theEvent; |
| 5289 | time = System.currentTimeMillis(); |
| 5290 | // snapshot KeyWaiter state |
| 5291 | lastWin = mLastWin; |
| 5292 | lastBinder = mLastBinder; |
| 5293 | finished = mFinished; |
| 5294 | gotFirstWindow = mGotFirstWindow; |
| 5295 | eventDispatching = mEventDispatching; |
| 5296 | timeToSwitch = mTimeToSwitch; |
| 5297 | wasFrozen = mWasFrozen; |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5298 | curFocus = mCurrentFocus; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5299 | // cache the paused state at ctor time as well |
| 5300 | if (theFocus == null || theFocus.mToken == null) { |
| 5301 | Log.i(TAG, "focus " + theFocus + " mToken is null at event dispatch!"); |
| 5302 | focusPaused = false; |
| 5303 | } else { |
| 5304 | focusPaused = theFocus.mToken.paused; |
| 5305 | } |
| 5306 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5307 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5308 | public String toString() { |
| 5309 | return "{{" + event + " to " + focus + " @ " + time |
| 5310 | + " lw=" + lastWin + " lb=" + lastBinder |
| 5311 | + " fin=" + finished + " gfw=" + gotFirstWindow |
| 5312 | + " ed=" + eventDispatching + " tts=" + timeToSwitch |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5313 | + " wf=" + wasFrozen + " fp=" + focusPaused |
| 5314 | + " mcf=" + mCurrentFocus + "}}"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5315 | } |
| 5316 | }; |
| 5317 | private DispatchState mDispatchState = null; |
| 5318 | public void recordDispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 5319 | mDispatchState = new DispatchState(theEvent, theFocus); |
| 5320 | } |
| 5321 | // END NOSHIP |
| 5322 | |
| 5323 | public static final int RETURN_NOTHING = 0; |
| 5324 | public static final int RETURN_PENDING_POINTER = 1; |
| 5325 | public static final int RETURN_PENDING_TRACKBALL = 2; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5326 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5327 | final Object SKIP_TARGET_TOKEN = new Object(); |
| 5328 | final Object CONSUMED_EVENT_TOKEN = new Object(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5329 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5330 | private WindowState mLastWin = null; |
| 5331 | private IBinder mLastBinder = null; |
| 5332 | private boolean mFinished = true; |
| 5333 | private boolean mGotFirstWindow = false; |
| 5334 | private boolean mEventDispatching = true; |
| 5335 | private long mTimeToSwitch = 0; |
| 5336 | /* package */ boolean mWasFrozen = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5337 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5338 | // Target of Motion events |
| 5339 | WindowState mMotionTarget; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5340 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5341 | // Windows above the target who would like to receive an "outside" |
| 5342 | // touch event for any down events outside of them. |
| 5343 | WindowState mOutsideTouchTargets; |
| 5344 | |
| 5345 | /** |
| 5346 | * Wait for the last event dispatch to complete, then find the next |
| 5347 | * target that should receive the given event and wait for that one |
| 5348 | * to be ready to receive it. |
| 5349 | */ |
| 5350 | Object waitForNextEventTarget(KeyEvent nextKey, QueuedEvent qev, |
| 5351 | MotionEvent nextMotion, boolean isPointerEvent, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5352 | boolean failIfTimeout, int callingPid, int callingUid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5353 | long startTime = SystemClock.uptimeMillis(); |
| 5354 | long keyDispatchingTimeout = 5 * 1000; |
| 5355 | long waitedFor = 0; |
| 5356 | |
| 5357 | while (true) { |
| 5358 | // Figure out which window we care about. It is either the |
| 5359 | // last window we are waiting to have process the event or, |
| 5360 | // if none, then the next window we think the event should go |
| 5361 | // to. Note: we retrieve mLastWin outside of the lock, so |
| 5362 | // it may change before we lock. Thus we must check it again. |
| 5363 | WindowState targetWin = mLastWin; |
| 5364 | boolean targetIsNew = targetWin == null; |
| 5365 | if (DEBUG_INPUT) Log.v( |
| 5366 | TAG, "waitForLastKey: mFinished=" + mFinished + |
| 5367 | ", mLastWin=" + mLastWin); |
| 5368 | if (targetIsNew) { |
| 5369 | Object target = findTargetWindow(nextKey, qev, nextMotion, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5370 | isPointerEvent, callingPid, callingUid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5371 | if (target == SKIP_TARGET_TOKEN) { |
| 5372 | // The user has pressed a special key, and we are |
| 5373 | // dropping all pending events before it. |
| 5374 | if (DEBUG_INPUT) Log.v(TAG, "Skipping: " + nextKey |
| 5375 | + " " + nextMotion); |
| 5376 | return null; |
| 5377 | } |
| 5378 | if (target == CONSUMED_EVENT_TOKEN) { |
| 5379 | if (DEBUG_INPUT) Log.v(TAG, "Consumed: " + nextKey |
| 5380 | + " " + nextMotion); |
| 5381 | return target; |
| 5382 | } |
| 5383 | targetWin = (WindowState)target; |
| 5384 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5385 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5386 | AppWindowToken targetApp = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5387 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5388 | // Now: is it okay to send the next event to this window? |
| 5389 | synchronized (this) { |
| 5390 | // First: did we come here based on the last window not |
| 5391 | // being null, but it changed by the time we got here? |
| 5392 | // If so, try again. |
| 5393 | if (!targetIsNew && mLastWin == null) { |
| 5394 | continue; |
| 5395 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5396 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5397 | // We never dispatch events if not finished with the |
| 5398 | // last one, or the display is frozen. |
| 5399 | if (mFinished && !mDisplayFrozen) { |
| 5400 | // If event dispatching is disabled, then we |
| 5401 | // just consume the events. |
| 5402 | if (!mEventDispatching) { |
| 5403 | if (DEBUG_INPUT) Log.v(TAG, |
| 5404 | "Skipping event; dispatching disabled: " |
| 5405 | + nextKey + " " + nextMotion); |
| 5406 | return null; |
| 5407 | } |
| 5408 | if (targetWin != null) { |
| 5409 | // If this is a new target, and that target is not |
| 5410 | // paused or unresponsive, then all looks good to |
| 5411 | // handle the event. |
| 5412 | if (targetIsNew && !targetWin.mToken.paused) { |
| 5413 | return targetWin; |
| 5414 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5415 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5416 | // If we didn't find a target window, and there is no |
| 5417 | // focused app window, then just eat the events. |
| 5418 | } else if (mFocusedApp == null) { |
| 5419 | if (DEBUG_INPUT) Log.v(TAG, |
| 5420 | "Skipping event; no focused app: " |
| 5421 | + nextKey + " " + nextMotion); |
| 5422 | return null; |
| 5423 | } |
| 5424 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5425 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5426 | if (DEBUG_INPUT) Log.v( |
| 5427 | TAG, "Waiting for last key in " + mLastBinder |
| 5428 | + " target=" + targetWin |
| 5429 | + " mFinished=" + mFinished |
| 5430 | + " mDisplayFrozen=" + mDisplayFrozen |
| 5431 | + " targetIsNew=" + targetIsNew |
| 5432 | + " paused=" |
| 5433 | + (targetWin != null ? targetWin.mToken.paused : false) |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5434 | + " mFocusedApp=" + mFocusedApp |
| 5435 | + " mCurrentFocus=" + mCurrentFocus); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5436 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5437 | targetApp = targetWin != null |
| 5438 | ? targetWin.mAppToken : mFocusedApp; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5439 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5440 | long curTimeout = keyDispatchingTimeout; |
| 5441 | if (mTimeToSwitch != 0) { |
| 5442 | long now = SystemClock.uptimeMillis(); |
| 5443 | if (mTimeToSwitch <= now) { |
| 5444 | // If an app switch key has been pressed, and we have |
| 5445 | // waited too long for the current app to finish |
| 5446 | // processing keys, then wait no more! |
| 5447 | doFinishedKeyLocked(true); |
| 5448 | continue; |
| 5449 | } |
| 5450 | long switchTimeout = mTimeToSwitch - now; |
| 5451 | if (curTimeout > switchTimeout) { |
| 5452 | curTimeout = switchTimeout; |
| 5453 | } |
| 5454 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5455 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5456 | try { |
| 5457 | // after that continue |
| 5458 | // processing keys, so we don't get stuck. |
| 5459 | if (DEBUG_INPUT) Log.v( |
| 5460 | TAG, "Waiting for key dispatch: " + curTimeout); |
| 5461 | wait(curTimeout); |
| 5462 | if (DEBUG_INPUT) Log.v(TAG, "Finished waiting @" |
| 5463 | + SystemClock.uptimeMillis() + " startTime=" |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5464 | + startTime + " switchTime=" + mTimeToSwitch |
| 5465 | + " target=" + targetWin + " mLW=" + mLastWin |
| 5466 | + " mLB=" + mLastBinder + " fin=" + mFinished |
| 5467 | + " mCurrentFocus=" + mCurrentFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5468 | } catch (InterruptedException e) { |
| 5469 | } |
| 5470 | } |
| 5471 | |
| 5472 | // If we were frozen during configuration change, restart the |
| 5473 | // timeout checks from now; otherwise look at whether we timed |
| 5474 | // out before awakening. |
| 5475 | if (mWasFrozen) { |
| 5476 | waitedFor = 0; |
| 5477 | mWasFrozen = false; |
| 5478 | } else { |
| 5479 | waitedFor = SystemClock.uptimeMillis() - startTime; |
| 5480 | } |
| 5481 | |
| 5482 | if (waitedFor >= keyDispatchingTimeout && mTimeToSwitch == 0) { |
| 5483 | IApplicationToken at = null; |
| 5484 | synchronized (this) { |
| 5485 | Log.w(TAG, "Key dispatching timed out sending to " + |
| 5486 | (targetWin != null ? targetWin.mAttrs.getTitle() |
| 5487 | : "<null>")); |
| 5488 | // NOSHIP debugging |
| 5489 | Log.w(TAG, "Dispatch state: " + mDispatchState); |
| 5490 | Log.w(TAG, "Current state: " + new DispatchState(nextKey, targetWin)); |
| 5491 | // END NOSHIP |
| 5492 | //dump(); |
| 5493 | if (targetWin != null) { |
| 5494 | at = targetWin.getAppToken(); |
| 5495 | } else if (targetApp != null) { |
| 5496 | at = targetApp.appToken; |
| 5497 | } |
| 5498 | } |
| 5499 | |
| 5500 | boolean abort = true; |
| 5501 | if (at != null) { |
| 5502 | try { |
| 5503 | long timeout = at.getKeyDispatchingTimeout(); |
| 5504 | if (timeout > waitedFor) { |
| 5505 | // we did not wait the proper amount of time for this application. |
| 5506 | // set the timeout to be the real timeout and wait again. |
| 5507 | keyDispatchingTimeout = timeout - waitedFor; |
| 5508 | continue; |
| 5509 | } else { |
| 5510 | abort = at.keyDispatchingTimedOut(); |
| 5511 | } |
| 5512 | } catch (RemoteException ex) { |
| 5513 | } |
| 5514 | } |
| 5515 | |
| 5516 | synchronized (this) { |
| 5517 | if (abort && (mLastWin == targetWin || targetWin == null)) { |
| 5518 | mFinished = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5519 | if (mLastWin != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5520 | if (DEBUG_INPUT) Log.v(TAG, |
| 5521 | "Window " + mLastWin + |
| 5522 | " timed out on key input"); |
| 5523 | if (mLastWin.mToken.paused) { |
| 5524 | Log.w(TAG, "Un-pausing dispatching to this window"); |
| 5525 | mLastWin.mToken.paused = false; |
| 5526 | } |
| 5527 | } |
| 5528 | if (mMotionTarget == targetWin) { |
| 5529 | mMotionTarget = null; |
| 5530 | } |
| 5531 | mLastWin = null; |
| 5532 | mLastBinder = null; |
| 5533 | if (failIfTimeout || targetWin == null) { |
| 5534 | return null; |
| 5535 | } |
| 5536 | } else { |
| 5537 | Log.w(TAG, "Continuing to wait for key to be dispatched"); |
| 5538 | startTime = SystemClock.uptimeMillis(); |
| 5539 | } |
| 5540 | } |
| 5541 | } |
| 5542 | } |
| 5543 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5544 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5545 | Object findTargetWindow(KeyEvent nextKey, QueuedEvent qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5546 | MotionEvent nextMotion, boolean isPointerEvent, |
| 5547 | int callingPid, int callingUid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5548 | mOutsideTouchTargets = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5549 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5550 | if (nextKey != null) { |
| 5551 | // Find the target window for a normal key event. |
| 5552 | final int keycode = nextKey.getKeyCode(); |
| 5553 | final int repeatCount = nextKey.getRepeatCount(); |
| 5554 | final boolean down = nextKey.getAction() != KeyEvent.ACTION_UP; |
| 5555 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(keycode); |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5556 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5557 | if (!dispatch) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5558 | if (callingUid == 0 || |
| 5559 | mContext.checkPermission( |
| 5560 | android.Manifest.permission.INJECT_EVENTS, |
| 5561 | callingPid, callingUid) |
| 5562 | == PackageManager.PERMISSION_GRANTED) { |
| 5563 | mPolicy.interceptKeyTi(null, keycode, |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 5564 | nextKey.getMetaState(), down, repeatCount, |
| 5565 | nextKey.getFlags()); |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5566 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5567 | Log.w(TAG, "Event timeout during app switch: dropping " |
| 5568 | + nextKey); |
| 5569 | return SKIP_TARGET_TOKEN; |
| 5570 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5571 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5572 | // System.out.println("##### [" + SystemClock.uptimeMillis() + "] WindowManagerService.dispatchKey(" + keycode + ", " + down + ", " + repeatCount + ")"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5573 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5574 | WindowState focus = null; |
| 5575 | synchronized(mWindowMap) { |
| 5576 | focus = getFocusedWindowLocked(); |
| 5577 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5578 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5579 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5580 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5581 | if (callingUid == 0 || |
| 5582 | (focus != null && callingUid == focus.mSession.mUid) || |
| 5583 | mContext.checkPermission( |
| 5584 | android.Manifest.permission.INJECT_EVENTS, |
| 5585 | callingPid, callingUid) |
| 5586 | == PackageManager.PERMISSION_GRANTED) { |
| 5587 | if (mPolicy.interceptKeyTi(focus, |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 5588 | keycode, nextKey.getMetaState(), down, repeatCount, |
| 5589 | nextKey.getFlags())) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5590 | return CONSUMED_EVENT_TOKEN; |
| 5591 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5592 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5593 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5594 | return focus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5595 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5596 | } else if (!isPointerEvent) { |
| 5597 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(-1); |
| 5598 | if (!dispatch) { |
| 5599 | Log.w(TAG, "Event timeout during app switch: dropping trackball " |
| 5600 | + nextMotion); |
| 5601 | return SKIP_TARGET_TOKEN; |
| 5602 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5603 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5604 | WindowState focus = null; |
| 5605 | synchronized(mWindowMap) { |
| 5606 | focus = getFocusedWindowLocked(); |
| 5607 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5608 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5609 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
| 5610 | return focus; |
| 5611 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5612 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5613 | if (nextMotion == null) { |
| 5614 | return SKIP_TARGET_TOKEN; |
| 5615 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5616 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5617 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey( |
| 5618 | KeyEvent.KEYCODE_UNKNOWN); |
| 5619 | if (!dispatch) { |
| 5620 | Log.w(TAG, "Event timeout during app switch: dropping pointer " |
| 5621 | + nextMotion); |
| 5622 | return SKIP_TARGET_TOKEN; |
| 5623 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5624 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5625 | // Find the target window for a pointer event. |
| 5626 | int action = nextMotion.getAction(); |
| 5627 | final float xf = nextMotion.getX(); |
| 5628 | final float yf = nextMotion.getY(); |
| 5629 | final long eventTime = nextMotion.getEventTime(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5630 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5631 | final boolean screenWasOff = qev != null |
| 5632 | && (qev.flags&WindowManagerPolicy.FLAG_BRIGHT_HERE) != 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5633 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5634 | WindowState target = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5635 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5636 | synchronized(mWindowMap) { |
| 5637 | synchronized (this) { |
| 5638 | if (action == MotionEvent.ACTION_DOWN) { |
| 5639 | if (mMotionTarget != null) { |
| 5640 | // this is weird, we got a pen down, but we thought it was |
| 5641 | // already down! |
| 5642 | // XXX: We should probably send an ACTION_UP to the current |
| 5643 | // target. |
| 5644 | Log.w(TAG, "Pointer down received while already down in: " |
| 5645 | + mMotionTarget); |
| 5646 | mMotionTarget = null; |
| 5647 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5648 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5649 | // ACTION_DOWN is special, because we need to lock next events to |
| 5650 | // the window we'll land onto. |
| 5651 | final int x = (int)xf; |
| 5652 | final int y = (int)yf; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5653 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5654 | final ArrayList windows = mWindows; |
| 5655 | final int N = windows.size(); |
| 5656 | WindowState topErrWindow = null; |
| 5657 | final Rect tmpRect = mTempRect; |
| 5658 | for (int i=N-1; i>=0; i--) { |
| 5659 | WindowState child = (WindowState)windows.get(i); |
| 5660 | //Log.i(TAG, "Checking dispatch to: " + child); |
| 5661 | final int flags = child.mAttrs.flags; |
| 5662 | if ((flags & WindowManager.LayoutParams.FLAG_SYSTEM_ERROR) != 0) { |
| 5663 | if (topErrWindow == null) { |
| 5664 | topErrWindow = child; |
| 5665 | } |
| 5666 | } |
| 5667 | if (!child.isVisibleLw()) { |
| 5668 | //Log.i(TAG, "Not visible!"); |
| 5669 | continue; |
| 5670 | } |
| 5671 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 5672 | //Log.i(TAG, "Not touchable!"); |
| 5673 | if ((flags & WindowManager.LayoutParams |
| 5674 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 5675 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 5676 | mOutsideTouchTargets = child; |
| 5677 | } |
| 5678 | continue; |
| 5679 | } |
| 5680 | tmpRect.set(child.mFrame); |
| 5681 | if (child.mTouchableInsets == ViewTreeObserver |
| 5682 | .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) { |
| 5683 | // The touch is inside of the window if it is |
| 5684 | // inside the frame, AND the content part of that |
| 5685 | // frame that was given by the application. |
| 5686 | tmpRect.left += child.mGivenContentInsets.left; |
| 5687 | tmpRect.top += child.mGivenContentInsets.top; |
| 5688 | tmpRect.right -= child.mGivenContentInsets.right; |
| 5689 | tmpRect.bottom -= child.mGivenContentInsets.bottom; |
| 5690 | } else if (child.mTouchableInsets == ViewTreeObserver |
| 5691 | .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) { |
| 5692 | // The touch is inside of the window if it is |
| 5693 | // inside the frame, AND the visible part of that |
| 5694 | // frame that was given by the application. |
| 5695 | tmpRect.left += child.mGivenVisibleInsets.left; |
| 5696 | tmpRect.top += child.mGivenVisibleInsets.top; |
| 5697 | tmpRect.right -= child.mGivenVisibleInsets.right; |
| 5698 | tmpRect.bottom -= child.mGivenVisibleInsets.bottom; |
| 5699 | } |
| 5700 | final int touchFlags = flags & |
| 5701 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 5702 | |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 5703 | if (tmpRect.contains(x, y) || touchFlags == 0) { |
| 5704 | //Log.i(TAG, "Using this target!"); |
| 5705 | if (!screenWasOff || (flags & |
| 5706 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING) != 0) { |
| 5707 | mMotionTarget = child; |
| 5708 | } else { |
| 5709 | //Log.i(TAG, "Waking, skip!"); |
| 5710 | mMotionTarget = null; |
| 5711 | } |
| 5712 | break; |
| 5713 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5714 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5715 | if ((flags & WindowManager.LayoutParams |
| 5716 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 5717 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 5718 | mOutsideTouchTargets = child; |
| 5719 | //Log.i(TAG, "Adding to outside target list: " + child); |
| 5720 | } |
| 5721 | } |
| 5722 | |
| 5723 | // if there's an error window but it's not accepting |
| 5724 | // focus (typically because it is not yet visible) just |
| 5725 | // wait for it -- any other focused window may in fact |
| 5726 | // be in ANR state. |
| 5727 | if (topErrWindow != null && mMotionTarget != topErrWindow) { |
| 5728 | mMotionTarget = null; |
| 5729 | } |
| 5730 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5731 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5732 | target = mMotionTarget; |
| 5733 | } |
| 5734 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5735 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5736 | wakeupIfNeeded(target, eventType(nextMotion)); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5737 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5738 | // Pointer events are a little different -- if there isn't a |
| 5739 | // target found for any event, then just drop it. |
| 5740 | return target != null ? target : SKIP_TARGET_TOKEN; |
| 5741 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5742 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5743 | boolean checkShouldDispatchKey(int keycode) { |
| 5744 | synchronized (this) { |
| 5745 | if (mPolicy.isAppSwitchKeyTqTiLwLi(keycode)) { |
| 5746 | mTimeToSwitch = 0; |
| 5747 | return true; |
| 5748 | } |
| 5749 | if (mTimeToSwitch != 0 |
| 5750 | && mTimeToSwitch < SystemClock.uptimeMillis()) { |
| 5751 | return false; |
| 5752 | } |
| 5753 | return true; |
| 5754 | } |
| 5755 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5756 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5757 | void bindTargetWindowLocked(WindowState win, |
| 5758 | int pendingWhat, QueuedEvent pendingMotion) { |
| 5759 | synchronized (this) { |
| 5760 | bindTargetWindowLockedLocked(win, pendingWhat, pendingMotion); |
| 5761 | } |
| 5762 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5763 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5764 | void bindTargetWindowLocked(WindowState win) { |
| 5765 | synchronized (this) { |
| 5766 | bindTargetWindowLockedLocked(win, RETURN_NOTHING, null); |
| 5767 | } |
| 5768 | } |
| 5769 | |
| 5770 | void bindTargetWindowLockedLocked(WindowState win, |
| 5771 | int pendingWhat, QueuedEvent pendingMotion) { |
| 5772 | mLastWin = win; |
| 5773 | mLastBinder = win.mClient.asBinder(); |
| 5774 | mFinished = false; |
| 5775 | if (pendingMotion != null) { |
| 5776 | final Session s = win.mSession; |
| 5777 | if (pendingWhat == RETURN_PENDING_POINTER) { |
| 5778 | releasePendingPointerLocked(s); |
| 5779 | s.mPendingPointerMove = pendingMotion; |
| 5780 | s.mPendingPointerWindow = win; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5781 | if (DEBUG_INPUT) Log.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5782 | "bindTargetToWindow " + s.mPendingPointerMove); |
| 5783 | } else if (pendingWhat == RETURN_PENDING_TRACKBALL) { |
| 5784 | releasePendingTrackballLocked(s); |
| 5785 | s.mPendingTrackballMove = pendingMotion; |
| 5786 | s.mPendingTrackballWindow = win; |
| 5787 | } |
| 5788 | } |
| 5789 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5790 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5791 | void releasePendingPointerLocked(Session s) { |
| 5792 | if (DEBUG_INPUT) Log.v(TAG, |
| 5793 | "releasePendingPointer " + s.mPendingPointerMove); |
| 5794 | if (s.mPendingPointerMove != null) { |
| 5795 | mQueue.recycleEvent(s.mPendingPointerMove); |
| 5796 | s.mPendingPointerMove = null; |
| 5797 | } |
| 5798 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5799 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5800 | void releasePendingTrackballLocked(Session s) { |
| 5801 | if (s.mPendingTrackballMove != null) { |
| 5802 | mQueue.recycleEvent(s.mPendingTrackballMove); |
| 5803 | s.mPendingTrackballMove = null; |
| 5804 | } |
| 5805 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5806 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5807 | MotionEvent finishedKey(Session session, IWindow client, boolean force, |
| 5808 | int returnWhat) { |
| 5809 | if (DEBUG_INPUT) Log.v( |
| 5810 | TAG, "finishedKey: client=" + client + ", force=" + force); |
| 5811 | |
| 5812 | if (client == null) { |
| 5813 | return null; |
| 5814 | } |
| 5815 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5816 | MotionEvent res = null; |
| 5817 | QueuedEvent qev = null; |
| 5818 | WindowState win = null; |
| 5819 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5820 | synchronized (this) { |
| 5821 | if (DEBUG_INPUT) Log.v( |
| 5822 | TAG, "finishedKey: client=" + client.asBinder() |
| 5823 | + ", force=" + force + ", last=" + mLastBinder |
| 5824 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) + ")"); |
| 5825 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5826 | if (returnWhat == RETURN_PENDING_POINTER) { |
| 5827 | qev = session.mPendingPointerMove; |
| 5828 | win = session.mPendingPointerWindow; |
| 5829 | session.mPendingPointerMove = null; |
| 5830 | session.mPendingPointerWindow = null; |
| 5831 | } else if (returnWhat == RETURN_PENDING_TRACKBALL) { |
| 5832 | qev = session.mPendingTrackballMove; |
| 5833 | win = session.mPendingTrackballWindow; |
| 5834 | session.mPendingTrackballMove = null; |
| 5835 | session.mPendingTrackballWindow = null; |
| 5836 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5837 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5838 | if (mLastBinder == client.asBinder()) { |
| 5839 | if (DEBUG_INPUT) Log.v( |
| 5840 | TAG, "finishedKey: last paused=" |
| 5841 | + ((mLastWin != null) ? mLastWin.mToken.paused : "null")); |
| 5842 | if (mLastWin != null && (!mLastWin.mToken.paused || force |
| 5843 | || !mEventDispatching)) { |
| 5844 | doFinishedKeyLocked(false); |
| 5845 | } else { |
| 5846 | // Make sure to wake up anyone currently waiting to |
| 5847 | // dispatch a key, so they can re-evaluate their |
| 5848 | // current situation. |
| 5849 | mFinished = true; |
| 5850 | notifyAll(); |
| 5851 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5852 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5853 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5854 | if (qev != null) { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5855 | res = (MotionEvent)qev.event; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5856 | if (DEBUG_INPUT) Log.v(TAG, |
| 5857 | "Returning pending motion: " + res); |
| 5858 | mQueue.recycleEvent(qev); |
| 5859 | if (win != null && returnWhat == RETURN_PENDING_POINTER) { |
| 5860 | res.offsetLocation(-win.mFrame.left, -win.mFrame.top); |
| 5861 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5862 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5863 | } |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5864 | |
| 5865 | if (res != null && returnWhat == RETURN_PENDING_POINTER) { |
| 5866 | synchronized (mWindowMap) { |
| 5867 | if (mWallpaperTarget == win) { |
| 5868 | sendPointerToWallpaperLocked(win, res, res.getEventTime()); |
| 5869 | } |
| 5870 | } |
| 5871 | } |
| 5872 | |
| 5873 | return res; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5874 | } |
| 5875 | |
| 5876 | void tickle() { |
| 5877 | synchronized (this) { |
| 5878 | notifyAll(); |
| 5879 | } |
| 5880 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5881 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5882 | void handleNewWindowLocked(WindowState newWindow) { |
| 5883 | if (!newWindow.canReceiveKeys()) { |
| 5884 | return; |
| 5885 | } |
| 5886 | synchronized (this) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5887 | if (DEBUG_INPUT) Log.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5888 | TAG, "New key dispatch window: win=" |
| 5889 | + newWindow.mClient.asBinder() |
| 5890 | + ", last=" + mLastBinder |
| 5891 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 5892 | + "), finished=" + mFinished + ", paused=" |
| 5893 | + newWindow.mToken.paused); |
| 5894 | |
| 5895 | // Displaying a window implicitly causes dispatching to |
| 5896 | // be unpaused. (This is to protect against bugs if someone |
| 5897 | // pauses dispatching but forgets to resume.) |
| 5898 | newWindow.mToken.paused = false; |
| 5899 | |
| 5900 | mGotFirstWindow = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5901 | |
| 5902 | if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) { |
| 5903 | if (DEBUG_INPUT) Log.v(TAG, |
| 5904 | "New SYSTEM_ERROR window; resetting state"); |
| 5905 | mLastWin = null; |
| 5906 | mLastBinder = null; |
| 5907 | mMotionTarget = null; |
| 5908 | mFinished = true; |
| 5909 | } else if (mLastWin != null) { |
| 5910 | // If the new window is above the window we are |
| 5911 | // waiting on, then stop waiting and let key dispatching |
| 5912 | // start on the new guy. |
| 5913 | if (DEBUG_INPUT) Log.v( |
| 5914 | TAG, "Last win layer=" + mLastWin.mLayer |
| 5915 | + ", new win layer=" + newWindow.mLayer); |
| 5916 | if (newWindow.mLayer >= mLastWin.mLayer) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5917 | // The new window is above the old; finish pending input to the last |
| 5918 | // window and start directing it to the new one. |
| 5919 | mLastWin.mToken.paused = false; |
| 5920 | doFinishedKeyLocked(true); // does a notifyAll() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5921 | } |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5922 | // Either the new window is lower, so there is no need to wake key waiters, |
| 5923 | // or we just finished key input to the previous window, which implicitly |
| 5924 | // notified the key waiters. In both cases, we don't need to issue the |
| 5925 | // notification here. |
| 5926 | return; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5927 | } |
| 5928 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5929 | // Now that we've put a new window state in place, make the event waiter |
| 5930 | // take notice and retarget its attentions. |
| 5931 | notifyAll(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5932 | } |
| 5933 | } |
| 5934 | |
| 5935 | void pauseDispatchingLocked(WindowToken token) { |
| 5936 | synchronized (this) |
| 5937 | { |
| 5938 | if (DEBUG_INPUT) Log.v(TAG, "Pausing WindowToken " + token); |
| 5939 | token.paused = true; |
| 5940 | |
| 5941 | /* |
| 5942 | if (mLastWin != null && !mFinished && mLastWin.mBaseLayer <= layer) { |
| 5943 | mPaused = true; |
| 5944 | } else { |
| 5945 | if (mLastWin == null) { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 5946 | 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] | 5947 | } else if (mFinished) { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 5948 | 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] | 5949 | } else { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 5950 | 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] | 5951 | } |
| 5952 | } |
| 5953 | */ |
| 5954 | } |
| 5955 | } |
| 5956 | |
| 5957 | void resumeDispatchingLocked(WindowToken token) { |
| 5958 | synchronized (this) { |
| 5959 | if (token.paused) { |
| 5960 | if (DEBUG_INPUT) Log.v( |
| 5961 | TAG, "Resuming WindowToken " + token |
| 5962 | + ", last=" + mLastBinder |
| 5963 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 5964 | + "), finished=" + mFinished + ", paused=" |
| 5965 | + token.paused); |
| 5966 | token.paused = false; |
| 5967 | if (mLastWin != null && mLastWin.mToken == token && mFinished) { |
| 5968 | doFinishedKeyLocked(true); |
| 5969 | } else { |
| 5970 | notifyAll(); |
| 5971 | } |
| 5972 | } |
| 5973 | } |
| 5974 | } |
| 5975 | |
| 5976 | void setEventDispatchingLocked(boolean enabled) { |
| 5977 | synchronized (this) { |
| 5978 | mEventDispatching = enabled; |
| 5979 | notifyAll(); |
| 5980 | } |
| 5981 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5982 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5983 | void appSwitchComing() { |
| 5984 | synchronized (this) { |
| 5985 | // Don't wait for more than .5 seconds for app to finish |
| 5986 | // processing the pending events. |
| 5987 | long now = SystemClock.uptimeMillis() + 500; |
| 5988 | if (DEBUG_INPUT) Log.v(TAG, "appSwitchComing: " + now); |
| 5989 | if (mTimeToSwitch == 0 || now < mTimeToSwitch) { |
| 5990 | mTimeToSwitch = now; |
| 5991 | } |
| 5992 | notifyAll(); |
| 5993 | } |
| 5994 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5995 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5996 | private final void doFinishedKeyLocked(boolean doRecycle) { |
| 5997 | if (mLastWin != null) { |
| 5998 | releasePendingPointerLocked(mLastWin.mSession); |
| 5999 | releasePendingTrackballLocked(mLastWin.mSession); |
| 6000 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6001 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6002 | if (mLastWin == null || !mLastWin.mToken.paused |
| 6003 | || !mLastWin.isVisibleLw()) { |
| 6004 | // If the current window has been paused, we aren't -really- |
| 6005 | // finished... so let the waiters still wait. |
| 6006 | mLastWin = null; |
| 6007 | mLastBinder = null; |
| 6008 | } |
| 6009 | mFinished = true; |
| 6010 | notifyAll(); |
| 6011 | } |
| 6012 | } |
| 6013 | |
| 6014 | private class KeyQ extends KeyInputQueue |
| 6015 | implements KeyInputQueue.FilterCallback { |
| 6016 | PowerManager.WakeLock mHoldingScreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6017 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6018 | KeyQ() { |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 6019 | super(mContext, WindowManagerService.this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6020 | PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE); |
| 6021 | mHoldingScreen = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 6022 | "KEEP_SCREEN_ON_FLAG"); |
| 6023 | mHoldingScreen.setReferenceCounted(false); |
| 6024 | } |
| 6025 | |
| 6026 | @Override |
| 6027 | boolean preprocessEvent(InputDevice device, RawInputEvent event) { |
| 6028 | if (mPolicy.preprocessInputEventTq(event)) { |
| 6029 | return true; |
| 6030 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6031 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6032 | switch (event.type) { |
| 6033 | case RawInputEvent.EV_KEY: { |
| 6034 | // XXX begin hack |
| 6035 | if (DEBUG) { |
| 6036 | if (event.keycode == KeyEvent.KEYCODE_G) { |
| 6037 | if (event.value != 0) { |
| 6038 | // G down |
| 6039 | mPolicy.screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 6040 | } |
| 6041 | return false; |
| 6042 | } |
| 6043 | if (event.keycode == KeyEvent.KEYCODE_D) { |
| 6044 | if (event.value != 0) { |
| 6045 | //dump(); |
| 6046 | } |
| 6047 | return false; |
| 6048 | } |
| 6049 | } |
| 6050 | // XXX end hack |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6051 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6052 | boolean screenIsOff = !mPowerManager.screenIsOn(); |
| 6053 | boolean screenIsDim = !mPowerManager.screenIsBright(); |
| 6054 | int actions = mPolicy.interceptKeyTq(event, !screenIsOff); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6055 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6056 | if ((actions & WindowManagerPolicy.ACTION_GO_TO_SLEEP) != 0) { |
| 6057 | mPowerManager.goToSleep(event.when); |
| 6058 | } |
| 6059 | |
| 6060 | if (screenIsOff) { |
| 6061 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6062 | } |
| 6063 | if (screenIsDim) { |
| 6064 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6065 | } |
| 6066 | if ((actions & WindowManagerPolicy.ACTION_POKE_USER_ACTIVITY) != 0) { |
| 6067 | mPowerManager.userActivity(event.when, false, |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6068 | LocalPowerManager.BUTTON_EVENT, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6069 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6070 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6071 | if ((actions & WindowManagerPolicy.ACTION_PASS_TO_USER) != 0) { |
| 6072 | if (event.value != 0 && mPolicy.isAppSwitchKeyTqTiLwLi(event.keycode)) { |
| 6073 | filterQueue(this); |
| 6074 | mKeyWaiter.appSwitchComing(); |
| 6075 | } |
| 6076 | return true; |
| 6077 | } else { |
| 6078 | return false; |
| 6079 | } |
| 6080 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6081 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6082 | case RawInputEvent.EV_REL: { |
| 6083 | boolean screenIsOff = !mPowerManager.screenIsOn(); |
| 6084 | boolean screenIsDim = !mPowerManager.screenIsBright(); |
| 6085 | if (screenIsOff) { |
| 6086 | if (!mPolicy.isWakeRelMovementTq(event.deviceId, |
| 6087 | device.classes, event)) { |
| 6088 | //Log.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| 6089 | return false; |
| 6090 | } |
| 6091 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6092 | } |
| 6093 | if (screenIsDim) { |
| 6094 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6095 | } |
| 6096 | return true; |
| 6097 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6098 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6099 | case RawInputEvent.EV_ABS: { |
| 6100 | boolean screenIsOff = !mPowerManager.screenIsOn(); |
| 6101 | boolean screenIsDim = !mPowerManager.screenIsBright(); |
| 6102 | if (screenIsOff) { |
| 6103 | if (!mPolicy.isWakeAbsMovementTq(event.deviceId, |
| 6104 | device.classes, event)) { |
| 6105 | //Log.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| 6106 | return false; |
| 6107 | } |
| 6108 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6109 | } |
| 6110 | if (screenIsDim) { |
| 6111 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6112 | } |
| 6113 | return true; |
| 6114 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6115 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6116 | default: |
| 6117 | return true; |
| 6118 | } |
| 6119 | } |
| 6120 | |
| 6121 | public int filterEvent(QueuedEvent ev) { |
| 6122 | switch (ev.classType) { |
| 6123 | case RawInputEvent.CLASS_KEYBOARD: |
| 6124 | KeyEvent ke = (KeyEvent)ev.event; |
| 6125 | if (mPolicy.isMovementKeyTi(ke.getKeyCode())) { |
| 6126 | Log.w(TAG, "Dropping movement key during app switch: " |
| 6127 | + ke.getKeyCode() + ", action=" + ke.getAction()); |
| 6128 | return FILTER_REMOVE; |
| 6129 | } |
| 6130 | return FILTER_ABORT; |
| 6131 | default: |
| 6132 | return FILTER_KEEP; |
| 6133 | } |
| 6134 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6135 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6136 | /** |
| 6137 | * Must be called with the main window manager lock held. |
| 6138 | */ |
| 6139 | void setHoldScreenLocked(boolean holding) { |
| 6140 | boolean state = mHoldingScreen.isHeld(); |
| 6141 | if (holding != state) { |
| 6142 | if (holding) { |
| 6143 | mHoldingScreen.acquire(); |
| 6144 | } else { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6145 | mPolicy.screenOnStoppedLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6146 | mHoldingScreen.release(); |
| 6147 | } |
| 6148 | } |
| 6149 | } |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6150 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6151 | |
| 6152 | public boolean detectSafeMode() { |
| 6153 | mSafeMode = mPolicy.detectSafeMode(); |
| 6154 | return mSafeMode; |
| 6155 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6156 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6157 | public void systemReady() { |
| 6158 | mPolicy.systemReady(); |
| 6159 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6160 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6161 | private final class InputDispatcherThread extends Thread { |
| 6162 | // Time to wait when there is nothing to do: 9999 seconds. |
| 6163 | static final int LONG_WAIT=9999*1000; |
| 6164 | |
| 6165 | public InputDispatcherThread() { |
| 6166 | super("InputDispatcher"); |
| 6167 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6168 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6169 | @Override |
| 6170 | public void run() { |
| 6171 | while (true) { |
| 6172 | try { |
| 6173 | process(); |
| 6174 | } catch (Exception e) { |
| 6175 | Log.e(TAG, "Exception in input dispatcher", e); |
| 6176 | } |
| 6177 | } |
| 6178 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6179 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6180 | private void process() { |
| 6181 | android.os.Process.setThreadPriority( |
| 6182 | android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6183 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6184 | // The last key event we saw |
| 6185 | KeyEvent lastKey = null; |
| 6186 | |
| 6187 | // Last keydown time for auto-repeating keys |
| 6188 | long lastKeyTime = SystemClock.uptimeMillis(); |
| 6189 | long nextKeyTime = lastKeyTime+LONG_WAIT; |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6190 | long downTime = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6191 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6192 | // How many successive repeats we generated |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6193 | int keyRepeatCount = 0; |
| 6194 | |
| 6195 | // Need to report that configuration has changed? |
| 6196 | boolean configChanged = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6197 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6198 | while (true) { |
| 6199 | long curTime = SystemClock.uptimeMillis(); |
| 6200 | |
| 6201 | if (DEBUG_INPUT) Log.v( |
| 6202 | TAG, "Waiting for next key: now=" + curTime |
| 6203 | + ", repeat @ " + nextKeyTime); |
| 6204 | |
| 6205 | // Retrieve next event, waiting only as long as the next |
| 6206 | // repeat timeout. If the configuration has changed, then |
| 6207 | // don't wait at all -- we'll report the change as soon as |
| 6208 | // we have processed all events. |
| 6209 | QueuedEvent ev = mQueue.getEvent( |
| 6210 | (int)((!configChanged && curTime < nextKeyTime) |
| 6211 | ? (nextKeyTime-curTime) : 0)); |
| 6212 | |
| 6213 | if (DEBUG_INPUT && ev != null) Log.v( |
| 6214 | TAG, "Event: type=" + ev.classType + " data=" + ev.event); |
| 6215 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6216 | if (MEASURE_LATENCY) { |
| 6217 | lt.sample("2 got event ", System.nanoTime() - ev.whenNano); |
| 6218 | } |
| 6219 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6220 | try { |
| 6221 | if (ev != null) { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6222 | curTime = SystemClock.uptimeMillis(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6223 | int eventType; |
| 6224 | if (ev.classType == RawInputEvent.CLASS_TOUCHSCREEN) { |
| 6225 | eventType = eventType((MotionEvent)ev.event); |
| 6226 | } else if (ev.classType == RawInputEvent.CLASS_KEYBOARD || |
| 6227 | ev.classType == RawInputEvent.CLASS_TRACKBALL) { |
| 6228 | eventType = LocalPowerManager.BUTTON_EVENT; |
| 6229 | } else { |
| 6230 | eventType = LocalPowerManager.OTHER_EVENT; |
| 6231 | } |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6232 | try { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6233 | if ((curTime - mLastBatteryStatsCallTime) |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6234 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6235 | mLastBatteryStatsCallTime = curTime; |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6236 | mBatteryStats.noteInputEvent(); |
| 6237 | } |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6238 | } catch (RemoteException e) { |
| 6239 | // Ignore |
| 6240 | } |
| Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 6241 | |
| 6242 | if (eventType != TOUCH_EVENT |
| 6243 | && eventType != LONG_TOUCH_EVENT |
| 6244 | && eventType != CHEEK_EVENT) { |
| 6245 | mPowerManager.userActivity(curTime, false, |
| 6246 | eventType, false); |
| 6247 | } else if (mLastTouchEventType != eventType |
| 6248 | || (curTime - mLastUserActivityCallTime) |
| 6249 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 6250 | mLastUserActivityCallTime = curTime; |
| 6251 | mLastTouchEventType = eventType; |
| 6252 | mPowerManager.userActivity(curTime, false, |
| 6253 | eventType, false); |
| 6254 | } |
| 6255 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6256 | switch (ev.classType) { |
| 6257 | case RawInputEvent.CLASS_KEYBOARD: |
| 6258 | KeyEvent ke = (KeyEvent)ev.event; |
| 6259 | if (ke.isDown()) { |
| 6260 | lastKey = ke; |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6261 | downTime = curTime; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6262 | keyRepeatCount = 0; |
| 6263 | lastKeyTime = curTime; |
| 6264 | nextKeyTime = lastKeyTime |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6265 | + ViewConfiguration.getLongPressTimeout(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6266 | if (DEBUG_INPUT) Log.v( |
| 6267 | TAG, "Received key down: first repeat @ " |
| 6268 | + nextKeyTime); |
| 6269 | } else { |
| 6270 | lastKey = null; |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6271 | downTime = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6272 | // Arbitrary long timeout. |
| 6273 | lastKeyTime = curTime; |
| 6274 | nextKeyTime = curTime + LONG_WAIT; |
| 6275 | if (DEBUG_INPUT) Log.v( |
| 6276 | TAG, "Received key up: ignore repeat @ " |
| 6277 | + nextKeyTime); |
| 6278 | } |
| 6279 | dispatchKey((KeyEvent)ev.event, 0, 0); |
| 6280 | mQueue.recycleEvent(ev); |
| 6281 | break; |
| 6282 | case RawInputEvent.CLASS_TOUCHSCREEN: |
| 6283 | //Log.i(TAG, "Read next event " + ev); |
| 6284 | dispatchPointer(ev, (MotionEvent)ev.event, 0, 0); |
| 6285 | break; |
| 6286 | case RawInputEvent.CLASS_TRACKBALL: |
| 6287 | dispatchTrackball(ev, (MotionEvent)ev.event, 0, 0); |
| 6288 | break; |
| 6289 | case RawInputEvent.CLASS_CONFIGURATION_CHANGED: |
| 6290 | configChanged = true; |
| 6291 | break; |
| 6292 | default: |
| 6293 | mQueue.recycleEvent(ev); |
| 6294 | break; |
| 6295 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6296 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6297 | } else if (configChanged) { |
| 6298 | configChanged = false; |
| 6299 | sendNewConfiguration(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6300 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6301 | } else if (lastKey != null) { |
| 6302 | curTime = SystemClock.uptimeMillis(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6303 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6304 | // Timeout occurred while key was down. If it is at or |
| 6305 | // past the key repeat time, dispatch the repeat. |
| 6306 | if (DEBUG_INPUT) Log.v( |
| 6307 | TAG, "Key timeout: repeat=" + nextKeyTime |
| 6308 | + ", now=" + curTime); |
| 6309 | if (curTime < nextKeyTime) { |
| 6310 | continue; |
| 6311 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6312 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6313 | lastKeyTime = nextKeyTime; |
| 6314 | nextKeyTime = nextKeyTime + KEY_REPEAT_DELAY; |
| 6315 | keyRepeatCount++; |
| 6316 | if (DEBUG_INPUT) Log.v( |
| 6317 | TAG, "Key repeat: count=" + keyRepeatCount |
| 6318 | + ", next @ " + nextKeyTime); |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6319 | KeyEvent newEvent; |
| 6320 | if (downTime != 0 && (downTime |
| 6321 | + ViewConfiguration.getLongPressTimeout()) |
| 6322 | <= curTime) { |
| 6323 | newEvent = KeyEvent.changeTimeRepeat(lastKey, |
| 6324 | curTime, keyRepeatCount, |
| 6325 | lastKey.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 6326 | downTime = 0; |
| 6327 | } else { |
| 6328 | newEvent = KeyEvent.changeTimeRepeat(lastKey, |
| 6329 | curTime, keyRepeatCount); |
| 6330 | } |
| 6331 | dispatchKey(newEvent, 0, 0); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6332 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6333 | } else { |
| 6334 | curTime = SystemClock.uptimeMillis(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6335 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6336 | lastKeyTime = curTime; |
| 6337 | nextKeyTime = curTime + LONG_WAIT; |
| 6338 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6339 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6340 | } catch (Exception e) { |
| 6341 | Log.e(TAG, |
| 6342 | "Input thread received uncaught exception: " + e, e); |
| 6343 | } |
| 6344 | } |
| 6345 | } |
| 6346 | } |
| 6347 | |
| 6348 | // ------------------------------------------------------------- |
| 6349 | // Client Session State |
| 6350 | // ------------------------------------------------------------- |
| 6351 | |
| 6352 | private final class Session extends IWindowSession.Stub |
| 6353 | implements IBinder.DeathRecipient { |
| 6354 | final IInputMethodClient mClient; |
| 6355 | final IInputContext mInputContext; |
| 6356 | final int mUid; |
| 6357 | final int mPid; |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6358 | final String mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6359 | SurfaceSession mSurfaceSession; |
| 6360 | int mNumWindow = 0; |
| 6361 | boolean mClientDead = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6362 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6363 | /** |
| 6364 | * Current pointer move event being dispatched to client window... must |
| 6365 | * hold key lock to access. |
| 6366 | */ |
| 6367 | QueuedEvent mPendingPointerMove; |
| 6368 | WindowState mPendingPointerWindow; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6369 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6370 | /** |
| 6371 | * Current trackball move event being dispatched to client window... must |
| 6372 | * hold key lock to access. |
| 6373 | */ |
| 6374 | QueuedEvent mPendingTrackballMove; |
| 6375 | WindowState mPendingTrackballWindow; |
| 6376 | |
| 6377 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 6378 | mClient = client; |
| 6379 | mInputContext = inputContext; |
| 6380 | mUid = Binder.getCallingUid(); |
| 6381 | mPid = Binder.getCallingPid(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6382 | StringBuilder sb = new StringBuilder(); |
| 6383 | sb.append("Session{"); |
| 6384 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 6385 | sb.append(" uid "); |
| 6386 | sb.append(mUid); |
| 6387 | sb.append("}"); |
| 6388 | mStringName = sb.toString(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6389 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6390 | synchronized (mWindowMap) { |
| 6391 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 6392 | IBinder b = ServiceManager.getService( |
| 6393 | Context.INPUT_METHOD_SERVICE); |
| 6394 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 6395 | } |
| 6396 | } |
| 6397 | long ident = Binder.clearCallingIdentity(); |
| 6398 | try { |
| 6399 | // Note: it is safe to call in to the input method manager |
| 6400 | // here because we are not holding our lock. |
| 6401 | if (mInputMethodManager != null) { |
| 6402 | mInputMethodManager.addClient(client, inputContext, |
| 6403 | mUid, mPid); |
| 6404 | } else { |
| 6405 | client.setUsingInputMethod(false); |
| 6406 | } |
| 6407 | client.asBinder().linkToDeath(this, 0); |
| 6408 | } catch (RemoteException e) { |
| 6409 | // The caller has died, so we can just forget about this. |
| 6410 | try { |
| 6411 | if (mInputMethodManager != null) { |
| 6412 | mInputMethodManager.removeClient(client); |
| 6413 | } |
| 6414 | } catch (RemoteException ee) { |
| 6415 | } |
| 6416 | } finally { |
| 6417 | Binder.restoreCallingIdentity(ident); |
| 6418 | } |
| 6419 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6420 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6421 | @Override |
| 6422 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 6423 | throws RemoteException { |
| 6424 | try { |
| 6425 | return super.onTransact(code, data, reply, flags); |
| 6426 | } catch (RuntimeException e) { |
| 6427 | // Log all 'real' exceptions thrown to the caller |
| 6428 | if (!(e instanceof SecurityException)) { |
| 6429 | Log.e(TAG, "Window Session Crash", e); |
| 6430 | } |
| 6431 | throw e; |
| 6432 | } |
| 6433 | } |
| 6434 | |
| 6435 | public void binderDied() { |
| 6436 | // Note: it is safe to call in to the input method manager |
| 6437 | // here because we are not holding our lock. |
| 6438 | try { |
| 6439 | if (mInputMethodManager != null) { |
| 6440 | mInputMethodManager.removeClient(mClient); |
| 6441 | } |
| 6442 | } catch (RemoteException e) { |
| 6443 | } |
| 6444 | synchronized(mWindowMap) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 6445 | mClient.asBinder().unlinkToDeath(this, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6446 | mClientDead = true; |
| 6447 | killSessionLocked(); |
| 6448 | } |
| 6449 | } |
| 6450 | |
| 6451 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
| 6452 | int viewVisibility, Rect outContentInsets) { |
| 6453 | return addWindow(this, window, attrs, viewVisibility, outContentInsets); |
| 6454 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6455 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6456 | public void remove(IWindow window) { |
| 6457 | removeWindow(this, window); |
| 6458 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6459 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6460 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 6461 | int requestedWidth, int requestedHeight, int viewFlags, |
| 6462 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
| 6463 | Rect outVisibleInsets, Surface outSurface) { |
| 6464 | return relayoutWindow(this, window, attrs, |
| 6465 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
| 6466 | outFrame, outContentInsets, outVisibleInsets, outSurface); |
| 6467 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6468 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6469 | public void setTransparentRegion(IWindow window, Region region) { |
| 6470 | setTransparentRegionWindow(this, window, region); |
| 6471 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6472 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6473 | public void setInsets(IWindow window, int touchableInsets, |
| 6474 | Rect contentInsets, Rect visibleInsets) { |
| 6475 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 6476 | visibleInsets); |
| 6477 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6478 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6479 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 6480 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 6481 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6482 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6483 | public void finishDrawing(IWindow window) { |
| 6484 | if (localLOGV) Log.v( |
| 6485 | TAG, "IWindow finishDrawing called for " + window); |
| 6486 | finishDrawingWindow(this, window); |
| 6487 | } |
| 6488 | |
| 6489 | public void finishKey(IWindow window) { |
| 6490 | if (localLOGV) Log.v( |
| 6491 | TAG, "IWindow finishKey called for " + window); |
| 6492 | mKeyWaiter.finishedKey(this, window, false, |
| 6493 | KeyWaiter.RETURN_NOTHING); |
| 6494 | } |
| 6495 | |
| 6496 | public MotionEvent getPendingPointerMove(IWindow window) { |
| 6497 | if (localLOGV) Log.v( |
| 6498 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 6499 | return mKeyWaiter.finishedKey(this, window, false, |
| 6500 | KeyWaiter.RETURN_PENDING_POINTER); |
| 6501 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6502 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6503 | public MotionEvent getPendingTrackballMove(IWindow window) { |
| 6504 | if (localLOGV) Log.v( |
| 6505 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 6506 | return mKeyWaiter.finishedKey(this, window, false, |
| 6507 | KeyWaiter.RETURN_PENDING_TRACKBALL); |
| 6508 | } |
| 6509 | |
| 6510 | public void setInTouchMode(boolean mode) { |
| 6511 | synchronized(mWindowMap) { |
| 6512 | mInTouchMode = mode; |
| 6513 | } |
| 6514 | } |
| 6515 | |
| 6516 | public boolean getInTouchMode() { |
| 6517 | synchronized(mWindowMap) { |
| 6518 | return mInTouchMode; |
| 6519 | } |
| 6520 | } |
| 6521 | |
| 6522 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 6523 | boolean always) { |
| 6524 | synchronized(mWindowMap) { |
| 6525 | long ident = Binder.clearCallingIdentity(); |
| 6526 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6527 | return mPolicy.performHapticFeedbackLw( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6528 | windowForClientLocked(this, window), effectId, always); |
| 6529 | } finally { |
| 6530 | Binder.restoreCallingIdentity(ident); |
| 6531 | } |
| 6532 | } |
| 6533 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6534 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6535 | public void setWallpaperPosition(IBinder window, float x, float y) { |
| 6536 | synchronized(mWindowMap) { |
| 6537 | long ident = Binder.clearCallingIdentity(); |
| 6538 | try { |
| 6539 | setWindowWallpaperPositionLocked(windowForClientLocked(this, window), |
| 6540 | x, y); |
| 6541 | } finally { |
| 6542 | Binder.restoreCallingIdentity(ident); |
| 6543 | } |
| 6544 | } |
| 6545 | } |
| 6546 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6547 | public void wallpaperOffsetsComplete(IBinder window) { |
| 6548 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 6549 | } |
| 6550 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6551 | void windowAddedLocked() { |
| 6552 | if (mSurfaceSession == null) { |
| 6553 | if (localLOGV) Log.v( |
| 6554 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 6555 | mSurfaceSession = new SurfaceSession(); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6556 | if (SHOW_TRANSACTIONS) Log.i( |
| 6557 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6558 | mSessions.add(this); |
| 6559 | } |
| 6560 | mNumWindow++; |
| 6561 | } |
| 6562 | |
| 6563 | void windowRemovedLocked() { |
| 6564 | mNumWindow--; |
| 6565 | killSessionLocked(); |
| 6566 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6567 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6568 | void killSessionLocked() { |
| 6569 | if (mNumWindow <= 0 && mClientDead) { |
| 6570 | mSessions.remove(this); |
| 6571 | if (mSurfaceSession != null) { |
| 6572 | if (localLOGV) Log.v( |
| 6573 | TAG, "Last window removed from " + this |
| 6574 | + ", destroying " + mSurfaceSession); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6575 | if (SHOW_TRANSACTIONS) Log.i( |
| 6576 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6577 | try { |
| 6578 | mSurfaceSession.kill(); |
| 6579 | } catch (Exception e) { |
| 6580 | Log.w(TAG, "Exception thrown when killing surface session " |
| 6581 | + mSurfaceSession + " in session " + this |
| 6582 | + ": " + e.toString()); |
| 6583 | } |
| 6584 | mSurfaceSession = null; |
| 6585 | } |
| 6586 | } |
| 6587 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6588 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6589 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6590 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 6591 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 6592 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
| 6593 | if (mPendingPointerWindow != null || mPendingPointerMove != null) { |
| 6594 | pw.print(prefix); |
| 6595 | pw.print("mPendingPointerWindow="); pw.print(mPendingPointerWindow); |
| 6596 | pw.print(" mPendingPointerMove="); pw.println(mPendingPointerMove); |
| 6597 | } |
| 6598 | if (mPendingTrackballWindow != null || mPendingTrackballMove != null) { |
| 6599 | pw.print(prefix); |
| 6600 | pw.print("mPendingTrackballWindow="); pw.print(mPendingTrackballWindow); |
| 6601 | pw.print(" mPendingTrackballMove="); pw.println(mPendingTrackballMove); |
| 6602 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6603 | } |
| 6604 | |
| 6605 | @Override |
| 6606 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6607 | return mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6608 | } |
| 6609 | } |
| 6610 | |
| 6611 | // ------------------------------------------------------------- |
| 6612 | // Client Window State |
| 6613 | // ------------------------------------------------------------- |
| 6614 | |
| 6615 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 6616 | final Session mSession; |
| 6617 | final IWindow mClient; |
| 6618 | WindowToken mToken; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6619 | WindowToken mRootToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6620 | AppWindowToken mAppToken; |
| 6621 | AppWindowToken mTargetAppToken; |
| 6622 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 6623 | final DeathRecipient mDeathRecipient; |
| 6624 | final WindowState mAttachedWindow; |
| 6625 | final ArrayList mChildWindows = new ArrayList(); |
| 6626 | final int mBaseLayer; |
| 6627 | final int mSubLayer; |
| 6628 | final boolean mLayoutAttached; |
| 6629 | final boolean mIsImWindow; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6630 | final boolean mIsWallpaper; |
| 6631 | final boolean mIsFloatingLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6632 | int mViewVisibility; |
| 6633 | boolean mPolicyVisibility = true; |
| 6634 | boolean mPolicyVisibilityAfterAnim = true; |
| 6635 | boolean mAppFreezing; |
| 6636 | Surface mSurface; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6637 | boolean mReportDestroySurface; |
| 6638 | boolean mSurfacePendingDestroy; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6639 | boolean mAttachedHidden; // is our parent window hidden? |
| 6640 | boolean mLastHidden; // was this window last hidden? |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6641 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6642 | int mRequestedWidth; |
| 6643 | int mRequestedHeight; |
| 6644 | int mLastRequestedWidth; |
| 6645 | int mLastRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6646 | int mLayer; |
| 6647 | int mAnimLayer; |
| 6648 | int mLastLayer; |
| 6649 | boolean mHaveFrame; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6650 | boolean mObscured; |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 6651 | boolean mTurnOnScreen; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6652 | |
| 6653 | WindowState mNextOutsideTouch; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6654 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6655 | // Actual frame shown on-screen (may be modified by animation) |
| 6656 | final Rect mShownFrame = new Rect(); |
| 6657 | final Rect mLastShownFrame = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6658 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6659 | /** |
| 6660 | * Insets that determine the actually visible area |
| 6661 | */ |
| 6662 | final Rect mVisibleInsets = new Rect(); |
| 6663 | final Rect mLastVisibleInsets = new Rect(); |
| 6664 | boolean mVisibleInsetsChanged; |
| 6665 | |
| 6666 | /** |
| 6667 | * Insets that are covered by system windows |
| 6668 | */ |
| 6669 | final Rect mContentInsets = new Rect(); |
| 6670 | final Rect mLastContentInsets = new Rect(); |
| 6671 | boolean mContentInsetsChanged; |
| 6672 | |
| 6673 | /** |
| 6674 | * Set to true if we are waiting for this window to receive its |
| 6675 | * given internal insets before laying out other windows based on it. |
| 6676 | */ |
| 6677 | boolean mGivenInsetsPending; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6678 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6679 | /** |
| 6680 | * These are the content insets that were given during layout for |
| 6681 | * this window, to be applied to windows behind it. |
| 6682 | */ |
| 6683 | final Rect mGivenContentInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6684 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6685 | /** |
| 6686 | * These are the visible insets that were given during layout for |
| 6687 | * this window, to be applied to windows behind it. |
| 6688 | */ |
| 6689 | final Rect mGivenVisibleInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6690 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6691 | /** |
| 6692 | * Flag indicating whether the touchable region should be adjusted by |
| 6693 | * the visible insets; if false the area outside the visible insets is |
| 6694 | * NOT touchable, so we must use those to adjust the frame during hit |
| 6695 | * tests. |
| 6696 | */ |
| 6697 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6698 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6699 | // Current transformation being applied. |
| 6700 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 6701 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 6702 | float mHScale=1, mVScale=1; |
| 6703 | float mLastHScale=1, mLastVScale=1; |
| 6704 | final Matrix mTmpMatrix = new Matrix(); |
| 6705 | |
| 6706 | // "Real" frame that the application sees. |
| 6707 | final Rect mFrame = new Rect(); |
| 6708 | final Rect mLastFrame = new Rect(); |
| 6709 | |
| 6710 | final Rect mContainingFrame = new Rect(); |
| 6711 | final Rect mDisplayFrame = new Rect(); |
| 6712 | final Rect mContentFrame = new Rect(); |
| 6713 | final Rect mVisibleFrame = new Rect(); |
| 6714 | |
| 6715 | float mShownAlpha = 1; |
| 6716 | float mAlpha = 1; |
| 6717 | float mLastAlpha = 1; |
| 6718 | |
| 6719 | // Set to true if, when the window gets displayed, it should perform |
| 6720 | // an enter animation. |
| 6721 | boolean mEnterAnimationPending; |
| 6722 | |
| 6723 | // Currently running animation. |
| 6724 | boolean mAnimating; |
| 6725 | boolean mLocalAnimating; |
| 6726 | Animation mAnimation; |
| 6727 | boolean mAnimationIsEntrance; |
| 6728 | boolean mHasTransformation; |
| 6729 | boolean mHasLocalTransformation; |
| 6730 | final Transformation mTransformation = new Transformation(); |
| 6731 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6732 | // If a window showing a wallpaper: the requested offset for the |
| 6733 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 6734 | float mWallpaperX = -1; |
| 6735 | float mWallpaperY = -1; |
| 6736 | |
| 6737 | // Wallpaper windows: pixels offset based on above variables. |
| 6738 | int mXOffset; |
| 6739 | int mYOffset; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6740 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6741 | // This is set after IWindowSession.relayout() has been called at |
| 6742 | // least once for the window. It allows us to detect the situation |
| 6743 | // where we don't yet have a surface, but should have one soon, so |
| 6744 | // we can give the window focus before waiting for the relayout. |
| 6745 | boolean mRelayoutCalled; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6746 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6747 | // This is set after the Surface has been created but before the |
| 6748 | // window has been drawn. During this time the surface is hidden. |
| 6749 | boolean mDrawPending; |
| 6750 | |
| 6751 | // This is set after the window has finished drawing for the first |
| 6752 | // time but before its surface is shown. The surface will be |
| 6753 | // displayed when the next layout is run. |
| 6754 | boolean mCommitDrawPending; |
| 6755 | |
| 6756 | // This is set during the time after the window's drawing has been |
| 6757 | // committed, and before its surface is actually shown. It is used |
| 6758 | // to delay showing the surface until all windows in a token are ready |
| 6759 | // to be shown. |
| 6760 | boolean mReadyToShow; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6761 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6762 | // Set when the window has been shown in the screen the first time. |
| 6763 | boolean mHasDrawn; |
| 6764 | |
| 6765 | // Currently running an exit animation? |
| 6766 | boolean mExiting; |
| 6767 | |
| 6768 | // Currently on the mDestroySurface list? |
| 6769 | boolean mDestroying; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6770 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6771 | // Completely remove from window manager after exit animation? |
| 6772 | boolean mRemoveOnExit; |
| 6773 | |
| 6774 | // Set when the orientation is changing and this window has not yet |
| 6775 | // been updated for the new orientation. |
| 6776 | boolean mOrientationChanging; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6777 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6778 | // Is this window now (or just being) removed? |
| 6779 | boolean mRemoved; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6780 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6781 | WindowState(Session s, IWindow c, WindowToken token, |
| 6782 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 6783 | int viewVisibility) { |
| 6784 | mSession = s; |
| 6785 | mClient = c; |
| 6786 | mToken = token; |
| 6787 | mAttrs.copyFrom(a); |
| 6788 | mViewVisibility = viewVisibility; |
| 6789 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 6790 | mAlpha = a.alpha; |
| 6791 | if (localLOGV) Log.v( |
| 6792 | TAG, "Window " + this + " client=" + c.asBinder() |
| 6793 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 6794 | try { |
| 6795 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 6796 | } catch (RemoteException e) { |
| 6797 | mDeathRecipient = null; |
| 6798 | mAttachedWindow = null; |
| 6799 | mLayoutAttached = false; |
| 6800 | mIsImWindow = false; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6801 | mIsWallpaper = false; |
| 6802 | mIsFloatingLayer = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6803 | mBaseLayer = 0; |
| 6804 | mSubLayer = 0; |
| 6805 | return; |
| 6806 | } |
| 6807 | mDeathRecipient = deathRecipient; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6808 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6809 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 6810 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 6811 | // The multiplier here is to reserve space for multiple |
| 6812 | // windows in the same type layer. |
| 6813 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 6814 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 6815 | + TYPE_LAYER_OFFSET; |
| 6816 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 6817 | mAttachedWindow = attachedWindow; |
| 6818 | mAttachedWindow.mChildWindows.add(this); |
| 6819 | mLayoutAttached = mAttrs.type != |
| 6820 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 6821 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 6822 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6823 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 6824 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6825 | } else { |
| 6826 | // The multiplier here is to reserve space for multiple |
| 6827 | // windows in the same type layer. |
| 6828 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 6829 | * TYPE_LAYER_MULTIPLIER |
| 6830 | + TYPE_LAYER_OFFSET; |
| 6831 | mSubLayer = 0; |
| 6832 | mAttachedWindow = null; |
| 6833 | mLayoutAttached = false; |
| 6834 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 6835 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6836 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 6837 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6838 | } |
| 6839 | |
| 6840 | WindowState appWin = this; |
| 6841 | while (appWin.mAttachedWindow != null) { |
| 6842 | appWin = mAttachedWindow; |
| 6843 | } |
| 6844 | WindowToken appToken = appWin.mToken; |
| 6845 | while (appToken.appWindowToken == null) { |
| 6846 | WindowToken parent = mTokenMap.get(appToken.token); |
| 6847 | if (parent == null || appToken == parent) { |
| 6848 | break; |
| 6849 | } |
| 6850 | appToken = parent; |
| 6851 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6852 | mRootToken = appToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6853 | mAppToken = appToken.appWindowToken; |
| 6854 | |
| 6855 | mSurface = null; |
| 6856 | mRequestedWidth = 0; |
| 6857 | mRequestedHeight = 0; |
| 6858 | mLastRequestedWidth = 0; |
| 6859 | mLastRequestedHeight = 0; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6860 | mXOffset = 0; |
| 6861 | mYOffset = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6862 | mLayer = 0; |
| 6863 | mAnimLayer = 0; |
| 6864 | mLastLayer = 0; |
| 6865 | } |
| 6866 | |
| 6867 | void attach() { |
| 6868 | if (localLOGV) Log.v( |
| 6869 | TAG, "Attaching " + this + " token=" + mToken |
| 6870 | + ", list=" + mToken.windows); |
| 6871 | mSession.windowAddedLocked(); |
| 6872 | } |
| 6873 | |
| 6874 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 6875 | mHaveFrame = true; |
| 6876 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6877 | final Rect container = mContainingFrame; |
| 6878 | container.set(pf); |
| 6879 | |
| 6880 | final Rect display = mDisplayFrame; |
| 6881 | display.set(df); |
| 6882 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6883 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6884 | container.intersect(mCompatibleScreenFrame); |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6885 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 6886 | display.intersect(mCompatibleScreenFrame); |
| 6887 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6888 | } |
| 6889 | |
| 6890 | final int pw = container.right - container.left; |
| 6891 | final int ph = container.bottom - container.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6892 | |
| 6893 | int w,h; |
| 6894 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 6895 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 6896 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 6897 | } else { |
| 6898 | w = mAttrs.width == mAttrs.FILL_PARENT ? pw : mRequestedWidth; |
| 6899 | h = mAttrs.height== mAttrs.FILL_PARENT ? ph : mRequestedHeight; |
| 6900 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6901 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6902 | final Rect content = mContentFrame; |
| 6903 | content.set(cf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6904 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6905 | final Rect visible = mVisibleFrame; |
| 6906 | visible.set(vf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6907 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6908 | final Rect frame = mFrame; |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6909 | final int fw = frame.width(); |
| 6910 | final int fh = frame.height(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6911 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6912 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 6913 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 6914 | |
| 6915 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 6916 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 6917 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 6918 | |
| 6919 | //System.out.println("Out: " + mFrame); |
| 6920 | |
| 6921 | // Now make sure the window fits in the overall display. |
| 6922 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6923 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6924 | // Make sure the content and visible frames are inside of the |
| 6925 | // final window frame. |
| 6926 | if (content.left < frame.left) content.left = frame.left; |
| 6927 | if (content.top < frame.top) content.top = frame.top; |
| 6928 | if (content.right > frame.right) content.right = frame.right; |
| 6929 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 6930 | if (visible.left < frame.left) visible.left = frame.left; |
| 6931 | if (visible.top < frame.top) visible.top = frame.top; |
| 6932 | if (visible.right > frame.right) visible.right = frame.right; |
| 6933 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6934 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6935 | final Rect contentInsets = mContentInsets; |
| 6936 | contentInsets.left = content.left-frame.left; |
| 6937 | contentInsets.top = content.top-frame.top; |
| 6938 | contentInsets.right = frame.right-content.right; |
| 6939 | contentInsets.bottom = frame.bottom-content.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6940 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6941 | final Rect visibleInsets = mVisibleInsets; |
| 6942 | visibleInsets.left = visible.left-frame.left; |
| 6943 | visibleInsets.top = visible.top-frame.top; |
| 6944 | visibleInsets.right = frame.right-visible.right; |
| 6945 | visibleInsets.bottom = frame.bottom-visible.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6946 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 6947 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 6948 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6949 | mDisplay.getHeight(), false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6950 | } |
| 6951 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6952 | if (localLOGV) { |
| 6953 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 6954 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
| 6955 | Log.v(TAG, "Resolving (mRequestedWidth=" |
| 6956 | + mRequestedWidth + ", mRequestedheight=" |
| 6957 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 6958 | + "): frame=" + mFrame.toShortString() |
| 6959 | + " ci=" + contentInsets.toShortString() |
| 6960 | + " vi=" + visibleInsets.toShortString()); |
| 6961 | //} |
| 6962 | } |
| 6963 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6964 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6965 | public Rect getFrameLw() { |
| 6966 | return mFrame; |
| 6967 | } |
| 6968 | |
| 6969 | public Rect getShownFrameLw() { |
| 6970 | return mShownFrame; |
| 6971 | } |
| 6972 | |
| 6973 | public Rect getDisplayFrameLw() { |
| 6974 | return mDisplayFrame; |
| 6975 | } |
| 6976 | |
| 6977 | public Rect getContentFrameLw() { |
| 6978 | return mContentFrame; |
| 6979 | } |
| 6980 | |
| 6981 | public Rect getVisibleFrameLw() { |
| 6982 | return mVisibleFrame; |
| 6983 | } |
| 6984 | |
| 6985 | public boolean getGivenInsetsPendingLw() { |
| 6986 | return mGivenInsetsPending; |
| 6987 | } |
| 6988 | |
| 6989 | public Rect getGivenContentInsetsLw() { |
| 6990 | return mGivenContentInsets; |
| 6991 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6992 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6993 | public Rect getGivenVisibleInsetsLw() { |
| 6994 | return mGivenVisibleInsets; |
| 6995 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6996 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6997 | public WindowManager.LayoutParams getAttrs() { |
| 6998 | return mAttrs; |
| 6999 | } |
| 7000 | |
| 7001 | public int getSurfaceLayer() { |
| 7002 | return mLayer; |
| 7003 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7004 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7005 | public IApplicationToken getAppToken() { |
| 7006 | return mAppToken != null ? mAppToken.appToken : null; |
| 7007 | } |
| 7008 | |
| 7009 | public boolean hasAppShownWindows() { |
| 7010 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 7011 | } |
| 7012 | |
| 7013 | public boolean hasAppStartingIcon() { |
| 7014 | return mAppToken != null ? (mAppToken.startingData != null) : false; |
| 7015 | } |
| 7016 | |
| 7017 | public WindowManagerPolicy.WindowState getAppStartingWindow() { |
| 7018 | return mAppToken != null ? mAppToken.startingWindow : null; |
| 7019 | } |
| 7020 | |
| 7021 | public void setAnimation(Animation anim) { |
| 7022 | if (localLOGV) Log.v( |
| 7023 | TAG, "Setting animation in " + this + ": " + anim); |
| 7024 | mAnimating = false; |
| 7025 | mLocalAnimating = false; |
| 7026 | mAnimation = anim; |
| 7027 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 7028 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 7029 | } |
| 7030 | |
| 7031 | public void clearAnimation() { |
| 7032 | if (mAnimation != null) { |
| 7033 | mAnimating = true; |
| 7034 | mLocalAnimating = false; |
| 7035 | mAnimation = null; |
| 7036 | } |
| 7037 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7038 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7039 | Surface createSurfaceLocked() { |
| 7040 | if (mSurface == null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7041 | mReportDestroySurface = false; |
| 7042 | mSurfacePendingDestroy = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7043 | mDrawPending = true; |
| 7044 | mCommitDrawPending = false; |
| 7045 | mReadyToShow = false; |
| 7046 | if (mAppToken != null) { |
| 7047 | mAppToken.allDrawn = false; |
| 7048 | } |
| 7049 | |
| 7050 | int flags = 0; |
| Mathias Agopian | 317a628 | 2009-08-13 17:29:02 -0700 | [diff] [blame] | 7051 | if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7052 | flags |= Surface.PUSH_BUFFERS; |
| 7053 | } |
| 7054 | |
| 7055 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 7056 | flags |= Surface.SECURE; |
| 7057 | } |
| 7058 | if (DEBUG_VISIBILITY) Log.v( |
| 7059 | TAG, "Creating surface in session " |
| 7060 | + mSession.mSurfaceSession + " window " + this |
| 7061 | + " w=" + mFrame.width() |
| 7062 | + " h=" + mFrame.height() + " format=" |
| 7063 | + mAttrs.format + " flags=" + flags); |
| 7064 | |
| 7065 | int w = mFrame.width(); |
| 7066 | int h = mFrame.height(); |
| 7067 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 7068 | // for a scaled surface, we always want the requested |
| 7069 | // size. |
| 7070 | w = mRequestedWidth; |
| 7071 | h = mRequestedHeight; |
| 7072 | } |
| 7073 | |
| Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 7074 | // Something is wrong and SurfaceFlinger will not like this, |
| 7075 | // try to revert to sane values |
| 7076 | if (w <= 0) w = 1; |
| 7077 | if (h <= 0) h = 1; |
| 7078 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7079 | try { |
| 7080 | mSurface = new Surface( |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7081 | mSession.mSurfaceSession, mSession.mPid, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7082 | 0, w, h, mAttrs.format, flags); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7083 | if (SHOW_TRANSACTIONS) Log.i(TAG, " CREATE SURFACE " |
| 7084 | + mSurface + " IN SESSION " |
| 7085 | + mSession.mSurfaceSession |
| 7086 | + ": pid=" + mSession.mPid + " format=" |
| 7087 | + mAttrs.format + " flags=0x" |
| 7088 | + Integer.toHexString(flags)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7089 | } catch (Surface.OutOfResourcesException e) { |
| 7090 | Log.w(TAG, "OutOfResourcesException creating surface"); |
| 7091 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 7092 | return null; |
| 7093 | } catch (Exception e) { |
| 7094 | Log.e(TAG, "Exception creating surface", e); |
| 7095 | return null; |
| 7096 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7097 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7098 | if (localLOGV) Log.v( |
| 7099 | TAG, "Got surface: " + mSurface |
| 7100 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 7101 | + ", animLayer=" + mAnimLayer); |
| 7102 | if (SHOW_TRANSACTIONS) { |
| 7103 | Log.i(TAG, ">>> OPEN TRANSACTION"); |
| 7104 | Log.i(TAG, " SURFACE " + mSurface + ": CREATE (" |
| 7105 | + mAttrs.getTitle() + ") pos=(" + |
| 7106 | mFrame.left + "," + mFrame.top + ") (" + |
| 7107 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 7108 | mAnimLayer + " HIDE"); |
| 7109 | } |
| 7110 | Surface.openTransaction(); |
| 7111 | try { |
| 7112 | try { |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7113 | mSurface.setPosition(mFrame.left + mXOffset, |
| 7114 | mFrame.top + mYOffset); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7115 | mSurface.setLayer(mAnimLayer); |
| 7116 | mSurface.hide(); |
| 7117 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7118 | if (SHOW_TRANSACTIONS) Log.i(TAG, " SURFACE " |
| 7119 | + mSurface + ": DITHER"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7120 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 7121 | Surface.SURFACE_DITHER); |
| 7122 | } |
| 7123 | } catch (RuntimeException e) { |
| 7124 | Log.w(TAG, "Error creating surface in " + w, e); |
| 7125 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 7126 | } |
| 7127 | mLastHidden = true; |
| 7128 | } finally { |
| 7129 | if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION"); |
| 7130 | Surface.closeTransaction(); |
| 7131 | } |
| 7132 | if (localLOGV) Log.v( |
| 7133 | TAG, "Created surface " + this); |
| 7134 | } |
| 7135 | return mSurface; |
| 7136 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7137 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7138 | void destroySurfaceLocked() { |
| 7139 | // Window is no longer on-screen, so can no longer receive |
| 7140 | // key events... if we were waiting for it to finish |
| 7141 | // handling a key event, the wait is over! |
| 7142 | mKeyWaiter.finishedKey(mSession, mClient, true, |
| 7143 | KeyWaiter.RETURN_NOTHING); |
| 7144 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 7145 | mKeyWaiter.releasePendingTrackballLocked(mSession); |
| 7146 | |
| 7147 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 7148 | mAppToken.startingDisplayed = false; |
| 7149 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7150 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7151 | if (mSurface != null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7152 | mDrawPending = false; |
| 7153 | mCommitDrawPending = false; |
| 7154 | mReadyToShow = false; |
| 7155 | |
| 7156 | int i = mChildWindows.size(); |
| 7157 | while (i > 0) { |
| 7158 | i--; |
| 7159 | WindowState c = (WindowState)mChildWindows.get(i); |
| 7160 | c.mAttachedHidden = true; |
| 7161 | } |
| 7162 | |
| 7163 | if (mReportDestroySurface) { |
| 7164 | mReportDestroySurface = false; |
| 7165 | mSurfacePendingDestroy = true; |
| 7166 | try { |
| 7167 | mClient.dispatchGetNewSurface(); |
| 7168 | // We'll really destroy on the next time around. |
| 7169 | return; |
| 7170 | } catch (RemoteException e) { |
| 7171 | } |
| 7172 | } |
| 7173 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7174 | try { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7175 | if (DEBUG_VISIBILITY) { |
| 7176 | RuntimeException e = new RuntimeException(); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7177 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7178 | Log.w(TAG, "Window " + this + " destroying surface " |
| 7179 | + mSurface + ", session " + mSession, e); |
| 7180 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7181 | if (SHOW_TRANSACTIONS) { |
| 7182 | RuntimeException ex = new RuntimeException(); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7183 | if (!HIDE_STACK_CRAWLS) ex.fillInStackTrace(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7184 | Log.i(TAG, " SURFACE " + mSurface + ": DESTROY (" |
| 7185 | + mAttrs.getTitle() + ")", ex); |
| 7186 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7187 | mSurface.destroy(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7188 | } catch (RuntimeException e) { |
| 7189 | Log.w(TAG, "Exception thrown when destroying Window " + this |
| 7190 | + " surface " + mSurface + " session " + mSession |
| 7191 | + ": " + e.toString()); |
| 7192 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7193 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7194 | mSurface = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7195 | } |
| 7196 | } |
| 7197 | |
| 7198 | boolean finishDrawingLocked() { |
| 7199 | if (mDrawPending) { |
| 7200 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Log.v( |
| 7201 | TAG, "finishDrawingLocked: " + mSurface); |
| 7202 | mCommitDrawPending = true; |
| 7203 | mDrawPending = false; |
| 7204 | return true; |
| 7205 | } |
| 7206 | return false; |
| 7207 | } |
| 7208 | |
| 7209 | // This must be called while inside a transaction. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7210 | boolean commitFinishDrawingLocked(long currentTime) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7211 | //Log.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
| 7212 | if (!mCommitDrawPending) { |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7213 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7214 | } |
| 7215 | mCommitDrawPending = false; |
| 7216 | mReadyToShow = true; |
| 7217 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 7218 | final AppWindowToken atoken = mAppToken; |
| 7219 | if (atoken == null || atoken.allDrawn || starting) { |
| 7220 | performShowLocked(); |
| 7221 | } |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7222 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7223 | } |
| 7224 | |
| 7225 | // This must be called while inside a transaction. |
| 7226 | boolean performShowLocked() { |
| 7227 | if (DEBUG_VISIBILITY) { |
| 7228 | RuntimeException e = new RuntimeException(); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7229 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7230 | Log.v(TAG, "performShow on " + this |
| 7231 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 7232 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 7233 | } |
| 7234 | if (mReadyToShow && isReadyForDisplay()) { |
| 7235 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Log.i( |
| 7236 | TAG, " SURFACE " + mSurface + ": SHOW (performShowLocked)"); |
| 7237 | if (DEBUG_VISIBILITY) Log.v(TAG, "Showing " + this |
| 7238 | + " during animation: policyVis=" + mPolicyVisibility |
| 7239 | + " attHidden=" + mAttachedHidden |
| 7240 | + " tok.hiddenRequested=" |
| 7241 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7242 | + " tok.hidden=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7243 | + (mAppToken != null ? mAppToken.hidden : false) |
| 7244 | + " animating=" + mAnimating |
| 7245 | + " tok animating=" |
| 7246 | + (mAppToken != null ? mAppToken.animating : false)); |
| 7247 | if (!showSurfaceRobustlyLocked(this)) { |
| 7248 | return false; |
| 7249 | } |
| 7250 | mLastAlpha = -1; |
| 7251 | mHasDrawn = true; |
| 7252 | mLastHidden = false; |
| 7253 | mReadyToShow = false; |
| 7254 | enableScreenIfNeededLocked(); |
| 7255 | |
| 7256 | applyEnterAnimationLocked(this); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7257 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7258 | int i = mChildWindows.size(); |
| 7259 | while (i > 0) { |
| 7260 | i--; |
| 7261 | WindowState c = (WindowState)mChildWindows.get(i); |
| 7262 | if (c.mSurface != null && c.mAttachedHidden) { |
| 7263 | c.mAttachedHidden = false; |
| 7264 | c.performShowLocked(); |
| 7265 | } |
| 7266 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7267 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7268 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 7269 | && mAppToken != null) { |
| 7270 | mAppToken.firstWindowDrawn = true; |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7271 | |
| 7272 | if (mAppToken.startingData != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7273 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Log.v(TAG, |
| 7274 | "Finish starting " + mToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7275 | + ": first real window is shown, no animation"); |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7276 | // If this initial window is animating, stop it -- we |
| 7277 | // will do an animation to reveal it from behind the |
| 7278 | // starting window, so there is no need for it to also |
| 7279 | // be doing its own stuff. |
| 7280 | if (mAnimation != null) { |
| 7281 | mAnimation = null; |
| 7282 | // Make sure we clean up the animation. |
| 7283 | mAnimating = true; |
| 7284 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7285 | mFinishedStarting.add(mAppToken); |
| 7286 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7287 | } |
| 7288 | mAppToken.updateReportedVisibilityLocked(); |
| 7289 | } |
| 7290 | } |
| 7291 | return true; |
| 7292 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7293 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7294 | // This must be called while inside a transaction. Returns true if |
| 7295 | // there is more animation to run. |
| 7296 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| 7297 | if (!mDisplayFrozen) { |
| 7298 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7299 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7300 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 7301 | mHasTransformation = true; |
| 7302 | mHasLocalTransformation = true; |
| 7303 | if (!mLocalAnimating) { |
| 7304 | if (DEBUG_ANIM) Log.v( |
| 7305 | TAG, "Starting animation in " + this + |
| 7306 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 7307 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 7308 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 7309 | mAnimation.setStartTime(currentTime); |
| 7310 | mLocalAnimating = true; |
| 7311 | mAnimating = true; |
| 7312 | } |
| 7313 | mTransformation.clear(); |
| 7314 | final boolean more = mAnimation.getTransformation( |
| 7315 | currentTime, mTransformation); |
| 7316 | if (DEBUG_ANIM) Log.v( |
| 7317 | TAG, "Stepped animation in " + this + |
| 7318 | ": more=" + more + ", xform=" + mTransformation); |
| 7319 | if (more) { |
| 7320 | // we're not done! |
| 7321 | return true; |
| 7322 | } |
| 7323 | if (DEBUG_ANIM) Log.v( |
| 7324 | TAG, "Finished animation in " + this + |
| 7325 | " @ " + currentTime); |
| 7326 | mAnimation = null; |
| 7327 | //WindowManagerService.this.dump(); |
| 7328 | } |
| 7329 | mHasLocalTransformation = false; |
| 7330 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7331 | && mAppToken.animation != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7332 | // When our app token is animating, we kind-of pretend like |
| 7333 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 7334 | // part of this check means that we will only do this if |
| 7335 | // our window is not currently exiting, or it is not |
| 7336 | // locally animating itself. The idea being that one that |
| 7337 | // is exiting and doing a local animation should be removed |
| 7338 | // once that animation is done. |
| 7339 | mAnimating = true; |
| 7340 | mHasTransformation = true; |
| 7341 | mTransformation.clear(); |
| 7342 | return false; |
| 7343 | } else if (mHasTransformation) { |
| 7344 | // Little trick to get through the path below to act like |
| 7345 | // we have finished an animation. |
| 7346 | mAnimating = true; |
| 7347 | } else if (isAnimating()) { |
| 7348 | mAnimating = true; |
| 7349 | } |
| 7350 | } else if (mAnimation != null) { |
| 7351 | // If the display is frozen, and there is a pending animation, |
| 7352 | // clear it and make sure we run the cleanup code. |
| 7353 | mAnimating = true; |
| 7354 | mLocalAnimating = true; |
| 7355 | mAnimation = null; |
| 7356 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7357 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7358 | if (!mAnimating && !mLocalAnimating) { |
| 7359 | return false; |
| 7360 | } |
| 7361 | |
| 7362 | if (DEBUG_ANIM) Log.v( |
| 7363 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 7364 | + ", reportedVisible=" |
| 7365 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7366 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7367 | mAnimating = false; |
| 7368 | mLocalAnimating = false; |
| 7369 | mAnimation = null; |
| 7370 | mAnimLayer = mLayer; |
| 7371 | if (mIsImWindow) { |
| 7372 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7373 | } else if (mIsWallpaper) { |
| 7374 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7375 | } |
| 7376 | if (DEBUG_LAYERS) Log.v(TAG, "Stepping win " + this |
| 7377 | + " anim layer: " + mAnimLayer); |
| 7378 | mHasTransformation = false; |
| 7379 | mHasLocalTransformation = false; |
| 7380 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 7381 | mTransformation.clear(); |
| 7382 | if (mHasDrawn |
| 7383 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 7384 | && mAppToken != null |
| 7385 | && mAppToken.firstWindowDrawn |
| 7386 | && mAppToken.startingData != null) { |
| 7387 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Finish starting " |
| 7388 | + mToken + ": first real window done animating"); |
| 7389 | mFinishedStarting.add(mAppToken); |
| 7390 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7391 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7392 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7393 | finishExit(); |
| 7394 | |
| 7395 | if (mAppToken != null) { |
| 7396 | mAppToken.updateReportedVisibilityLocked(); |
| 7397 | } |
| 7398 | |
| 7399 | return false; |
| 7400 | } |
| 7401 | |
| 7402 | void finishExit() { |
| 7403 | if (DEBUG_ANIM) Log.v( |
| 7404 | TAG, "finishExit in " + this |
| 7405 | + ": exiting=" + mExiting |
| 7406 | + " remove=" + mRemoveOnExit |
| 7407 | + " windowAnimating=" + isWindowAnimating()); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7408 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7409 | final int N = mChildWindows.size(); |
| 7410 | for (int i=0; i<N; i++) { |
| 7411 | ((WindowState)mChildWindows.get(i)).finishExit(); |
| 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 (!mExiting) { |
| 7415 | return; |
| 7416 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7417 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7418 | if (isWindowAnimating()) { |
| 7419 | return; |
| 7420 | } |
| 7421 | |
| 7422 | if (localLOGV) Log.v( |
| 7423 | TAG, "Exit animation finished in " + this |
| 7424 | + ": remove=" + mRemoveOnExit); |
| 7425 | if (mSurface != null) { |
| 7426 | mDestroySurface.add(this); |
| 7427 | mDestroying = true; |
| 7428 | if (SHOW_TRANSACTIONS) Log.i( |
| 7429 | TAG, " SURFACE " + mSurface + ": HIDE (finishExit)"); |
| 7430 | try { |
| 7431 | mSurface.hide(); |
| 7432 | } catch (RuntimeException e) { |
| 7433 | Log.w(TAG, "Error hiding surface in " + this, e); |
| 7434 | } |
| 7435 | mLastHidden = true; |
| 7436 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 7437 | } |
| 7438 | mExiting = false; |
| 7439 | if (mRemoveOnExit) { |
| 7440 | mPendingRemove.add(this); |
| 7441 | mRemoveOnExit = false; |
| 7442 | } |
| 7443 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7444 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7445 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 7446 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 7447 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 7448 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 7449 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 7450 | return true; |
| 7451 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7452 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7453 | void computeShownFrameLocked() { |
| 7454 | final boolean selfTransformation = mHasLocalTransformation; |
| 7455 | Transformation attachedTransformation = |
| 7456 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 7457 | ? mAttachedWindow.mTransformation : null; |
| 7458 | Transformation appTransformation = |
| 7459 | (mAppToken != null && mAppToken.hasTransformation) |
| 7460 | ? mAppToken.transformation : null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7461 | |
| 7462 | // Wallpapers are animated based on the "real" window they |
| 7463 | // are currently targeting. |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7464 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7465 | && mWallpaperTarget != null) { |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7466 | if (mWallpaperTarget.mHasLocalTransformation && |
| 7467 | mWallpaperTarget.mAnimation != null && |
| 7468 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7469 | attachedTransformation = mWallpaperTarget.mTransformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7470 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
| 7471 | Log.v(TAG, "WP target attached xform: " + attachedTransformation); |
| 7472 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7473 | } |
| 7474 | if (mWallpaperTarget.mAppToken != null && |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7475 | mWallpaperTarget.mAppToken.hasTransformation && |
| 7476 | mWallpaperTarget.mAppToken.animation != null && |
| 7477 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7478 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7479 | if (DEBUG_WALLPAPER && appTransformation != null) { |
| 7480 | Log.v(TAG, "WP target app xform: " + appTransformation); |
| 7481 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7482 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7483 | } |
| 7484 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7485 | if (selfTransformation || attachedTransformation != null |
| 7486 | || appTransformation != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7487 | // cache often used attributes locally |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7488 | final Rect frame = mFrame; |
| 7489 | final float tmpFloats[] = mTmpFloats; |
| 7490 | final Matrix tmpMatrix = mTmpMatrix; |
| 7491 | |
| 7492 | // Compute the desired transformation. |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7493 | tmpMatrix.setTranslate(0, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7494 | if (selfTransformation) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7495 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7496 | } |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7497 | tmpMatrix.postTranslate(frame.left, frame.top); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7498 | if (attachedTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7499 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7500 | } |
| 7501 | if (appTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7502 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7503 | } |
| 7504 | |
| 7505 | // "convert" it into SurfaceFlinger's format |
| 7506 | // (a 2x2 matrix + an offset) |
| 7507 | // Here we must not transform the position of the surface |
| 7508 | // since it is already included in the transformation. |
| 7509 | //Log.i(TAG, "Transform: " + matrix); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7510 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7511 | tmpMatrix.getValues(tmpFloats); |
| 7512 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 7513 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 7514 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 7515 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7516 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 7517 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7518 | int w = frame.width(); |
| 7519 | int h = frame.height(); |
| 7520 | mShownFrame.set(x, y, x+w, y+h); |
| 7521 | |
| 7522 | // Now set the alpha... but because our current hardware |
| 7523 | // can't do alpha transformation on a non-opaque surface, |
| 7524 | // turn it off if we are running an animation that is also |
| 7525 | // transforming since it is more important to have that |
| 7526 | // animation be smooth. |
| 7527 | mShownAlpha = mAlpha; |
| 7528 | if (!mLimitedAlphaCompositing |
| 7529 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 7530 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 7531 | && x == frame.left && y == frame.top))) { |
| 7532 | //Log.i(TAG, "Applying alpha transform"); |
| 7533 | if (selfTransformation) { |
| 7534 | mShownAlpha *= mTransformation.getAlpha(); |
| 7535 | } |
| 7536 | if (attachedTransformation != null) { |
| 7537 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 7538 | } |
| 7539 | if (appTransformation != null) { |
| 7540 | mShownAlpha *= appTransformation.getAlpha(); |
| 7541 | } |
| 7542 | } else { |
| 7543 | //Log.i(TAG, "Not applying alpha transform"); |
| 7544 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7545 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7546 | if (localLOGV) Log.v( |
| 7547 | TAG, "Continuing animation in " + this + |
| 7548 | ": " + mShownFrame + |
| 7549 | ", alpha=" + mTransformation.getAlpha()); |
| 7550 | return; |
| 7551 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7552 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7553 | mShownFrame.set(mFrame); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7554 | if (mXOffset != 0 || mYOffset != 0) { |
| 7555 | mShownFrame.offset(mXOffset, mYOffset); |
| 7556 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7557 | mShownAlpha = mAlpha; |
| 7558 | mDsDx = 1; |
| 7559 | mDtDx = 0; |
| 7560 | mDsDy = 0; |
| 7561 | mDtDy = 1; |
| 7562 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7563 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7564 | /** |
| 7565 | * Is this window visible? It is not visible if there is no |
| 7566 | * surface, or we are in the process of running an exit animation |
| 7567 | * that will remove the surface, or its app token has been hidden. |
| 7568 | */ |
| 7569 | public boolean isVisibleLw() { |
| 7570 | final AppWindowToken atoken = mAppToken; |
| 7571 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7572 | && (atoken == null || !atoken.hiddenRequested) |
| 7573 | && !mExiting && !mDestroying; |
| 7574 | } |
| 7575 | |
| 7576 | /** |
| 7577 | * Is this window visible, ignoring its app token? It is not visible |
| 7578 | * if there is no surface, or we are in the process of running an exit animation |
| 7579 | * that will remove the surface. |
| 7580 | */ |
| 7581 | public boolean isWinVisibleLw() { |
| 7582 | final AppWindowToken atoken = mAppToken; |
| 7583 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7584 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 7585 | && !mExiting && !mDestroying; |
| 7586 | } |
| 7587 | |
| 7588 | /** |
| 7589 | * The same as isVisible(), but follows the current hidden state of |
| 7590 | * the associated app token, not the pending requested hidden state. |
| 7591 | */ |
| 7592 | boolean isVisibleNow() { |
| 7593 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7594 | && !mRootToken.hidden && !mExiting && !mDestroying; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7595 | } |
| 7596 | |
| 7597 | /** |
| 7598 | * Same as isVisible(), but we also count it as visible between the |
| 7599 | * call to IWindowSession.add() and the first relayout(). |
| 7600 | */ |
| 7601 | boolean isVisibleOrAdding() { |
| 7602 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7603 | return ((mSurface != null && !mReportDestroySurface) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7604 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 7605 | && mPolicyVisibility && !mAttachedHidden |
| 7606 | && (atoken == null || !atoken.hiddenRequested) |
| 7607 | && !mExiting && !mDestroying; |
| 7608 | } |
| 7609 | |
| 7610 | /** |
| 7611 | * Is this window currently on-screen? It is on-screen either if it |
| 7612 | * is visible or it is currently running an animation before no longer |
| 7613 | * being visible. |
| 7614 | */ |
| 7615 | boolean isOnScreen() { |
| 7616 | final AppWindowToken atoken = mAppToken; |
| 7617 | if (atoken != null) { |
| 7618 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7619 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7620 | || mAnimation != null || atoken.animation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7621 | } else { |
| 7622 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7623 | && (!mAttachedHidden || mAnimation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7624 | } |
| 7625 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7626 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7627 | /** |
| 7628 | * Like isOnScreen(), but we don't return true if the window is part |
| 7629 | * of a transition that has not yet been started. |
| 7630 | */ |
| 7631 | boolean isReadyForDisplay() { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7632 | if (mRootToken.waitingToShow && |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7633 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7634 | return false; |
| 7635 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7636 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7637 | final boolean animating = atoken != null |
| 7638 | ? (atoken.animation != null) : false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7639 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7640 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 7641 | && !mRootToken.hidden) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7642 | || mAnimation != null || animating); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7643 | } |
| 7644 | |
| 7645 | /** Is the window or its container currently animating? */ |
| 7646 | boolean isAnimating() { |
| 7647 | final WindowState attached = mAttachedWindow; |
| 7648 | final AppWindowToken atoken = mAppToken; |
| 7649 | return mAnimation != null |
| 7650 | || (attached != null && attached.mAnimation != null) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7651 | || (atoken != null && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7652 | (atoken.animation != null |
| 7653 | || atoken.inPendingTransaction)); |
| 7654 | } |
| 7655 | |
| 7656 | /** Is this window currently animating? */ |
| 7657 | boolean isWindowAnimating() { |
| 7658 | return mAnimation != null; |
| 7659 | } |
| 7660 | |
| 7661 | /** |
| 7662 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 7663 | * been drawn. |
| 7664 | */ |
| 7665 | public boolean isDisplayedLw() { |
| 7666 | final AppWindowToken atoken = mAppToken; |
| 7667 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7668 | && !mDrawPending && !mCommitDrawPending |
| 7669 | && ((!mAttachedHidden && |
| 7670 | (atoken == null || !atoken.hiddenRequested)) |
| 7671 | || mAnimating); |
| 7672 | } |
| 7673 | |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7674 | /** |
| 7675 | * Returns true if the window has a surface that it has drawn a |
| 7676 | * complete UI in to. |
| 7677 | */ |
| 7678 | public boolean isDrawnLw() { |
| 7679 | final AppWindowToken atoken = mAppToken; |
| 7680 | return mSurface != null && !mDestroying |
| 7681 | && !mDrawPending && !mCommitDrawPending; |
| 7682 | } |
| 7683 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7684 | public boolean fillsScreenLw(int screenWidth, int screenHeight, |
| 7685 | boolean shownFrame, boolean onlyOpaque) { |
| 7686 | if (mSurface == null) { |
| 7687 | return false; |
| 7688 | } |
| 7689 | if (mAppToken != null && !mAppToken.appFullscreen) { |
| 7690 | return false; |
| 7691 | } |
| 7692 | if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) { |
| 7693 | return false; |
| 7694 | } |
| 7695 | final Rect frame = shownFrame ? mShownFrame : mFrame; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7696 | |
| 7697 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| 7698 | return frame.left <= mCompatibleScreenFrame.left && |
| 7699 | frame.top <= mCompatibleScreenFrame.top && |
| 7700 | frame.right >= mCompatibleScreenFrame.right && |
| 7701 | frame.bottom >= mCompatibleScreenFrame.bottom; |
| 7702 | } else { |
| 7703 | return frame.left <= 0 && frame.top <= 0 |
| 7704 | && frame.right >= screenWidth |
| 7705 | && frame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7706 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7707 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7708 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7709 | /** |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7710 | * Return true if the window is opaque and fully drawn. This indicates |
| 7711 | * it may obscure windows behind it. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7712 | */ |
| 7713 | boolean isOpaqueDrawn() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7714 | return (mAttrs.format == PixelFormat.OPAQUE |
| 7715 | || mAttrs.type == TYPE_WALLPAPER) |
| 7716 | && mSurface != null && mAnimation == null |
| 7717 | && (mAppToken == null || mAppToken.animation == null) |
| 7718 | && !mDrawPending && !mCommitDrawPending; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7719 | } |
| 7720 | |
| 7721 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 7722 | return |
| 7723 | // only if the application is requesting compatible window |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7724 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 7725 | // only if it's visible |
| 7726 | mHasDrawn && mViewVisibility == View.VISIBLE && |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7727 | // and only if the application fills the compatible screen |
| 7728 | mFrame.left <= mCompatibleScreenFrame.left && |
| 7729 | mFrame.top <= mCompatibleScreenFrame.top && |
| 7730 | mFrame.right >= mCompatibleScreenFrame.right && |
| 7731 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7732 | // and starting window do not need background filler |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7733 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7734 | } |
| 7735 | |
| 7736 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 7737 | return mFrame.left <= 0 && mFrame.top <= 0 && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7738 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7739 | } |
| 7740 | |
| 7741 | void removeLocked() { |
| 7742 | if (mAttachedWindow != null) { |
| 7743 | mAttachedWindow.mChildWindows.remove(this); |
| 7744 | } |
| 7745 | destroySurfaceLocked(); |
| 7746 | mSession.windowRemovedLocked(); |
| 7747 | try { |
| 7748 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 7749 | } catch (RuntimeException e) { |
| 7750 | // Ignore if it has already been removed (usually because |
| 7751 | // we are doing this as part of processing a death note.) |
| 7752 | } |
| 7753 | } |
| 7754 | |
| 7755 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 7756 | public void binderDied() { |
| 7757 | try { |
| 7758 | synchronized(mWindowMap) { |
| 7759 | WindowState win = windowForClientLocked(mSession, mClient); |
| 7760 | Log.i(TAG, "WIN DEATH: " + win); |
| 7761 | if (win != null) { |
| 7762 | removeWindowLocked(mSession, win); |
| 7763 | } |
| 7764 | } |
| 7765 | } catch (IllegalArgumentException ex) { |
| 7766 | // This will happen if the window has already been |
| 7767 | // removed. |
| 7768 | } |
| 7769 | } |
| 7770 | } |
| 7771 | |
| 7772 | /** Returns true if this window desires key events. */ |
| 7773 | public final boolean canReceiveKeys() { |
| 7774 | return isVisibleOrAdding() |
| 7775 | && (mViewVisibility == View.VISIBLE) |
| 7776 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 7777 | } |
| 7778 | |
| 7779 | public boolean hasDrawnLw() { |
| 7780 | return mHasDrawn; |
| 7781 | } |
| 7782 | |
| 7783 | public boolean showLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7784 | return showLw(doAnimation, true); |
| 7785 | } |
| 7786 | |
| 7787 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 7788 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 7789 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7790 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7791 | mPolicyVisibility = true; |
| 7792 | mPolicyVisibilityAfterAnim = true; |
| 7793 | if (doAnimation) { |
| 7794 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 7795 | } |
| 7796 | if (requestAnim) { |
| 7797 | requestAnimationLocked(0); |
| 7798 | } |
| 7799 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7800 | } |
| 7801 | |
| 7802 | public boolean hideLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7803 | return hideLw(doAnimation, true); |
| 7804 | } |
| 7805 | |
| 7806 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7807 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 7808 | : mPolicyVisibility; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7809 | if (!current) { |
| 7810 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7811 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7812 | if (doAnimation) { |
| 7813 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 7814 | if (mAnimation == null) { |
| 7815 | doAnimation = false; |
| 7816 | } |
| 7817 | } |
| 7818 | if (doAnimation) { |
| 7819 | mPolicyVisibilityAfterAnim = false; |
| 7820 | } else { |
| 7821 | mPolicyVisibilityAfterAnim = false; |
| 7822 | mPolicyVisibility = false; |
| 7823 | } |
| 7824 | if (requestAnim) { |
| 7825 | requestAnimationLocked(0); |
| 7826 | } |
| 7827 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7828 | } |
| 7829 | |
| 7830 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7831 | StringBuilder sb = new StringBuilder(64); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7832 | |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7833 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 7834 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 7835 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 7836 | if (mAttachedWindow != null || mLayoutAttached) { |
| 7837 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 7838 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 7839 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7840 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 7841 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 7842 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7843 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 7844 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7845 | } |
| 7846 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 7847 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 7848 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 7849 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 7850 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 7851 | pw.print("="); pw.print(mAnimLayer); |
| 7852 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 7853 | if (mSurface != null) { |
| 7854 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
| 7855 | } |
| 7856 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 7857 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 7858 | if (mAppToken != null) { |
| 7859 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 7860 | } |
| 7861 | if (mTargetAppToken != null) { |
| 7862 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 7863 | } |
| 7864 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 7865 | pw.print(Integer.toHexString(mViewVisibility)); |
| 7866 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7867 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 7868 | pw.print(" mObscured="); pw.println(mObscured); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7869 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 7870 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 7871 | pw.print(mPolicyVisibility); |
| 7872 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 7873 | pw.print(mPolicyVisibilityAfterAnim); |
| 7874 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 7875 | } |
| 7876 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7877 | pw.print(" h="); pw.println(mRequestedHeight); |
| 7878 | if (mXOffset != 0 || mYOffset != 0) { |
| 7879 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 7880 | pw.print(" y="); pw.println(mYOffset); |
| 7881 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7882 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 7883 | mGivenContentInsets.printShortString(pw); |
| 7884 | pw.print(" mGivenVisibleInsets="); |
| 7885 | mGivenVisibleInsets.printShortString(pw); |
| 7886 | pw.println(); |
| 7887 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 7888 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 7889 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 7890 | } |
| 7891 | pw.print(prefix); pw.print("mShownFrame="); |
| 7892 | mShownFrame.printShortString(pw); |
| 7893 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 7894 | pw.println(); |
| 7895 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 7896 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 7897 | pw.println(); |
| 7898 | pw.print(prefix); pw.print("mContainingFrame="); |
| 7899 | mContainingFrame.printShortString(pw); |
| 7900 | pw.print(" mDisplayFrame="); |
| 7901 | mDisplayFrame.printShortString(pw); |
| 7902 | pw.println(); |
| 7903 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 7904 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 7905 | pw.println(); |
| 7906 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 7907 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 7908 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 7909 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 7910 | pw.println(); |
| 7911 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 7912 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 7913 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 7914 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 7915 | } |
| 7916 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 7917 | || mAnimation != null) { |
| 7918 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 7919 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 7920 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 7921 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 7922 | } |
| 7923 | if (mHasTransformation || mHasLocalTransformation) { |
| 7924 | pw.print(prefix); pw.print("XForm: has="); |
| 7925 | pw.print(mHasTransformation); |
| 7926 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 7927 | pw.print(" "); mTransformation.printShortString(pw); |
| 7928 | pw.println(); |
| 7929 | } |
| 7930 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 7931 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 7932 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 7933 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 7934 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 7935 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 7936 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 7937 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 7938 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 7939 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7940 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7941 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 7942 | pw.print(mOrientationChanging); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7943 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 7944 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7945 | } |
| Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 7946 | if (mHScale != 1 || mVScale != 1) { |
| 7947 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 7948 | pw.print(" mVScale="); pw.println(mVScale); |
| 7949 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7950 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7951 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 7952 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 7953 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7954 | } |
| 7955 | |
| 7956 | @Override |
| 7957 | public String toString() { |
| 7958 | return "Window{" |
| 7959 | + Integer.toHexString(System.identityHashCode(this)) |
| 7960 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 7961 | } |
| 7962 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7963 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7964 | // ------------------------------------------------------------- |
| 7965 | // Window Token State |
| 7966 | // ------------------------------------------------------------- |
| 7967 | |
| 7968 | class WindowToken { |
| 7969 | // The actual token. |
| 7970 | final IBinder token; |
| 7971 | |
| 7972 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 7973 | final int windowType; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7974 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7975 | // Set if this token was explicitly added by a client, so should |
| 7976 | // not be removed when all windows are removed. |
| 7977 | final boolean explicit; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7978 | |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7979 | // For printing. |
| 7980 | String stringName; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7981 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7982 | // If this is an AppWindowToken, this is non-null. |
| 7983 | AppWindowToken appWindowToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7984 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7985 | // All of the windows associated with this token. |
| 7986 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 7987 | |
| 7988 | // Is key dispatching paused for this token? |
| 7989 | boolean paused = false; |
| 7990 | |
| 7991 | // Should this token's windows be hidden? |
| 7992 | boolean hidden; |
| 7993 | |
| 7994 | // Temporary for finding which tokens no longer have visible windows. |
| 7995 | boolean hasVisible; |
| 7996 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7997 | // Set to true when this token is in a pending transaction where it |
| 7998 | // will be shown. |
| 7999 | boolean waitingToShow; |
| 8000 | |
| 8001 | // Set to true when this token is in a pending transaction where it |
| 8002 | // will be hidden. |
| 8003 | boolean waitingToHide; |
| 8004 | |
| 8005 | // Set to true when this token is in a pending transaction where its |
| 8006 | // windows will be put to the bottom of the list. |
| 8007 | boolean sendingToBottom; |
| 8008 | |
| 8009 | // Set to true when this token is in a pending transaction where its |
| 8010 | // windows will be put to the top of the list. |
| 8011 | boolean sendingToTop; |
| 8012 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8013 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 8014 | token = _token; |
| 8015 | windowType = type; |
| 8016 | explicit = _explicit; |
| 8017 | } |
| 8018 | |
| 8019 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8020 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 8021 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 8022 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 8023 | pw.print(" hidden="); pw.print(hidden); |
| 8024 | pw.print(" hasVisible="); pw.println(hasVisible); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8025 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 8026 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 8027 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 8028 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 8029 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 8030 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8031 | } |
| 8032 | |
| 8033 | @Override |
| 8034 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8035 | if (stringName == null) { |
| 8036 | StringBuilder sb = new StringBuilder(); |
| 8037 | sb.append("WindowToken{"); |
| 8038 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8039 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8040 | stringName = sb.toString(); |
| 8041 | } |
| 8042 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8043 | } |
| 8044 | }; |
| 8045 | |
| 8046 | class AppWindowToken extends WindowToken { |
| 8047 | // Non-null only for application tokens. |
| 8048 | final IApplicationToken appToken; |
| 8049 | |
| 8050 | // All of the windows and child windows that are included in this |
| 8051 | // application token. Note this list is NOT sorted! |
| 8052 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 8053 | |
| 8054 | int groupId = -1; |
| 8055 | boolean appFullscreen; |
| 8056 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8057 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8058 | // These are used for determining when all windows associated with |
| 8059 | // an activity have been drawn, so they can be made visible together |
| 8060 | // at the same time. |
| 8061 | int lastTransactionSequence = mTransactionSequence-1; |
| 8062 | int numInterestingWindows; |
| 8063 | int numDrawnWindows; |
| 8064 | boolean inPendingTransaction; |
| 8065 | boolean allDrawn; |
| 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 token going to be hidden in a little while? If so, it |
| 8068 | // won't be taken into account for setting the screen orientation. |
| 8069 | boolean willBeHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8070 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8071 | // Is this window's surface needed? This is almost like hidden, except |
| 8072 | // it will sometimes be true a little earlier: when the token has |
| 8073 | // been shown, but is still waiting for its app transition to execute |
| 8074 | // before making its windows shown. |
| 8075 | boolean hiddenRequested; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8076 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8077 | // Have we told the window clients to hide themselves? |
| 8078 | boolean clientHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8079 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8080 | // Last visibility state we reported to the app token. |
| 8081 | boolean reportedVisible; |
| 8082 | |
| 8083 | // Set to true when the token has been removed from the window mgr. |
| 8084 | boolean removed; |
| 8085 | |
| 8086 | // Have we been asked to have this token keep the screen frozen? |
| 8087 | boolean freezingScreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8088 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8089 | boolean animating; |
| 8090 | Animation animation; |
| 8091 | boolean hasTransformation; |
| 8092 | final Transformation transformation = new Transformation(); |
| 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 | // Offset to the window of all layers in the token, for use by |
| 8095 | // AppWindowToken animations. |
| 8096 | int animLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8097 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8098 | // Information about an application starting window if displayed. |
| 8099 | StartingData startingData; |
| 8100 | WindowState startingWindow; |
| 8101 | View startingView; |
| 8102 | boolean startingDisplayed; |
| 8103 | boolean startingMoved; |
| 8104 | boolean firstWindowDrawn; |
| 8105 | |
| 8106 | AppWindowToken(IApplicationToken _token) { |
| 8107 | super(_token.asBinder(), |
| 8108 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 8109 | appWindowToken = this; |
| 8110 | appToken = _token; |
| 8111 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8112 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8113 | public void setAnimation(Animation anim) { |
| 8114 | if (localLOGV) Log.v( |
| 8115 | TAG, "Setting animation in " + this + ": " + anim); |
| 8116 | animation = anim; |
| 8117 | animating = false; |
| 8118 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 8119 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 8120 | int zorder = anim.getZAdjustment(); |
| 8121 | int adj = 0; |
| 8122 | if (zorder == Animation.ZORDER_TOP) { |
| 8123 | adj = TYPE_LAYER_OFFSET; |
| 8124 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 8125 | adj = -TYPE_LAYER_OFFSET; |
| 8126 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8127 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8128 | if (animLayerAdjustment != adj) { |
| 8129 | animLayerAdjustment = adj; |
| 8130 | updateLayers(); |
| 8131 | } |
| 8132 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8133 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8134 | public void setDummyAnimation() { |
| 8135 | if (animation == null) { |
| 8136 | if (localLOGV) Log.v( |
| 8137 | TAG, "Setting dummy animation in " + this); |
| 8138 | animation = sDummyAnimation; |
| 8139 | } |
| 8140 | } |
| 8141 | |
| 8142 | public void clearAnimation() { |
| 8143 | if (animation != null) { |
| 8144 | animation = null; |
| 8145 | animating = true; |
| 8146 | } |
| 8147 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8148 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8149 | void updateLayers() { |
| 8150 | final int N = allAppWindows.size(); |
| 8151 | final int adj = animLayerAdjustment; |
| 8152 | for (int i=0; i<N; i++) { |
| 8153 | WindowState w = allAppWindows.get(i); |
| 8154 | w.mAnimLayer = w.mLayer + adj; |
| 8155 | if (DEBUG_LAYERS) Log.v(TAG, "Updating layer " + w + ": " |
| 8156 | + w.mAnimLayer); |
| 8157 | if (w == mInputMethodTarget) { |
| 8158 | setInputMethodAnimLayerAdjustment(adj); |
| 8159 | } |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8160 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8161 | setWallpaperAnimLayerAdjustmentLocked(adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8162 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8163 | } |
| 8164 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8165 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8166 | void sendAppVisibilityToClients() { |
| 8167 | final int N = allAppWindows.size(); |
| 8168 | for (int i=0; i<N; i++) { |
| 8169 | WindowState win = allAppWindows.get(i); |
| 8170 | if (win == startingWindow && clientHidden) { |
| 8171 | // Don't hide the starting window. |
| 8172 | continue; |
| 8173 | } |
| 8174 | try { |
| 8175 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 8176 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 8177 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 8178 | } catch (RemoteException e) { |
| 8179 | } |
| 8180 | } |
| 8181 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8182 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8183 | void showAllWindowsLocked() { |
| 8184 | final int NW = allAppWindows.size(); |
| 8185 | for (int i=0; i<NW; i++) { |
| 8186 | WindowState w = allAppWindows.get(i); |
| 8187 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 8188 | "performing show on: " + w); |
| 8189 | w.performShowLocked(); |
| 8190 | } |
| 8191 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8192 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8193 | // This must be called while inside a transaction. |
| 8194 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| 8195 | if (!mDisplayFrozen) { |
| 8196 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8197 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8198 | if (animation == sDummyAnimation) { |
| 8199 | // This guy is going to animate, but not yet. For now count |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8200 | // it as not animating for purposes of scheduling transactions; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8201 | // when it is really time to animate, this will be set to |
| 8202 | // a real animation and the next call will execute normally. |
| 8203 | return false; |
| 8204 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8205 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8206 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 8207 | if (!animating) { |
| 8208 | if (DEBUG_ANIM) Log.v( |
| 8209 | TAG, "Starting animation in " + this + |
| 8210 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 8211 | + " scale=" + mTransitionAnimationScale |
| 8212 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 8213 | animation.initialize(dw, dh, dw, dh); |
| 8214 | animation.setStartTime(currentTime); |
| 8215 | animating = true; |
| 8216 | } |
| 8217 | transformation.clear(); |
| 8218 | final boolean more = animation.getTransformation( |
| 8219 | currentTime, transformation); |
| 8220 | if (DEBUG_ANIM) Log.v( |
| 8221 | TAG, "Stepped animation in " + this + |
| 8222 | ": more=" + more + ", xform=" + transformation); |
| 8223 | if (more) { |
| 8224 | // we're done! |
| 8225 | hasTransformation = true; |
| 8226 | return true; |
| 8227 | } |
| 8228 | if (DEBUG_ANIM) Log.v( |
| 8229 | TAG, "Finished animation in " + this + |
| 8230 | " @ " + currentTime); |
| 8231 | animation = null; |
| 8232 | } |
| 8233 | } else if (animation != null) { |
| 8234 | // If the display is frozen, and there is a pending animation, |
| 8235 | // clear it and make sure we run the cleanup code. |
| 8236 | animating = true; |
| 8237 | animation = null; |
| 8238 | } |
| 8239 | |
| 8240 | hasTransformation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8241 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8242 | if (!animating) { |
| 8243 | return false; |
| 8244 | } |
| 8245 | |
| 8246 | clearAnimation(); |
| 8247 | animating = false; |
| 8248 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 8249 | moveInputMethodWindowsIfNeededLocked(true); |
| 8250 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8251 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8252 | if (DEBUG_ANIM) Log.v( |
| 8253 | TAG, "Animation done in " + this |
| 8254 | + ": reportedVisible=" + reportedVisible); |
| 8255 | |
| 8256 | transformation.clear(); |
| 8257 | if (animLayerAdjustment != 0) { |
| 8258 | animLayerAdjustment = 0; |
| 8259 | updateLayers(); |
| 8260 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8261 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8262 | final int N = windows.size(); |
| 8263 | for (int i=0; i<N; i++) { |
| 8264 | ((WindowState)windows.get(i)).finishExit(); |
| 8265 | } |
| 8266 | updateReportedVisibilityLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8267 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8268 | return false; |
| 8269 | } |
| 8270 | |
| 8271 | void updateReportedVisibilityLocked() { |
| 8272 | if (appToken == null) { |
| 8273 | return; |
| 8274 | } |
| 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 | int numInteresting = 0; |
| 8277 | int numVisible = 0; |
| 8278 | boolean nowGone = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8279 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8280 | if (DEBUG_VISIBILITY) Log.v(TAG, "Update reported visibility: " + this); |
| 8281 | final int N = allAppWindows.size(); |
| 8282 | for (int i=0; i<N; i++) { |
| 8283 | WindowState win = allAppWindows.get(i); |
| 8284 | if (win == startingWindow || win.mAppFreezing) { |
| 8285 | continue; |
| 8286 | } |
| 8287 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8288 | Log.v(TAG, "Win " + win + ": isDrawn=" |
| 8289 | + win.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8290 | + ", isAnimating=" + win.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8291 | if (!win.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8292 | Log.v(TAG, "Not displayed: s=" + win.mSurface |
| 8293 | + " pv=" + win.mPolicyVisibility |
| 8294 | + " dp=" + win.mDrawPending |
| 8295 | + " cdp=" + win.mCommitDrawPending |
| 8296 | + " ah=" + win.mAttachedHidden |
| 8297 | + " th=" |
| 8298 | + (win.mAppToken != null |
| 8299 | ? win.mAppToken.hiddenRequested : false) |
| 8300 | + " a=" + win.mAnimating); |
| 8301 | } |
| 8302 | } |
| 8303 | numInteresting++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8304 | if (win.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8305 | if (!win.isAnimating()) { |
| 8306 | numVisible++; |
| 8307 | } |
| 8308 | nowGone = false; |
| 8309 | } else if (win.isAnimating()) { |
| 8310 | nowGone = false; |
| 8311 | } |
| 8312 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8313 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8314 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
| 8315 | if (DEBUG_VISIBILITY) Log.v(TAG, "VIS " + this + ": interesting=" |
| 8316 | + numInteresting + " visible=" + numVisible); |
| 8317 | if (nowVisible != reportedVisible) { |
| 8318 | if (DEBUG_VISIBILITY) Log.v( |
| 8319 | TAG, "Visibility changed in " + this |
| 8320 | + ": vis=" + nowVisible); |
| 8321 | reportedVisible = nowVisible; |
| 8322 | Message m = mH.obtainMessage( |
| 8323 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 8324 | nowVisible ? 1 : 0, |
| 8325 | nowGone ? 1 : 0, |
| 8326 | this); |
| 8327 | mH.sendMessage(m); |
| 8328 | } |
| 8329 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8330 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8331 | WindowState findMainWindow() { |
| 8332 | int j = windows.size(); |
| 8333 | while (j > 0) { |
| 8334 | j--; |
| 8335 | WindowState win = windows.get(j); |
| 8336 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 8337 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 8338 | return win; |
| 8339 | } |
| 8340 | } |
| 8341 | return null; |
| 8342 | } |
| 8343 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8344 | void dump(PrintWriter pw, String prefix) { |
| 8345 | super.dump(pw, prefix); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8346 | if (appToken != null) { |
| 8347 | pw.print(prefix); pw.println("app=true"); |
| 8348 | } |
| 8349 | if (allAppWindows.size() > 0) { |
| 8350 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 8351 | } |
| 8352 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8353 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8354 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 8355 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 8356 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 8357 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 8358 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 8359 | if (paused || freezingScreen) { |
| 8360 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 8361 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 8362 | } |
| 8363 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 8364 | || inPendingTransaction || allDrawn) { |
| 8365 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 8366 | pw.print(numInterestingWindows); |
| 8367 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 8368 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 8369 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 8370 | } |
| 8371 | if (animating || animation != null) { |
| 8372 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 8373 | pw.print(" animation="); pw.println(animation); |
| 8374 | } |
| 8375 | if (animLayerAdjustment != 0) { |
| 8376 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 8377 | } |
| 8378 | if (hasTransformation) { |
| 8379 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 8380 | pw.print(" transformation="); transformation.printShortString(pw); |
| 8381 | pw.println(); |
| 8382 | } |
| 8383 | if (startingData != null || removed || firstWindowDrawn) { |
| 8384 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 8385 | pw.print(" removed="); pw.print(removed); |
| 8386 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 8387 | } |
| 8388 | if (startingWindow != null || startingView != null |
| 8389 | || startingDisplayed || startingMoved) { |
| 8390 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 8391 | pw.print(" startingView="); pw.print(startingView); |
| 8392 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 8393 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 8394 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8395 | } |
| 8396 | |
| 8397 | @Override |
| 8398 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8399 | if (stringName == null) { |
| 8400 | StringBuilder sb = new StringBuilder(); |
| 8401 | sb.append("AppWindowToken{"); |
| 8402 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8403 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8404 | stringName = sb.toString(); |
| 8405 | } |
| 8406 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8407 | } |
| 8408 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8409 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8410 | // ------------------------------------------------------------- |
| 8411 | // DummyAnimation |
| 8412 | // ------------------------------------------------------------- |
| 8413 | |
| 8414 | // This is an animation that does nothing: it just immediately finishes |
| 8415 | // itself every time it is called. It is used as a stub animation in cases |
| 8416 | // where we want to synchronize multiple things that may be animating. |
| 8417 | static final class DummyAnimation extends Animation { |
| 8418 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 8419 | return false; |
| 8420 | } |
| 8421 | } |
| 8422 | static final Animation sDummyAnimation = new DummyAnimation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8423 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8424 | // ------------------------------------------------------------- |
| 8425 | // Async Handler |
| 8426 | // ------------------------------------------------------------- |
| 8427 | |
| 8428 | static final class StartingData { |
| 8429 | final String pkg; |
| 8430 | final int theme; |
| 8431 | final CharSequence nonLocalizedLabel; |
| 8432 | final int labelRes; |
| 8433 | final int icon; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8434 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8435 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 8436 | int _labelRes, int _icon) { |
| 8437 | pkg = _pkg; |
| 8438 | theme = _theme; |
| 8439 | nonLocalizedLabel = _nonLocalizedLabel; |
| 8440 | labelRes = _labelRes; |
| 8441 | icon = _icon; |
| 8442 | } |
| 8443 | } |
| 8444 | |
| 8445 | private final class H extends Handler { |
| 8446 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 8447 | public static final int REPORT_LOSING_FOCUS = 3; |
| 8448 | public static final int ANIMATE = 4; |
| 8449 | public static final int ADD_STARTING = 5; |
| 8450 | public static final int REMOVE_STARTING = 6; |
| 8451 | public static final int FINISHED_STARTING = 7; |
| 8452 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8453 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 8454 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 8455 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 8456 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 8457 | public static final int FORCE_GC = 15; |
| 8458 | public static final int ENABLE_SCREEN = 16; |
| 8459 | public static final int APP_FREEZE_TIMEOUT = 17; |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8460 | public static final int COMPUTE_AND_SEND_NEW_CONFIGURATION = 18; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8461 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8462 | private Session mLastReportedHold; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8463 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8464 | public H() { |
| 8465 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8466 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8467 | @Override |
| 8468 | public void handleMessage(Message msg) { |
| 8469 | switch (msg.what) { |
| 8470 | case REPORT_FOCUS_CHANGE: { |
| 8471 | WindowState lastFocus; |
| 8472 | WindowState newFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8473 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8474 | synchronized(mWindowMap) { |
| 8475 | lastFocus = mLastFocus; |
| 8476 | newFocus = mCurrentFocus; |
| 8477 | if (lastFocus == newFocus) { |
| 8478 | // Focus is not changing, so nothing to do. |
| 8479 | return; |
| 8480 | } |
| 8481 | mLastFocus = newFocus; |
| 8482 | //Log.i(TAG, "Focus moving from " + lastFocus |
| 8483 | // + " to " + newFocus); |
| 8484 | if (newFocus != null && lastFocus != null |
| 8485 | && !newFocus.isDisplayedLw()) { |
| 8486 | //Log.i(TAG, "Delaying loss of focus..."); |
| 8487 | mLosingFocus.add(lastFocus); |
| 8488 | lastFocus = null; |
| 8489 | } |
| 8490 | } |
| 8491 | |
| 8492 | if (lastFocus != newFocus) { |
| 8493 | //System.out.println("Changing focus from " + lastFocus |
| 8494 | // + " to " + newFocus); |
| 8495 | if (newFocus != null) { |
| 8496 | try { |
| 8497 | //Log.i(TAG, "Gaining focus: " + newFocus); |
| 8498 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 8499 | } catch (RemoteException e) { |
| 8500 | // Ignore if process has died. |
| 8501 | } |
| 8502 | } |
| 8503 | |
| 8504 | if (lastFocus != null) { |
| 8505 | try { |
| 8506 | //Log.i(TAG, "Losing focus: " + lastFocus); |
| 8507 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 8508 | } catch (RemoteException e) { |
| 8509 | // Ignore if process has died. |
| 8510 | } |
| 8511 | } |
| 8512 | } |
| 8513 | } break; |
| 8514 | |
| 8515 | case REPORT_LOSING_FOCUS: { |
| 8516 | ArrayList<WindowState> losers; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8517 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8518 | synchronized(mWindowMap) { |
| 8519 | losers = mLosingFocus; |
| 8520 | mLosingFocus = new ArrayList<WindowState>(); |
| 8521 | } |
| 8522 | |
| 8523 | final int N = losers.size(); |
| 8524 | for (int i=0; i<N; i++) { |
| 8525 | try { |
| 8526 | //Log.i(TAG, "Losing delayed focus: " + losers.get(i)); |
| 8527 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 8528 | } catch (RemoteException e) { |
| 8529 | // Ignore if process has died. |
| 8530 | } |
| 8531 | } |
| 8532 | } break; |
| 8533 | |
| 8534 | case ANIMATE: { |
| 8535 | synchronized(mWindowMap) { |
| 8536 | mAnimationPending = false; |
| 8537 | performLayoutAndPlaceSurfacesLocked(); |
| 8538 | } |
| 8539 | } break; |
| 8540 | |
| 8541 | case ADD_STARTING: { |
| 8542 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8543 | final StartingData sd = wtoken.startingData; |
| 8544 | |
| 8545 | if (sd == null) { |
| 8546 | // Animation has been canceled... do nothing. |
| 8547 | return; |
| 8548 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8549 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8550 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Add starting " |
| 8551 | + wtoken + ": pkg=" + sd.pkg); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8552 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8553 | View view = null; |
| 8554 | try { |
| 8555 | view = mPolicy.addStartingWindow( |
| 8556 | wtoken.token, sd.pkg, |
| 8557 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 8558 | sd.icon); |
| 8559 | } catch (Exception e) { |
| 8560 | Log.w(TAG, "Exception when adding starting window", e); |
| 8561 | } |
| 8562 | |
| 8563 | if (view != null) { |
| 8564 | boolean abort = false; |
| 8565 | |
| 8566 | synchronized(mWindowMap) { |
| 8567 | if (wtoken.removed || wtoken.startingData == null) { |
| 8568 | // If the window was successfully added, then |
| 8569 | // we need to remove it. |
| 8570 | if (wtoken.startingWindow != null) { |
| 8571 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 8572 | "Aborted starting " + wtoken |
| 8573 | + ": removed=" + wtoken.removed |
| 8574 | + " startingData=" + wtoken.startingData); |
| 8575 | wtoken.startingWindow = null; |
| 8576 | wtoken.startingData = null; |
| 8577 | abort = true; |
| 8578 | } |
| 8579 | } else { |
| 8580 | wtoken.startingView = view; |
| 8581 | } |
| 8582 | if (DEBUG_STARTING_WINDOW && !abort) Log.v(TAG, |
| 8583 | "Added starting " + wtoken |
| 8584 | + ": startingWindow=" |
| 8585 | + wtoken.startingWindow + " startingView=" |
| 8586 | + wtoken.startingView); |
| 8587 | } |
| 8588 | |
| 8589 | if (abort) { |
| 8590 | try { |
| 8591 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 8592 | } catch (Exception e) { |
| 8593 | Log.w(TAG, "Exception when removing starting window", e); |
| 8594 | } |
| 8595 | } |
| 8596 | } |
| 8597 | } break; |
| 8598 | |
| 8599 | case REMOVE_STARTING: { |
| 8600 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8601 | IBinder token = null; |
| 8602 | View view = null; |
| 8603 | synchronized (mWindowMap) { |
| 8604 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Remove starting " |
| 8605 | + wtoken + ": startingWindow=" |
| 8606 | + wtoken.startingWindow + " startingView=" |
| 8607 | + wtoken.startingView); |
| 8608 | if (wtoken.startingWindow != null) { |
| 8609 | view = wtoken.startingView; |
| 8610 | token = wtoken.token; |
| 8611 | wtoken.startingData = null; |
| 8612 | wtoken.startingView = null; |
| 8613 | wtoken.startingWindow = null; |
| 8614 | } |
| 8615 | } |
| 8616 | if (view != null) { |
| 8617 | try { |
| 8618 | mPolicy.removeStartingWindow(token, view); |
| 8619 | } catch (Exception e) { |
| 8620 | Log.w(TAG, "Exception when removing starting window", e); |
| 8621 | } |
| 8622 | } |
| 8623 | } break; |
| 8624 | |
| 8625 | case FINISHED_STARTING: { |
| 8626 | IBinder token = null; |
| 8627 | View view = null; |
| 8628 | while (true) { |
| 8629 | synchronized (mWindowMap) { |
| 8630 | final int N = mFinishedStarting.size(); |
| 8631 | if (N <= 0) { |
| 8632 | break; |
| 8633 | } |
| 8634 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 8635 | |
| 8636 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 8637 | "Finished starting " + wtoken |
| 8638 | + ": startingWindow=" + wtoken.startingWindow |
| 8639 | + " startingView=" + wtoken.startingView); |
| 8640 | |
| 8641 | if (wtoken.startingWindow == null) { |
| 8642 | continue; |
| 8643 | } |
| 8644 | |
| 8645 | view = wtoken.startingView; |
| 8646 | token = wtoken.token; |
| 8647 | wtoken.startingData = null; |
| 8648 | wtoken.startingView = null; |
| 8649 | wtoken.startingWindow = null; |
| 8650 | } |
| 8651 | |
| 8652 | try { |
| 8653 | mPolicy.removeStartingWindow(token, view); |
| 8654 | } catch (Exception e) { |
| 8655 | Log.w(TAG, "Exception when removing starting window", e); |
| 8656 | } |
| 8657 | } |
| 8658 | } break; |
| 8659 | |
| 8660 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 8661 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8662 | |
| 8663 | boolean nowVisible = msg.arg1 != 0; |
| 8664 | boolean nowGone = msg.arg2 != 0; |
| 8665 | |
| 8666 | try { |
| 8667 | if (DEBUG_VISIBILITY) Log.v( |
| 8668 | TAG, "Reporting visible in " + wtoken |
| 8669 | + " visible=" + nowVisible |
| 8670 | + " gone=" + nowGone); |
| 8671 | if (nowVisible) { |
| 8672 | wtoken.appToken.windowsVisible(); |
| 8673 | } else { |
| 8674 | wtoken.appToken.windowsGone(); |
| 8675 | } |
| 8676 | } catch (RemoteException ex) { |
| 8677 | } |
| 8678 | } break; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8679 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8680 | case WINDOW_FREEZE_TIMEOUT: { |
| 8681 | synchronized (mWindowMap) { |
| 8682 | Log.w(TAG, "Window freeze timeout expired."); |
| 8683 | int i = mWindows.size(); |
| 8684 | while (i > 0) { |
| 8685 | i--; |
| 8686 | WindowState w = (WindowState)mWindows.get(i); |
| 8687 | if (w.mOrientationChanging) { |
| 8688 | w.mOrientationChanging = false; |
| 8689 | Log.w(TAG, "Force clearing orientation change: " + w); |
| 8690 | } |
| 8691 | } |
| 8692 | performLayoutAndPlaceSurfacesLocked(); |
| 8693 | } |
| 8694 | break; |
| 8695 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8696 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8697 | case HOLD_SCREEN_CHANGED: { |
| 8698 | Session oldHold; |
| 8699 | Session newHold; |
| 8700 | synchronized (mWindowMap) { |
| 8701 | oldHold = mLastReportedHold; |
| 8702 | newHold = (Session)msg.obj; |
| 8703 | mLastReportedHold = newHold; |
| 8704 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8705 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8706 | if (oldHold != newHold) { |
| 8707 | try { |
| 8708 | if (oldHold != null) { |
| 8709 | mBatteryStats.noteStopWakelock(oldHold.mUid, |
| 8710 | "window", |
| 8711 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8712 | } |
| 8713 | if (newHold != null) { |
| 8714 | mBatteryStats.noteStartWakelock(newHold.mUid, |
| 8715 | "window", |
| 8716 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8717 | } |
| 8718 | } catch (RemoteException e) { |
| 8719 | } |
| 8720 | } |
| 8721 | break; |
| 8722 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8723 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8724 | case APP_TRANSITION_TIMEOUT: { |
| 8725 | synchronized (mWindowMap) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8726 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8727 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 8728 | "*** APP TRANSITION TIMEOUT"); |
| 8729 | mAppTransitionReady = true; |
| 8730 | mAppTransitionTimeout = true; |
| 8731 | performLayoutAndPlaceSurfacesLocked(); |
| 8732 | } |
| 8733 | } |
| 8734 | break; |
| 8735 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8736 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8737 | case PERSIST_ANIMATION_SCALE: { |
| 8738 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8739 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 8740 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8741 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 8742 | break; |
| 8743 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8744 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8745 | case FORCE_GC: { |
| 8746 | synchronized(mWindowMap) { |
| 8747 | if (mAnimationPending) { |
| 8748 | // If we are animating, don't do the gc now but |
| 8749 | // delay a bit so we don't interrupt the animation. |
| 8750 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 8751 | 2000); |
| 8752 | return; |
| 8753 | } |
| 8754 | // If we are currently rotating the display, it will |
| 8755 | // schedule a new message when done. |
| 8756 | if (mDisplayFrozen) { |
| 8757 | return; |
| 8758 | } |
| 8759 | mFreezeGcPending = 0; |
| 8760 | } |
| 8761 | Runtime.getRuntime().gc(); |
| 8762 | break; |
| 8763 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8764 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8765 | case ENABLE_SCREEN: { |
| 8766 | performEnableScreen(); |
| 8767 | break; |
| 8768 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8769 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8770 | case APP_FREEZE_TIMEOUT: { |
| 8771 | synchronized (mWindowMap) { |
| 8772 | Log.w(TAG, "App freeze timeout expired."); |
| 8773 | int i = mAppTokens.size(); |
| 8774 | while (i > 0) { |
| 8775 | i--; |
| 8776 | AppWindowToken tok = mAppTokens.get(i); |
| 8777 | if (tok.freezingScreen) { |
| 8778 | Log.w(TAG, "Force clearing freeze: " + tok); |
| 8779 | unsetAppFreezingScreenLocked(tok, true, true); |
| 8780 | } |
| 8781 | } |
| 8782 | } |
| 8783 | break; |
| 8784 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8785 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8786 | case COMPUTE_AND_SEND_NEW_CONFIGURATION: { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 8787 | if (updateOrientationFromAppTokensUnchecked(null, null) != null) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8788 | sendNewConfiguration(); |
| 8789 | } |
| 8790 | break; |
| 8791 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8792 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8793 | } |
| 8794 | } |
| 8795 | } |
| 8796 | |
| 8797 | // ------------------------------------------------------------- |
| 8798 | // IWindowManager API |
| 8799 | // ------------------------------------------------------------- |
| 8800 | |
| 8801 | public IWindowSession openSession(IInputMethodClient client, |
| 8802 | IInputContext inputContext) { |
| 8803 | if (client == null) throw new IllegalArgumentException("null client"); |
| 8804 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
| 8805 | return new Session(client, inputContext); |
| 8806 | } |
| 8807 | |
| 8808 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 8809 | synchronized (mWindowMap) { |
| 8810 | // The focus for the client is the window immediately below |
| 8811 | // where we would place the input method window. |
| 8812 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 8813 | WindowState imFocus; |
| 8814 | if (idx > 0) { |
| 8815 | imFocus = (WindowState)mWindows.get(idx-1); |
| 8816 | if (imFocus != null) { |
| 8817 | if (imFocus.mSession.mClient != null && |
| 8818 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 8819 | return true; |
| 8820 | } |
| 8821 | } |
| 8822 | } |
| 8823 | } |
| 8824 | return false; |
| 8825 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8826 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8827 | // ------------------------------------------------------------- |
| 8828 | // Internals |
| 8829 | // ------------------------------------------------------------- |
| 8830 | |
| 8831 | final WindowState windowForClientLocked(Session session, IWindow client) { |
| 8832 | return windowForClientLocked(session, client.asBinder()); |
| 8833 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8834 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8835 | final WindowState windowForClientLocked(Session session, IBinder client) { |
| 8836 | WindowState win = mWindowMap.get(client); |
| 8837 | if (localLOGV) Log.v( |
| 8838 | TAG, "Looking up client " + client + ": " + win); |
| 8839 | if (win == null) { |
| 8840 | RuntimeException ex = new RuntimeException(); |
| 8841 | Log.w(TAG, "Requested window " + client + " does not exist", ex); |
| 8842 | return null; |
| 8843 | } |
| 8844 | if (session != null && win.mSession != session) { |
| 8845 | RuntimeException ex = new RuntimeException(); |
| 8846 | Log.w(TAG, "Requested window " + client + " is in session " + |
| 8847 | win.mSession + ", not " + session, ex); |
| 8848 | return null; |
| 8849 | } |
| 8850 | |
| 8851 | return win; |
| 8852 | } |
| 8853 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8854 | final void rebuildAppWindowListLocked() { |
| 8855 | int NW = mWindows.size(); |
| 8856 | int i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8857 | int lastWallpaper = -1; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8858 | int numRemoved = 0; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8859 | |
| 8860 | // First remove all existing app windows. |
| 8861 | i=0; |
| 8862 | while (i < NW) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8863 | WindowState w = (WindowState)mWindows.get(i); |
| 8864 | if (w.mAppToken != null) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8865 | WindowState win = (WindowState)mWindows.remove(i); |
| 8866 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, |
| 8867 | "Rebuild removing window: " + win); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8868 | NW--; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8869 | numRemoved++; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8870 | continue; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8871 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 8872 | && lastWallpaper == i-1) { |
| 8873 | lastWallpaper = i; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8874 | } |
| 8875 | i++; |
| 8876 | } |
| 8877 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8878 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 8879 | // so skip them before adding app tokens. |
| 8880 | lastWallpaper++; |
| 8881 | i = lastWallpaper; |
| 8882 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8883 | // First add all of the exiting app tokens... these are no longer |
| 8884 | // in the main app list, but still have windows shown. We put them |
| 8885 | // in the back because now that the animation is over we no longer |
| 8886 | // will care about them. |
| 8887 | int NT = mExitingAppTokens.size(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8888 | for (int j=0; j<NT; j++) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8889 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 8890 | } |
| 8891 | |
| 8892 | // And add in the still active app tokens in Z order. |
| 8893 | NT = mAppTokens.size(); |
| 8894 | for (int j=0; j<NT; j++) { |
| 8895 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8896 | } |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8897 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8898 | i -= lastWallpaper; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8899 | if (i != numRemoved) { |
| 8900 | Log.w(TAG, "Rebuild removed " + numRemoved |
| 8901 | + " windows but added " + i); |
| 8902 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8903 | } |
| 8904 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8905 | private final void assignLayersLocked() { |
| 8906 | int N = mWindows.size(); |
| 8907 | int curBaseLayer = 0; |
| 8908 | int curLayer = 0; |
| 8909 | int i; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8910 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8911 | for (i=0; i<N; i++) { |
| 8912 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8913 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 8914 | || (i > 0 && w.mIsWallpaper)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8915 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 8916 | w.mLayer = curLayer; |
| 8917 | } else { |
| 8918 | curBaseLayer = curLayer = w.mBaseLayer; |
| 8919 | w.mLayer = curLayer; |
| 8920 | } |
| 8921 | if (w.mTargetAppToken != null) { |
| 8922 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 8923 | } else if (w.mAppToken != null) { |
| 8924 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 8925 | } else { |
| 8926 | w.mAnimLayer = w.mLayer; |
| 8927 | } |
| 8928 | if (w.mIsImWindow) { |
| 8929 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8930 | } else if (w.mIsWallpaper) { |
| 8931 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8932 | } |
| 8933 | if (DEBUG_LAYERS) Log.v(TAG, "Assign layer " + w + ": " |
| 8934 | + w.mAnimLayer); |
| 8935 | //System.out.println( |
| 8936 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 8937 | } |
| 8938 | } |
| 8939 | |
| 8940 | private boolean mInLayout = false; |
| 8941 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 8942 | if (mInLayout) { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 8943 | if (DEBUG) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8944 | throw new RuntimeException("Recursive call!"); |
| 8945 | } |
| 8946 | Log.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
| 8947 | return; |
| 8948 | } |
| 8949 | |
| 8950 | boolean recoveringMemory = false; |
| 8951 | if (mForceRemoves != null) { |
| 8952 | recoveringMemory = true; |
| 8953 | // Wait a little it for things to settle down, and off we go. |
| 8954 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 8955 | WindowState ws = mForceRemoves.get(i); |
| 8956 | Log.i(TAG, "Force removing: " + ws); |
| 8957 | removeWindowInnerLocked(ws.mSession, ws); |
| 8958 | } |
| 8959 | mForceRemoves = null; |
| 8960 | Log.w(TAG, "Due to memory failure, waiting a bit for next layout"); |
| 8961 | Object tmp = new Object(); |
| 8962 | synchronized (tmp) { |
| 8963 | try { |
| 8964 | tmp.wait(250); |
| 8965 | } catch (InterruptedException e) { |
| 8966 | } |
| 8967 | } |
| 8968 | } |
| 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 | mInLayout = true; |
| 8971 | try { |
| 8972 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8973 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8974 | int i = mPendingRemove.size()-1; |
| 8975 | if (i >= 0) { |
| 8976 | while (i >= 0) { |
| 8977 | WindowState w = mPendingRemove.get(i); |
| 8978 | removeWindowInnerLocked(w.mSession, w); |
| 8979 | i--; |
| 8980 | } |
| 8981 | mPendingRemove.clear(); |
| 8982 | |
| 8983 | mInLayout = false; |
| 8984 | assignLayersLocked(); |
| 8985 | mLayoutNeeded = true; |
| 8986 | performLayoutAndPlaceSurfacesLocked(); |
| 8987 | |
| 8988 | } else { |
| 8989 | mInLayout = false; |
| 8990 | if (mLayoutNeeded) { |
| 8991 | requestAnimationLocked(0); |
| 8992 | } |
| 8993 | } |
| 8994 | } catch (RuntimeException e) { |
| 8995 | mInLayout = false; |
| 8996 | Log.e(TAG, "Unhandled exception while layout out windows", e); |
| 8997 | } |
| 8998 | } |
| 8999 | |
| 9000 | private final void performLayoutLockedInner() { |
| 9001 | final int dw = mDisplay.getWidth(); |
| 9002 | final int dh = mDisplay.getHeight(); |
| 9003 | |
| 9004 | final int N = mWindows.size(); |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9005 | int repeats = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9006 | int i; |
| 9007 | |
| 9008 | // FIRST LOOP: Perform a layout, if needed. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9009 | |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9010 | while (mLayoutNeeded) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9011 | mPolicy.beginLayoutLw(dw, dh); |
| 9012 | |
| 9013 | // First perform layout of any root windows (not attached |
| 9014 | // to another window). |
| 9015 | int topAttached = -1; |
| 9016 | for (i = N-1; i >= 0; i--) { |
| 9017 | WindowState win = (WindowState) mWindows.get(i); |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9018 | |
| 9019 | // Don't do layout of a window if it is not visible, or |
| 9020 | // soon won't be visible, to avoid wasting time and funky |
| 9021 | // changes while a window is animating away. |
| 9022 | final AppWindowToken atoken = win.mAppToken; |
| 9023 | final boolean gone = win.mViewVisibility == View.GONE |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9024 | || !win.mRelayoutCalled |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9025 | || win.mRootToken.hidden |
| 9026 | || (atoken != null && atoken.hiddenRequested) |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9027 | || win.mAttachedHidden |
| 9028 | || win.mExiting || win.mDestroying; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9029 | |
| 9030 | // If this view is GONE, then skip it -- keep the current |
| 9031 | // frame, and let the caller know so they can ignore it |
| 9032 | // if they want. (We do the normal layout for INVISIBLE |
| 9033 | // windows, since that means "perform layout as normal, |
| 9034 | // just don't display"). |
| 9035 | if (!gone || !win.mHaveFrame) { |
| 9036 | if (!win.mLayoutAttached) { |
| 9037 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 9038 | } else { |
| 9039 | if (topAttached < 0) topAttached = i; |
| 9040 | } |
| 9041 | } |
| 9042 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9043 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9044 | // Now perform layout of attached windows, which usually |
| 9045 | // depend on the position of the window they are attached to. |
| 9046 | // XXX does not deal with windows that are attached to windows |
| 9047 | // that are themselves attached. |
| 9048 | for (i = topAttached; i >= 0; i--) { |
| 9049 | WindowState win = (WindowState) mWindows.get(i); |
| 9050 | |
| 9051 | // If this view is GONE, then skip it -- keep the current |
| 9052 | // frame, and let the caller know so they can ignore it |
| 9053 | // if they want. (We do the normal layout for INVISIBLE |
| 9054 | // windows, since that means "perform layout as normal, |
| 9055 | // just don't display"). |
| 9056 | if (win.mLayoutAttached) { |
| 9057 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 9058 | || !win.mHaveFrame) { |
| 9059 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 9060 | } |
| 9061 | } |
| 9062 | } |
| 9063 | |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9064 | int changes = mPolicy.finishLayoutLw(); |
| 9065 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 9066 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9067 | assignLayersLocked(); |
| 9068 | } |
| 9069 | } |
| 9070 | if (changes == 0) { |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9071 | mLayoutNeeded = false; |
| 9072 | } else if (repeats > 2) { |
| 9073 | Log.w(TAG, "Layout repeat aborted after too many iterations"); |
| 9074 | mLayoutNeeded = false; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9075 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 9076 | Configuration newConfig = updateOrientationFromAppTokensLocked( |
| 9077 | null, null); |
| 9078 | if (newConfig != null) { |
| 9079 | mLayoutNeeded = true; |
| 9080 | mH.sendEmptyMessage(H.COMPUTE_AND_SEND_NEW_CONFIGURATION); |
| 9081 | } |
| 9082 | } |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9083 | } else { |
| 9084 | repeats++; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9085 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 9086 | Configuration newConfig = updateOrientationFromAppTokensLocked( |
| 9087 | null, null); |
| 9088 | if (newConfig != null) { |
| 9089 | mH.sendEmptyMessage(H.COMPUTE_AND_SEND_NEW_CONFIGURATION); |
| 9090 | } |
| 9091 | } |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9092 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9093 | } |
| 9094 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9095 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9096 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 9097 | boolean recoveringMemory) { |
| 9098 | final long currentTime = SystemClock.uptimeMillis(); |
| 9099 | final int dw = mDisplay.getWidth(); |
| 9100 | final int dh = mDisplay.getHeight(); |
| 9101 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9102 | int i; |
| 9103 | |
| 9104 | // FIRST LOOP: Perform a layout, if needed. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9105 | performLayoutLockedInner(); |
| 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 (mFxSession == null) { |
| 9108 | mFxSession = new SurfaceSession(); |
| 9109 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9110 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9111 | if (SHOW_TRANSACTIONS) Log.i(TAG, ">>> OPEN TRANSACTION"); |
| 9112 | |
| 9113 | // Initialize state of exiting tokens. |
| 9114 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9115 | mExitingTokens.get(i).hasVisible = false; |
| 9116 | } |
| 9117 | |
| 9118 | // Initialize state of exiting applications. |
| 9119 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9120 | mExitingAppTokens.get(i).hasVisible = false; |
| 9121 | } |
| 9122 | |
| 9123 | // SECOND LOOP: Execute animations and update visibility of windows. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9124 | boolean orientationChangeComplete = true; |
| 9125 | Session holdScreen = null; |
| 9126 | float screenBrightness = -1; |
| 9127 | boolean focusDisplayed = false; |
| 9128 | boolean animating = false; |
| 9129 | |
| 9130 | Surface.openTransaction(); |
| 9131 | try { |
| 9132 | boolean restart; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9133 | boolean forceHiding = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9134 | |
| 9135 | do { |
| 9136 | final int transactionSequence = ++mTransactionSequence; |
| 9137 | |
| 9138 | // Update animations of all applications, including those |
| 9139 | // associated with exiting/removed apps |
| 9140 | boolean tokensAnimating = false; |
| 9141 | final int NAT = mAppTokens.size(); |
| 9142 | for (i=0; i<NAT; i++) { |
| 9143 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9144 | tokensAnimating = true; |
| 9145 | } |
| 9146 | } |
| 9147 | final int NEAT = mExitingAppTokens.size(); |
| 9148 | for (i=0; i<NEAT; i++) { |
| 9149 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9150 | tokensAnimating = true; |
| 9151 | } |
| 9152 | } |
| 9153 | |
| 9154 | animating = tokensAnimating; |
| 9155 | restart = false; |
| 9156 | |
| 9157 | boolean tokenMayBeDrawn = false; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9158 | boolean wallpaperMayChange = false; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9159 | boolean focusMayChange = false; |
| 9160 | boolean wallpaperForceHidingChanged = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9161 | |
| 9162 | mPolicy.beginAnimationLw(dw, dh); |
| 9163 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9164 | final int N = mWindows.size(); |
| 9165 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9166 | for (i=N-1; i>=0; i--) { |
| 9167 | WindowState w = (WindowState)mWindows.get(i); |
| 9168 | |
| 9169 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9170 | |
| 9171 | if (w.mSurface != null) { |
| 9172 | // Execute animation. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9173 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 9174 | if ((w.mAttrs.flags |
| 9175 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9176 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 9177 | "First draw done in potential wallpaper target " + w); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9178 | wallpaperMayChange = true; |
| 9179 | } |
| 9180 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9181 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9182 | boolean wasAnimating = w.mAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9183 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 9184 | animating = true; |
| 9185 | //w.dump(" "); |
| 9186 | } |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9187 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 9188 | wallpaperMayChange = true; |
| 9189 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9190 | |
| 9191 | if (mPolicy.doesForceHide(w, attrs)) { |
| 9192 | if (!wasAnimating && animating) { |
| 9193 | wallpaperForceHidingChanged = true; |
| 9194 | focusMayChange = true; |
| 9195 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 9196 | forceHiding = true; |
| 9197 | } |
| 9198 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9199 | boolean changed; |
| 9200 | if (forceHiding) { |
| 9201 | changed = w.hideLw(false, false); |
| 9202 | } else { |
| 9203 | changed = w.showLw(false, false); |
| 9204 | if (changed && wallpaperForceHidingChanged |
| 9205 | && w.isReadyForDisplay()) { |
| 9206 | // Assume we will need to animate. If |
| 9207 | // we don't (because the wallpaper will |
| 9208 | // stay with the lock screen), then we will |
| 9209 | // clean up later. |
| 9210 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 9211 | if (a != null) { |
| 9212 | w.setAnimation(a); |
| 9213 | } |
| 9214 | } |
| 9215 | } |
| 9216 | if (changed && (attrs.flags |
| 9217 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 9218 | wallpaperMayChange = true; |
| 9219 | } |
| 9220 | } |
| 9221 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9222 | mPolicy.animatingWindowLw(w, attrs); |
| 9223 | } |
| 9224 | |
| 9225 | final AppWindowToken atoken = w.mAppToken; |
| 9226 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 9227 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 9228 | atoken.lastTransactionSequence = transactionSequence; |
| 9229 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 9230 | atoken.startingDisplayed = false; |
| 9231 | } |
| 9232 | if ((w.isOnScreen() || w.mAttrs.type |
| 9233 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 9234 | && !w.mExiting && !w.mDestroying) { |
| 9235 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9236 | Log.v(TAG, "Eval win " + w + ": isDrawn=" |
| 9237 | + w.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9238 | + ", isAnimating=" + w.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9239 | if (!w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9240 | Log.v(TAG, "Not displayed: s=" + w.mSurface |
| 9241 | + " pv=" + w.mPolicyVisibility |
| 9242 | + " dp=" + w.mDrawPending |
| 9243 | + " cdp=" + w.mCommitDrawPending |
| 9244 | + " ah=" + w.mAttachedHidden |
| 9245 | + " th=" + atoken.hiddenRequested |
| 9246 | + " a=" + w.mAnimating); |
| 9247 | } |
| 9248 | } |
| 9249 | if (w != atoken.startingWindow) { |
| 9250 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 9251 | atoken.numInterestingWindows++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9252 | if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9253 | atoken.numDrawnWindows++; |
| 9254 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Log.v(TAG, |
| 9255 | "tokenMayBeDrawn: " + atoken |
| 9256 | + " freezingScreen=" + atoken.freezingScreen |
| 9257 | + " mAppFreezing=" + w.mAppFreezing); |
| 9258 | tokenMayBeDrawn = true; |
| 9259 | } |
| 9260 | } |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9261 | } else if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9262 | atoken.startingDisplayed = true; |
| 9263 | } |
| 9264 | } |
| 9265 | } else if (w.mReadyToShow) { |
| 9266 | w.performShowLocked(); |
| 9267 | } |
| 9268 | } |
| 9269 | |
| 9270 | if (mPolicy.finishAnimationLw()) { |
| 9271 | restart = true; |
| 9272 | } |
| 9273 | |
| 9274 | if (tokenMayBeDrawn) { |
| 9275 | // See if any windows have been drawn, so they (and others |
| 9276 | // associated with them) can now be shown. |
| 9277 | final int NT = mTokenList.size(); |
| 9278 | for (i=0; i<NT; i++) { |
| 9279 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 9280 | if (wtoken == null) { |
| 9281 | continue; |
| 9282 | } |
| 9283 | if (wtoken.freezingScreen) { |
| 9284 | int numInteresting = wtoken.numInterestingWindows; |
| 9285 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| 9286 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 9287 | "allDrawn: " + wtoken |
| 9288 | + " interesting=" + numInteresting |
| 9289 | + " drawn=" + wtoken.numDrawnWindows); |
| 9290 | wtoken.showAllWindowsLocked(); |
| 9291 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 9292 | orientationChangeComplete = true; |
| 9293 | } |
| 9294 | } else if (!wtoken.allDrawn) { |
| 9295 | int numInteresting = wtoken.numInterestingWindows; |
| 9296 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| 9297 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 9298 | "allDrawn: " + wtoken |
| 9299 | + " interesting=" + numInteresting |
| 9300 | + " drawn=" + wtoken.numDrawnWindows); |
| 9301 | wtoken.allDrawn = true; |
| 9302 | restart = true; |
| 9303 | |
| 9304 | // We can now show all of the drawn windows! |
| 9305 | if (!mOpeningApps.contains(wtoken)) { |
| 9306 | wtoken.showAllWindowsLocked(); |
| 9307 | } |
| 9308 | } |
| 9309 | } |
| 9310 | } |
| 9311 | } |
| 9312 | |
| 9313 | // If we are ready to perform an app transition, check through |
| 9314 | // all of the app tokens to be shown and see if they are ready |
| 9315 | // to go. |
| 9316 | if (mAppTransitionReady) { |
| 9317 | int NN = mOpeningApps.size(); |
| 9318 | boolean goodToGo = true; |
| 9319 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9320 | "Checking " + NN + " opening apps (frozen=" |
| 9321 | + mDisplayFrozen + " timeout=" |
| 9322 | + mAppTransitionTimeout + ")..."); |
| 9323 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 9324 | // If the display isn't frozen, wait to do anything until |
| 9325 | // all of the apps are ready. Otherwise just go because |
| 9326 | // we'll unfreeze the display when everyone is ready. |
| 9327 | for (i=0; i<NN && goodToGo; i++) { |
| 9328 | AppWindowToken wtoken = mOpeningApps.get(i); |
| 9329 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9330 | "Check opening app" + wtoken + ": allDrawn=" |
| 9331 | + wtoken.allDrawn + " startingDisplayed=" |
| 9332 | + wtoken.startingDisplayed); |
| 9333 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 9334 | && !wtoken.startingMoved) { |
| 9335 | goodToGo = false; |
| 9336 | } |
| 9337 | } |
| 9338 | } |
| 9339 | if (goodToGo) { |
| 9340 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "**** GOOD TO GO"); |
| 9341 | int transit = mNextAppTransition; |
| 9342 | if (mSkipAppTransitionAnimation) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9343 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9344 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9345 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9346 | mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9347 | mAppTransitionRunning = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9348 | mAppTransitionTimeout = false; |
| 9349 | mStartingIconInTransition = false; |
| 9350 | mSkipAppTransitionAnimation = false; |
| 9351 | |
| 9352 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 9353 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9354 | // If there are applications waiting to come to the |
| 9355 | // top of the stack, now is the time to move their windows. |
| 9356 | // (Note that we don't do apps going to the bottom |
| 9357 | // here -- we want to keep their windows in the old |
| 9358 | // Z-order until the animation completes.) |
| 9359 | if (mToTopApps.size() > 0) { |
| 9360 | NN = mAppTokens.size(); |
| 9361 | for (i=0; i<NN; i++) { |
| 9362 | AppWindowToken wtoken = mAppTokens.get(i); |
| 9363 | if (wtoken.sendingToTop) { |
| 9364 | wtoken.sendingToTop = false; |
| 9365 | moveAppWindowsLocked(wtoken, NN, false); |
| 9366 | } |
| 9367 | } |
| 9368 | mToTopApps.clear(); |
| 9369 | } |
| 9370 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9371 | WindowState oldWallpaper = mWallpaperTarget; |
| 9372 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9373 | adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9374 | wallpaperMayChange = false; |
| 9375 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9376 | // The top-most window will supply the layout params, |
| 9377 | // and we will determine it below. |
| 9378 | LayoutParams animLp = null; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9379 | AppWindowToken animToken = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9380 | int bestAnimLayer = -1; |
| 9381 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9382 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9383 | "New wallpaper target=" + mWallpaperTarget |
| 9384 | + ", lower target=" + mLowerWallpaperTarget |
| 9385 | + ", upper target=" + mUpperWallpaperTarget); |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9386 | int foundWallpapers = 0; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9387 | // Do a first pass through the tokens for two |
| 9388 | // things: |
| 9389 | // (1) Determine if both the closing and opening |
| 9390 | // app token sets are wallpaper targets, in which |
| 9391 | // case special animations are needed |
| 9392 | // (since the wallpaper needs to stay static |
| 9393 | // behind them). |
| 9394 | // (2) Find the layout params of the top-most |
| 9395 | // application window in the tokens, which is |
| 9396 | // what will control the animation theme. |
| 9397 | final int NC = mClosingApps.size(); |
| 9398 | NN = NC + mOpeningApps.size(); |
| 9399 | for (i=0; i<NN; i++) { |
| 9400 | AppWindowToken wtoken; |
| 9401 | int mode; |
| 9402 | if (i < NC) { |
| 9403 | wtoken = mClosingApps.get(i); |
| 9404 | mode = 1; |
| 9405 | } else { |
| 9406 | wtoken = mOpeningApps.get(i-NC); |
| 9407 | mode = 2; |
| 9408 | } |
| 9409 | if (mLowerWallpaperTarget != null) { |
| 9410 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 9411 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 9412 | foundWallpapers |= mode; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9413 | } |
| 9414 | } |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9415 | if (wtoken.appFullscreen) { |
| 9416 | WindowState ws = wtoken.findMainWindow(); |
| 9417 | if (ws != null) { |
| 9418 | // If this is a compatibility mode |
| 9419 | // window, we will always use its anim. |
| 9420 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 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 = Integer.MAX_VALUE; |
| 9424 | } else if (ws.mLayer > bestAnimLayer) { |
| 9425 | animLp = ws.mAttrs; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9426 | animToken = ws.mAppToken; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9427 | bestAnimLayer = ws.mLayer; |
| 9428 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9429 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9430 | } |
| 9431 | } |
| 9432 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9433 | if (foundWallpapers == 3) { |
| 9434 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9435 | "Wallpaper animation!"); |
| 9436 | switch (transit) { |
| 9437 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 9438 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 9439 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 9440 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 9441 | break; |
| 9442 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 9443 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 9444 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 9445 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 9446 | break; |
| 9447 | } |
| 9448 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9449 | "New transit: " + transit); |
| 9450 | } else if (oldWallpaper != null) { |
| 9451 | // We are transitioning from an activity with |
| 9452 | // a wallpaper to one without. |
| 9453 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
| 9454 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9455 | "New transit away from wallpaper: " + transit); |
| 9456 | } else if (mWallpaperTarget != null) { |
| 9457 | // We are transitioning from an activity without |
| 9458 | // a wallpaper to now showing the wallpaper |
| 9459 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
| 9460 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9461 | "New transit into wallpaper: " + transit); |
| 9462 | } |
| 9463 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9464 | if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) { |
| 9465 | mLastEnterAnimToken = animToken; |
| 9466 | mLastEnterAnimParams = animLp; |
| 9467 | } else if (mLastEnterAnimParams != null) { |
| 9468 | animLp = mLastEnterAnimParams; |
| 9469 | mLastEnterAnimToken = null; |
| 9470 | mLastEnterAnimParams = null; |
| 9471 | } |
| 9472 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9473 | NN = mOpeningApps.size(); |
| 9474 | for (i=0; i<NN; i++) { |
| 9475 | AppWindowToken wtoken = mOpeningApps.get(i); |
| 9476 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9477 | "Now opening app" + wtoken); |
| 9478 | wtoken.reportedVisible = false; |
| 9479 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9480 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9481 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9482 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9483 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9484 | wtoken.showAllWindowsLocked(); |
| 9485 | } |
| 9486 | NN = mClosingApps.size(); |
| 9487 | for (i=0; i<NN; i++) { |
| 9488 | AppWindowToken wtoken = mClosingApps.get(i); |
| 9489 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9490 | "Now closing app" + wtoken); |
| 9491 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9492 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9493 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9494 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9495 | wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9496 | // Force the allDrawn flag, because we want to start |
| 9497 | // this guy's animations regardless of whether it's |
| 9498 | // gotten drawn. |
| 9499 | wtoken.allDrawn = true; |
| 9500 | } |
| 9501 | |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 9502 | mNextAppTransitionPackage = null; |
| 9503 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9504 | mOpeningApps.clear(); |
| 9505 | mClosingApps.clear(); |
| 9506 | |
| 9507 | // This has changed the visibility of windows, so perform |
| 9508 | // a new layout to get them all up-to-date. |
| 9509 | mLayoutNeeded = true; |
| Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 9510 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 9511 | assignLayersLocked(); |
| 9512 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9513 | performLayoutLockedInner(); |
| 9514 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9515 | focusMayChange = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9516 | |
| 9517 | restart = true; |
| 9518 | } |
| 9519 | } |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9520 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9521 | if (!animating && mAppTransitionRunning) { |
| 9522 | // We have finished the animation of an app transition. To do |
| 9523 | // this, we have delayed a lot of operations like showing and |
| 9524 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 9525 | // reflects the correct Z-order, but the window list may now |
| 9526 | // be out of sync with it. So here we will just rebuild the |
| 9527 | // entire app window list. Fun! |
| 9528 | mAppTransitionRunning = false; |
| 9529 | // Clear information about apps that were moving. |
| 9530 | mToBottomApps.clear(); |
| 9531 | |
| 9532 | rebuildAppWindowListLocked(); |
| 9533 | restart = true; |
| 9534 | moveInputMethodWindowsIfNeededLocked(false); |
| 9535 | wallpaperMayChange = true; |
| 9536 | mLayoutNeeded = true; |
| 9537 | } |
| 9538 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9539 | int adjResult = 0; |
| 9540 | |
| 9541 | if (wallpaperForceHidingChanged) { |
| 9542 | // At this point, there was a window with a wallpaper that |
| 9543 | // was force hiding other windows behind it, but now it |
| 9544 | // is going away. This may be simple -- just animate |
| 9545 | // away the wallpaper and its window -- or it may be |
| 9546 | // hard -- the wallpaper now needs to be shown behind |
| 9547 | // something that was hidden. |
| 9548 | WindowState oldWallpaper = mWallpaperTarget; |
| 9549 | adjResult = adjustWallpaperWindowsLocked(); |
| 9550 | wallpaperMayChange = false; |
| 9551 | if (false) Log.v(TAG, "****** OLD: " + oldWallpaper |
| 9552 | + " NEW: " + mWallpaperTarget); |
| 9553 | if (mLowerWallpaperTarget == null) { |
| 9554 | // Whoops, we don't need a special wallpaper animation. |
| 9555 | // Clear them out. |
| 9556 | forceHiding = false; |
| 9557 | for (i=N-1; i>=0; i--) { |
| 9558 | WindowState w = (WindowState)mWindows.get(i); |
| 9559 | if (w.mSurface != null) { |
| 9560 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9561 | if (mPolicy.doesForceHide(w, attrs)) { |
| 9562 | forceHiding = true; |
| 9563 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9564 | if (!w.mAnimating) { |
| 9565 | // We set the animation above so it |
| 9566 | // is not yet running. |
| 9567 | w.clearAnimation(); |
| 9568 | } |
| 9569 | } |
| 9570 | } |
| 9571 | } |
| 9572 | } |
| 9573 | } |
| 9574 | |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9575 | if (wallpaperMayChange) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9576 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 9577 | "Wallpaper may change! Adjusting"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9578 | adjResult = adjustWallpaperWindowsLocked(); |
| 9579 | } |
| 9580 | |
| 9581 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9582 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 9583 | "Wallpaper layer changed: assigning layers + relayout"); |
| 9584 | restart = true; |
| 9585 | mLayoutNeeded = true; |
| 9586 | assignLayersLocked(); |
| 9587 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
| 9588 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 9589 | "Wallpaper visibility changed: relayout"); |
| 9590 | restart = true; |
| 9591 | mLayoutNeeded = true; |
| 9592 | } |
| 9593 | |
| 9594 | if (focusMayChange) { |
| 9595 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9596 | restart = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9597 | adjResult = 0; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9598 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9599 | } |
| 9600 | |
| 9601 | if (mLayoutNeeded) { |
| 9602 | restart = true; |
| 9603 | performLayoutLockedInner(); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9604 | } |
| 9605 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9606 | } while (restart); |
| 9607 | |
| 9608 | // THIRD LOOP: Update the surfaces of all windows. |
| 9609 | |
| 9610 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 9611 | |
| 9612 | boolean obscured = false; |
| 9613 | boolean blurring = false; |
| 9614 | boolean dimming = false; |
| 9615 | boolean covered = false; |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9616 | boolean syswin = false; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9617 | boolean backgroundFillerShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9618 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9619 | final int N = mWindows.size(); |
| 9620 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9621 | for (i=N-1; i>=0; i--) { |
| 9622 | WindowState w = (WindowState)mWindows.get(i); |
| 9623 | |
| 9624 | boolean displayed = false; |
| 9625 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9626 | final int attrFlags = attrs.flags; |
| 9627 | |
| 9628 | if (w.mSurface != null) { |
| 9629 | w.computeShownFrameLocked(); |
| 9630 | if (localLOGV) Log.v( |
| 9631 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 9632 | + ": new=" + w.mShownFrame + ", old=" |
| 9633 | + w.mLastShownFrame); |
| 9634 | |
| 9635 | boolean resize; |
| 9636 | int width, height; |
| 9637 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 9638 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 9639 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 9640 | // for a scaled surface, we just want to use |
| 9641 | // the requested size. |
| 9642 | width = w.mRequestedWidth; |
| 9643 | height = w.mRequestedHeight; |
| 9644 | w.mLastRequestedWidth = width; |
| 9645 | w.mLastRequestedHeight = height; |
| 9646 | w.mLastShownFrame.set(w.mShownFrame); |
| 9647 | try { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9648 | if (SHOW_TRANSACTIONS) Log.i( |
| 9649 | TAG, " SURFACE " + w.mSurface |
| 9650 | + ": POS " + w.mShownFrame.left |
| 9651 | + ", " + w.mShownFrame.top); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9652 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 9653 | } catch (RuntimeException e) { |
| 9654 | Log.w(TAG, "Error positioning surface in " + w, e); |
| 9655 | if (!recoveringMemory) { |
| 9656 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 9657 | } |
| 9658 | } |
| 9659 | } else { |
| 9660 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 9661 | width = w.mShownFrame.width(); |
| 9662 | height = w.mShownFrame.height(); |
| 9663 | w.mLastShownFrame.set(w.mShownFrame); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9664 | } |
| 9665 | |
| 9666 | if (resize) { |
| 9667 | if (width < 1) width = 1; |
| 9668 | if (height < 1) height = 1; |
| 9669 | if (w.mSurface != null) { |
| 9670 | try { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9671 | if (SHOW_TRANSACTIONS) Log.i( |
| 9672 | TAG, " SURFACE " + w.mSurface + ": POS " |
| 9673 | + w.mShownFrame.left + "," |
| 9674 | + w.mShownFrame.top + " SIZE " |
| 9675 | + w.mShownFrame.width() + "x" |
| 9676 | + w.mShownFrame.height()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9677 | w.mSurface.setSize(width, height); |
| 9678 | w.mSurface.setPosition(w.mShownFrame.left, |
| 9679 | w.mShownFrame.top); |
| 9680 | } catch (RuntimeException e) { |
| 9681 | // If something goes wrong with the surface (such |
| 9682 | // as running out of memory), don't take down the |
| 9683 | // entire system. |
| 9684 | Log.e(TAG, "Failure updating surface of " + w |
| 9685 | + "size=(" + width + "x" + height |
| 9686 | + "), pos=(" + w.mShownFrame.left |
| 9687 | + "," + w.mShownFrame.top + ")", e); |
| 9688 | if (!recoveringMemory) { |
| 9689 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 9690 | } |
| 9691 | } |
| 9692 | } |
| 9693 | } |
| 9694 | if (!w.mAppFreezing) { |
| 9695 | w.mContentInsetsChanged = |
| 9696 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 9697 | w.mVisibleInsetsChanged = |
| 9698 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9699 | if (!w.mLastFrame.equals(w.mFrame) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9700 | || w.mContentInsetsChanged |
| 9701 | || w.mVisibleInsetsChanged) { |
| 9702 | w.mLastFrame.set(w.mFrame); |
| 9703 | w.mLastContentInsets.set(w.mContentInsets); |
| 9704 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9705 | // If the screen is currently frozen, then keep |
| 9706 | // it frozen until this window draws at its new |
| 9707 | // orientation. |
| 9708 | if (mDisplayFrozen) { |
| 9709 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 9710 | "Resizing while display frozen: " + w); |
| 9711 | w.mOrientationChanging = true; |
| 9712 | if (mWindowsFreezingScreen) { |
| 9713 | mWindowsFreezingScreen = true; |
| 9714 | // XXX should probably keep timeout from |
| 9715 | // when we first froze the display. |
| 9716 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 9717 | mH.sendMessageDelayed(mH.obtainMessage( |
| 9718 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 9719 | } |
| 9720 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9721 | // If the orientation is changing, then we need to |
| 9722 | // hold off on unfreezing the display until this |
| 9723 | // window has been redrawn; to do that, we need |
| 9724 | // to go through the process of getting informed |
| 9725 | // by the application when it has finished drawing. |
| 9726 | if (w.mOrientationChanging) { |
| 9727 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 9728 | "Orientation start waiting for draw in " |
| 9729 | + w + ", surface " + w.mSurface); |
| 9730 | w.mDrawPending = true; |
| 9731 | w.mCommitDrawPending = false; |
| 9732 | w.mReadyToShow = false; |
| 9733 | if (w.mAppToken != null) { |
| 9734 | w.mAppToken.allDrawn = false; |
| 9735 | } |
| 9736 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9737 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9738 | "Resizing window " + w + " to " + w.mFrame); |
| 9739 | mResizingWindows.add(w); |
| 9740 | } else if (w.mOrientationChanging) { |
| 9741 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
| 9742 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 9743 | "Orientation not waiting for draw in " |
| 9744 | + w + ", surface " + w.mSurface); |
| 9745 | w.mOrientationChanging = false; |
| 9746 | } |
| 9747 | } |
| 9748 | } |
| 9749 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9750 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9751 | if (!w.mLastHidden) { |
| 9752 | //dump(); |
| 9753 | w.mLastHidden = true; |
| 9754 | if (SHOW_TRANSACTIONS) Log.i( |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9755 | TAG, " SURFACE " + w.mSurface + ": HIDE (performLayout)"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9756 | if (w.mSurface != null) { |
| 9757 | try { |
| 9758 | w.mSurface.hide(); |
| 9759 | } catch (RuntimeException e) { |
| 9760 | Log.w(TAG, "Exception hiding surface in " + w); |
| 9761 | } |
| 9762 | } |
| 9763 | mKeyWaiter.releasePendingPointerLocked(w.mSession); |
| 9764 | } |
| 9765 | // If we are waiting for this window to handle an |
| 9766 | // orientation change, well, it is hidden, so |
| 9767 | // doesn't really matter. Note that this does |
| 9768 | // introduce a potential glitch if the window |
| 9769 | // becomes unhidden before it has drawn for the |
| 9770 | // new orientation. |
| 9771 | if (w.mOrientationChanging) { |
| 9772 | w.mOrientationChanging = false; |
| 9773 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 9774 | "Orientation change skips hidden " + w); |
| 9775 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9776 | } else if (w.mLastLayer != w.mAnimLayer |
| 9777 | || w.mLastAlpha != w.mShownAlpha |
| 9778 | || w.mLastDsDx != w.mDsDx |
| 9779 | || w.mLastDtDx != w.mDtDx |
| 9780 | || w.mLastDsDy != w.mDsDy |
| 9781 | || w.mLastDtDy != w.mDtDy |
| 9782 | || w.mLastHScale != w.mHScale |
| 9783 | || w.mLastVScale != w.mVScale |
| 9784 | || w.mLastHidden) { |
| 9785 | displayed = true; |
| 9786 | w.mLastAlpha = w.mShownAlpha; |
| 9787 | w.mLastLayer = w.mAnimLayer; |
| 9788 | w.mLastDsDx = w.mDsDx; |
| 9789 | w.mLastDtDx = w.mDtDx; |
| 9790 | w.mLastDsDy = w.mDsDy; |
| 9791 | w.mLastDtDy = w.mDtDy; |
| 9792 | w.mLastHScale = w.mHScale; |
| 9793 | w.mLastVScale = w.mVScale; |
| 9794 | if (SHOW_TRANSACTIONS) Log.i( |
| 9795 | TAG, " SURFACE " + w.mSurface + ": alpha=" |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9796 | + w.mShownAlpha + " layer=" + w.mAnimLayer |
| 9797 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 9798 | + "," + (w.mDtDx*w.mVScale) |
| 9799 | + "][" + (w.mDsDy*w.mHScale) |
| 9800 | + "," + (w.mDtDy*w.mVScale) + "]"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9801 | if (w.mSurface != null) { |
| 9802 | try { |
| 9803 | w.mSurface.setAlpha(w.mShownAlpha); |
| 9804 | w.mSurface.setLayer(w.mAnimLayer); |
| 9805 | w.mSurface.setMatrix( |
| 9806 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 9807 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 9808 | } catch (RuntimeException e) { |
| 9809 | Log.w(TAG, "Error updating surface in " + w, e); |
| 9810 | if (!recoveringMemory) { |
| 9811 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 9812 | } |
| 9813 | } |
| 9814 | } |
| 9815 | |
| 9816 | if (w.mLastHidden && !w.mDrawPending |
| 9817 | && !w.mCommitDrawPending |
| 9818 | && !w.mReadyToShow) { |
| 9819 | if (SHOW_TRANSACTIONS) Log.i( |
| 9820 | TAG, " SURFACE " + w.mSurface + ": SHOW (performLayout)"); |
| 9821 | if (DEBUG_VISIBILITY) Log.v(TAG, "Showing " + w |
| 9822 | + " during relayout"); |
| 9823 | if (showSurfaceRobustlyLocked(w)) { |
| 9824 | w.mHasDrawn = true; |
| 9825 | w.mLastHidden = false; |
| 9826 | } else { |
| 9827 | w.mOrientationChanging = false; |
| 9828 | } |
| 9829 | } |
| 9830 | if (w.mSurface != null) { |
| 9831 | w.mToken.hasVisible = true; |
| 9832 | } |
| 9833 | } else { |
| 9834 | displayed = true; |
| 9835 | } |
| 9836 | |
| 9837 | if (displayed) { |
| 9838 | if (!covered) { |
| 9839 | if (attrs.width == LayoutParams.FILL_PARENT |
| 9840 | && attrs.height == LayoutParams.FILL_PARENT) { |
| 9841 | covered = true; |
| 9842 | } |
| 9843 | } |
| 9844 | if (w.mOrientationChanging) { |
| 9845 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 9846 | orientationChangeComplete = false; |
| 9847 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 9848 | "Orientation continue waiting for draw in " + w); |
| 9849 | } else { |
| 9850 | w.mOrientationChanging = false; |
| 9851 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 9852 | "Orientation change complete in " + w); |
| 9853 | } |
| 9854 | } |
| 9855 | w.mToken.hasVisible = true; |
| 9856 | } |
| 9857 | } else if (w.mOrientationChanging) { |
| 9858 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 9859 | "Orientation change skips hidden " + w); |
| 9860 | w.mOrientationChanging = false; |
| 9861 | } |
| 9862 | |
| 9863 | final boolean canBeSeen = w.isDisplayedLw(); |
| 9864 | |
| 9865 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 9866 | focusDisplayed = true; |
| 9867 | } |
| 9868 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 9869 | final boolean obscuredChanged = w.mObscured != obscured; |
| 9870 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9871 | // Update effect. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9872 | if (!(w.mObscured=obscured)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9873 | if (w.mSurface != null) { |
| 9874 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 9875 | holdScreen = w.mSession; |
| 9876 | } |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9877 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 9878 | && screenBrightness < 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9879 | screenBrightness = w.mAttrs.screenBrightness; |
| 9880 | } |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9881 | if (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 9882 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 9883 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR) { |
| 9884 | syswin = true; |
| 9885 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9886 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9887 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9888 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 9889 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9890 | // This window completely covers everything behind it, |
| 9891 | // so we want to leave all of them as unblurred (for |
| 9892 | // performance reasons). |
| 9893 | obscured = true; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9894 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
| 9895 | if (SHOW_TRANSACTIONS) Log.d(TAG, "showing background filler"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9896 | // This window is in compatibility mode, and needs background filler. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9897 | obscured = true; |
| 9898 | if (mBackgroundFillerSurface == null) { |
| 9899 | try { |
| 9900 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
| 9901 | 0, dw, dh, |
| 9902 | PixelFormat.OPAQUE, |
| 9903 | Surface.FX_SURFACE_NORMAL); |
| 9904 | } catch (Exception e) { |
| 9905 | Log.e(TAG, "Exception creating filler surface", e); |
| 9906 | } |
| 9907 | } |
| 9908 | try { |
| 9909 | mBackgroundFillerSurface.setPosition(0, 0); |
| 9910 | mBackgroundFillerSurface.setSize(dw, dh); |
| 9911 | // Using the same layer as Dim because they will never be shown at the |
| 9912 | // same time. |
| 9913 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 9914 | mBackgroundFillerSurface.show(); |
| 9915 | } catch (RuntimeException e) { |
| 9916 | Log.e(TAG, "Exception showing filler surface"); |
| 9917 | } |
| 9918 | backgroundFillerShown = true; |
| 9919 | mBackgroundFillerShown = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9920 | } else if (canBeSeen && !obscured && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9921 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
| 9922 | if (localLOGV) Log.v(TAG, "Win " + w |
| 9923 | + ": blurring=" + blurring |
| 9924 | + " obscured=" + obscured |
| 9925 | + " displayed=" + displayed); |
| 9926 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 9927 | if (!dimming) { |
| 9928 | //Log.i(TAG, "DIM BEHIND: " + w); |
| 9929 | dimming = true; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9930 | if (mDimAnimator == null) { |
| 9931 | mDimAnimator = new DimAnimator(mFxSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9932 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9933 | mDimAnimator.show(dw, dh); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9934 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9935 | mDimAnimator.updateParameters(w, currentTime); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9936 | } |
| 9937 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 9938 | if (!blurring) { |
| 9939 | //Log.i(TAG, "BLUR BEHIND: " + w); |
| 9940 | blurring = true; |
| 9941 | mBlurShown = true; |
| 9942 | if (mBlurSurface == null) { |
| 9943 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " |
| 9944 | + mBlurSurface + ": CREATE"); |
| 9945 | try { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9946 | mBlurSurface = new Surface(mFxSession, 0, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9947 | -1, 16, 16, |
| 9948 | PixelFormat.OPAQUE, |
| 9949 | Surface.FX_SURFACE_BLUR); |
| 9950 | } catch (Exception e) { |
| 9951 | Log.e(TAG, "Exception creating Blur surface", e); |
| 9952 | } |
| 9953 | } |
| 9954 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " |
| 9955 | + mBlurSurface + ": SHOW pos=(0,0) (" + |
| 9956 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
| 9957 | if (mBlurSurface != null) { |
| 9958 | mBlurSurface.setPosition(0, 0); |
| 9959 | mBlurSurface.setSize(dw, dh); |
| 9960 | try { |
| 9961 | mBlurSurface.show(); |
| 9962 | } catch (RuntimeException e) { |
| 9963 | Log.w(TAG, "Failure showing blur surface", e); |
| 9964 | } |
| 9965 | } |
| 9966 | } |
| 9967 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 9968 | } |
| 9969 | } |
| 9970 | } |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 9971 | |
| 9972 | if (obscuredChanged && mWallpaperTarget == w) { |
| 9973 | // This is the wallpaper target and its obscured state |
| 9974 | // changed... make sure the current wallaper's visibility |
| 9975 | // has been updated accordingly. |
| 9976 | updateWallpaperVisibilityLocked(); |
| 9977 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9978 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9979 | |
| 9980 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 9981 | mBackgroundFillerShown = false; |
| 9982 | if (SHOW_TRANSACTIONS) Log.d(TAG, "hiding background filler"); |
| 9983 | try { |
| 9984 | mBackgroundFillerSurface.hide(); |
| 9985 | } catch (RuntimeException e) { |
| 9986 | Log.e(TAG, "Exception hiding filler surface", e); |
| 9987 | } |
| 9988 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9989 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9990 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
| 9991 | animating |= mDimAnimator.updateSurface(dimming, currentTime, mDisplayFrozen); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9992 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9993 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9994 | if (!blurring && mBlurShown) { |
| 9995 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " + mBlurSurface |
| 9996 | + ": HIDE"); |
| 9997 | try { |
| 9998 | mBlurSurface.hide(); |
| 9999 | } catch (IllegalArgumentException e) { |
| 10000 | Log.w(TAG, "Illegal argument exception hiding blur surface"); |
| 10001 | } |
| 10002 | mBlurShown = false; |
| 10003 | } |
| 10004 | |
| 10005 | if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION"); |
| 10006 | } catch (RuntimeException e) { |
| 10007 | Log.e(TAG, "Unhandled exception in Window Manager", e); |
| 10008 | } |
| 10009 | |
| 10010 | Surface.closeTransaction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10011 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10012 | if (DEBUG_ORIENTATION && mDisplayFrozen) Log.v(TAG, |
| 10013 | "With display frozen, orientationChangeComplete=" |
| 10014 | + orientationChangeComplete); |
| 10015 | if (orientationChangeComplete) { |
| 10016 | if (mWindowsFreezingScreen) { |
| 10017 | mWindowsFreezingScreen = false; |
| 10018 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10019 | } |
| 10020 | if (mAppsFreezingScreen == 0) { |
| 10021 | stopFreezingDisplayLocked(); |
| 10022 | } |
| 10023 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10024 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10025 | i = mResizingWindows.size(); |
| 10026 | if (i > 0) { |
| 10027 | do { |
| 10028 | i--; |
| 10029 | WindowState win = mResizingWindows.get(i); |
| 10030 | try { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10031 | if (DEBUG_ORIENTATION) Log.v(TAG, "Reporting new frame to " |
| 10032 | + win + ": " + win.mFrame); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10033 | win.mClient.resized(win.mFrame.width(), |
| 10034 | win.mFrame.height(), win.mLastContentInsets, |
| 10035 | win.mLastVisibleInsets, win.mDrawPending); |
| 10036 | win.mContentInsetsChanged = false; |
| 10037 | win.mVisibleInsetsChanged = false; |
| 10038 | } catch (RemoteException e) { |
| 10039 | win.mOrientationChanging = false; |
| 10040 | } |
| 10041 | } while (i > 0); |
| 10042 | mResizingWindows.clear(); |
| 10043 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10044 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10045 | // Destroy the surface of any windows that are no longer visible. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10046 | boolean wallpaperDestroyed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10047 | i = mDestroySurface.size(); |
| 10048 | if (i > 0) { |
| 10049 | do { |
| 10050 | i--; |
| 10051 | WindowState win = mDestroySurface.get(i); |
| 10052 | win.mDestroying = false; |
| 10053 | if (mInputMethodWindow == win) { |
| 10054 | mInputMethodWindow = null; |
| 10055 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10056 | if (win == mWallpaperTarget) { |
| 10057 | wallpaperDestroyed = true; |
| 10058 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10059 | win.destroySurfaceLocked(); |
| 10060 | } while (i > 0); |
| 10061 | mDestroySurface.clear(); |
| 10062 | } |
| 10063 | |
| 10064 | // Time to remove any exiting tokens? |
| 10065 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 10066 | WindowToken token = mExitingTokens.get(i); |
| 10067 | if (!token.hasVisible) { |
| 10068 | mExitingTokens.remove(i); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10069 | if (token.windowType == TYPE_WALLPAPER) { |
| 10070 | mWallpaperTokens.remove(token); |
| 10071 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10072 | } |
| 10073 | } |
| 10074 | |
| 10075 | // Time to remove any exiting applications? |
| 10076 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10077 | AppWindowToken token = mExitingAppTokens.get(i); |
| 10078 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 10079 | // Make sure there is no animation running on this token, |
| 10080 | // so any windows associated with it will be removed as |
| 10081 | // soon as their animations are complete |
| 10082 | token.animation = null; |
| 10083 | token.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10084 | mAppTokens.remove(token); |
| 10085 | mExitingAppTokens.remove(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10086 | if (mLastEnterAnimToken == token) { |
| 10087 | mLastEnterAnimToken = null; |
| 10088 | mLastEnterAnimParams = null; |
| 10089 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10090 | } |
| 10091 | } |
| 10092 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10093 | boolean needRelayout = false; |
| 10094 | |
| 10095 | if (!animating && mAppTransitionRunning) { |
| 10096 | // We have finished the animation of an app transition. To do |
| 10097 | // this, we have delayed a lot of operations like showing and |
| 10098 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10099 | // reflects the correct Z-order, but the window list may now |
| 10100 | // be out of sync with it. So here we will just rebuild the |
| 10101 | // entire app window list. Fun! |
| 10102 | mAppTransitionRunning = false; |
| 10103 | needRelayout = true; |
| 10104 | rebuildAppWindowListLocked(); |
| 10105 | // Clear information about apps that were moving. |
| 10106 | mToBottomApps.clear(); |
| 10107 | } |
| 10108 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10109 | if (focusDisplayed) { |
| 10110 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 10111 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10112 | if (wallpaperDestroyed) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10113 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10114 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10115 | if (needRelayout) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10116 | requestAnimationLocked(0); |
| 10117 | } else if (animating) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10118 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 10119 | } |
| 10120 | mQueue.setHoldScreenLocked(holdScreen != null); |
| 10121 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 10122 | mPowerManager.setScreenBrightnessOverride(-1); |
| 10123 | } else { |
| 10124 | mPowerManager.setScreenBrightnessOverride((int) |
| 10125 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 10126 | } |
| 10127 | if (holdScreen != mHoldingScreenOn) { |
| 10128 | mHoldingScreenOn = holdScreen; |
| 10129 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 10130 | mH.sendMessage(m); |
| 10131 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10132 | |
| 10133 | if (mTurnOnScreen) { |
| 10134 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 10135 | LocalPowerManager.BUTTON_EVENT, true); |
| 10136 | mTurnOnScreen = false; |
| 10137 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10138 | } |
| 10139 | |
| 10140 | void requestAnimationLocked(long delay) { |
| 10141 | if (!mAnimationPending) { |
| 10142 | mAnimationPending = true; |
| 10143 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 10144 | } |
| 10145 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10146 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10147 | /** |
| 10148 | * Have the surface flinger show a surface, robustly dealing with |
| 10149 | * error conditions. In particular, if there is not enough memory |
| 10150 | * to show the surface, then we will try to get rid of other surfaces |
| 10151 | * in order to succeed. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10152 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10153 | * @return Returns true if the surface was successfully shown. |
| 10154 | */ |
| 10155 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 10156 | try { |
| 10157 | if (win.mSurface != null) { |
| 10158 | win.mSurface.show(); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10159 | if (win.mTurnOnScreen) { |
| 10160 | win.mTurnOnScreen = false; |
| 10161 | mTurnOnScreen = true; |
| 10162 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10163 | } |
| 10164 | return true; |
| 10165 | } catch (RuntimeException e) { |
| 10166 | Log.w(TAG, "Failure showing surface " + win.mSurface + " in " + win); |
| 10167 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10168 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10169 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10170 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10171 | return false; |
| 10172 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10173 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10174 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 10175 | final Surface surface = win.mSurface; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10176 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10177 | EventLog.writeEvent(LOG_WM_NO_SURFACE_MEMORY, win.toString(), |
| 10178 | win.mSession.mPid, operation); |
| 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 | if (mForceRemoves == null) { |
| 10181 | mForceRemoves = new ArrayList<WindowState>(); |
| 10182 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10183 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10184 | long callingIdentity = Binder.clearCallingIdentity(); |
| 10185 | try { |
| 10186 | // There was some problem... first, do a sanity check of the |
| 10187 | // window list to make sure we haven't left any dangling surfaces |
| 10188 | // around. |
| 10189 | int N = mWindows.size(); |
| 10190 | boolean leakedSurface = false; |
| 10191 | Log.i(TAG, "Out of memory for surface! Looking for leaks..."); |
| 10192 | for (int i=0; i<N; i++) { |
| 10193 | WindowState ws = (WindowState)mWindows.get(i); |
| 10194 | if (ws.mSurface != null) { |
| 10195 | if (!mSessions.contains(ws.mSession)) { |
| 10196 | Log.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
| 10197 | + ws + " surface=" + ws.mSurface |
| 10198 | + " token=" + win.mToken |
| 10199 | + " pid=" + ws.mSession.mPid |
| 10200 | + " uid=" + ws.mSession.mUid); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10201 | ws.mSurface.destroy(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10202 | ws.mSurface = null; |
| 10203 | mForceRemoves.add(ws); |
| 10204 | i--; |
| 10205 | N--; |
| 10206 | leakedSurface = true; |
| 10207 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
| 10208 | Log.w(TAG, "LEAKED SURFACE (app token hidden): " |
| 10209 | + ws + " surface=" + ws.mSurface |
| 10210 | + " token=" + win.mAppToken); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10211 | ws.mSurface.destroy(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10212 | ws.mSurface = null; |
| 10213 | leakedSurface = true; |
| 10214 | } |
| 10215 | } |
| 10216 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10217 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10218 | boolean killedApps = false; |
| 10219 | if (!leakedSurface) { |
| 10220 | Log.w(TAG, "No leaked surfaces; killing applicatons!"); |
| 10221 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 10222 | for (int i=0; i<N; i++) { |
| 10223 | WindowState ws = (WindowState)mWindows.get(i); |
| 10224 | if (ws.mSurface != null) { |
| 10225 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 10226 | } |
| 10227 | } |
| 10228 | if (pidCandidates.size() > 0) { |
| 10229 | int[] pids = new int[pidCandidates.size()]; |
| 10230 | for (int i=0; i<pids.length; i++) { |
| 10231 | pids[i] = pidCandidates.keyAt(i); |
| 10232 | } |
| 10233 | try { |
| 10234 | if (mActivityManager.killPidsForMemory(pids)) { |
| 10235 | killedApps = true; |
| 10236 | } |
| 10237 | } catch (RemoteException e) { |
| 10238 | } |
| 10239 | } |
| 10240 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10241 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10242 | if (leakedSurface || killedApps) { |
| 10243 | // We managed to reclaim some memory, so get rid of the trouble |
| 10244 | // surface and ask the app to request another one. |
| 10245 | Log.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry."); |
| 10246 | if (surface != null) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10247 | surface.destroy(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10248 | win.mSurface = null; |
| 10249 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10250 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10251 | try { |
| 10252 | win.mClient.dispatchGetNewSurface(); |
| 10253 | } catch (RemoteException e) { |
| 10254 | } |
| 10255 | } |
| 10256 | } finally { |
| 10257 | Binder.restoreCallingIdentity(callingIdentity); |
| 10258 | } |
| 10259 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10260 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10261 | private boolean updateFocusedWindowLocked(int mode) { |
| 10262 | WindowState newFocus = computeFocusedWindowLocked(); |
| 10263 | if (mCurrentFocus != newFocus) { |
| 10264 | // This check makes sure that we don't already have the focus |
| 10265 | // change message pending. |
| 10266 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 10267 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
| 10268 | if (localLOGV) Log.v( |
| 10269 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 10270 | final WindowState oldFocus = mCurrentFocus; |
| 10271 | mCurrentFocus = newFocus; |
| 10272 | mLosingFocus.remove(newFocus); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10273 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10274 | final WindowState imWindow = mInputMethodWindow; |
| 10275 | if (newFocus != imWindow && oldFocus != imWindow) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10276 | if (moveInputMethodWindowsIfNeededLocked( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10277 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10278 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 10279 | mLayoutNeeded = true; |
| 10280 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10281 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 10282 | performLayoutLockedInner(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10283 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 10284 | // Client will do the layout, but we need to assign layers |
| 10285 | // for handleNewWindowLocked() below. |
| 10286 | assignLayersLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10287 | } |
| 10288 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10289 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10290 | if (newFocus != null && mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 10291 | mKeyWaiter.handleNewWindowLocked(newFocus); |
| 10292 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10293 | return true; |
| 10294 | } |
| 10295 | return false; |
| 10296 | } |
| 10297 | |
| 10298 | private WindowState computeFocusedWindowLocked() { |
| 10299 | WindowState result = null; |
| 10300 | WindowState win; |
| 10301 | |
| 10302 | int i = mWindows.size() - 1; |
| 10303 | int nextAppIndex = mAppTokens.size()-1; |
| 10304 | WindowToken nextApp = nextAppIndex >= 0 |
| 10305 | ? mAppTokens.get(nextAppIndex) : null; |
| 10306 | |
| 10307 | while (i >= 0) { |
| 10308 | win = (WindowState)mWindows.get(i); |
| 10309 | |
| 10310 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 10311 | TAG, "Looking for focus: " + i |
| 10312 | + " = " + win |
| 10313 | + ", flags=" + win.mAttrs.flags |
| 10314 | + ", canReceive=" + win.canReceiveKeys()); |
| 10315 | |
| 10316 | AppWindowToken thisApp = win.mAppToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10317 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10318 | // If this window's application has been removed, just skip it. |
| 10319 | if (thisApp != null && thisApp.removed) { |
| 10320 | i--; |
| 10321 | continue; |
| 10322 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10323 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10324 | // If there is a focused app, don't allow focus to go to any |
| 10325 | // windows below it. If this is an application window, step |
| 10326 | // through the app tokens until we find its app. |
| 10327 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 10328 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 10329 | int origAppIndex = nextAppIndex; |
| 10330 | while (nextAppIndex > 0) { |
| 10331 | if (nextApp == mFocusedApp) { |
| 10332 | // Whoops, we are below the focused app... no focus |
| 10333 | // for you! |
| 10334 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 10335 | TAG, "Reached focused app: " + mFocusedApp); |
| 10336 | return null; |
| 10337 | } |
| 10338 | nextAppIndex--; |
| 10339 | nextApp = mAppTokens.get(nextAppIndex); |
| 10340 | if (nextApp == thisApp) { |
| 10341 | break; |
| 10342 | } |
| 10343 | } |
| 10344 | if (thisApp != nextApp) { |
| 10345 | // Uh oh, the app token doesn't exist! This shouldn't |
| 10346 | // happen, but if it does we can get totally hosed... |
| 10347 | // so restart at the original app. |
| 10348 | nextAppIndex = origAppIndex; |
| 10349 | nextApp = mAppTokens.get(nextAppIndex); |
| 10350 | } |
| 10351 | } |
| 10352 | |
| 10353 | // Dispatch to this window if it is wants key events. |
| 10354 | if (win.canReceiveKeys()) { |
| 10355 | if (DEBUG_FOCUS) Log.v( |
| 10356 | TAG, "Found focus @ " + i + " = " + win); |
| 10357 | result = win; |
| 10358 | break; |
| 10359 | } |
| 10360 | |
| 10361 | i--; |
| 10362 | } |
| 10363 | |
| 10364 | return result; |
| 10365 | } |
| 10366 | |
| 10367 | private void startFreezingDisplayLocked() { |
| 10368 | if (mDisplayFrozen) { |
| Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 10369 | // Freezing the display also suspends key event delivery, to |
| 10370 | // keep events from going astray while the display is reconfigured. |
| 10371 | // If someone has changed orientation again while the screen is |
| 10372 | // still frozen, the events will continue to be blocked while the |
| 10373 | // successive orientation change is processed. To prevent spurious |
| 10374 | // ANRs, we reset the event dispatch timeout in this case. |
| 10375 | synchronized (mKeyWaiter) { |
| 10376 | mKeyWaiter.mWasFrozen = true; |
| 10377 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10378 | return; |
| 10379 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10380 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10381 | mScreenFrozenLock.acquire(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10382 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10383 | long now = SystemClock.uptimeMillis(); |
| 10384 | //Log.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
| 10385 | if (mFreezeGcPending != 0) { |
| 10386 | if (now > (mFreezeGcPending+1000)) { |
| 10387 | //Log.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| 10388 | mH.removeMessages(H.FORCE_GC); |
| 10389 | Runtime.getRuntime().gc(); |
| 10390 | mFreezeGcPending = now; |
| 10391 | } |
| 10392 | } else { |
| 10393 | mFreezeGcPending = now; |
| 10394 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10395 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10396 | mDisplayFrozen = true; |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 10397 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 10398 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10399 | mNextAppTransitionPackage = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10400 | mAppTransitionReady = true; |
| 10401 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10402 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10403 | if (PROFILE_ORIENTATION) { |
| 10404 | File file = new File("/data/system/frozen"); |
| 10405 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 10406 | } |
| 10407 | Surface.freezeDisplay(0); |
| 10408 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10409 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10410 | private void stopFreezingDisplayLocked() { |
| 10411 | if (!mDisplayFrozen) { |
| 10412 | return; |
| 10413 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10414 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10415 | mDisplayFrozen = false; |
| 10416 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 10417 | if (PROFILE_ORIENTATION) { |
| 10418 | Debug.stopMethodTracing(); |
| 10419 | } |
| 10420 | Surface.unfreezeDisplay(0); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10421 | |
| Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 10422 | // Reset the key delivery timeout on unfreeze, too. We force a wakeup here |
| 10423 | // too because regular key delivery processing should resume immediately. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10424 | synchronized (mKeyWaiter) { |
| 10425 | mKeyWaiter.mWasFrozen = true; |
| 10426 | mKeyWaiter.notifyAll(); |
| 10427 | } |
| 10428 | |
| 10429 | // A little kludge: a lot could have happened while the |
| 10430 | // display was frozen, so now that we are coming back we |
| 10431 | // do a gc so that any remote references the system |
| 10432 | // processes holds on others can be released if they are |
| 10433 | // no longer needed. |
| 10434 | mH.removeMessages(H.FORCE_GC); |
| 10435 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 10436 | 2000); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10437 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10438 | mScreenFrozenLock.release(); |
| 10439 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10440 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10441 | @Override |
| 10442 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 10443 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 10444 | != PackageManager.PERMISSION_GRANTED) { |
| 10445 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 10446 | + Binder.getCallingPid() |
| 10447 | + ", uid=" + Binder.getCallingUid()); |
| 10448 | return; |
| 10449 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10450 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10451 | synchronized(mWindowMap) { |
| 10452 | pw.println("Current Window Manager state:"); |
| 10453 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 10454 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10455 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 10456 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10457 | w.dump(pw, " "); |
| 10458 | } |
| 10459 | if (mInputMethodDialogs.size() > 0) { |
| 10460 | pw.println(" "); |
| 10461 | pw.println(" Input method dialogs:"); |
| 10462 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 10463 | WindowState w = mInputMethodDialogs.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10464 | 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] | 10465 | } |
| 10466 | } |
| 10467 | if (mPendingRemove.size() > 0) { |
| 10468 | pw.println(" "); |
| 10469 | pw.println(" Remove pending for:"); |
| 10470 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 10471 | WindowState w = mPendingRemove.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10472 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 10473 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10474 | w.dump(pw, " "); |
| 10475 | } |
| 10476 | } |
| 10477 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 10478 | pw.println(" "); |
| 10479 | pw.println(" Windows force removing:"); |
| 10480 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 10481 | WindowState w = mForceRemoves.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10482 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 10483 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10484 | w.dump(pw, " "); |
| 10485 | } |
| 10486 | } |
| 10487 | if (mDestroySurface.size() > 0) { |
| 10488 | pw.println(" "); |
| 10489 | pw.println(" Windows waiting to destroy their surface:"); |
| 10490 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 10491 | WindowState w = mDestroySurface.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10492 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 10493 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10494 | w.dump(pw, " "); |
| 10495 | } |
| 10496 | } |
| 10497 | if (mLosingFocus.size() > 0) { |
| 10498 | pw.println(" "); |
| 10499 | pw.println(" Windows losing focus:"); |
| 10500 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 10501 | WindowState w = mLosingFocus.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10502 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 10503 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10504 | w.dump(pw, " "); |
| 10505 | } |
| 10506 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10507 | if (mResizingWindows.size() > 0) { |
| 10508 | pw.println(" "); |
| 10509 | pw.println(" Windows waiting to resize:"); |
| 10510 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 10511 | WindowState w = mResizingWindows.get(i); |
| 10512 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 10513 | pw.print(w); pw.println(":"); |
| 10514 | w.dump(pw, " "); |
| 10515 | } |
| 10516 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10517 | if (mSessions.size() > 0) { |
| 10518 | pw.println(" "); |
| 10519 | pw.println(" All active sessions:"); |
| 10520 | Iterator<Session> it = mSessions.iterator(); |
| 10521 | while (it.hasNext()) { |
| 10522 | Session s = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10523 | pw.print(" Session "); pw.print(s); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10524 | s.dump(pw, " "); |
| 10525 | } |
| 10526 | } |
| 10527 | if (mTokenMap.size() > 0) { |
| 10528 | pw.println(" "); |
| 10529 | pw.println(" All tokens:"); |
| 10530 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 10531 | while (it.hasNext()) { |
| 10532 | WindowToken token = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10533 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10534 | token.dump(pw, " "); |
| 10535 | } |
| 10536 | } |
| 10537 | if (mTokenList.size() > 0) { |
| 10538 | pw.println(" "); |
| 10539 | pw.println(" Window token list:"); |
| 10540 | for (int i=0; i<mTokenList.size(); i++) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10541 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 10542 | pw.println(mTokenList.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10543 | } |
| 10544 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10545 | if (mWallpaperTokens.size() > 0) { |
| 10546 | pw.println(" "); |
| 10547 | pw.println(" Wallpaper tokens:"); |
| 10548 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 10549 | WindowToken token = mWallpaperTokens.get(i); |
| 10550 | pw.print(" Wallpaper #"); pw.print(i); |
| 10551 | pw.print(' '); pw.print(token); pw.println(':'); |
| 10552 | token.dump(pw, " "); |
| 10553 | } |
| 10554 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10555 | if (mAppTokens.size() > 0) { |
| 10556 | pw.println(" "); |
| 10557 | pw.println(" Application tokens in Z order:"); |
| 10558 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10559 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 10560 | pw.println(mAppTokens.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10561 | } |
| 10562 | } |
| 10563 | if (mFinishedStarting.size() > 0) { |
| 10564 | pw.println(" "); |
| 10565 | pw.println(" Finishing start of application tokens:"); |
| 10566 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 10567 | WindowToken token = mFinishedStarting.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10568 | pw.print(" Finished Starting #"); pw.print(i); |
| 10569 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10570 | token.dump(pw, " "); |
| 10571 | } |
| 10572 | } |
| 10573 | if (mExitingTokens.size() > 0) { |
| 10574 | pw.println(" "); |
| 10575 | pw.println(" Exiting tokens:"); |
| 10576 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 10577 | WindowToken token = mExitingTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10578 | pw.print(" Exiting #"); pw.print(i); |
| 10579 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10580 | token.dump(pw, " "); |
| 10581 | } |
| 10582 | } |
| 10583 | if (mExitingAppTokens.size() > 0) { |
| 10584 | pw.println(" "); |
| 10585 | pw.println(" Exiting application tokens:"); |
| 10586 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10587 | WindowToken token = mExitingAppTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10588 | pw.print(" Exiting App #"); pw.print(i); |
| 10589 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10590 | token.dump(pw, " "); |
| 10591 | } |
| 10592 | } |
| 10593 | pw.println(" "); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10594 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 10595 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 10596 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 10597 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 10598 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
| Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 10599 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10600 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 10601 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 10602 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 10603 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10604 | pw.print(" mInTouchMode="); pw.println(mInTouchMode); |
| 10605 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 10606 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 10607 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 10608 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10609 | if (mDimAnimator != null) { |
| 10610 | mDimAnimator.printTo(pw); |
| 10611 | } else { |
| 10612 | pw.print( " no DimAnimator "); |
| 10613 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10614 | pw.print(" mInputMethodAnimLayerAdjustment="); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 10615 | pw.print(mInputMethodAnimLayerAdjustment); |
| 10616 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 10617 | pw.println(mWallpaperAnimLayerAdjustment); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10618 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 10619 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10620 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 10621 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
| 10622 | pw.print(" mAppsFreezingScreen="); pw.println(mAppsFreezingScreen); |
| 10623 | pw.print(" mRotation="); pw.print(mRotation); |
| 10624 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 10625 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 10626 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 10627 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 10628 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 10629 | pw.print(" mNextAppTransition=0x"); |
| 10630 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 10631 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10632 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10633 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10634 | if (mNextAppTransitionPackage != null) { |
| 10635 | pw.print(" mNextAppTransitionPackage="); |
| 10636 | pw.print(mNextAppTransitionPackage); |
| 10637 | pw.print(", mNextAppTransitionEnter=0x"); |
| 10638 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 10639 | pw.print(", mNextAppTransitionExit=0x"); |
| 10640 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 10641 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10642 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 10643 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10644 | if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) { |
| 10645 | pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken); |
| 10646 | pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams); |
| 10647 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10648 | if (mOpeningApps.size() > 0) { |
| 10649 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 10650 | } |
| 10651 | if (mClosingApps.size() > 0) { |
| 10652 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 10653 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10654 | if (mToTopApps.size() > 0) { |
| 10655 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 10656 | } |
| 10657 | if (mToBottomApps.size() > 0) { |
| 10658 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 10659 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10660 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 10661 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10662 | pw.println(" KeyWaiter state:"); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10663 | pw.print(" mLastWin="); pw.print(mKeyWaiter.mLastWin); |
| 10664 | pw.print(" mLastBinder="); pw.println(mKeyWaiter.mLastBinder); |
| 10665 | pw.print(" mFinished="); pw.print(mKeyWaiter.mFinished); |
| 10666 | pw.print(" mGotFirstWindow="); pw.print(mKeyWaiter.mGotFirstWindow); |
| 10667 | pw.print(" mEventDispatching="); pw.print(mKeyWaiter.mEventDispatching); |
| 10668 | pw.print(" mTimeToSwitch="); pw.println(mKeyWaiter.mTimeToSwitch); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10669 | } |
| 10670 | } |
| 10671 | |
| 10672 | public void monitor() { |
| 10673 | synchronized (mWindowMap) { } |
| 10674 | synchronized (mKeyguardDisabled) { } |
| 10675 | synchronized (mKeyWaiter) { } |
| 10676 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10677 | |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 10678 | public void virtualKeyFeedback(KeyEvent event) { |
| 10679 | mPolicy.keyFeedbackFromInput(event); |
| 10680 | } |
| 10681 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10682 | /** |
| 10683 | * DimAnimator class that controls the dim animation. This holds the surface and |
| 10684 | * all state used for dim animation. |
| 10685 | */ |
| 10686 | private static class DimAnimator { |
| 10687 | Surface mDimSurface; |
| 10688 | boolean mDimShown = false; |
| 10689 | float mDimCurrentAlpha; |
| 10690 | float mDimTargetAlpha; |
| 10691 | float mDimDeltaPerMs; |
| 10692 | long mLastDimAnimTime; |
| 10693 | |
| 10694 | DimAnimator (SurfaceSession session) { |
| 10695 | if (mDimSurface == null) { |
| 10696 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 10697 | + mDimSurface + ": CREATE"); |
| 10698 | try { |
| 10699 | mDimSurface = new Surface(session, 0, -1, 16, 16, PixelFormat.OPAQUE, |
| 10700 | Surface.FX_SURFACE_DIM); |
| 10701 | } catch (Exception e) { |
| 10702 | Log.e(TAG, "Exception creating Dim surface", e); |
| 10703 | } |
| 10704 | } |
| 10705 | } |
| 10706 | |
| 10707 | /** |
| 10708 | * Show the dim surface. |
| 10709 | */ |
| 10710 | void show(int dw, int dh) { |
| 10711 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 10712 | dw + "x" + dh + ")"); |
| 10713 | mDimShown = true; |
| 10714 | try { |
| 10715 | mDimSurface.setPosition(0, 0); |
| 10716 | mDimSurface.setSize(dw, dh); |
| 10717 | mDimSurface.show(); |
| 10718 | } catch (RuntimeException e) { |
| 10719 | Log.w(TAG, "Failure showing dim surface", e); |
| 10720 | } |
| 10721 | } |
| 10722 | |
| 10723 | /** |
| 10724 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 10725 | * {@link updateSurface} after all windows are examined. |
| 10726 | */ |
| 10727 | void updateParameters(WindowState w, long currentTime) { |
| 10728 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 10729 | |
| 10730 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10731 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface |
| 10732 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10733 | if (mDimTargetAlpha != target) { |
| 10734 | // If the desired dim level has changed, then |
| 10735 | // start an animation to it. |
| 10736 | mLastDimAnimTime = currentTime; |
| 10737 | long duration = (w.mAnimating && w.mAnimation != null) |
| 10738 | ? w.mAnimation.computeDurationHint() |
| 10739 | : DEFAULT_DIM_DURATION; |
| 10740 | if (target > mDimTargetAlpha) { |
| 10741 | // This is happening behind the activity UI, |
| 10742 | // so we can make it run a little longer to |
| 10743 | // give a stronger impression without disrupting |
| 10744 | // the user. |
| 10745 | duration *= DIM_DURATION_MULTIPLIER; |
| 10746 | } |
| 10747 | if (duration < 1) { |
| 10748 | // Don't divide by zero |
| 10749 | duration = 1; |
| 10750 | } |
| 10751 | mDimTargetAlpha = target; |
| 10752 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 10753 | } |
| 10754 | } |
| 10755 | |
| 10756 | /** |
| 10757 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 10758 | * false when the animation is finished and the dim surface is hidden. |
| 10759 | */ |
| 10760 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 10761 | if (!dimming) { |
| 10762 | if (mDimTargetAlpha != 0) { |
| 10763 | mLastDimAnimTime = currentTime; |
| 10764 | mDimTargetAlpha = 0; |
| 10765 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 10766 | } |
| 10767 | } |
| 10768 | |
| 10769 | boolean animating = false; |
| 10770 | if (mLastDimAnimTime != 0) { |
| 10771 | mDimCurrentAlpha += mDimDeltaPerMs |
| 10772 | * (currentTime-mLastDimAnimTime); |
| 10773 | boolean more = true; |
| 10774 | if (displayFrozen) { |
| 10775 | // If the display is frozen, there is no reason to animate. |
| 10776 | more = false; |
| 10777 | } else if (mDimDeltaPerMs > 0) { |
| 10778 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 10779 | more = false; |
| 10780 | } |
| 10781 | } else if (mDimDeltaPerMs < 0) { |
| 10782 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 10783 | more = false; |
| 10784 | } |
| 10785 | } else { |
| 10786 | more = false; |
| 10787 | } |
| 10788 | |
| 10789 | // Do we need to continue animating? |
| 10790 | if (more) { |
| 10791 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 10792 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 10793 | mLastDimAnimTime = currentTime; |
| 10794 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 10795 | animating = true; |
| 10796 | } else { |
| 10797 | mDimCurrentAlpha = mDimTargetAlpha; |
| 10798 | mLastDimAnimTime = 0; |
| 10799 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 10800 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 10801 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 10802 | if (!dimming) { |
| 10803 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface |
| 10804 | + ": HIDE"); |
| 10805 | try { |
| 10806 | mDimSurface.hide(); |
| 10807 | } catch (RuntimeException e) { |
| 10808 | Log.w(TAG, "Illegal argument exception hiding dim surface"); |
| 10809 | } |
| 10810 | mDimShown = false; |
| 10811 | } |
| 10812 | } |
| 10813 | } |
| 10814 | return animating; |
| 10815 | } |
| 10816 | |
| 10817 | public void printTo(PrintWriter pw) { |
| 10818 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 10819 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 10820 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 10821 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 10822 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 10823 | } |
| 10824 | } |
| 10825 | |
| 10826 | /** |
| 10827 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 10828 | * This is used for opening/closing transition for apps in compatible mode. |
| 10829 | */ |
| 10830 | private static class FadeInOutAnimation extends Animation { |
| 10831 | int mWidth; |
| 10832 | boolean mFadeIn; |
| 10833 | |
| 10834 | public FadeInOutAnimation(boolean fadeIn) { |
| 10835 | setInterpolator(new AccelerateInterpolator()); |
| 10836 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 10837 | mFadeIn = fadeIn; |
| 10838 | } |
| 10839 | |
| 10840 | @Override |
| 10841 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 10842 | float x = interpolatedTime; |
| 10843 | if (!mFadeIn) { |
| 10844 | x = 1.0f - x; // reverse the interpolation for fade out |
| 10845 | } |
| 10846 | if (x < 0.5) { |
| 10847 | // move the window out of the screen. |
| 10848 | t.getMatrix().setTranslate(mWidth, 0); |
| 10849 | } else { |
| 10850 | t.getMatrix().setTranslate(0, 0);// show |
| 10851 | t.setAlpha((x - 0.5f) * 2); |
| 10852 | } |
| 10853 | } |
| 10854 | |
| 10855 | @Override |
| 10856 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 10857 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 10858 | mWidth = width; |
| 10859 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10860 | |
| 10861 | @Override |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 10862 | public int getZAdjustment() { |
| 10863 | return Animation.ZORDER_TOP; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10864 | } |
| 10865 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10866 | } |