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; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 66 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | import android.os.Debug; |
| 68 | import android.os.Handler; |
| 69 | import android.os.IBinder; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 70 | import android.os.LatencyTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | import android.os.LocalPowerManager; |
| 72 | import android.os.Looper; |
| 73 | import android.os.Message; |
| 74 | import android.os.Parcel; |
| 75 | import android.os.ParcelFileDescriptor; |
| 76 | import android.os.Power; |
| 77 | import android.os.PowerManager; |
| 78 | import android.os.Process; |
| 79 | import android.os.RemoteException; |
| 80 | import android.os.ServiceManager; |
| 81 | import android.os.SystemClock; |
| 82 | import android.os.SystemProperties; |
| 83 | import android.os.TokenWatcher; |
| 84 | import android.provider.Settings; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 85 | import android.util.DisplayMetrics; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | import android.util.EventLog; |
| 87 | import android.util.Log; |
| 88 | import android.util.SparseIntArray; |
| 89 | import android.view.Display; |
| 90 | import android.view.Gravity; |
| 91 | import android.view.IApplicationToken; |
| 92 | import android.view.IOnKeyguardExitResult; |
| 93 | import android.view.IRotationWatcher; |
| 94 | import android.view.IWindow; |
| 95 | import android.view.IWindowManager; |
| 96 | import android.view.IWindowSession; |
| 97 | import android.view.KeyEvent; |
| 98 | import android.view.MotionEvent; |
| 99 | import android.view.RawInputEvent; |
| 100 | import android.view.Surface; |
| 101 | import android.view.SurfaceSession; |
| 102 | import android.view.View; |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 103 | import android.view.ViewConfiguration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | import android.view.ViewTreeObserver; |
| 105 | import android.view.WindowManager; |
| 106 | import android.view.WindowManagerImpl; |
| 107 | import android.view.WindowManagerPolicy; |
| 108 | import android.view.WindowManager.LayoutParams; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 109 | import android.view.animation.AccelerateInterpolator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | import android.view.animation.Animation; |
| 111 | import android.view.animation.AnimationUtils; |
| 112 | import android.view.animation.Transformation; |
| 113 | |
| 114 | import java.io.BufferedWriter; |
| 115 | import java.io.File; |
| 116 | import java.io.FileDescriptor; |
| 117 | import java.io.IOException; |
| 118 | import java.io.OutputStream; |
| 119 | import java.io.OutputStreamWriter; |
| 120 | import java.io.PrintWriter; |
| 121 | import java.io.StringWriter; |
| 122 | import java.net.Socket; |
| 123 | import java.util.ArrayList; |
| 124 | import java.util.HashMap; |
| 125 | import java.util.HashSet; |
| 126 | import java.util.Iterator; |
| 127 | import java.util.List; |
| 128 | |
| 129 | /** {@hide} */ |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 130 | public class WindowManagerService extends IWindowManager.Stub |
| 131 | implements Watchdog.Monitor, KeyInputQueue.HapticFeedbackCallback { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | static final String TAG = "WindowManager"; |
| 133 | static final boolean DEBUG = false; |
| 134 | static final boolean DEBUG_FOCUS = false; |
| 135 | static final boolean DEBUG_ANIM = false; |
| 136 | static final boolean DEBUG_LAYERS = false; |
| 137 | static final boolean DEBUG_INPUT = false; |
| 138 | static final boolean DEBUG_INPUT_METHOD = false; |
| 139 | static final boolean DEBUG_VISIBILITY = false; |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 140 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | static final boolean DEBUG_ORIENTATION = false; |
| 142 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 143 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 144 | static final boolean DEBUG_REORDER = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 145 | static final boolean DEBUG_WALLPAPER = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | static final boolean SHOW_TRANSACTIONS = false; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 147 | static final boolean HIDE_STACK_CRAWLS = true; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 148 | static final boolean MEASURE_LATENCY = false; |
| 149 | static private LatencyTimer lt; |
| 150 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | static final boolean PROFILE_ORIENTATION = false; |
| 152 | static final boolean BLUR = true; |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 153 | static final boolean localLOGV = DEBUG; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 154 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | static final int LOG_WM_NO_SURFACE_MEMORY = 31000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 156 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | /** How long to wait for subsequent key repeats, in milliseconds */ |
| 158 | static final int KEY_REPEAT_DELAY = 50; |
| 159 | |
| 160 | /** How much to multiply the policy's type layer, to reserve room |
| 161 | * for multiple windows of the same type and Z-ordering adjustment |
| 162 | * with TYPE_LAYER_OFFSET. */ |
| 163 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 164 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 166 | * or below others in the same layer. */ |
| 167 | static final int TYPE_LAYER_OFFSET = 1000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 168 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | /** How much to increment the layer for each window, to reserve room |
| 170 | * for effect surfaces between them. |
| 171 | */ |
| 172 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | /** The maximum length we will accept for a loaded animation duration: |
| 175 | * this is 10 seconds. |
| 176 | */ |
| 177 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 178 | |
| 179 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 180 | * value to another, when no window animation is driving it. |
| 181 | */ |
| 182 | static final int DEFAULT_DIM_DURATION = 200; |
| 183 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 184 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 185 | * compatible windows. |
| 186 | */ |
| 187 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 188 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | /** Adjustment to time to perform a dim, to make it more dramatic. |
| 190 | */ |
| 191 | static final int DIM_DURATION_MULTIPLIER = 6; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 192 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 193 | static final int INJECT_FAILED = 0; |
| 194 | static final int INJECT_SUCCEEDED = 1; |
| 195 | static final int INJECT_NO_PERMISSION = -1; |
| 196 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 198 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 199 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 200 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 201 | |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 202 | /** The minimum time between dispatching touch events. */ |
| 203 | int mMinWaitTimeBetweenTouchEvents = 1000 / 35; |
| 204 | |
| 205 | // Last touch event time |
| 206 | long mLastTouchEventTime = 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 207 | |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 208 | // Last touch event type |
| 209 | int mLastTouchEventType = OTHER_EVENT; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 210 | |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 211 | // Time to wait before calling useractivity again. This saves CPU usage |
| 212 | // when we get a flood of touch events. |
| 213 | static final int MIN_TIME_BETWEEN_USERACTIVITIES = 1000; |
| 214 | |
| 215 | // Last time we call user activity |
| 216 | long mLastUserActivityCallTime = 0; |
| 217 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 218 | // Last time we updated battery stats |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 219 | long mLastBatteryStatsCallTime = 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 220 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | private static final String SYSTEM_SECURE = "ro.secure"; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 222 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | |
| 224 | /** |
| 225 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 226 | * the window policy has finished. |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 227 | * This is set to true only if mKeyguardTokenWatcher.acquired() has |
| 228 | * actually disabled the keyguard. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | */ |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 230 | private boolean mKeyguardDisabled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 232 | final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher( |
| 233 | new Handler(), "WindowManagerService.mKeyguardTokenWatcher") { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | public void acquired() { |
| 235 | mPolicy.enableKeyguard(false); |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 236 | mKeyguardDisabled = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | } |
| 238 | public void released() { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 239 | mPolicy.enableKeyguard(true); |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 240 | synchronized (mKeyguardTokenWatcher) { |
| 241 | mKeyguardDisabled = false; |
| 242 | mKeyguardTokenWatcher.notifyAll(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | }; |
| 246 | |
| 247 | final Context mContext; |
| 248 | |
| 249 | final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 250 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | final boolean mLimitedAlphaCompositing; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 252 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 254 | |
| 255 | final IActivityManager mActivityManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 256 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 257 | final IBatteryStats mBatteryStats; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 258 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | /** |
| 260 | * All currently active sessions with clients. |
| 261 | */ |
| 262 | final HashSet<Session> mSessions = new HashSet<Session>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 263 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 264 | /** |
| 265 | * Mapping from an IWindow IBinder to the server's Window object. |
| 266 | * This is also used as the lock for all of our state. |
| 267 | */ |
| 268 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 269 | |
| 270 | /** |
| 271 | * Mapping from a token IBinder to a WindowToken object. |
| 272 | */ |
| 273 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 274 | new HashMap<IBinder, WindowToken>(); |
| 275 | |
| 276 | /** |
| 277 | * The same tokens as mTokenMap, stored in a list for efficient iteration |
| 278 | * over them. |
| 279 | */ |
| 280 | final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 281 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 282 | /** |
| 283 | * Window tokens that are in the process of exiting, but still |
| 284 | * on screen for animations. |
| 285 | */ |
| 286 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 287 | |
| 288 | /** |
| 289 | * Z-ordered (bottom-most first) list of all application tokens, for |
| 290 | * controlling the ordering of windows in different applications. This |
| 291 | * contains WindowToken objects. |
| 292 | */ |
| 293 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 294 | |
| 295 | /** |
| 296 | * Application tokens that are in the process of exiting, but still |
| 297 | * on screen for animations. |
| 298 | */ |
| 299 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 300 | |
| 301 | /** |
| 302 | * List of window tokens that have finished starting their application, |
| 303 | * and now need to have the policy remove their windows. |
| 304 | */ |
| 305 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 306 | |
| 307 | /** |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 308 | * This was the app token that was used to retrieve the last enter |
| 309 | * animation. It will be used for the next exit animation. |
| 310 | */ |
| 311 | AppWindowToken mLastEnterAnimToken; |
| 312 | |
| 313 | /** |
| 314 | * These were the layout params used to retrieve the last enter animation. |
| 315 | * They will be used for the next exit animation. |
| 316 | */ |
| 317 | LayoutParams mLastEnterAnimParams; |
| 318 | |
| 319 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 320 | * Z-ordered (bottom-most first) list of all Window objects. |
| 321 | */ |
| 322 | final ArrayList mWindows = new ArrayList(); |
| 323 | |
| 324 | /** |
| 325 | * Windows that are being resized. Used so we can tell the client about |
| 326 | * the resize after closing the transaction in which we resized the |
| 327 | * underlying surface. |
| 328 | */ |
| 329 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 330 | |
| 331 | /** |
| 332 | * Windows whose animations have ended and now must be removed. |
| 333 | */ |
| 334 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 335 | |
| 336 | /** |
| 337 | * Windows whose surface should be destroyed. |
| 338 | */ |
| 339 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 340 | |
| 341 | /** |
| 342 | * Windows that have lost input focus and are waiting for the new |
| 343 | * focus window to be displayed before they are told about this. |
| 344 | */ |
| 345 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 346 | |
| 347 | /** |
| 348 | * This is set when we have run out of memory, and will either be an empty |
| 349 | * list or contain windows that need to be force removed. |
| 350 | */ |
| 351 | ArrayList<WindowState> mForceRemoves; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 352 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 353 | IInputMethodManager mInputMethodManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 354 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 355 | SurfaceSession mFxSession; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 356 | private DimAnimator mDimAnimator = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 357 | Surface mBlurSurface; |
| 358 | boolean mBlurShown; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 359 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 360 | int mTransactionSequence = 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 361 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | final float[] mTmpFloats = new float[9]; |
| 363 | |
| 364 | boolean mSafeMode; |
| 365 | boolean mDisplayEnabled = false; |
| 366 | boolean mSystemBooted = false; |
| 367 | int mRotation = 0; |
| 368 | int mRequestedRotation = 0; |
| 369 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 370 | int mLastRotationFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 371 | ArrayList<IRotationWatcher> mRotationWatchers |
| 372 | = new ArrayList<IRotationWatcher>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | boolean mLayoutNeeded = true; |
| 375 | boolean mAnimationPending = false; |
| 376 | boolean mDisplayFrozen = false; |
| 377 | boolean mWindowsFreezingScreen = false; |
| 378 | long mFreezeGcPending = 0; |
| 379 | int mAppsFreezingScreen = 0; |
| 380 | |
| 381 | // This is held as long as we have the screen frozen, to give us time to |
| 382 | // perform a rotation animation when turning off shows the lock screen which |
| 383 | // changes the orientation. |
| 384 | PowerManager.WakeLock mScreenFrozenLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 385 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 386 | // State management of app transitions. When we are preparing for a |
| 387 | // transition, mNextAppTransition will be the kind of transition to |
| 388 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 389 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 390 | // made visible or hidden at the next transition. |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 391 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 392 | String mNextAppTransitionPackage; |
| 393 | int mNextAppTransitionEnter; |
| 394 | int mNextAppTransitionExit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 395 | boolean mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 396 | boolean mAppTransitionRunning = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | boolean mAppTransitionTimeout = false; |
| 398 | boolean mStartingIconInTransition = false; |
| 399 | boolean mSkipAppTransitionAnimation = false; |
| 400 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 401 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 402 | final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>(); |
| 403 | final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 404 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 405 | //flag to detect fat touch events |
| 406 | boolean mFatTouch = false; |
| 407 | Display mDisplay; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 408 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | H mH = new H(); |
| 410 | |
| 411 | WindowState mCurrentFocus = null; |
| 412 | WindowState mLastFocus = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | // This just indicates the window the input method is on top of, not |
| 415 | // necessarily the window its input is going to. |
| 416 | WindowState mInputMethodTarget = null; |
| 417 | WindowState mUpcomingInputMethodTarget = null; |
| 418 | boolean mInputMethodTargetWaitingAnim; |
| 419 | int mInputMethodAnimLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 420 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 421 | WindowState mInputMethodWindow = null; |
| 422 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 423 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 424 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
| 425 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 426 | // If non-null, this is the currently visible window that is associated |
| 427 | // with the wallpaper. |
| 428 | WindowState mWallpaperTarget = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 429 | // If non-null, we are in the middle of animating from one wallpaper target |
| 430 | // to another, and this is the lower one in Z-order. |
| 431 | WindowState mLowerWallpaperTarget = null; |
| 432 | // If non-null, we are in the middle of animating from one wallpaper target |
| 433 | // to another, and this is the higher one in Z-order. |
| 434 | WindowState mUpperWallpaperTarget = null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 435 | int mWallpaperAnimLayerAdjustment; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 436 | float mLastWallpaperX = -1; |
| 437 | float mLastWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 438 | float mLastWallpaperXStep = -1; |
| 439 | float mLastWallpaperYStep = -1; |
Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 440 | boolean mSendingPointersToWallpaper = false; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 441 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 442 | // changing its scroll position. |
| 443 | WindowState mWaitingOnWallpaper; |
| 444 | // The last time we had a timeout when waiting for a wallpaper. |
| 445 | long mLastWallpaperTimeoutTime; |
| 446 | // We give a wallpaper up to 150ms to finish scrolling. |
| 447 | static final long WALLPAPER_TIMEOUT = 150; |
| 448 | // Time we wait after a timeout before trying to wait again. |
| 449 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | AppWindowToken mFocusedApp = null; |
| 452 | |
| 453 | PowerManagerService mPowerManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 454 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | float mWindowAnimationScale = 1.0f; |
| 456 | float mTransitionAnimationScale = 1.0f; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 457 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 458 | final KeyWaiter mKeyWaiter = new KeyWaiter(); |
| 459 | final KeyQ mQueue; |
| 460 | final InputDispatcherThread mInputThread; |
| 461 | |
| 462 | // Who is holding the screen on. |
| 463 | Session mHoldingScreenOn; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 464 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 465 | boolean mTurnOnScreen; |
| 466 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 467 | /** |
| 468 | * Whether the UI is currently running in touch mode (not showing |
| 469 | * navigational focus because the user is directly pressing the screen). |
| 470 | */ |
| 471 | boolean mInTouchMode = false; |
| 472 | |
| 473 | private ViewServer mViewServer; |
| 474 | |
| 475 | final Rect mTempRect = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 476 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 477 | final Configuration mTempConfiguration = new Configuration(); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 478 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 479 | |
| 480 | // The frame use to limit the size of the app running in compatibility mode. |
| 481 | Rect mCompatibleScreenFrame = new Rect(); |
| 482 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 483 | Surface mBackgroundFillerSurface = null; |
| 484 | boolean mBackgroundFillerShown = false; |
| 485 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 486 | public static WindowManagerService main(Context context, |
| 487 | PowerManagerService pm, boolean haveInputMethods) { |
| 488 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 489 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 490 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 491 | synchronized (thr) { |
| 492 | while (thr.mService == null) { |
| 493 | try { |
| 494 | thr.wait(); |
| 495 | } catch (InterruptedException e) { |
| 496 | } |
| 497 | } |
| 498 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 499 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 500 | return thr.mService; |
| 501 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 502 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | static class WMThread extends Thread { |
| 504 | WindowManagerService mService; |
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 | private final Context mContext; |
| 507 | private final PowerManagerService mPM; |
| 508 | private final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 509 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 510 | public WMThread(Context context, PowerManagerService pm, |
| 511 | boolean haveInputMethods) { |
| 512 | super("WindowManager"); |
| 513 | mContext = context; |
| 514 | mPM = pm; |
| 515 | mHaveInputMethods = haveInputMethods; |
| 516 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 517 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 518 | public void run() { |
| 519 | Looper.prepare(); |
| 520 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 521 | mHaveInputMethods); |
| 522 | android.os.Process.setThreadPriority( |
| 523 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 524 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 525 | synchronized (this) { |
| 526 | mService = s; |
| 527 | notifyAll(); |
| 528 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 529 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 530 | Looper.loop(); |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | static class PolicyThread extends Thread { |
| 535 | private final WindowManagerPolicy mPolicy; |
| 536 | private final WindowManagerService mService; |
| 537 | private final Context mContext; |
| 538 | private final PowerManagerService mPM; |
| 539 | boolean mRunning = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 540 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 541 | public PolicyThread(WindowManagerPolicy policy, |
| 542 | WindowManagerService service, Context context, |
| 543 | PowerManagerService pm) { |
| 544 | super("WindowManagerPolicy"); |
| 545 | mPolicy = policy; |
| 546 | mService = service; |
| 547 | mContext = context; |
| 548 | mPM = pm; |
| 549 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 550 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 551 | public void run() { |
| 552 | Looper.prepare(); |
| 553 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
| 554 | // Log.VERBOSE, "WindowManagerPolicy")); |
| 555 | android.os.Process.setThreadPriority( |
| 556 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
| 557 | mPolicy.init(mContext, mService, mPM); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 558 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 559 | synchronized (this) { |
| 560 | mRunning = true; |
| 561 | notifyAll(); |
| 562 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 563 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 564 | Looper.loop(); |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | private WindowManagerService(Context context, PowerManagerService pm, |
| 569 | boolean haveInputMethods) { |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 570 | if (MEASURE_LATENCY) { |
| 571 | lt = new LatencyTimer(100, 1000); |
| 572 | } |
| 573 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 574 | mContext = context; |
| 575 | mHaveInputMethods = haveInputMethods; |
| 576 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 577 | com.android.internal.R.bool.config_sf_limitedAlpha); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 578 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 579 | mPowerManager = pm; |
| 580 | mPowerManager.setPolicy(mPolicy); |
| 581 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 582 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 583 | "SCREEN_FROZEN"); |
| 584 | mScreenFrozenLock.setReferenceCounted(false); |
| 585 | |
| 586 | mActivityManager = ActivityManagerNative.getDefault(); |
| 587 | mBatteryStats = BatteryStatsService.getService(); |
| 588 | |
| 589 | // Get persisted window scale setting |
| 590 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 591 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 592 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 593 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 594 | |
Michael Chan | 9f028e6 | 2009-08-04 17:37:46 -0700 | [diff] [blame] | 595 | int max_events_per_sec = 35; |
| 596 | try { |
| 597 | max_events_per_sec = Integer.parseInt(SystemProperties |
| 598 | .get("windowsmgr.max_events_per_sec")); |
| 599 | if (max_events_per_sec < 1) { |
| 600 | max_events_per_sec = 35; |
| 601 | } |
| 602 | } catch (NumberFormatException e) { |
| 603 | } |
| 604 | mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec; |
| 605 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 606 | mQueue = new KeyQ(); |
| 607 | |
| 608 | mInputThread = new InputDispatcherThread(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 609 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 610 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 611 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 612 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 613 | synchronized (thr) { |
| 614 | while (!thr.mRunning) { |
| 615 | try { |
| 616 | thr.wait(); |
| 617 | } catch (InterruptedException e) { |
| 618 | } |
| 619 | } |
| 620 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 621 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 622 | mInputThread.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 623 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 624 | // Add ourself to the Watchdog monitors. |
| 625 | Watchdog.getInstance().addMonitor(this); |
| 626 | } |
| 627 | |
| 628 | @Override |
| 629 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 630 | throws RemoteException { |
| 631 | try { |
| 632 | return super.onTransact(code, data, reply, flags); |
| 633 | } catch (RuntimeException e) { |
| 634 | // The window manager only throws security exceptions, so let's |
| 635 | // log all others. |
| 636 | if (!(e instanceof SecurityException)) { |
| 637 | Log.e(TAG, "Window Manager Crash", e); |
| 638 | } |
| 639 | throw e; |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | private void placeWindowAfter(Object pos, WindowState window) { |
| 644 | final int i = mWindows.indexOf(pos); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 645 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Log.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 646 | TAG, "Adding window " + window + " at " |
| 647 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 648 | mWindows.add(i+1, window); |
| 649 | } |
| 650 | |
| 651 | private void placeWindowBefore(Object pos, WindowState window) { |
| 652 | final int i = mWindows.indexOf(pos); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 653 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Log.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 654 | TAG, "Adding window " + window + " at " |
| 655 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 656 | mWindows.add(i, window); |
| 657 | } |
| 658 | |
| 659 | //This method finds out the index of a window that has the same app token as |
| 660 | //win. used for z ordering the windows in mWindows |
| 661 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 662 | //use a local variable to cache mWindows |
| 663 | ArrayList localmWindows = mWindows; |
| 664 | int jmax = localmWindows.size(); |
| 665 | if(jmax == 0) { |
| 666 | return -1; |
| 667 | } |
| 668 | for(int j = (jmax-1); j >= 0; j--) { |
| 669 | WindowState wentry = (WindowState)localmWindows.get(j); |
| 670 | if(wentry.mAppToken == win.mAppToken) { |
| 671 | return j; |
| 672 | } |
| 673 | } |
| 674 | return -1; |
| 675 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 676 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 677 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 678 | final IWindow client = win.mClient; |
| 679 | final WindowToken token = win.mToken; |
| 680 | final ArrayList localmWindows = mWindows; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 681 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 682 | final int N = localmWindows.size(); |
| 683 | final WindowState attached = win.mAttachedWindow; |
| 684 | int i; |
| 685 | if (attached == null) { |
| 686 | int tokenWindowsPos = token.windows.size(); |
| 687 | if (token.appWindowToken != null) { |
| 688 | int index = tokenWindowsPos-1; |
| 689 | if (index >= 0) { |
| 690 | // If this application has existing windows, we |
| 691 | // simply place the new window on top of them... but |
| 692 | // keep the starting window on top. |
| 693 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 694 | // Base windows go behind everything else. |
| 695 | placeWindowBefore(token.windows.get(0), win); |
| 696 | tokenWindowsPos = 0; |
| 697 | } else { |
| 698 | AppWindowToken atoken = win.mAppToken; |
| 699 | if (atoken != null && |
| 700 | token.windows.get(index) == atoken.startingWindow) { |
| 701 | placeWindowBefore(token.windows.get(index), win); |
| 702 | tokenWindowsPos--; |
| 703 | } else { |
| 704 | int newIdx = findIdxBasedOnAppTokens(win); |
| 705 | if(newIdx != -1) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 706 | //there is a window above this one associated with the same |
| 707 | //apptoken note that the window could be a floating window |
| 708 | //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] | 709 | //windows associated with this token. |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 710 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Log.v( |
| 711 | TAG, "Adding window " + win + " at " |
| 712 | + (newIdx+1) + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 713 | localmWindows.add(newIdx+1, win); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 714 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 715 | } |
| 716 | } |
| 717 | } else { |
| 718 | if (localLOGV) Log.v( |
| 719 | TAG, "Figuring out where to add app window " |
| 720 | + client.asBinder() + " (token=" + token + ")"); |
| 721 | // Figure out where the window should go, based on the |
| 722 | // order of applications. |
| 723 | final int NA = mAppTokens.size(); |
| 724 | Object pos = null; |
| 725 | for (i=NA-1; i>=0; i--) { |
| 726 | AppWindowToken t = mAppTokens.get(i); |
| 727 | if (t == token) { |
| 728 | i--; |
| 729 | break; |
| 730 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 731 | |
| 732 | // We haven't reached the token yet; if this token |
| 733 | // is not going to the bottom and has windows, we can |
| 734 | // use it as an anchor for when we do reach the token. |
| 735 | if (!t.sendingToBottom && t.windows.size() > 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 736 | pos = t.windows.get(0); |
| 737 | } |
| 738 | } |
| 739 | // We now know the index into the apps. If we found |
| 740 | // an app window above, that gives us the position; else |
| 741 | // we need to look some more. |
| 742 | if (pos != null) { |
| 743 | // Move behind any windows attached to this one. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 744 | WindowToken atoken = |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 745 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 746 | if (atoken != null) { |
| 747 | final int NC = atoken.windows.size(); |
| 748 | if (NC > 0) { |
| 749 | WindowState bottom = atoken.windows.get(0); |
| 750 | if (bottom.mSubLayer < 0) { |
| 751 | pos = bottom; |
| 752 | } |
| 753 | } |
| 754 | } |
| 755 | placeWindowBefore(pos, win); |
| 756 | } else { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 757 | // Continue looking down until we find the first |
| 758 | // token that has windows. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 759 | while (i >= 0) { |
| 760 | AppWindowToken t = mAppTokens.get(i); |
| 761 | final int NW = t.windows.size(); |
| 762 | if (NW > 0) { |
| 763 | pos = t.windows.get(NW-1); |
| 764 | break; |
| 765 | } |
| 766 | i--; |
| 767 | } |
| 768 | if (pos != null) { |
| 769 | // Move in front of any windows attached to this |
| 770 | // one. |
| 771 | WindowToken atoken = |
| 772 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 773 | if (atoken != null) { |
| 774 | final int NC = atoken.windows.size(); |
| 775 | if (NC > 0) { |
| 776 | WindowState top = atoken.windows.get(NC-1); |
| 777 | if (top.mSubLayer >= 0) { |
| 778 | pos = top; |
| 779 | } |
| 780 | } |
| 781 | } |
| 782 | placeWindowAfter(pos, win); |
| 783 | } else { |
| 784 | // Just search for the start of this layer. |
| 785 | final int myLayer = win.mBaseLayer; |
| 786 | for (i=0; i<N; i++) { |
| 787 | WindowState w = (WindowState)localmWindows.get(i); |
| 788 | if (w.mBaseLayer > myLayer) { |
| 789 | break; |
| 790 | } |
| 791 | } |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 792 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Log.v( |
| 793 | TAG, "Adding window " + win + " at " |
| 794 | + i + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 795 | localmWindows.add(i, win); |
| 796 | } |
| 797 | } |
| 798 | } |
| 799 | } else { |
| 800 | // Figure out where window should go, based on layer. |
| 801 | final int myLayer = win.mBaseLayer; |
| 802 | for (i=N-1; i>=0; i--) { |
| 803 | if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) { |
| 804 | i++; |
| 805 | break; |
| 806 | } |
| 807 | } |
| 808 | if (i < 0) i = 0; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 809 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Log.v( |
| 810 | TAG, "Adding window " + win + " at " |
| 811 | + i + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 812 | localmWindows.add(i, win); |
| 813 | } |
| 814 | if (addToToken) { |
| 815 | token.windows.add(tokenWindowsPos, win); |
| 816 | } |
| 817 | |
| 818 | } else { |
| 819 | // Figure out this window's ordering relative to the window |
| 820 | // it is attached to. |
| 821 | final int NA = token.windows.size(); |
| 822 | final int sublayer = win.mSubLayer; |
| 823 | int largestSublayer = Integer.MIN_VALUE; |
| 824 | WindowState windowWithLargestSublayer = null; |
| 825 | for (i=0; i<NA; i++) { |
| 826 | WindowState w = token.windows.get(i); |
| 827 | final int wSublayer = w.mSubLayer; |
| 828 | if (wSublayer >= largestSublayer) { |
| 829 | largestSublayer = wSublayer; |
| 830 | windowWithLargestSublayer = w; |
| 831 | } |
| 832 | if (sublayer < 0) { |
| 833 | // For negative sublayers, we go below all windows |
| 834 | // in the same sublayer. |
| 835 | if (wSublayer >= sublayer) { |
| 836 | if (addToToken) { |
| 837 | token.windows.add(i, win); |
| 838 | } |
| 839 | placeWindowBefore( |
| 840 | wSublayer >= 0 ? attached : w, win); |
| 841 | break; |
| 842 | } |
| 843 | } else { |
| 844 | // For positive sublayers, we go above all windows |
| 845 | // in the same sublayer. |
| 846 | if (wSublayer > sublayer) { |
| 847 | if (addToToken) { |
| 848 | token.windows.add(i, win); |
| 849 | } |
| 850 | placeWindowBefore(w, win); |
| 851 | break; |
| 852 | } |
| 853 | } |
| 854 | } |
| 855 | if (i >= NA) { |
| 856 | if (addToToken) { |
| 857 | token.windows.add(win); |
| 858 | } |
| 859 | if (sublayer < 0) { |
| 860 | placeWindowBefore(attached, win); |
| 861 | } else { |
| 862 | placeWindowAfter(largestSublayer >= 0 |
| 863 | ? windowWithLargestSublayer |
| 864 | : attached, |
| 865 | win); |
| 866 | } |
| 867 | } |
| 868 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 869 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 870 | if (win.mAppToken != null && addToToken) { |
| 871 | win.mAppToken.allAppWindows.add(win); |
| 872 | } |
| 873 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 874 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 875 | static boolean canBeImeTarget(WindowState w) { |
| 876 | final int fl = w.mAttrs.flags |
| 877 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 878 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 879 | return w.isVisibleOrAdding(); |
| 880 | } |
| 881 | return false; |
| 882 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 883 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 884 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
| 885 | final ArrayList localmWindows = mWindows; |
| 886 | final int N = localmWindows.size(); |
| 887 | WindowState w = null; |
| 888 | int i = N; |
| 889 | while (i > 0) { |
| 890 | i--; |
| 891 | w = (WindowState)localmWindows.get(i); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 892 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 893 | //Log.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
| 894 | // + Integer.toHexString(w.mAttrs.flags)); |
| 895 | if (canBeImeTarget(w)) { |
| 896 | //Log.i(TAG, "Putting input method here!"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 897 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 898 | // Yet more tricksyness! If this window is a "starting" |
| 899 | // window, we do actually want to be on top of it, but |
| 900 | // it is not -really- where input will go. So if the caller |
| 901 | // is not actually looking to move the IME, look down below |
| 902 | // for a real window to target... |
| 903 | if (!willMove |
| 904 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 905 | && i > 0) { |
| 906 | WindowState wb = (WindowState)localmWindows.get(i-1); |
| 907 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 908 | i--; |
| 909 | w = wb; |
| 910 | } |
| 911 | } |
| 912 | break; |
| 913 | } |
| 914 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | mUpcomingInputMethodTarget = w; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 917 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 918 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Desired input method target=" |
| 919 | + w + " willMove=" + willMove); |
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 | if (willMove && w != null) { |
| 922 | final WindowState curTarget = mInputMethodTarget; |
| 923 | if (curTarget != null && curTarget.mAppToken != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 924 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 925 | // Now some fun for dealing with window animations that |
| 926 | // modify the Z order. We need to look at all windows below |
| 927 | // the current target that are in this app, finding the highest |
| 928 | // visible one in layering. |
| 929 | AppWindowToken token = curTarget.mAppToken; |
| 930 | WindowState highestTarget = null; |
| 931 | int highestPos = 0; |
| 932 | if (token.animating || token.animation != null) { |
| 933 | int pos = 0; |
| 934 | pos = localmWindows.indexOf(curTarget); |
| 935 | while (pos >= 0) { |
| 936 | WindowState win = (WindowState)localmWindows.get(pos); |
| 937 | if (win.mAppToken != token) { |
| 938 | break; |
| 939 | } |
| 940 | if (!win.mRemoved) { |
| 941 | if (highestTarget == null || win.mAnimLayer > |
| 942 | highestTarget.mAnimLayer) { |
| 943 | highestTarget = win; |
| 944 | highestPos = pos; |
| 945 | } |
| 946 | } |
| 947 | pos--; |
| 948 | } |
| 949 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 950 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 951 | if (highestTarget != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 952 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "mNextAppTransition=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 953 | + mNextAppTransition + " " + highestTarget |
| 954 | + " animating=" + highestTarget.isAnimating() |
| 955 | + " layer=" + highestTarget.mAnimLayer |
| 956 | + " new layer=" + w.mAnimLayer); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 957 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 958 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 959 | // If we are currently setting up for an animation, |
| 960 | // hold everything until we can find out what will happen. |
| 961 | mInputMethodTargetWaitingAnim = true; |
| 962 | mInputMethodTarget = highestTarget; |
| 963 | return highestPos + 1; |
| 964 | } else if (highestTarget.isAnimating() && |
| 965 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 966 | // If the window we are currently targeting is involved |
| 967 | // with an animation, and it is on top of the next target |
| 968 | // we will be over, then hold off on moving until |
| 969 | // that is done. |
| 970 | mInputMethodTarget = highestTarget; |
| 971 | return highestPos + 1; |
| 972 | } |
| 973 | } |
| 974 | } |
| 975 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 976 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 977 | //Log.i(TAG, "Placing input method @" + (i+1)); |
| 978 | if (w != null) { |
| 979 | if (willMove) { |
| 980 | RuntimeException e = new RuntimeException(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 981 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 982 | if (DEBUG_INPUT_METHOD) Log.w(TAG, "Moving IM target from " |
| 983 | + mInputMethodTarget + " to " + w, e); |
| 984 | mInputMethodTarget = w; |
| 985 | if (w.mAppToken != null) { |
| 986 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 987 | } else { |
| 988 | setInputMethodAnimLayerAdjustment(0); |
| 989 | } |
| 990 | } |
| 991 | return i+1; |
| 992 | } |
| 993 | if (willMove) { |
| 994 | RuntimeException e = new RuntimeException(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 995 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 996 | if (DEBUG_INPUT_METHOD) Log.w(TAG, "Moving IM target from " |
| 997 | + mInputMethodTarget + " to null", e); |
| 998 | mInputMethodTarget = null; |
| 999 | setInputMethodAnimLayerAdjustment(0); |
| 1000 | } |
| 1001 | return -1; |
| 1002 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1003 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1004 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1005 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1006 | if (pos >= 0) { |
| 1007 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1008 | if (DEBUG_WINDOW_MOVEMENT) Log.v( |
| 1009 | TAG, "Adding input method window " + win + " at " + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1010 | mWindows.add(pos, win); |
| 1011 | moveInputMethodDialogsLocked(pos+1); |
| 1012 | return; |
| 1013 | } |
| 1014 | win.mTargetAppToken = null; |
| 1015 | addWindowToListInOrderLocked(win, true); |
| 1016 | moveInputMethodDialogsLocked(pos); |
| 1017 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1018 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1019 | void setInputMethodAnimLayerAdjustment(int adj) { |
| 1020 | if (DEBUG_LAYERS) Log.v(TAG, "Setting im layer adj to " + adj); |
| 1021 | mInputMethodAnimLayerAdjustment = adj; |
| 1022 | WindowState imw = mInputMethodWindow; |
| 1023 | if (imw != null) { |
| 1024 | imw.mAnimLayer = imw.mLayer + adj; |
| 1025 | if (DEBUG_LAYERS) Log.v(TAG, "IM win " + imw |
| 1026 | + " anim layer: " + imw.mAnimLayer); |
| 1027 | int wi = imw.mChildWindows.size(); |
| 1028 | while (wi > 0) { |
| 1029 | wi--; |
| 1030 | WindowState cw = (WindowState)imw.mChildWindows.get(wi); |
| 1031 | cw.mAnimLayer = cw.mLayer + adj; |
| 1032 | if (DEBUG_LAYERS) Log.v(TAG, "IM win " + cw |
| 1033 | + " anim layer: " + cw.mAnimLayer); |
| 1034 | } |
| 1035 | } |
| 1036 | int di = mInputMethodDialogs.size(); |
| 1037 | while (di > 0) { |
| 1038 | di --; |
| 1039 | imw = mInputMethodDialogs.get(di); |
| 1040 | imw.mAnimLayer = imw.mLayer + adj; |
| 1041 | if (DEBUG_LAYERS) Log.v(TAG, "IM win " + imw |
| 1042 | + " anim layer: " + imw.mAnimLayer); |
| 1043 | } |
| 1044 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1045 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1046 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1047 | int wpos = mWindows.indexOf(win); |
| 1048 | if (wpos >= 0) { |
| 1049 | if (wpos < interestingPos) interestingPos--; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1050 | 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] | 1051 | mWindows.remove(wpos); |
| 1052 | int NC = win.mChildWindows.size(); |
| 1053 | while (NC > 0) { |
| 1054 | NC--; |
| 1055 | WindowState cw = (WindowState)win.mChildWindows.get(NC); |
| 1056 | int cpos = mWindows.indexOf(cw); |
| 1057 | if (cpos >= 0) { |
| 1058 | if (cpos < interestingPos) interestingPos--; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1059 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Temp removing child at " |
| 1060 | + cpos + ": " + cw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1061 | mWindows.remove(cpos); |
| 1062 | } |
| 1063 | } |
| 1064 | } |
| 1065 | return interestingPos; |
| 1066 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1067 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1068 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1069 | addWindowToListInOrderLocked(win, false); |
| 1070 | // This is a hack to get all of the child windows added as well |
| 1071 | // at the right position. Child windows should be rare and |
| 1072 | // this case should be rare, so it shouldn't be that big a deal. |
| 1073 | int wpos = mWindows.indexOf(win); |
| 1074 | if (wpos >= 0) { |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1075 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "ReAdd removing from " + wpos |
| 1076 | + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1077 | mWindows.remove(wpos); |
| 1078 | reAddWindowLocked(wpos, win); |
| 1079 | } |
| 1080 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1081 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1082 | void logWindowList(String prefix) { |
| 1083 | int N = mWindows.size(); |
| 1084 | while (N > 0) { |
| 1085 | N--; |
| 1086 | Log.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
| 1087 | } |
| 1088 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1089 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1090 | void moveInputMethodDialogsLocked(int pos) { |
| 1091 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1092 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1093 | final int N = dialogs.size(); |
| 1094 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Removing " + N + " dialogs w/pos=" + pos); |
| 1095 | for (int i=0; i<N; i++) { |
| 1096 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1097 | } |
| 1098 | if (DEBUG_INPUT_METHOD) { |
| 1099 | Log.v(TAG, "Window list w/pos=" + pos); |
| 1100 | logWindowList(" "); |
| 1101 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1102 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1103 | if (pos >= 0) { |
| 1104 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1105 | if (pos < mWindows.size()) { |
| 1106 | WindowState wp = (WindowState)mWindows.get(pos); |
| 1107 | if (wp == mInputMethodWindow) { |
| 1108 | pos++; |
| 1109 | } |
| 1110 | } |
| 1111 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Adding " + N + " dialogs at pos=" + pos); |
| 1112 | for (int i=0; i<N; i++) { |
| 1113 | WindowState win = dialogs.get(i); |
| 1114 | win.mTargetAppToken = targetAppToken; |
| 1115 | pos = reAddWindowLocked(pos, win); |
| 1116 | } |
| 1117 | if (DEBUG_INPUT_METHOD) { |
| 1118 | Log.v(TAG, "Final window list:"); |
| 1119 | logWindowList(" "); |
| 1120 | } |
| 1121 | return; |
| 1122 | } |
| 1123 | for (int i=0; i<N; i++) { |
| 1124 | WindowState win = dialogs.get(i); |
| 1125 | win.mTargetAppToken = null; |
| 1126 | reAddWindowToListInOrderLocked(win); |
| 1127 | if (DEBUG_INPUT_METHOD) { |
| 1128 | Log.v(TAG, "No IM target, final list:"); |
| 1129 | logWindowList(" "); |
| 1130 | } |
| 1131 | } |
| 1132 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1133 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1134 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1135 | final WindowState imWin = mInputMethodWindow; |
| 1136 | final int DN = mInputMethodDialogs.size(); |
| 1137 | if (imWin == null && DN == 0) { |
| 1138 | return false; |
| 1139 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1141 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1142 | if (imPos >= 0) { |
| 1143 | // In this case, the input method windows are to be placed |
| 1144 | // immediately above the window they are targeting. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1145 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1146 | // First check to see if the input method windows are already |
| 1147 | // located here, and contiguous. |
| 1148 | final int N = mWindows.size(); |
| 1149 | WindowState firstImWin = imPos < N |
| 1150 | ? (WindowState)mWindows.get(imPos) : null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1151 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1152 | // Figure out the actual input method window that should be |
| 1153 | // at the bottom of their stack. |
| 1154 | WindowState baseImWin = imWin != null |
| 1155 | ? imWin : mInputMethodDialogs.get(0); |
| 1156 | if (baseImWin.mChildWindows.size() > 0) { |
| 1157 | WindowState cw = (WindowState)baseImWin.mChildWindows.get(0); |
| 1158 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1159 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1160 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1161 | if (firstImWin == baseImWin) { |
| 1162 | // The windows haven't moved... but are they still contiguous? |
| 1163 | // First find the top IM window. |
| 1164 | int pos = imPos+1; |
| 1165 | while (pos < N) { |
| 1166 | if (!((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1167 | break; |
| 1168 | } |
| 1169 | pos++; |
| 1170 | } |
| 1171 | pos++; |
| 1172 | // Now there should be no more input method windows above. |
| 1173 | while (pos < N) { |
| 1174 | if (((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1175 | break; |
| 1176 | } |
| 1177 | pos++; |
| 1178 | } |
| 1179 | if (pos >= N) { |
| 1180 | // All is good! |
| 1181 | return false; |
| 1182 | } |
| 1183 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1184 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1185 | if (imWin != null) { |
| 1186 | if (DEBUG_INPUT_METHOD) { |
| 1187 | Log.v(TAG, "Moving IM from " + imPos); |
| 1188 | logWindowList(" "); |
| 1189 | } |
| 1190 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1191 | if (DEBUG_INPUT_METHOD) { |
| 1192 | Log.v(TAG, "List after moving with new pos " + imPos + ":"); |
| 1193 | logWindowList(" "); |
| 1194 | } |
| 1195 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1196 | reAddWindowLocked(imPos, imWin); |
| 1197 | if (DEBUG_INPUT_METHOD) { |
| 1198 | Log.v(TAG, "List after moving IM to " + imPos + ":"); |
| 1199 | logWindowList(" "); |
| 1200 | } |
| 1201 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1202 | } else { |
| 1203 | moveInputMethodDialogsLocked(imPos); |
| 1204 | } |
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 | } else { |
| 1207 | // In this case, the input method windows go in a fixed layer, |
| 1208 | // because they aren't currently associated with a focus window. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1209 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1210 | if (imWin != null) { |
| 1211 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Moving IM from " + imPos); |
| 1212 | tmpRemoveWindowLocked(0, imWin); |
| 1213 | imWin.mTargetAppToken = null; |
| 1214 | reAddWindowToListInOrderLocked(imWin); |
| 1215 | if (DEBUG_INPUT_METHOD) { |
| 1216 | Log.v(TAG, "List with no IM target:"); |
| 1217 | logWindowList(" "); |
| 1218 | } |
| 1219 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1220 | } else { |
| 1221 | moveInputMethodDialogsLocked(-1);; |
| 1222 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1223 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | if (needAssignLayers) { |
| 1227 | assignLayersLocked(); |
| 1228 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1229 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1230 | return true; |
| 1231 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1232 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1233 | void adjustInputMethodDialogsLocked() { |
| 1234 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1235 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1236 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1237 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
| 1238 | if (DEBUG_WALLPAPER) Log.v(TAG, "Wallpaper vis: target obscured=" |
| 1239 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1240 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1241 | ? wallpaperTarget.mAppToken.animation : null) |
| 1242 | + " upper=" + mUpperWallpaperTarget |
| 1243 | + " lower=" + mLowerWallpaperTarget); |
| 1244 | return (wallpaperTarget != null |
| 1245 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1246 | && wallpaperTarget.mAppToken.animation != null))) |
| 1247 | || mUpperWallpaperTarget != null |
| 1248 | || mLowerWallpaperTarget != null; |
| 1249 | } |
| 1250 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1251 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1252 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
| 1253 | |
| 1254 | int adjustWallpaperWindowsLocked() { |
| 1255 | int changed = 0; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1256 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1257 | final int dw = mDisplay.getWidth(); |
| 1258 | final int dh = mDisplay.getHeight(); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1259 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1260 | // First find top-most window that has asked to be on top of the |
| 1261 | // wallpaper; all wallpapers go behind it. |
| 1262 | final ArrayList localmWindows = mWindows; |
| 1263 | int N = localmWindows.size(); |
| 1264 | WindowState w = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1265 | WindowState foundW = null; |
| 1266 | int foundI = 0; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1267 | WindowState topCurW = null; |
| 1268 | int topCurI = 0; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1269 | int i = N; |
| 1270 | while (i > 0) { |
| 1271 | i--; |
| 1272 | w = (WindowState)localmWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1273 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1274 | if (topCurW == null) { |
| 1275 | topCurW = w; |
| 1276 | topCurI = i; |
| 1277 | } |
| 1278 | continue; |
| 1279 | } |
| 1280 | topCurW = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1281 | if (w.mAppToken != null) { |
| 1282 | // If this window's app token is hidden and not animating, |
| 1283 | // it is of no interest to us. |
| 1284 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
| 1285 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 1286 | "Skipping hidden or animating token: " + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1287 | topCurW = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1288 | continue; |
| 1289 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1290 | } |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1291 | if (DEBUG_WALLPAPER) Log.v(TAG, "Win " + w + ": readyfordisplay=" |
| 1292 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1293 | + " commitdrawpending=" + w.mCommitDrawPending); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1294 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1295 | && (mWallpaperTarget == w |
| 1296 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1297 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 1298 | "Found wallpaper activity: #" + i + "=" + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1299 | foundW = w; |
| 1300 | foundI = i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1301 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1302 | && w.mAppToken.animation != null) |
| 1303 | || w.mAnimation != null)) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1304 | // The current wallpaper target is animating, so we'll |
| 1305 | // look behind it for another possible target and figure |
| 1306 | // out what is going on below. |
| 1307 | if (DEBUG_WALLPAPER) Log.v(TAG, "Win " + w |
| 1308 | + ": token animating, looking behind."); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1309 | continue; |
| 1310 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1311 | break; |
| 1312 | } |
| 1313 | } |
| 1314 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1315 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1316 | // If we are currently waiting for an app transition, and either |
| 1317 | // the current target or the next target are involved with it, |
| 1318 | // then hold off on doing anything with the wallpaper. |
| 1319 | // Note that we are checking here for just whether the target |
| 1320 | // is part of an app token... which is potentially overly aggressive |
| 1321 | // (the app token may not be involved in the transition), but good |
| 1322 | // enough (we'll just wait until whatever transition is pending |
| 1323 | // executes). |
| 1324 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1325 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 1326 | "Wallpaper not changing: waiting for app anim in current target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1327 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1328 | } |
| 1329 | if (foundW != null && foundW.mAppToken != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1330 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 1331 | "Wallpaper not changing: waiting for app anim in found target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1332 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1333 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1334 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1335 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1336 | if (mWallpaperTarget != foundW) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1337 | if (DEBUG_WALLPAPER) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1338 | Log.v(TAG, "New wallpaper target: " + foundW |
| 1339 | + " oldTarget: " + mWallpaperTarget); |
| 1340 | } |
| 1341 | |
| 1342 | mLowerWallpaperTarget = null; |
| 1343 | mUpperWallpaperTarget = null; |
| 1344 | |
| 1345 | WindowState oldW = mWallpaperTarget; |
| 1346 | mWallpaperTarget = foundW; |
| 1347 | |
| 1348 | // Now what is happening... if the current and new targets are |
| 1349 | // animating, then we are in our super special mode! |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1350 | if (foundW != null && oldW != null) { |
| 1351 | boolean oldAnim = oldW.mAnimation != null |
| 1352 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1353 | boolean foundAnim = foundW.mAnimation != null |
| 1354 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1355 | if (DEBUG_WALLPAPER) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1356 | Log.v(TAG, "New animation: " + foundAnim |
| 1357 | + " old animation: " + oldAnim); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1358 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1359 | if (foundAnim && oldAnim) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1360 | int oldI = localmWindows.indexOf(oldW); |
| 1361 | if (DEBUG_WALLPAPER) { |
| 1362 | Log.v(TAG, "New i: " + foundI + " old i: " + oldI); |
| 1363 | } |
| 1364 | if (oldI >= 0) { |
| 1365 | if (DEBUG_WALLPAPER) { |
| 1366 | Log.v(TAG, "Animating wallpapers: old#" + oldI |
| 1367 | + "=" + oldW + "; new#" + foundI |
| 1368 | + "=" + foundW); |
| 1369 | } |
| 1370 | |
| 1371 | // Set the new target correctly. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1372 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1373 | if (DEBUG_WALLPAPER) { |
| 1374 | Log.v(TAG, "Old wallpaper still the target."); |
| 1375 | } |
| 1376 | mWallpaperTarget = oldW; |
| 1377 | } |
| 1378 | |
| 1379 | // Now set the upper and lower wallpaper targets |
| 1380 | // correctly, and make sure that we are positioning |
| 1381 | // the wallpaper below the lower. |
| 1382 | if (foundI > oldI) { |
| 1383 | // The new target is on top of the old one. |
| 1384 | if (DEBUG_WALLPAPER) { |
| 1385 | Log.v(TAG, "Found target above old target."); |
| 1386 | } |
| 1387 | mUpperWallpaperTarget = foundW; |
| 1388 | mLowerWallpaperTarget = oldW; |
| 1389 | foundW = oldW; |
| 1390 | foundI = oldI; |
| 1391 | } else { |
| 1392 | // The new target is below the old one. |
| 1393 | if (DEBUG_WALLPAPER) { |
| 1394 | Log.v(TAG, "Found target below old target."); |
| 1395 | } |
| 1396 | mUpperWallpaperTarget = oldW; |
| 1397 | mLowerWallpaperTarget = foundW; |
| 1398 | } |
| 1399 | } |
| 1400 | } |
| 1401 | } |
| 1402 | |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1403 | } else if (mLowerWallpaperTarget != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1404 | // Is it time to stop animating? |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1405 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1406 | || (mLowerWallpaperTarget.mAppToken != null |
| 1407 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1408 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1409 | || (mUpperWallpaperTarget.mAppToken != null |
| 1410 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1411 | if (!lowerAnimating || !upperAnimating) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1412 | if (DEBUG_WALLPAPER) { |
| 1413 | Log.v(TAG, "No longer animating wallpaper targets!"); |
| 1414 | } |
| 1415 | mLowerWallpaperTarget = null; |
| 1416 | mUpperWallpaperTarget = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1417 | } |
| 1418 | } |
| 1419 | |
| 1420 | boolean visible = foundW != null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1421 | if (visible) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1422 | // The window is visible to the compositor... but is it visible |
| 1423 | // to the user? That is what the wallpaper cares about. |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1424 | visible = isWallpaperVisible(foundW); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1425 | if (DEBUG_WALLPAPER) Log.v(TAG, "Wallpaper visibility: " + visible); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1426 | |
| 1427 | // If the wallpaper target is animating, we may need to copy |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1428 | // its layer adjustment. Only do this if we are not transfering |
| 1429 | // between two wallpaper targets. |
| 1430 | mWallpaperAnimLayerAdjustment = |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1431 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1432 | ? foundW.mAppToken.animLayerAdjustment : 0; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1433 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1434 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1435 | * TYPE_LAYER_MULTIPLIER |
| 1436 | + TYPE_LAYER_OFFSET; |
| 1437 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1438 | // Now w is the window we are supposed to be behind... but we |
| 1439 | // 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] | 1440 | // AND any starting window associated with it, AND below the |
| 1441 | // maximum layer the policy allows for wallpapers. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1442 | while (foundI > 0) { |
| 1443 | WindowState wb = (WindowState)localmWindows.get(foundI-1); |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1444 | if (wb.mBaseLayer < maxLayer && |
| 1445 | wb.mAttachedWindow != foundW && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1446 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1447 | wb.mToken != foundW.mToken)) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1448 | // This window is not related to the previous one in any |
| 1449 | // interesting way, so stop here. |
| 1450 | break; |
| 1451 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1452 | foundW = wb; |
| 1453 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1454 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1455 | } else { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1456 | if (DEBUG_WALLPAPER) Log.v(TAG, "No wallpaper target"); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1457 | } |
| 1458 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1459 | if (foundW == null && topCurW != null) { |
| 1460 | // There is no wallpaper target, so it goes at the bottom. |
| 1461 | // We will assume it is the same place as last time, if known. |
| 1462 | foundW = topCurW; |
| 1463 | foundI = topCurI+1; |
| 1464 | } else { |
| 1465 | // Okay i is the position immediately above the wallpaper. Look at |
| 1466 | // what is below it for later. |
| 1467 | foundW = foundI > 0 ? (WindowState)localmWindows.get(foundI-1) : null; |
| 1468 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1469 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1470 | if (visible) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1471 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1472 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1473 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1474 | } |
| 1475 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1476 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1477 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1478 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1479 | } |
| 1480 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1481 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1482 | // are correctly placed. |
| 1483 | int curTokenIndex = mWallpaperTokens.size(); |
| 1484 | while (curTokenIndex > 0) { |
| 1485 | curTokenIndex--; |
| 1486 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1487 | if (token.hidden == visible) { |
| 1488 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1489 | token.hidden = !visible; |
| 1490 | // Need to do a layout to ensure the wallpaper now has the |
| 1491 | // correct size. |
| 1492 | mLayoutNeeded = true; |
| 1493 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1494 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1495 | int curWallpaperIndex = token.windows.size(); |
| 1496 | while (curWallpaperIndex > 0) { |
| 1497 | curWallpaperIndex--; |
| 1498 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1499 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1500 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1501 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1502 | } |
| 1503 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1504 | // First, make sure the client has the current visibility |
| 1505 | // state. |
| 1506 | if (wallpaper.mWallpaperVisible != visible) { |
| 1507 | wallpaper.mWallpaperVisible = visible; |
| 1508 | try { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1509 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Log.v(TAG, |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1510 | "Setting visibility of wallpaper " + wallpaper |
| 1511 | + ": " + visible); |
| 1512 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1513 | } catch (RemoteException e) { |
| 1514 | } |
| 1515 | } |
| 1516 | |
| 1517 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1518 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Log.v(TAG, "Wallpaper win " |
| 1519 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1520 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1521 | // First, if this window is at the current index, then all |
| 1522 | // is well. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1523 | if (wallpaper == foundW) { |
| 1524 | foundI--; |
| 1525 | foundW = foundI > 0 |
| 1526 | ? (WindowState)localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1527 | continue; |
| 1528 | } |
| 1529 | |
| 1530 | // The window didn't match... the current wallpaper window, |
| 1531 | // wherever it is, is in the wrong place, so make sure it is |
| 1532 | // not in the list. |
| 1533 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1534 | if (oldIndex >= 0) { |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1535 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Wallpaper removing at " |
| 1536 | + oldIndex + ": " + wallpaper); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1537 | localmWindows.remove(oldIndex); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1538 | if (oldIndex < foundI) { |
| 1539 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1540 | } |
| 1541 | } |
| 1542 | |
| 1543 | // Now stick it in. |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1544 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Log.v(TAG, |
| 1545 | "Moving wallpaper " + wallpaper |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1546 | + " from " + oldIndex + " to " + foundI); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1547 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1548 | localmWindows.add(foundI, wallpaper); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1549 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1550 | } |
| 1551 | } |
| 1552 | |
| 1553 | return changed; |
| 1554 | } |
| 1555 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1556 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1557 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Log.v(TAG, |
| 1558 | "Setting wallpaper layer adj to " + adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1559 | mWallpaperAnimLayerAdjustment = adj; |
| 1560 | int curTokenIndex = mWallpaperTokens.size(); |
| 1561 | while (curTokenIndex > 0) { |
| 1562 | curTokenIndex--; |
| 1563 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1564 | int curWallpaperIndex = token.windows.size(); |
| 1565 | while (curWallpaperIndex > 0) { |
| 1566 | curWallpaperIndex--; |
| 1567 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1568 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1569 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Log.v(TAG, "Wallpaper win " |
| 1570 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1571 | } |
| 1572 | } |
| 1573 | } |
| 1574 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1575 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 1576 | boolean sync) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1577 | boolean changed = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1578 | boolean rawChanged = false; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1579 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1580 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1581 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 1582 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 1583 | changed = wallpaperWin.mXOffset != offset; |
| 1584 | if (changed) { |
| 1585 | if (DEBUG_WALLPAPER) Log.v(TAG, "Update wallpaper " |
| 1586 | + wallpaperWin + " x: " + offset); |
| 1587 | wallpaperWin.mXOffset = offset; |
| 1588 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1589 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1590 | wallpaperWin.mWallpaperX = wpx; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1591 | wallpaperWin.mWallpaperXStep = wpxs; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1592 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1593 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1594 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1595 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1596 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1597 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 1598 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 1599 | if (wallpaperWin.mYOffset != offset) { |
| 1600 | if (DEBUG_WALLPAPER) Log.v(TAG, "Update wallpaper " |
| 1601 | + wallpaperWin + " y: " + offset); |
| 1602 | changed = true; |
| 1603 | wallpaperWin.mYOffset = offset; |
| 1604 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1605 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1606 | wallpaperWin.mWallpaperY = wpy; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1607 | wallpaperWin.mWallpaperYStep = wpys; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1608 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1609 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1610 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1611 | if (rawChanged) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1612 | try { |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1613 | if (DEBUG_WALLPAPER) Log.v(TAG, "Report new wp offset " |
| 1614 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 1615 | + " y=" + wallpaperWin.mWallpaperY); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1616 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1617 | mWaitingOnWallpaper = wallpaperWin; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1618 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1619 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1620 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 1621 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1622 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1623 | if (mWaitingOnWallpaper != null) { |
| 1624 | long start = SystemClock.uptimeMillis(); |
| 1625 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 1626 | < start) { |
| 1627 | try { |
| 1628 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 1629 | "Waiting for offset complete..."); |
| 1630 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 1631 | } catch (InterruptedException e) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1632 | } |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1633 | if (DEBUG_WALLPAPER) Log.v(TAG, "Offset complete!"); |
| 1634 | if ((start+WALLPAPER_TIMEOUT) |
| 1635 | < SystemClock.uptimeMillis()) { |
| 1636 | Log.i(TAG, "Timeout waiting for wallpaper to offset: " |
| 1637 | + wallpaperWin); |
| 1638 | mLastWallpaperTimeoutTime = start; |
| 1639 | } |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1640 | } |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1641 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1642 | } |
| 1643 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1644 | } catch (RemoteException e) { |
| 1645 | } |
| 1646 | } |
| 1647 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1648 | return changed; |
| 1649 | } |
| 1650 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1651 | void wallpaperOffsetsComplete(IBinder window) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1652 | synchronized (mWindowMap) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1653 | if (mWaitingOnWallpaper != null && |
| 1654 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 1655 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1656 | mWindowMap.notifyAll(); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1657 | } |
| 1658 | } |
| 1659 | } |
| 1660 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1661 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1662 | final int dw = mDisplay.getWidth(); |
| 1663 | final int dh = mDisplay.getHeight(); |
| 1664 | |
| 1665 | boolean changed = false; |
| 1666 | |
| 1667 | WindowState target = mWallpaperTarget; |
| 1668 | if (target != null) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1669 | if (target.mWallpaperX >= 0) { |
| 1670 | mLastWallpaperX = target.mWallpaperX; |
| 1671 | } else if (changingTarget.mWallpaperX >= 0) { |
| 1672 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 1673 | } |
| 1674 | if (target.mWallpaperY >= 0) { |
| 1675 | mLastWallpaperY = target.mWallpaperY; |
| 1676 | } else if (changingTarget.mWallpaperY >= 0) { |
| 1677 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 1678 | } |
| 1679 | } |
| 1680 | |
| 1681 | int curTokenIndex = mWallpaperTokens.size(); |
| 1682 | while (curTokenIndex > 0) { |
| 1683 | curTokenIndex--; |
| 1684 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1685 | int curWallpaperIndex = token.windows.size(); |
| 1686 | while (curWallpaperIndex > 0) { |
| 1687 | curWallpaperIndex--; |
| 1688 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1689 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 1690 | wallpaper.computeShownFrameLocked(); |
| 1691 | changed = true; |
| 1692 | // We only want to be synchronous with one wallpaper. |
| 1693 | sync = false; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1694 | } |
| 1695 | } |
| 1696 | } |
| 1697 | |
| 1698 | return changed; |
| 1699 | } |
| 1700 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1701 | void updateWallpaperVisibilityLocked() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1702 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1703 | final int dw = mDisplay.getWidth(); |
| 1704 | final int dh = mDisplay.getHeight(); |
| 1705 | |
| 1706 | int curTokenIndex = mWallpaperTokens.size(); |
| 1707 | while (curTokenIndex > 0) { |
| 1708 | curTokenIndex--; |
| 1709 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1710 | if (token.hidden == visible) { |
| 1711 | token.hidden = !visible; |
| 1712 | // Need to do a layout to ensure the wallpaper now has the |
| 1713 | // correct size. |
| 1714 | mLayoutNeeded = true; |
| 1715 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1716 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1717 | int curWallpaperIndex = token.windows.size(); |
| 1718 | while (curWallpaperIndex > 0) { |
| 1719 | curWallpaperIndex--; |
| 1720 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1721 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1722 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | if (wallpaper.mWallpaperVisible != visible) { |
| 1726 | wallpaper.mWallpaperVisible = visible; |
| 1727 | try { |
| 1728 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Log.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1729 | "Updating visibility of wallpaper " + wallpaper |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1730 | + ": " + visible); |
| 1731 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1732 | } catch (RemoteException e) { |
| 1733 | } |
| 1734 | } |
| 1735 | } |
| 1736 | } |
| 1737 | } |
| 1738 | |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1739 | void sendPointerToWallpaperLocked(WindowState srcWin, |
| 1740 | MotionEvent pointer, long eventTime) { |
| 1741 | int curTokenIndex = mWallpaperTokens.size(); |
| 1742 | while (curTokenIndex > 0) { |
| 1743 | curTokenIndex--; |
| 1744 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1745 | int curWallpaperIndex = token.windows.size(); |
| 1746 | while (curWallpaperIndex > 0) { |
| 1747 | curWallpaperIndex--; |
| 1748 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1749 | if ((wallpaper.mAttrs.flags & |
| 1750 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 1751 | continue; |
| 1752 | } |
| 1753 | try { |
| 1754 | MotionEvent ev = MotionEvent.obtainNoHistory(pointer); |
Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 1755 | if (srcWin != null) { |
| 1756 | ev.offsetLocation(srcWin.mFrame.left-wallpaper.mFrame.left, |
| 1757 | srcWin.mFrame.top-wallpaper.mFrame.top); |
| 1758 | } else { |
| 1759 | ev.offsetLocation(-wallpaper.mFrame.left, -wallpaper.mFrame.top); |
| 1760 | } |
| 1761 | switch (pointer.getAction()) { |
| 1762 | case MotionEvent.ACTION_DOWN: |
| 1763 | mSendingPointersToWallpaper = true; |
| 1764 | break; |
| 1765 | case MotionEvent.ACTION_UP: |
| 1766 | mSendingPointersToWallpaper = false; |
| 1767 | break; |
| 1768 | } |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1769 | wallpaper.mClient.dispatchPointer(ev, eventTime, false); |
| 1770 | } catch (RemoteException e) { |
| 1771 | Log.w(TAG, "Failure sending pointer to wallpaper", e); |
| 1772 | } |
| 1773 | } |
| 1774 | } |
| 1775 | } |
| 1776 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1777 | public int addWindow(Session session, IWindow client, |
| 1778 | WindowManager.LayoutParams attrs, int viewVisibility, |
| 1779 | Rect outContentInsets) { |
| 1780 | int res = mPolicy.checkAddPermission(attrs); |
| 1781 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1782 | return res; |
| 1783 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1784 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1785 | boolean reportNewConfig = false; |
| 1786 | WindowState attachedWindow = null; |
| 1787 | WindowState win = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1788 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1789 | synchronized(mWindowMap) { |
| 1790 | // Instantiating a Display requires talking with the simulator, |
| 1791 | // so don't do it until we know the system is mostly up and |
| 1792 | // running. |
| 1793 | if (mDisplay == null) { |
| 1794 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 1795 | mDisplay = wm.getDefaultDisplay(); |
| 1796 | mQueue.setDisplay(mDisplay); |
| 1797 | reportNewConfig = true; |
| 1798 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1799 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1800 | if (mWindowMap.containsKey(client.asBinder())) { |
| 1801 | Log.w(TAG, "Window " + client + " is already added"); |
| 1802 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 1803 | } |
| 1804 | |
| 1805 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1806 | attachedWindow = windowForClientLocked(null, attrs.token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1807 | if (attachedWindow == null) { |
| 1808 | Log.w(TAG, "Attempted to add window with token that is not a window: " |
| 1809 | + attrs.token + ". Aborting."); |
| 1810 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1811 | } |
| 1812 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 1813 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
| 1814 | Log.w(TAG, "Attempted to add window with token that is a sub-window: " |
| 1815 | + attrs.token + ". Aborting."); |
| 1816 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1817 | } |
| 1818 | } |
| 1819 | |
| 1820 | boolean addToken = false; |
| 1821 | WindowToken token = mTokenMap.get(attrs.token); |
| 1822 | if (token == null) { |
| 1823 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1824 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1825 | Log.w(TAG, "Attempted to add application window with unknown token " |
| 1826 | + attrs.token + ". Aborting."); |
| 1827 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1828 | } |
| 1829 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 1830 | Log.w(TAG, "Attempted to add input method window with unknown token " |
| 1831 | + attrs.token + ". Aborting."); |
| 1832 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1833 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1834 | if (attrs.type == TYPE_WALLPAPER) { |
| 1835 | Log.w(TAG, "Attempted to add wallpaper window with unknown token " |
| 1836 | + attrs.token + ". Aborting."); |
| 1837 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1838 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1839 | token = new WindowToken(attrs.token, -1, false); |
| 1840 | addToken = true; |
| 1841 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1842 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1843 | AppWindowToken atoken = token.appWindowToken; |
| 1844 | if (atoken == null) { |
| 1845 | Log.w(TAG, "Attempted to add window with non-application token " |
| 1846 | + token + ". Aborting."); |
| 1847 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 1848 | } else if (atoken.removed) { |
| 1849 | Log.w(TAG, "Attempted to add window with exiting application token " |
| 1850 | + token + ". Aborting."); |
| 1851 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1852 | } |
| 1853 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 1854 | // No need for this guy! |
| 1855 | if (localLOGV) Log.v( |
| 1856 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 1857 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 1858 | } |
| 1859 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 1860 | if (token.windowType != TYPE_INPUT_METHOD) { |
| 1861 | Log.w(TAG, "Attempted to add input method window with bad token " |
| 1862 | + attrs.token + ". Aborting."); |
| 1863 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1864 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1865 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 1866 | if (token.windowType != TYPE_WALLPAPER) { |
| 1867 | Log.w(TAG, "Attempted to add wallpaper window with bad token " |
| 1868 | + attrs.token + ". Aborting."); |
| 1869 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1870 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1871 | } |
| 1872 | |
| 1873 | win = new WindowState(session, client, token, |
| 1874 | attachedWindow, attrs, viewVisibility); |
| 1875 | if (win.mDeathRecipient == null) { |
| 1876 | // Client has apparently died, so there is no reason to |
| 1877 | // continue. |
| 1878 | Log.w(TAG, "Adding window client " + client.asBinder() |
| 1879 | + " that is dead, aborting."); |
| 1880 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1881 | } |
| 1882 | |
| 1883 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1884 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1885 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 1886 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1887 | return res; |
| 1888 | } |
| 1889 | |
| 1890 | // From now on, no exceptions or errors allowed! |
| 1891 | |
| 1892 | res = WindowManagerImpl.ADD_OKAY; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1893 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1894 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1895 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1896 | if (addToken) { |
| 1897 | mTokenMap.put(attrs.token, token); |
| 1898 | mTokenList.add(token); |
| 1899 | } |
| 1900 | win.attach(); |
| 1901 | mWindowMap.put(client.asBinder(), win); |
| 1902 | |
| 1903 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 1904 | token.appWindowToken != null) { |
| 1905 | token.appWindowToken.startingWindow = win; |
| 1906 | } |
| 1907 | |
| 1908 | boolean imMayMove = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1909 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1910 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 1911 | mInputMethodWindow = win; |
| 1912 | addInputMethodWindowToListLocked(win); |
| 1913 | imMayMove = false; |
| 1914 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 1915 | mInputMethodDialogs.add(win); |
| 1916 | addWindowToListInOrderLocked(win, true); |
| 1917 | adjustInputMethodDialogsLocked(); |
| 1918 | imMayMove = false; |
| 1919 | } else { |
| 1920 | addWindowToListInOrderLocked(win, true); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1921 | if (attrs.type == TYPE_WALLPAPER) { |
| 1922 | mLastWallpaperTimeoutTime = 0; |
| 1923 | adjustWallpaperWindowsLocked(); |
| 1924 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1925 | adjustWallpaperWindowsLocked(); |
| 1926 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1927 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1928 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1929 | win.mEnterAnimationPending = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1930 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1931 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1932 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1933 | if (mInTouchMode) { |
| 1934 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 1935 | } |
| 1936 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 1937 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 1938 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1939 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1940 | boolean focusChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1941 | if (win.canReceiveKeys()) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1942 | if ((focusChanged=updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS)) |
| 1943 | == true) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1944 | imMayMove = false; |
| 1945 | } |
| 1946 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1947 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1948 | if (imMayMove) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1949 | moveInputMethodWindowsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1950 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1951 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1952 | assignLayersLocked(); |
| 1953 | // Don't do layout here, the window must call |
| 1954 | // relayout to be displayed, so we'll do it there. |
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 | //dump(); |
| 1957 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1958 | if (focusChanged) { |
| 1959 | if (mCurrentFocus != null) { |
| 1960 | mKeyWaiter.handleNewWindowLocked(mCurrentFocus); |
| 1961 | } |
| 1962 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1963 | if (localLOGV) Log.v( |
| 1964 | TAG, "New client " + client.asBinder() |
| 1965 | + ": window=" + win); |
| 1966 | } |
| 1967 | |
| 1968 | // sendNewConfiguration() checks caller permissions so we must call it with |
| 1969 | // privilege. updateOrientationFromAppTokens() clears and resets the caller |
| 1970 | // identity anyway, so it's safe to just clear & restore around this whole |
| 1971 | // block. |
| 1972 | final long origId = Binder.clearCallingIdentity(); |
| 1973 | if (reportNewConfig) { |
| 1974 | sendNewConfiguration(); |
| 1975 | } else { |
| 1976 | // Update Orientation after adding a window, only if the window needs to be |
| 1977 | // displayed right away |
| 1978 | if (win.isVisibleOrAdding()) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 1979 | if (updateOrientationFromAppTokensUnchecked(null, null) != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1980 | sendNewConfiguration(); |
| 1981 | } |
| 1982 | } |
| 1983 | } |
| 1984 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1985 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1986 | return res; |
| 1987 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1988 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1989 | public void removeWindow(Session session, IWindow client) { |
| 1990 | synchronized(mWindowMap) { |
| 1991 | WindowState win = windowForClientLocked(session, client); |
| 1992 | if (win == null) { |
| 1993 | return; |
| 1994 | } |
| 1995 | removeWindowLocked(session, win); |
| 1996 | } |
| 1997 | } |
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 | public void removeWindowLocked(Session session, WindowState win) { |
| 2000 | |
| 2001 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 2002 | TAG, "Remove " + win + " client=" |
| 2003 | + Integer.toHexString(System.identityHashCode( |
| 2004 | win.mClient.asBinder())) |
| 2005 | + ", surface=" + win.mSurface); |
| 2006 | |
| 2007 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2008 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2009 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 2010 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2011 | + " mExiting=" + win.mExiting |
| 2012 | + " isAnimating=" + win.isAnimating() |
| 2013 | + " app-animation=" |
| 2014 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2015 | + " inPendingTransaction=" |
| 2016 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2017 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2018 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2019 | boolean wasVisible = false; |
| 2020 | // First, see if we need to run an animation. If we do, we have |
| 2021 | // to hold off on removing the window until the animation is done. |
| 2022 | // If the display is frozen, just remove immediately, since the |
| 2023 | // animation wouldn't be seen. |
| 2024 | if (win.mSurface != null && !mDisplayFrozen) { |
| 2025 | // If we are not currently running the exit animation, we |
| 2026 | // need to see about starting one. |
| 2027 | if (wasVisible=win.isWinVisibleLw()) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2028 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2029 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2030 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2031 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2032 | } |
| 2033 | // Try starting an animation. |
| 2034 | if (applyAnimationLocked(win, transit, false)) { |
| 2035 | win.mExiting = true; |
| 2036 | } |
| 2037 | } |
| 2038 | if (win.mExiting || win.isAnimating()) { |
| 2039 | // The exit animation is running... wait for it! |
| 2040 | //Log.i(TAG, "*** Running exit animation..."); |
| 2041 | win.mExiting = true; |
| 2042 | win.mRemoveOnExit = true; |
| 2043 | mLayoutNeeded = true; |
| 2044 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 2045 | performLayoutAndPlaceSurfacesLocked(); |
| 2046 | if (win.mAppToken != null) { |
| 2047 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2048 | } |
| 2049 | //dump(); |
| 2050 | Binder.restoreCallingIdentity(origId); |
| 2051 | return; |
| 2052 | } |
| 2053 | } |
| 2054 | |
| 2055 | removeWindowInnerLocked(session, win); |
| 2056 | // Removing a visible window will effect the computed orientation |
| 2057 | // So just update orientation if needed. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2058 | if (wasVisible && computeForcedAppOrientationLocked() |
| 2059 | != mForcedAppOrientation) { |
| 2060 | 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] | 2061 | } |
| 2062 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2063 | Binder.restoreCallingIdentity(origId); |
| 2064 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2065 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2066 | private void removeWindowInnerLocked(Session session, WindowState win) { |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 2067 | mKeyWaiter.finishedKey(session, win.mClient, true, |
| 2068 | KeyWaiter.RETURN_NOTHING); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2069 | mKeyWaiter.releasePendingPointerLocked(win.mSession); |
| 2070 | mKeyWaiter.releasePendingTrackballLocked(win.mSession); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2071 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2072 | win.mRemoved = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2073 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2074 | if (mInputMethodTarget == win) { |
| 2075 | moveInputMethodWindowsIfNeededLocked(false); |
| 2076 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2077 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2078 | if (false) { |
| 2079 | RuntimeException e = new RuntimeException("here"); |
| 2080 | e.fillInStackTrace(); |
| 2081 | Log.w(TAG, "Removing window " + win, e); |
| 2082 | } |
| 2083 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2084 | mPolicy.removeWindowLw(win); |
| 2085 | win.removeLocked(); |
| 2086 | |
| 2087 | mWindowMap.remove(win.mClient.asBinder()); |
| 2088 | mWindows.remove(win); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 2089 | 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] | 2090 | |
| 2091 | if (mInputMethodWindow == win) { |
| 2092 | mInputMethodWindow = null; |
| 2093 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2094 | mInputMethodDialogs.remove(win); |
| 2095 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2096 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2097 | final WindowToken token = win.mToken; |
| 2098 | final AppWindowToken atoken = win.mAppToken; |
| 2099 | token.windows.remove(win); |
| 2100 | if (atoken != null) { |
| 2101 | atoken.allAppWindows.remove(win); |
| 2102 | } |
| 2103 | if (localLOGV) Log.v( |
| 2104 | TAG, "**** Removing window " + win + ": count=" |
| 2105 | + token.windows.size()); |
| 2106 | if (token.windows.size() == 0) { |
| 2107 | if (!token.explicit) { |
| 2108 | mTokenMap.remove(token.token); |
| 2109 | mTokenList.remove(token); |
| 2110 | } else if (atoken != null) { |
| 2111 | atoken.firstWindowDrawn = false; |
| 2112 | } |
| 2113 | } |
| 2114 | |
| 2115 | if (atoken != null) { |
| 2116 | if (atoken.startingWindow == win) { |
| 2117 | atoken.startingWindow = null; |
| 2118 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2119 | // If this is the last window and we had requested a starting |
| 2120 | // transition window, well there is no point now. |
| 2121 | atoken.startingData = null; |
| 2122 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2123 | // If this is the last window except for a starting transition |
| 2124 | // window, we need to get rid of the starting transition. |
| 2125 | if (DEBUG_STARTING_WINDOW) { |
| 2126 | Log.v(TAG, "Schedule remove starting " + token |
| 2127 | + ": no more real windows"); |
| 2128 | } |
| 2129 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2130 | mH.sendMessage(m); |
| 2131 | } |
| 2132 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2133 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2134 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2135 | mLastWallpaperTimeoutTime = 0; |
| 2136 | adjustWallpaperWindowsLocked(); |
| 2137 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2138 | adjustWallpaperWindowsLocked(); |
| 2139 | } |
| 2140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2141 | if (!mInLayout) { |
| 2142 | assignLayersLocked(); |
| 2143 | mLayoutNeeded = true; |
| 2144 | performLayoutAndPlaceSurfacesLocked(); |
| 2145 | if (win.mAppToken != null) { |
| 2146 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2147 | } |
| 2148 | } |
| 2149 | } |
| 2150 | |
| 2151 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 2152 | long origId = Binder.clearCallingIdentity(); |
| 2153 | try { |
| 2154 | synchronized (mWindowMap) { |
| 2155 | WindowState w = windowForClientLocked(session, client); |
| 2156 | if ((w != null) && (w.mSurface != null)) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2157 | if (SHOW_TRANSACTIONS) Log.i(TAG, ">>> OPEN TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2158 | Surface.openTransaction(); |
| 2159 | try { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2160 | if (SHOW_TRANSACTIONS) Log.i( |
| 2161 | TAG, " SURFACE " + w.mSurface |
| 2162 | + ": transparentRegionHint=" + region); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2163 | w.mSurface.setTransparentRegionHint(region); |
| 2164 | } finally { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2165 | if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2166 | Surface.closeTransaction(); |
| 2167 | } |
| 2168 | } |
| 2169 | } |
| 2170 | } finally { |
| 2171 | Binder.restoreCallingIdentity(origId); |
| 2172 | } |
| 2173 | } |
| 2174 | |
| 2175 | void setInsetsWindow(Session session, IWindow client, |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2176 | int touchableInsets, Rect contentInsets, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2177 | Rect visibleInsets) { |
| 2178 | long origId = Binder.clearCallingIdentity(); |
| 2179 | try { |
| 2180 | synchronized (mWindowMap) { |
| 2181 | WindowState w = windowForClientLocked(session, client); |
| 2182 | if (w != null) { |
| 2183 | w.mGivenInsetsPending = false; |
| 2184 | w.mGivenContentInsets.set(contentInsets); |
| 2185 | w.mGivenVisibleInsets.set(visibleInsets); |
| 2186 | w.mTouchableInsets = touchableInsets; |
| 2187 | mLayoutNeeded = true; |
| 2188 | performLayoutAndPlaceSurfacesLocked(); |
| 2189 | } |
| 2190 | } |
| 2191 | } finally { |
| 2192 | Binder.restoreCallingIdentity(origId); |
| 2193 | } |
| 2194 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2195 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2196 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2197 | Rect outDisplayFrame) { |
| 2198 | synchronized(mWindowMap) { |
| 2199 | WindowState win = windowForClientLocked(session, client); |
| 2200 | if (win == null) { |
| 2201 | outDisplayFrame.setEmpty(); |
| 2202 | return; |
| 2203 | } |
| 2204 | outDisplayFrame.set(win.mDisplayFrame); |
| 2205 | } |
| 2206 | } |
| 2207 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2208 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2209 | float xStep, float yStep) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2210 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2211 | window.mWallpaperX = x; |
| 2212 | window.mWallpaperY = y; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2213 | window.mWallpaperXStep = xStep; |
| 2214 | window.mWallpaperYStep = yStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2215 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2216 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2217 | } |
| 2218 | } |
| 2219 | } |
| 2220 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2221 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2222 | synchronized (mWindowMap) { |
| 2223 | if (mWaitingOnWallpaper != null && |
| 2224 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2225 | mWaitingOnWallpaper = null; |
| 2226 | mWindowMap.notifyAll(); |
| 2227 | } |
| 2228 | } |
| 2229 | } |
| 2230 | |
| 2231 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2232 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2233 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2234 | || window == mUpperWallpaperTarget) { |
| 2235 | boolean doWait = sync; |
| 2236 | int curTokenIndex = mWallpaperTokens.size(); |
| 2237 | while (curTokenIndex > 0) { |
| 2238 | curTokenIndex--; |
| 2239 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2240 | int curWallpaperIndex = token.windows.size(); |
| 2241 | while (curWallpaperIndex > 0) { |
| 2242 | curWallpaperIndex--; |
| 2243 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2244 | try { |
| 2245 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2246 | x, y, z, extras, sync); |
| 2247 | // We only want to be synchronous with one wallpaper. |
| 2248 | sync = false; |
| 2249 | } catch (RemoteException e) { |
| 2250 | } |
| 2251 | } |
| 2252 | } |
| 2253 | |
| 2254 | if (doWait) { |
| 2255 | // XXX Need to wait for result. |
| 2256 | } |
| 2257 | } |
| 2258 | |
| 2259 | return null; |
| 2260 | } |
| 2261 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2262 | public int relayoutWindow(Session session, IWindow client, |
| 2263 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2264 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2265 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
| 2266 | Surface outSurface) { |
| 2267 | boolean displayed = false; |
| 2268 | boolean inTouchMode; |
| 2269 | Configuration newConfig = null; |
| 2270 | long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2271 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2272 | synchronized(mWindowMap) { |
| 2273 | WindowState win = windowForClientLocked(session, client); |
| 2274 | if (win == null) { |
| 2275 | return 0; |
| 2276 | } |
| 2277 | win.mRequestedWidth = requestedWidth; |
| 2278 | win.mRequestedHeight = requestedHeight; |
| 2279 | |
| 2280 | if (attrs != null) { |
| 2281 | mPolicy.adjustWindowParamsLw(attrs); |
| 2282 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2283 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2284 | int attrChanges = 0; |
| 2285 | int flagChanges = 0; |
| 2286 | if (attrs != null) { |
| 2287 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2288 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2289 | } |
| 2290 | |
| 2291 | if (localLOGV) Log.v( |
| 2292 | TAG, "Relayout given client " + client.asBinder() |
| 2293 | + " (" + win.mAttrs.getTitle() + ")"); |
| 2294 | |
| 2295 | |
| 2296 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2297 | win.mAlpha = attrs.alpha; |
| 2298 | } |
| 2299 | |
| 2300 | final boolean scaledWindow = |
| 2301 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2302 | |
| 2303 | if (scaledWindow) { |
| 2304 | // requested{Width|Height} Surface's physical size |
| 2305 | // attrs.{width|height} Size on screen |
| 2306 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2307 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2308 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2309 | (attrs.height / (float)requestedHeight) : 1.0f; |
| 2310 | } |
| 2311 | |
| 2312 | boolean imMayMove = (flagChanges&( |
| 2313 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2314 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2315 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2316 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2317 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2318 | || (!win.mRelayoutCalled); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2319 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2320 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2321 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
| 2322 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2323 | win.mRelayoutCalled = true; |
| 2324 | final int oldVisibility = win.mViewVisibility; |
| 2325 | win.mViewVisibility = viewVisibility; |
| 2326 | if (viewVisibility == View.VISIBLE && |
| 2327 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2328 | displayed = !win.isVisibleLw(); |
| 2329 | if (win.mExiting) { |
| 2330 | win.mExiting = false; |
| 2331 | win.mAnimation = null; |
| 2332 | } |
| 2333 | if (win.mDestroying) { |
| 2334 | win.mDestroying = false; |
| 2335 | mDestroySurface.remove(win); |
| 2336 | } |
| 2337 | if (oldVisibility == View.GONE) { |
| 2338 | win.mEnterAnimationPending = true; |
| 2339 | } |
| 2340 | if (displayed && win.mSurface != null && !win.mDrawPending |
| 2341 | && !win.mCommitDrawPending && !mDisplayFrozen) { |
| 2342 | applyEnterAnimationLocked(win); |
| 2343 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2344 | if (displayed && (win.mAttrs.flags |
| 2345 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2346 | win.mTurnOnScreen = true; |
| 2347 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2348 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2349 | // To change the format, we need to re-build the surface. |
| 2350 | win.destroySurfaceLocked(); |
| 2351 | displayed = true; |
| 2352 | } |
| 2353 | try { |
| 2354 | Surface surface = win.createSurfaceLocked(); |
| 2355 | if (surface != null) { |
| 2356 | outSurface.copyFrom(surface); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2357 | win.mReportDestroySurface = false; |
| 2358 | win.mSurfacePendingDestroy = false; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2359 | if (SHOW_TRANSACTIONS) Log.i(TAG, |
| 2360 | " OUT SURFACE " + outSurface + ": copied"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2361 | } else { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2362 | // For some reason there isn't a surface. Clear the |
| 2363 | // caller's object so they see the same state. |
| 2364 | outSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2365 | } |
| 2366 | } catch (Exception e) { |
| 2367 | Log.w(TAG, "Exception thrown when creating surface for client " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2368 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2369 | e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2370 | Binder.restoreCallingIdentity(origId); |
| 2371 | return 0; |
| 2372 | } |
| 2373 | if (displayed) { |
| 2374 | focusMayChange = true; |
| 2375 | } |
| 2376 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2377 | && mInputMethodWindow == null) { |
| 2378 | mInputMethodWindow = win; |
| 2379 | imMayMove = true; |
| 2380 | } |
| 2381 | } else { |
| 2382 | win.mEnterAnimationPending = false; |
| 2383 | if (win.mSurface != null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2384 | if (DEBUG_VISIBILITY) Log.i(TAG, "Relayout invis " + win |
| 2385 | + ": mExiting=" + win.mExiting |
| 2386 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2387 | // If we are not currently running the exit animation, we |
| 2388 | // need to see about starting one. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2389 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2390 | // Try starting an animation; if there isn't one, we |
| 2391 | // can destroy the surface right away. |
| 2392 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2393 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2394 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2395 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2396 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2397 | applyAnimationLocked(win, transit, false)) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2398 | focusMayChange = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2399 | win.mExiting = true; |
| 2400 | mKeyWaiter.finishedKey(session, client, true, |
| 2401 | KeyWaiter.RETURN_NOTHING); |
| 2402 | } else if (win.isAnimating()) { |
| 2403 | // Currently in a hide animation... turn this into |
| 2404 | // an exit. |
| 2405 | win.mExiting = true; |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2406 | } else if (win == mWallpaperTarget) { |
| 2407 | // If the wallpaper is currently behind this |
| 2408 | // window, we need to change both of them inside |
| 2409 | // of a transaction to avoid artifacts. |
| 2410 | win.mExiting = true; |
| 2411 | win.mAnimating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2412 | } else { |
| 2413 | if (mInputMethodWindow == win) { |
| 2414 | mInputMethodWindow = null; |
| 2415 | } |
| 2416 | win.destroySurfaceLocked(); |
| 2417 | } |
| 2418 | } |
| 2419 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2420 | |
| 2421 | if (win.mSurface == null || (win.getAttrs().flags |
| 2422 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2423 | || win.mSurfacePendingDestroy) { |
| 2424 | // We are being called from a local process, which |
| 2425 | // means outSurface holds its current surface. Ensure the |
| 2426 | // surface object is cleared, but we don't want it actually |
| 2427 | // destroyed at this point. |
| 2428 | win.mSurfacePendingDestroy = false; |
| 2429 | outSurface.release(); |
| 2430 | if (DEBUG_VISIBILITY) Log.i(TAG, "Releasing surface in: " + win); |
| 2431 | } else if (win.mSurface != null) { |
| 2432 | if (DEBUG_VISIBILITY) Log.i(TAG, |
| 2433 | "Keeping surface, will report destroy: " + win); |
| 2434 | win.mReportDestroySurface = true; |
| 2435 | outSurface.copyFrom(win.mSurface); |
| 2436 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2437 | } |
| 2438 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2439 | if (focusMayChange) { |
| 2440 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 2441 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2442 | imMayMove = false; |
| 2443 | } |
| 2444 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2445 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2446 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2447 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2448 | // reassign them at this point if the IM window state gets shuffled |
| 2449 | boolean assignLayers = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2451 | if (imMayMove) { |
Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2452 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2453 | // Little hack here -- we -should- be able to rely on the |
| 2454 | // function to return true if the IME has moved and needs |
| 2455 | // its layer recomputed. However, if the IME was hidden |
| 2456 | // and isn't actually moved in the list, its layer may be |
| 2457 | // out of data so we make sure to recompute it. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2458 | assignLayers = true; |
| 2459 | } |
| 2460 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2461 | if (wallpaperMayMove) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2462 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2463 | assignLayers = true; |
| 2464 | } |
| 2465 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2466 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2467 | mLayoutNeeded = true; |
| 2468 | win.mGivenInsetsPending = insetsPending; |
| 2469 | if (assignLayers) { |
| 2470 | assignLayersLocked(); |
| 2471 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2472 | newConfig = updateOrientationFromAppTokensLocked(null, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2473 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2474 | if (displayed && win.mIsWallpaper) { |
| 2475 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2476 | mDisplay.getHeight(), false); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2477 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2478 | if (win.mAppToken != null) { |
| 2479 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2480 | } |
| 2481 | outFrame.set(win.mFrame); |
| 2482 | outContentInsets.set(win.mContentInsets); |
| 2483 | outVisibleInsets.set(win.mVisibleInsets); |
| 2484 | if (localLOGV) Log.v( |
| 2485 | TAG, "Relayout given client " + client.asBinder() |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2486 | + ", requestedWidth=" + requestedWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2487 | + ", requestedHeight=" + requestedHeight |
| 2488 | + ", viewVisibility=" + viewVisibility |
| 2489 | + "\nRelayout returning frame=" + outFrame |
| 2490 | + ", surface=" + outSurface); |
| 2491 | |
| 2492 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 2493 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2494 | |
| 2495 | inTouchMode = mInTouchMode; |
| 2496 | } |
| 2497 | |
| 2498 | if (newConfig != null) { |
| 2499 | sendNewConfiguration(); |
| 2500 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2501 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2502 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2503 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2504 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2505 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2506 | } |
| 2507 | |
| 2508 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2509 | final long origId = Binder.clearCallingIdentity(); |
| 2510 | synchronized(mWindowMap) { |
| 2511 | WindowState win = windowForClientLocked(session, client); |
| 2512 | if (win != null && win.finishDrawingLocked()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2513 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2514 | adjustWallpaperWindowsLocked(); |
| 2515 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2516 | mLayoutNeeded = true; |
| 2517 | performLayoutAndPlaceSurfacesLocked(); |
| 2518 | } |
| 2519 | } |
| 2520 | Binder.restoreCallingIdentity(origId); |
| 2521 | } |
| 2522 | |
| 2523 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
| 2524 | if (DEBUG_ANIM) Log.v(TAG, "Loading animations: params package=" |
| 2525 | + (lp != null ? lp.packageName : null) |
| 2526 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2527 | if (lp != null && lp.windowAnimations != 0) { |
| 2528 | // If this is a system resource, don't try to load it from the |
| 2529 | // application resources. It is nice to avoid loading application |
| 2530 | // resources if we can. |
| 2531 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2532 | int resId = lp.windowAnimations; |
| 2533 | if ((resId&0xFF000000) == 0x01000000) { |
| 2534 | packageName = "android"; |
| 2535 | } |
| 2536 | if (DEBUG_ANIM) Log.v(TAG, "Loading animations: picked package=" |
| 2537 | + packageName); |
| 2538 | return AttributeCache.instance().get(packageName, resId, |
| 2539 | com.android.internal.R.styleable.WindowAnimation); |
| 2540 | } |
| 2541 | return null; |
| 2542 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2543 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2544 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
| 2545 | if (DEBUG_ANIM) Log.v(TAG, "Loading animations: params package=" |
| 2546 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 2547 | if (packageName != null) { |
| 2548 | if ((resId&0xFF000000) == 0x01000000) { |
| 2549 | packageName = "android"; |
| 2550 | } |
| 2551 | if (DEBUG_ANIM) Log.v(TAG, "Loading animations: picked package=" |
| 2552 | + packageName); |
| 2553 | return AttributeCache.instance().get(packageName, resId, |
| 2554 | com.android.internal.R.styleable.WindowAnimation); |
| 2555 | } |
| 2556 | return null; |
| 2557 | } |
| 2558 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2559 | private void applyEnterAnimationLocked(WindowState win) { |
| 2560 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 2561 | if (win.mEnterAnimationPending) { |
| 2562 | win.mEnterAnimationPending = false; |
| 2563 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 2564 | } |
| 2565 | |
| 2566 | applyAnimationLocked(win, transit, true); |
| 2567 | } |
| 2568 | |
| 2569 | private boolean applyAnimationLocked(WindowState win, |
| 2570 | int transit, boolean isEntrance) { |
| 2571 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 2572 | // If we are trying to apply an animation, but already running |
| 2573 | // an animation of the same type, then just leave that one alone. |
| 2574 | return true; |
| 2575 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2576 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2577 | // Only apply an animation if the display isn't frozen. If it is |
| 2578 | // frozen, there is no reason to animate and it can cause strange |
| 2579 | // artifacts when we unfreeze the display if some different animation |
| 2580 | // is running. |
| 2581 | if (!mDisplayFrozen) { |
| 2582 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 2583 | int attr = -1; |
| 2584 | Animation a = null; |
| 2585 | if (anim != 0) { |
| 2586 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 2587 | } else { |
| 2588 | switch (transit) { |
| 2589 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 2590 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 2591 | break; |
| 2592 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 2593 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 2594 | break; |
| 2595 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 2596 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 2597 | break; |
| 2598 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 2599 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 2600 | break; |
| 2601 | } |
| 2602 | if (attr >= 0) { |
| 2603 | a = loadAnimation(win.mAttrs, attr); |
| 2604 | } |
| 2605 | } |
| 2606 | if (DEBUG_ANIM) Log.v(TAG, "applyAnimation: win=" + win |
| 2607 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 2608 | + " mAnimation=" + win.mAnimation |
| 2609 | + " isEntrance=" + isEntrance); |
| 2610 | if (a != null) { |
| 2611 | if (DEBUG_ANIM) { |
| 2612 | RuntimeException e = new RuntimeException(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 2613 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2614 | Log.v(TAG, "Loaded animation " + a + " for " + win, e); |
| 2615 | } |
| 2616 | win.setAnimation(a); |
| 2617 | win.mAnimationIsEntrance = isEntrance; |
| 2618 | } |
| 2619 | } else { |
| 2620 | win.clearAnimation(); |
| 2621 | } |
| 2622 | |
| 2623 | return win.mAnimation != null; |
| 2624 | } |
| 2625 | |
| 2626 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 2627 | int anim = 0; |
| 2628 | Context context = mContext; |
| 2629 | if (animAttr >= 0) { |
| 2630 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 2631 | if (ent != null) { |
| 2632 | context = ent.context; |
| 2633 | anim = ent.array.getResourceId(animAttr, 0); |
| 2634 | } |
| 2635 | } |
| 2636 | if (anim != 0) { |
| 2637 | return AnimationUtils.loadAnimation(context, anim); |
| 2638 | } |
| 2639 | return null; |
| 2640 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2641 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2642 | private Animation loadAnimation(String packageName, int resId) { |
| 2643 | int anim = 0; |
| 2644 | Context context = mContext; |
| 2645 | if (resId >= 0) { |
| 2646 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 2647 | if (ent != null) { |
| 2648 | context = ent.context; |
| 2649 | anim = resId; |
| 2650 | } |
| 2651 | } |
| 2652 | if (anim != 0) { |
| 2653 | return AnimationUtils.loadAnimation(context, anim); |
| 2654 | } |
| 2655 | return null; |
| 2656 | } |
| 2657 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2658 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 2659 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 2660 | // Only apply an animation if the display isn't frozen. If it is |
| 2661 | // frozen, there is no reason to animate and it can cause strange |
| 2662 | // artifacts when we unfreeze the display if some different animation |
| 2663 | // is running. |
| 2664 | if (!mDisplayFrozen) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2665 | Animation a; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 2666 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2667 | a = new FadeInOutAnimation(enter); |
| 2668 | if (DEBUG_ANIM) Log.v(TAG, |
| 2669 | "applying FadeInOutAnimation for a window in compatibility mode"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2670 | } else if (mNextAppTransitionPackage != null) { |
| 2671 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 2672 | mNextAppTransitionEnter : mNextAppTransitionExit); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2673 | } else { |
| 2674 | int animAttr = 0; |
| 2675 | switch (transit) { |
| 2676 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 2677 | animAttr = enter |
| 2678 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 2679 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 2680 | break; |
| 2681 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 2682 | animAttr = enter |
| 2683 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 2684 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 2685 | break; |
| 2686 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 2687 | animAttr = enter |
| 2688 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 2689 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 2690 | break; |
| 2691 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 2692 | animAttr = enter |
| 2693 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 2694 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 2695 | break; |
| 2696 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 2697 | animAttr = enter |
| 2698 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 2699 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 2700 | break; |
| 2701 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 2702 | animAttr = enter |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 2703 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2704 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 2705 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2706 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2707 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2708 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 2709 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2710 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2711 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2712 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2713 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 2714 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 2715 | break; |
| 2716 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 2717 | animAttr = enter |
| 2718 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 2719 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 2720 | break; |
| 2721 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 2722 | animAttr = enter |
| 2723 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 2724 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2725 | break; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2726 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 2727 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2728 | if (DEBUG_ANIM) Log.v(TAG, "applyAnimation: wtoken=" + wtoken |
| 2729 | + " anim=" + a |
| 2730 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 2731 | + " transit=" + transit); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2732 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2733 | if (a != null) { |
| 2734 | if (DEBUG_ANIM) { |
| 2735 | RuntimeException e = new RuntimeException(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 2736 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2737 | Log.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
| 2738 | } |
| 2739 | wtoken.setAnimation(a); |
| 2740 | } |
| 2741 | } else { |
| 2742 | wtoken.clearAnimation(); |
| 2743 | } |
| 2744 | |
| 2745 | return wtoken.animation != null; |
| 2746 | } |
| 2747 | |
| 2748 | // ------------------------------------------------------------- |
| 2749 | // Application Window Tokens |
| 2750 | // ------------------------------------------------------------- |
| 2751 | |
| 2752 | public void validateAppTokens(List tokens) { |
| 2753 | int v = tokens.size()-1; |
| 2754 | int m = mAppTokens.size()-1; |
| 2755 | while (v >= 0 && m >= 0) { |
| 2756 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2757 | if (wtoken.removed) { |
| 2758 | m--; |
| 2759 | continue; |
| 2760 | } |
| 2761 | if (tokens.get(v) != wtoken.token) { |
| 2762 | Log.w(TAG, "Tokens out of sync: external is " + tokens.get(v) |
| 2763 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 2764 | } |
| 2765 | v--; |
| 2766 | m--; |
| 2767 | } |
| 2768 | while (v >= 0) { |
| 2769 | Log.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v); |
| 2770 | v--; |
| 2771 | } |
| 2772 | while (m >= 0) { |
| 2773 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2774 | if (!wtoken.removed) { |
| 2775 | Log.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
| 2776 | } |
| 2777 | m--; |
| 2778 | } |
| 2779 | } |
| 2780 | |
| 2781 | boolean checkCallingPermission(String permission, String func) { |
| 2782 | // Quick check: if the calling permission is me, it's all okay. |
| 2783 | if (Binder.getCallingPid() == Process.myPid()) { |
| 2784 | return true; |
| 2785 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2786 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2787 | if (mContext.checkCallingPermission(permission) |
| 2788 | == PackageManager.PERMISSION_GRANTED) { |
| 2789 | return true; |
| 2790 | } |
| 2791 | String msg = "Permission Denial: " + func + " from pid=" |
| 2792 | + Binder.getCallingPid() |
| 2793 | + ", uid=" + Binder.getCallingUid() |
| 2794 | + " requires " + permission; |
| 2795 | Log.w(TAG, msg); |
| 2796 | return false; |
| 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 | AppWindowToken findAppWindowToken(IBinder token) { |
| 2800 | WindowToken wtoken = mTokenMap.get(token); |
| 2801 | if (wtoken == null) { |
| 2802 | return null; |
| 2803 | } |
| 2804 | return wtoken.appWindowToken; |
| 2805 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2806 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2807 | public void addWindowToken(IBinder token, int type) { |
| 2808 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2809 | "addWindowToken()")) { |
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 | WindowToken wtoken = mTokenMap.get(token); |
| 2815 | if (wtoken != null) { |
| 2816 | Log.w(TAG, "Attempted to add existing input method token: " + token); |
| 2817 | return; |
| 2818 | } |
| 2819 | wtoken = new WindowToken(token, type, true); |
| 2820 | mTokenMap.put(token, wtoken); |
| 2821 | mTokenList.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2822 | if (type == TYPE_WALLPAPER) { |
| 2823 | mWallpaperTokens.add(wtoken); |
| 2824 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2825 | } |
| 2826 | } |
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 | public void removeWindowToken(IBinder token) { |
| 2829 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2830 | "removeWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2831 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2832 | } |
| 2833 | |
| 2834 | final long origId = Binder.clearCallingIdentity(); |
| 2835 | synchronized(mWindowMap) { |
| 2836 | WindowToken wtoken = mTokenMap.remove(token); |
| 2837 | mTokenList.remove(wtoken); |
| 2838 | if (wtoken != null) { |
| 2839 | boolean delayed = false; |
| 2840 | if (!wtoken.hidden) { |
| 2841 | wtoken.hidden = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2842 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2843 | final int N = wtoken.windows.size(); |
| 2844 | boolean changed = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2845 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2846 | for (int i=0; i<N; i++) { |
| 2847 | WindowState win = wtoken.windows.get(i); |
| 2848 | |
| 2849 | if (win.isAnimating()) { |
| 2850 | delayed = true; |
| 2851 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2852 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2853 | if (win.isVisibleNow()) { |
| 2854 | applyAnimationLocked(win, |
| 2855 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 2856 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 2857 | KeyWaiter.RETURN_NOTHING); |
| 2858 | changed = true; |
| 2859 | } |
| 2860 | } |
| 2861 | |
| 2862 | if (changed) { |
| 2863 | mLayoutNeeded = true; |
| 2864 | performLayoutAndPlaceSurfacesLocked(); |
| 2865 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2866 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2867 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2868 | if (delayed) { |
| 2869 | mExitingTokens.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2870 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 2871 | mWallpaperTokens.remove(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2872 | } |
| 2873 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2874 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2875 | } else { |
| 2876 | Log.w(TAG, "Attempted to remove non-existing token: " + token); |
| 2877 | } |
| 2878 | } |
| 2879 | Binder.restoreCallingIdentity(origId); |
| 2880 | } |
| 2881 | |
| 2882 | public void addAppToken(int addPos, IApplicationToken token, |
| 2883 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 2884 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2885 | "addAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2886 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2887 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2888 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2889 | synchronized(mWindowMap) { |
| 2890 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 2891 | if (wtoken != null) { |
| 2892 | Log.w(TAG, "Attempted to add existing app token: " + token); |
| 2893 | return; |
| 2894 | } |
| 2895 | wtoken = new AppWindowToken(token); |
| 2896 | wtoken.groupId = groupId; |
| 2897 | wtoken.appFullscreen = fullscreen; |
| 2898 | wtoken.requestedOrientation = requestedOrientation; |
| 2899 | mAppTokens.add(addPos, wtoken); |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 2900 | 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] | 2901 | mTokenMap.put(token.asBinder(), wtoken); |
| 2902 | mTokenList.add(wtoken); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2903 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2904 | // Application tokens start out hidden. |
| 2905 | wtoken.hidden = true; |
| 2906 | wtoken.hiddenRequested = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2907 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2908 | //dump(); |
| 2909 | } |
| 2910 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2911 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2912 | public void setAppGroupId(IBinder token, int groupId) { |
| 2913 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2914 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2915 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2916 | } |
| 2917 | |
| 2918 | synchronized(mWindowMap) { |
| 2919 | AppWindowToken wtoken = findAppWindowToken(token); |
| 2920 | if (wtoken == null) { |
| 2921 | Log.w(TAG, "Attempted to set group id of non-existing app token: " + token); |
| 2922 | return; |
| 2923 | } |
| 2924 | wtoken.groupId = groupId; |
| 2925 | } |
| 2926 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2927 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2928 | public int getOrientationFromWindowsLocked() { |
| 2929 | int pos = mWindows.size() - 1; |
| 2930 | while (pos >= 0) { |
| 2931 | WindowState wtoken = (WindowState) mWindows.get(pos); |
| 2932 | pos--; |
| 2933 | if (wtoken.mAppToken != null) { |
| 2934 | // We hit an application window. so the orientation will be determined by the |
| 2935 | // app window. No point in continuing further. |
| 2936 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2937 | } |
| 2938 | if (!wtoken.isVisibleLw()) { |
| 2939 | continue; |
| 2940 | } |
| 2941 | int req = wtoken.mAttrs.screenOrientation; |
| 2942 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 2943 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 2944 | continue; |
| 2945 | } else { |
| 2946 | return req; |
| 2947 | } |
| 2948 | } |
| 2949 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2950 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2951 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2952 | public int getOrientationFromAppTokensLocked() { |
| 2953 | int pos = mAppTokens.size() - 1; |
| 2954 | int curGroup = 0; |
| 2955 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2956 | boolean findingBehind = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2957 | boolean haveGroup = false; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2958 | boolean lastFullscreen = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2959 | while (pos >= 0) { |
| 2960 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 2961 | pos--; |
Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2962 | // if we're about to tear down this window and not seek for |
| 2963 | // the behind activity, don't use it for orientation |
| 2964 | if (!findingBehind |
| 2965 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2966 | continue; |
| 2967 | } |
| 2968 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2969 | if (!haveGroup) { |
| 2970 | // We ignore any hidden applications on the top. |
| 2971 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
| 2972 | continue; |
| 2973 | } |
| 2974 | haveGroup = true; |
| 2975 | curGroup = wtoken.groupId; |
| 2976 | lastOrientation = wtoken.requestedOrientation; |
| 2977 | } else if (curGroup != wtoken.groupId) { |
| 2978 | // If we have hit a new application group, and the bottom |
| 2979 | // 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] | 2980 | // the orientation behind it, and the last app was |
| 2981 | // full screen, then we'll stick with the |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2982 | // user's orientation. |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2983 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 2984 | && lastFullscreen) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2985 | return lastOrientation; |
| 2986 | } |
| 2987 | } |
| 2988 | int or = wtoken.requestedOrientation; |
Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2989 | // If this application is fullscreen, and didn't explicitly say |
| 2990 | // 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] | 2991 | // orientation it has and ignores whatever is under it. |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2992 | lastFullscreen = wtoken.appFullscreen; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2993 | if (lastFullscreen |
Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2994 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2995 | return or; |
| 2996 | } |
| 2997 | // If this application has requested an explicit orientation, |
| 2998 | // then use it. |
| 2999 | if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || |
| 3000 | or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || |
| 3001 | or == ActivityInfo.SCREEN_ORIENTATION_SENSOR || |
| 3002 | or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR || |
| 3003 | or == ActivityInfo.SCREEN_ORIENTATION_USER) { |
| 3004 | return or; |
| 3005 | } |
Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 3006 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3007 | } |
| 3008 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3009 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3010 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3011 | public Configuration updateOrientationFromAppTokens( |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3012 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3013 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3014 | "updateOrientationFromAppTokens()")) { |
| 3015 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3016 | } |
| 3017 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3018 | Configuration config; |
| 3019 | long ident = Binder.clearCallingIdentity(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3020 | config = updateOrientationFromAppTokensUnchecked(currentConfig, |
| 3021 | freezeThisOneIfNeeded); |
| 3022 | Binder.restoreCallingIdentity(ident); |
| 3023 | return config; |
| 3024 | } |
| 3025 | |
| 3026 | Configuration updateOrientationFromAppTokensUnchecked( |
| 3027 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| 3028 | Configuration config; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3029 | synchronized(mWindowMap) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3030 | config = updateOrientationFromAppTokensLocked(currentConfig, freezeThisOneIfNeeded); |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3031 | if (config != null) { |
| 3032 | mLayoutNeeded = true; |
| 3033 | performLayoutAndPlaceSurfacesLocked(); |
| 3034 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3035 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3036 | return config; |
| 3037 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3038 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3039 | /* |
| 3040 | * The orientation is computed from non-application windows first. If none of |
| 3041 | * the non-application windows specify orientation, the orientation is computed from |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3042 | * application tokens. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3043 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3044 | * android.os.IBinder) |
| 3045 | */ |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3046 | Configuration updateOrientationFromAppTokensLocked( |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3047 | Configuration appConfig, IBinder freezeThisOneIfNeeded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3048 | boolean changed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3049 | long ident = Binder.clearCallingIdentity(); |
| 3050 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3051 | int req = computeForcedAppOrientationLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3052 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3053 | if (req != mForcedAppOrientation) { |
| 3054 | changed = true; |
| 3055 | mForcedAppOrientation = req; |
| 3056 | //send a message to Policy indicating orientation change to take |
| 3057 | //action like disabling/enabling sensors etc., |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3058 | mPolicy.setCurrentOrientationLw(req); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3059 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3060 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3061 | if (changed) { |
| 3062 | changed = setRotationUncheckedLocked( |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 3063 | WindowManagerPolicy.USE_LAST_ROTATION, |
| 3064 | mLastRotationFlags & (~Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3065 | if (changed) { |
| 3066 | if (freezeThisOneIfNeeded != null) { |
| 3067 | AppWindowToken wtoken = findAppWindowToken( |
| 3068 | freezeThisOneIfNeeded); |
| 3069 | if (wtoken != null) { |
| 3070 | startAppFreezingScreenLocked(wtoken, |
| 3071 | ActivityInfo.CONFIG_ORIENTATION); |
| 3072 | } |
| 3073 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 3074 | return computeNewConfigurationLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3075 | } |
| 3076 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3077 | |
| 3078 | // No obvious action we need to take, but if our current |
| 3079 | // state mismatches the activity maanager's, update it |
| 3080 | if (appConfig != null) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 3081 | mTempConfiguration.setToDefaults(); |
| 3082 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3083 | if (appConfig.diff(mTempConfiguration) != 0) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 3084 | return new Configuration(mTempConfiguration); |
| 3085 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3086 | } |
| 3087 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3088 | } finally { |
| 3089 | Binder.restoreCallingIdentity(ident); |
| 3090 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3091 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3092 | return null; |
| 3093 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3094 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3095 | int computeForcedAppOrientationLocked() { |
| 3096 | int req = getOrientationFromWindowsLocked(); |
| 3097 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3098 | req = getOrientationFromAppTokensLocked(); |
| 3099 | } |
| 3100 | return req; |
| 3101 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3102 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3103 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3104 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3105 | "setAppOrientation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3106 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3107 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3108 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3109 | synchronized(mWindowMap) { |
| 3110 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3111 | if (wtoken == null) { |
| 3112 | Log.w(TAG, "Attempted to set orientation of non-existing app token: " + token); |
| 3113 | return; |
| 3114 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3115 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3116 | wtoken.requestedOrientation = requestedOrientation; |
| 3117 | } |
| 3118 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3119 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3120 | public int getAppOrientation(IApplicationToken token) { |
| 3121 | synchronized(mWindowMap) { |
| 3122 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3123 | if (wtoken == null) { |
| 3124 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3125 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3126 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3127 | return wtoken.requestedOrientation; |
| 3128 | } |
| 3129 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3130 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3131 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3132 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3133 | "setFocusedApp()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3134 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3135 | } |
| 3136 | |
| 3137 | synchronized(mWindowMap) { |
| 3138 | boolean changed = false; |
| 3139 | if (token == null) { |
| 3140 | if (DEBUG_FOCUS) Log.v(TAG, "Clearing focused app, was " + mFocusedApp); |
| 3141 | changed = mFocusedApp != null; |
| 3142 | mFocusedApp = null; |
| 3143 | mKeyWaiter.tickle(); |
| 3144 | } else { |
| 3145 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3146 | if (newFocus == null) { |
| 3147 | Log.w(TAG, "Attempted to set focus to non-existing app token: " + token); |
| 3148 | return; |
| 3149 | } |
| 3150 | changed = mFocusedApp != newFocus; |
| 3151 | mFocusedApp = newFocus; |
| 3152 | if (DEBUG_FOCUS) Log.v(TAG, "Set focused app to: " + mFocusedApp); |
| 3153 | mKeyWaiter.tickle(); |
| 3154 | } |
| 3155 | |
| 3156 | if (moveFocusNow && changed) { |
| 3157 | final long origId = Binder.clearCallingIdentity(); |
| 3158 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3159 | Binder.restoreCallingIdentity(origId); |
| 3160 | } |
| 3161 | } |
| 3162 | } |
| 3163 | |
| 3164 | public void prepareAppTransition(int transit) { |
| 3165 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3166 | "prepareAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3167 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3168 | } |
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 | synchronized(mWindowMap) { |
| 3171 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 3172 | TAG, "Prepare app transition: transit=" + transit |
| 3173 | + " mNextAppTransition=" + mNextAppTransition); |
| 3174 | if (!mDisplayFrozen) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3175 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3176 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3177 | mNextAppTransition = transit; |
Dianne Hackborn | d7cd29d | 2009-07-01 11:22:45 -0700 | [diff] [blame] | 3178 | } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3179 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3180 | // Opening a new task always supersedes a close for the anim. |
| 3181 | mNextAppTransition = transit; |
| 3182 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3183 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3184 | // Opening a new activity always supersedes a close for the anim. |
| 3185 | mNextAppTransition = transit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3186 | } |
| 3187 | mAppTransitionReady = false; |
| 3188 | mAppTransitionTimeout = false; |
| 3189 | mStartingIconInTransition = false; |
| 3190 | mSkipAppTransitionAnimation = false; |
| 3191 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3192 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3193 | 5000); |
| 3194 | } |
| 3195 | } |
| 3196 | } |
| 3197 | |
| 3198 | public int getPendingAppTransition() { |
| 3199 | return mNextAppTransition; |
| 3200 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3201 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3202 | public void overridePendingAppTransition(String packageName, |
| 3203 | int enterAnim, int exitAnim) { |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3204 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3205 | mNextAppTransitionPackage = packageName; |
| 3206 | mNextAppTransitionEnter = enterAnim; |
| 3207 | mNextAppTransitionExit = exitAnim; |
| 3208 | } |
| 3209 | } |
| 3210 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3211 | public void executeAppTransition() { |
| 3212 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3213 | "executeAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3214 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3215 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3216 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3217 | synchronized(mWindowMap) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3218 | if (DEBUG_APP_TRANSITIONS) { |
| 3219 | RuntimeException e = new RuntimeException("here"); |
| 3220 | e.fillInStackTrace(); |
| 3221 | Log.w(TAG, "Execute app transition: mNextAppTransition=" |
| 3222 | + mNextAppTransition, e); |
| 3223 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3224 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3225 | mAppTransitionReady = true; |
| 3226 | final long origId = Binder.clearCallingIdentity(); |
| 3227 | performLayoutAndPlaceSurfacesLocked(); |
| 3228 | Binder.restoreCallingIdentity(origId); |
| 3229 | } |
| 3230 | } |
| 3231 | } |
| 3232 | |
| 3233 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3234 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| 3235 | IBinder transferFrom, boolean createIfNeeded) { |
| 3236 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3237 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3238 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3239 | } |
| 3240 | |
| 3241 | synchronized(mWindowMap) { |
| 3242 | if (DEBUG_STARTING_WINDOW) Log.v( |
| 3243 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3244 | + " transferFrom=" + transferFrom); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3245 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3246 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3247 | if (wtoken == null) { |
| 3248 | Log.w(TAG, "Attempted to set icon of non-existing app token: " + token); |
| 3249 | return; |
| 3250 | } |
| 3251 | |
| 3252 | // If the display is frozen, we won't do anything until the |
| 3253 | // actual window is displayed so there is no reason to put in |
| 3254 | // the starting window. |
| 3255 | if (mDisplayFrozen) { |
| 3256 | return; |
| 3257 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3258 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3259 | if (wtoken.startingData != null) { |
| 3260 | return; |
| 3261 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3262 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3263 | if (transferFrom != null) { |
| 3264 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3265 | if (ttoken != null) { |
| 3266 | WindowState startingWindow = ttoken.startingWindow; |
| 3267 | if (startingWindow != null) { |
| 3268 | if (mStartingIconInTransition) { |
| 3269 | // In this case, the starting icon has already |
| 3270 | // been displayed, so start letting windows get |
| 3271 | // shown immediately without any more transitions. |
| 3272 | mSkipAppTransitionAnimation = true; |
| 3273 | } |
| 3274 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 3275 | "Moving existing starting from " + ttoken |
| 3276 | + " to " + wtoken); |
| 3277 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3278 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3279 | // Transfer the starting window over to the new |
| 3280 | // token. |
| 3281 | wtoken.startingData = ttoken.startingData; |
| 3282 | wtoken.startingView = ttoken.startingView; |
| 3283 | wtoken.startingWindow = startingWindow; |
| 3284 | ttoken.startingData = null; |
| 3285 | ttoken.startingView = null; |
| 3286 | ttoken.startingWindow = null; |
| 3287 | ttoken.startingMoved = true; |
| 3288 | startingWindow.mToken = wtoken; |
Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3289 | startingWindow.mRootToken = wtoken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3290 | startingWindow.mAppToken = wtoken; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3291 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, |
| 3292 | "Removing starting window: " + startingWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3293 | mWindows.remove(startingWindow); |
| 3294 | ttoken.windows.remove(startingWindow); |
| 3295 | ttoken.allAppWindows.remove(startingWindow); |
| 3296 | addWindowToListInOrderLocked(startingWindow, true); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3297 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3298 | // Propagate other interesting state between the |
| 3299 | // tokens. If the old token is displayed, we should |
| 3300 | // immediately force the new one to be displayed. If |
| 3301 | // it is animating, we need to move that animation to |
| 3302 | // the new one. |
| 3303 | if (ttoken.allDrawn) { |
| 3304 | wtoken.allDrawn = true; |
| 3305 | } |
| 3306 | if (ttoken.firstWindowDrawn) { |
| 3307 | wtoken.firstWindowDrawn = true; |
| 3308 | } |
| 3309 | if (!ttoken.hidden) { |
| 3310 | wtoken.hidden = false; |
| 3311 | wtoken.hiddenRequested = false; |
| 3312 | wtoken.willBeHidden = false; |
| 3313 | } |
| 3314 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3315 | wtoken.clientHidden = ttoken.clientHidden; |
| 3316 | wtoken.sendAppVisibilityToClients(); |
| 3317 | } |
| 3318 | if (ttoken.animation != null) { |
| 3319 | wtoken.animation = ttoken.animation; |
| 3320 | wtoken.animating = ttoken.animating; |
| 3321 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3322 | ttoken.animation = null; |
| 3323 | ttoken.animLayerAdjustment = 0; |
| 3324 | wtoken.updateLayers(); |
| 3325 | ttoken.updateLayers(); |
| 3326 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3327 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3328 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3329 | mLayoutNeeded = true; |
| 3330 | performLayoutAndPlaceSurfacesLocked(); |
| 3331 | Binder.restoreCallingIdentity(origId); |
| 3332 | return; |
| 3333 | } else if (ttoken.startingData != null) { |
| 3334 | // The previous app was getting ready to show a |
| 3335 | // starting window, but hasn't yet done so. Steal it! |
| 3336 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 3337 | "Moving pending starting from " + ttoken |
| 3338 | + " to " + wtoken); |
| 3339 | wtoken.startingData = ttoken.startingData; |
| 3340 | ttoken.startingData = null; |
| 3341 | ttoken.startingMoved = true; |
| 3342 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3343 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3344 | // want to process the message ASAP, before any other queued |
| 3345 | // messages. |
| 3346 | mH.sendMessageAtFrontOfQueue(m); |
| 3347 | return; |
| 3348 | } |
| 3349 | } |
| 3350 | } |
| 3351 | |
| 3352 | // There is no existing starting window, and the caller doesn't |
| 3353 | // want us to create one, so that's it! |
| 3354 | if (!createIfNeeded) { |
| 3355 | return; |
| 3356 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3357 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3358 | // If this is a translucent or wallpaper window, then don't |
| 3359 | // show a starting window -- the current effect (a full-screen |
| 3360 | // opaque starting window that fades away to the real contents |
| 3361 | // when it is ready) does not work for this. |
| 3362 | if (theme != 0) { |
| 3363 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3364 | com.android.internal.R.styleable.Window); |
| 3365 | if (ent.array.getBoolean( |
| 3366 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3367 | return; |
| 3368 | } |
| 3369 | if (ent.array.getBoolean( |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3370 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3371 | return; |
| 3372 | } |
| 3373 | if (ent.array.getBoolean( |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3374 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3375 | return; |
| 3376 | } |
| 3377 | } |
| 3378 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3379 | mStartingIconInTransition = true; |
| 3380 | wtoken.startingData = new StartingData( |
| 3381 | pkg, theme, nonLocalizedLabel, |
| 3382 | labelRes, icon); |
| 3383 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3384 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3385 | // want to process the message ASAP, before any other queued |
| 3386 | // messages. |
| 3387 | mH.sendMessageAtFrontOfQueue(m); |
| 3388 | } |
| 3389 | } |
| 3390 | |
| 3391 | public void setAppWillBeHidden(IBinder token) { |
| 3392 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3393 | "setAppWillBeHidden()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3394 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3395 | } |
| 3396 | |
| 3397 | AppWindowToken wtoken; |
| 3398 | |
| 3399 | synchronized(mWindowMap) { |
| 3400 | wtoken = findAppWindowToken(token); |
| 3401 | if (wtoken == null) { |
| 3402 | Log.w(TAG, "Attempted to set will be hidden of non-existing app token: " + token); |
| 3403 | return; |
| 3404 | } |
| 3405 | wtoken.willBeHidden = true; |
| 3406 | } |
| 3407 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3408 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3409 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3410 | boolean visible, int transit, boolean performLayout) { |
| 3411 | boolean delayed = false; |
| 3412 | |
| 3413 | if (wtoken.clientHidden == visible) { |
| 3414 | wtoken.clientHidden = !visible; |
| 3415 | wtoken.sendAppVisibilityToClients(); |
| 3416 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3417 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3418 | wtoken.willBeHidden = false; |
| 3419 | if (wtoken.hidden == visible) { |
| 3420 | final int N = wtoken.allAppWindows.size(); |
| 3421 | boolean changed = false; |
| 3422 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 3423 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3424 | + " performLayout=" + performLayout); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3425 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3426 | boolean runningAppAnimation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3427 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3428 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3429 | if (wtoken.animation == sDummyAnimation) { |
| 3430 | wtoken.animation = null; |
| 3431 | } |
| 3432 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3433 | changed = true; |
| 3434 | if (wtoken.animation != null) { |
| 3435 | delayed = runningAppAnimation = true; |
| 3436 | } |
| 3437 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3438 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3439 | for (int i=0; i<N; i++) { |
| 3440 | WindowState win = wtoken.allAppWindows.get(i); |
| 3441 | if (win == wtoken.startingWindow) { |
| 3442 | continue; |
| 3443 | } |
| 3444 | |
| 3445 | if (win.isAnimating()) { |
| 3446 | delayed = true; |
| 3447 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3448 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3449 | //Log.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
| 3450 | //win.dump(" "); |
| 3451 | if (visible) { |
| 3452 | if (!win.isVisibleNow()) { |
| 3453 | if (!runningAppAnimation) { |
| 3454 | applyAnimationLocked(win, |
| 3455 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3456 | } |
| 3457 | changed = true; |
| 3458 | } |
| 3459 | } else if (win.isVisibleNow()) { |
| 3460 | if (!runningAppAnimation) { |
| 3461 | applyAnimationLocked(win, |
| 3462 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3463 | } |
| 3464 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 3465 | KeyWaiter.RETURN_NOTHING); |
| 3466 | changed = true; |
| 3467 | } |
| 3468 | } |
| 3469 | |
| 3470 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3471 | if (!visible) { |
| 3472 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3473 | } else { |
| 3474 | // If we are being set visible, and the starting window is |
| 3475 | // not yet displayed, then make sure it doesn't get displayed. |
| 3476 | WindowState swin = wtoken.startingWindow; |
| 3477 | if (swin != null && (swin.mDrawPending |
| 3478 | || swin.mCommitDrawPending)) { |
| 3479 | swin.mPolicyVisibility = false; |
| 3480 | swin.mPolicyVisibilityAfterAnim = false; |
| 3481 | } |
| 3482 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3483 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3484 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "setTokenVisibilityLocked: " + wtoken |
| 3485 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3486 | + wtoken.hiddenRequested); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3487 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3488 | if (changed && performLayout) { |
| 3489 | mLayoutNeeded = true; |
| 3490 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3491 | performLayoutAndPlaceSurfacesLocked(); |
| 3492 | } |
| 3493 | } |
| 3494 | |
| 3495 | if (wtoken.animation != null) { |
| 3496 | delayed = true; |
| 3497 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3498 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3499 | return delayed; |
| 3500 | } |
| 3501 | |
| 3502 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3503 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3504 | "setAppVisibility()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3505 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3506 | } |
| 3507 | |
| 3508 | AppWindowToken wtoken; |
| 3509 | |
| 3510 | synchronized(mWindowMap) { |
| 3511 | wtoken = findAppWindowToken(token); |
| 3512 | if (wtoken == null) { |
| 3513 | Log.w(TAG, "Attempted to set visibility of non-existing app token: " + token); |
| 3514 | return; |
| 3515 | } |
| 3516 | |
| 3517 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
| 3518 | RuntimeException e = new RuntimeException(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3519 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3520 | Log.v(TAG, "setAppVisibility(" + token + ", " + visible |
| 3521 | + "): mNextAppTransition=" + mNextAppTransition |
| 3522 | + " hidden=" + wtoken.hidden |
| 3523 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3524 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3525 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3526 | // If we are preparing an app transition, then delay changing |
| 3527 | // the visibility of this token until we execute that transition. |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3528 | if (!mDisplayFrozen && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3529 | // Already in requested state, don't do anything more. |
| 3530 | if (wtoken.hiddenRequested != visible) { |
| 3531 | return; |
| 3532 | } |
| 3533 | wtoken.hiddenRequested = !visible; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3534 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3535 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 3536 | TAG, "Setting dummy animation on: " + wtoken); |
| 3537 | wtoken.setDummyAnimation(); |
| 3538 | mOpeningApps.remove(wtoken); |
| 3539 | mClosingApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3540 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3541 | wtoken.inPendingTransaction = true; |
| 3542 | if (visible) { |
| 3543 | mOpeningApps.add(wtoken); |
| 3544 | wtoken.allDrawn = false; |
| 3545 | wtoken.startingDisplayed = false; |
| 3546 | wtoken.startingMoved = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3547 | wtoken.waitingToShow = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3548 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3549 | if (wtoken.clientHidden) { |
| 3550 | // In the case where we are making an app visible |
| 3551 | // but holding off for a transition, we still need |
| 3552 | // to tell the client to make its windows visible so |
| 3553 | // they get drawn. Otherwise, we will wait on |
| 3554 | // performing the transition until all windows have |
| 3555 | // been drawn, they never will be, and we are sad. |
| 3556 | wtoken.clientHidden = false; |
| 3557 | wtoken.sendAppVisibilityToClients(); |
| 3558 | } |
| 3559 | } else { |
| 3560 | mClosingApps.add(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3561 | wtoken.waitingToHide = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3562 | } |
| 3563 | return; |
| 3564 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3565 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3566 | final long origId = Binder.clearCallingIdentity(); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3567 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3568 | wtoken.updateReportedVisibilityLocked(); |
| 3569 | Binder.restoreCallingIdentity(origId); |
| 3570 | } |
| 3571 | } |
| 3572 | |
| 3573 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3574 | boolean unfreezeSurfaceNow, boolean force) { |
| 3575 | if (wtoken.freezingScreen) { |
| 3576 | if (DEBUG_ORIENTATION) Log.v(TAG, "Clear freezing of " + wtoken |
| 3577 | + " force=" + force); |
| 3578 | final int N = wtoken.allAppWindows.size(); |
| 3579 | boolean unfrozeWindows = false; |
| 3580 | for (int i=0; i<N; i++) { |
| 3581 | WindowState w = wtoken.allAppWindows.get(i); |
| 3582 | if (w.mAppFreezing) { |
| 3583 | w.mAppFreezing = false; |
| 3584 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 3585 | w.mOrientationChanging = true; |
| 3586 | } |
| 3587 | unfrozeWindows = true; |
| 3588 | } |
| 3589 | } |
| 3590 | if (force || unfrozeWindows) { |
| 3591 | if (DEBUG_ORIENTATION) Log.v(TAG, "No longer freezing: " + wtoken); |
| 3592 | wtoken.freezingScreen = false; |
| 3593 | mAppsFreezingScreen--; |
| 3594 | } |
| 3595 | if (unfreezeSurfaceNow) { |
| 3596 | if (unfrozeWindows) { |
| 3597 | mLayoutNeeded = true; |
| 3598 | performLayoutAndPlaceSurfacesLocked(); |
| 3599 | } |
| 3600 | if (mAppsFreezingScreen == 0 && !mWindowsFreezingScreen) { |
| 3601 | stopFreezingDisplayLocked(); |
| 3602 | } |
| 3603 | } |
| 3604 | } |
| 3605 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3606 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3607 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3608 | int configChanges) { |
| 3609 | if (DEBUG_ORIENTATION) { |
| 3610 | RuntimeException e = new RuntimeException(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3611 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3612 | Log.i(TAG, "Set freezing of " + wtoken.appToken |
| 3613 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 3614 | + wtoken.freezingScreen, e); |
| 3615 | } |
| 3616 | if (!wtoken.hiddenRequested) { |
| 3617 | if (!wtoken.freezingScreen) { |
| 3618 | wtoken.freezingScreen = true; |
| 3619 | mAppsFreezingScreen++; |
| 3620 | if (mAppsFreezingScreen == 1) { |
| 3621 | startFreezingDisplayLocked(); |
| 3622 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 3623 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 3624 | 5000); |
| 3625 | } |
| 3626 | } |
| 3627 | final int N = wtoken.allAppWindows.size(); |
| 3628 | for (int i=0; i<N; i++) { |
| 3629 | WindowState w = wtoken.allAppWindows.get(i); |
| 3630 | w.mAppFreezing = true; |
| 3631 | } |
| 3632 | } |
| 3633 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3634 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3635 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 3636 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3637 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3638 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3639 | } |
| 3640 | |
| 3641 | synchronized(mWindowMap) { |
| 3642 | if (configChanges == 0 && !mDisplayFrozen) { |
| 3643 | if (DEBUG_ORIENTATION) Log.v(TAG, "Skipping set freeze of " + token); |
| 3644 | return; |
| 3645 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3646 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3647 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3648 | if (wtoken == null || wtoken.appToken == null) { |
| 3649 | Log.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken); |
| 3650 | return; |
| 3651 | } |
| 3652 | final long origId = Binder.clearCallingIdentity(); |
| 3653 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 3654 | Binder.restoreCallingIdentity(origId); |
| 3655 | } |
| 3656 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3657 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3658 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 3659 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3660 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3661 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3662 | } |
| 3663 | |
| 3664 | synchronized(mWindowMap) { |
| 3665 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3666 | if (wtoken == null || wtoken.appToken == null) { |
| 3667 | return; |
| 3668 | } |
| 3669 | final long origId = Binder.clearCallingIdentity(); |
| 3670 | if (DEBUG_ORIENTATION) Log.v(TAG, "Clear freezing of " + token |
| 3671 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 3672 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 3673 | Binder.restoreCallingIdentity(origId); |
| 3674 | } |
| 3675 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3676 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3677 | public void removeAppToken(IBinder token) { |
| 3678 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3679 | "removeAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3680 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3681 | } |
| 3682 | |
| 3683 | AppWindowToken wtoken = null; |
| 3684 | AppWindowToken startingToken = null; |
| 3685 | boolean delayed = false; |
| 3686 | |
| 3687 | final long origId = Binder.clearCallingIdentity(); |
| 3688 | synchronized(mWindowMap) { |
| 3689 | WindowToken basewtoken = mTokenMap.remove(token); |
| 3690 | mTokenList.remove(basewtoken); |
| 3691 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
| 3692 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "Removing app token: " + wtoken); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3693 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3694 | wtoken.inPendingTransaction = false; |
| 3695 | mOpeningApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3696 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3697 | if (mClosingApps.contains(wtoken)) { |
| 3698 | delayed = true; |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3699 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3700 | mClosingApps.add(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3701 | wtoken.waitingToHide = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3702 | delayed = true; |
| 3703 | } |
| 3704 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 3705 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 3706 | + " animation=" + wtoken.animation |
| 3707 | + " animating=" + wtoken.animating); |
| 3708 | if (delayed) { |
| 3709 | // set the token aside because it has an active animation to be finished |
| 3710 | mExitingAppTokens.add(wtoken); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3711 | } else { |
| 3712 | // Make sure there is no animation running on this token, |
| 3713 | // so any windows associated with it will be removed as |
| 3714 | // soon as their animations are complete |
| 3715 | wtoken.animation = null; |
| 3716 | wtoken.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3717 | } |
| 3718 | mAppTokens.remove(wtoken); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3719 | if (mLastEnterAnimToken == wtoken) { |
| 3720 | mLastEnterAnimToken = null; |
| 3721 | mLastEnterAnimParams = null; |
| 3722 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3723 | wtoken.removed = true; |
| 3724 | if (wtoken.startingData != null) { |
| 3725 | startingToken = wtoken; |
| 3726 | } |
| 3727 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3728 | if (mFocusedApp == wtoken) { |
| 3729 | if (DEBUG_FOCUS) Log.v(TAG, "Removing focused app token:" + wtoken); |
| 3730 | mFocusedApp = null; |
| 3731 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3732 | mKeyWaiter.tickle(); |
| 3733 | } |
| 3734 | } else { |
| 3735 | Log.w(TAG, "Attempted to remove non-existing app token: " + token); |
| 3736 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3737 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3738 | if (!delayed && wtoken != null) { |
| 3739 | wtoken.updateReportedVisibilityLocked(); |
| 3740 | } |
| 3741 | } |
| 3742 | Binder.restoreCallingIdentity(origId); |
| 3743 | |
| 3744 | if (startingToken != null) { |
| 3745 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Schedule remove starting " |
| 3746 | + startingToken + ": app token removed"); |
| 3747 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 3748 | mH.sendMessage(m); |
| 3749 | } |
| 3750 | } |
| 3751 | |
| 3752 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 3753 | final int NW = token.windows.size(); |
| 3754 | for (int i=0; i<NW; i++) { |
| 3755 | WindowState win = token.windows.get(i); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3756 | 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] | 3757 | mWindows.remove(win); |
| 3758 | int j = win.mChildWindows.size(); |
| 3759 | while (j > 0) { |
| 3760 | j--; |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3761 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| 3762 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, |
| 3763 | "Tmp removing child window " + cwin); |
| 3764 | mWindows.remove(cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3765 | } |
| 3766 | } |
| 3767 | return NW > 0; |
| 3768 | } |
| 3769 | |
| 3770 | void dumpAppTokensLocked() { |
| 3771 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| 3772 | Log.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
| 3773 | } |
| 3774 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3775 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3776 | void dumpWindowsLocked() { |
| 3777 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 3778 | Log.v(TAG, " #" + i + ": " + mWindows.get(i)); |
| 3779 | } |
| 3780 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3781 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3782 | private int findWindowOffsetLocked(int tokenPos) { |
| 3783 | final int NW = mWindows.size(); |
| 3784 | |
| 3785 | if (tokenPos >= mAppTokens.size()) { |
| 3786 | int i = NW; |
| 3787 | while (i > 0) { |
| 3788 | i--; |
| 3789 | WindowState win = (WindowState)mWindows.get(i); |
| 3790 | if (win.getAppToken() != null) { |
| 3791 | return i+1; |
| 3792 | } |
| 3793 | } |
| 3794 | } |
| 3795 | |
| 3796 | while (tokenPos > 0) { |
| 3797 | // Find the first app token below the new position that has |
| 3798 | // a window displayed. |
| 3799 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
| 3800 | if (DEBUG_REORDER) Log.v(TAG, "Looking for lower windows @ " |
| 3801 | + tokenPos + " -- " + wtoken.token); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3802 | if (wtoken.sendingToBottom) { |
| 3803 | if (DEBUG_REORDER) Log.v(TAG, |
| 3804 | "Skipping token -- currently sending to bottom"); |
| 3805 | tokenPos--; |
| 3806 | continue; |
| 3807 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3808 | int i = wtoken.windows.size(); |
| 3809 | while (i > 0) { |
| 3810 | i--; |
| 3811 | WindowState win = wtoken.windows.get(i); |
| 3812 | int j = win.mChildWindows.size(); |
| 3813 | while (j > 0) { |
| 3814 | j--; |
| 3815 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3816 | if (cwin.mSubLayer >= 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3817 | for (int pos=NW-1; pos>=0; pos--) { |
| 3818 | if (mWindows.get(pos) == cwin) { |
| 3819 | if (DEBUG_REORDER) Log.v(TAG, |
| 3820 | "Found child win @" + (pos+1)); |
| 3821 | return pos+1; |
| 3822 | } |
| 3823 | } |
| 3824 | } |
| 3825 | } |
| 3826 | for (int pos=NW-1; pos>=0; pos--) { |
| 3827 | if (mWindows.get(pos) == win) { |
| 3828 | if (DEBUG_REORDER) Log.v(TAG, "Found win @" + (pos+1)); |
| 3829 | return pos+1; |
| 3830 | } |
| 3831 | } |
| 3832 | } |
| 3833 | tokenPos--; |
| 3834 | } |
| 3835 | |
| 3836 | return 0; |
| 3837 | } |
| 3838 | |
| 3839 | private final int reAddWindowLocked(int index, WindowState win) { |
| 3840 | final int NCW = win.mChildWindows.size(); |
| 3841 | boolean added = false; |
| 3842 | for (int j=0; j<NCW; j++) { |
| 3843 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| 3844 | if (!added && cwin.mSubLayer >= 0) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3845 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Re-adding child window at " |
| 3846 | + index + ": " + cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3847 | mWindows.add(index, win); |
| 3848 | index++; |
| 3849 | added = true; |
| 3850 | } |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3851 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Re-adding window at " |
| 3852 | + index + ": " + cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3853 | mWindows.add(index, cwin); |
| 3854 | index++; |
| 3855 | } |
| 3856 | if (!added) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3857 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Re-adding window at " |
| 3858 | + index + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3859 | mWindows.add(index, win); |
| 3860 | index++; |
| 3861 | } |
| 3862 | return index; |
| 3863 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3864 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3865 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 3866 | final int NW = token.windows.size(); |
| 3867 | for (int i=0; i<NW; i++) { |
| 3868 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 3869 | } |
| 3870 | return index; |
| 3871 | } |
| 3872 | |
| 3873 | public void moveAppToken(int index, IBinder token) { |
| 3874 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3875 | "moveAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3876 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3877 | } |
| 3878 | |
| 3879 | synchronized(mWindowMap) { |
| 3880 | if (DEBUG_REORDER) Log.v(TAG, "Initial app tokens:"); |
| 3881 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 3882 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 3883 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
| 3884 | Log.w(TAG, "Attempting to reorder token that doesn't exist: " |
| 3885 | + token + " (" + wtoken + ")"); |
| 3886 | return; |
| 3887 | } |
| 3888 | mAppTokens.add(index, wtoken); |
| 3889 | if (DEBUG_REORDER) Log.v(TAG, "Moved " + token + " to " + index + ":"); |
| 3890 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3891 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3892 | final long origId = Binder.clearCallingIdentity(); |
| 3893 | if (DEBUG_REORDER) Log.v(TAG, "Removing windows in " + token + ":"); |
| 3894 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3895 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
| 3896 | if (DEBUG_REORDER) Log.v(TAG, "Adding windows back in:"); |
| 3897 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3898 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
| 3899 | if (DEBUG_REORDER) Log.v(TAG, "Final window list:"); |
| 3900 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3901 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3902 | mLayoutNeeded = true; |
| 3903 | performLayoutAndPlaceSurfacesLocked(); |
| 3904 | } |
| 3905 | Binder.restoreCallingIdentity(origId); |
| 3906 | } |
| 3907 | } |
| 3908 | |
| 3909 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 3910 | // XXX This should be done more efficiently! |
| 3911 | // (take advantage of the fact that both lists should be |
| 3912 | // ordered in the same way.) |
| 3913 | int N = tokens.size(); |
| 3914 | for (int i=0; i<N; i++) { |
| 3915 | IBinder token = tokens.get(i); |
| 3916 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 3917 | if (!mAppTokens.remove(wtoken)) { |
| 3918 | Log.w(TAG, "Attempting to reorder token that doesn't exist: " |
| 3919 | + token + " (" + wtoken + ")"); |
| 3920 | i--; |
| 3921 | N--; |
| 3922 | } |
| 3923 | } |
| 3924 | } |
| 3925 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3926 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 3927 | boolean updateFocusAndLayout) { |
| 3928 | // First remove all of the windows from the list. |
| 3929 | tmpRemoveAppWindowsLocked(wtoken); |
| 3930 | |
| 3931 | // Where to start adding? |
| 3932 | int pos = findWindowOffsetLocked(tokenPos); |
| 3933 | |
| 3934 | // And now add them back at the correct place. |
| 3935 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 3936 | |
| 3937 | if (updateFocusAndLayout) { |
| 3938 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 3939 | assignLayersLocked(); |
| 3940 | } |
| 3941 | mLayoutNeeded = true; |
| 3942 | performLayoutAndPlaceSurfacesLocked(); |
| 3943 | } |
| 3944 | } |
| 3945 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3946 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 3947 | // First remove all of the windows from the list. |
| 3948 | final int N = tokens.size(); |
| 3949 | int i; |
| 3950 | for (i=0; i<N; i++) { |
| 3951 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 3952 | if (token != null) { |
| 3953 | tmpRemoveAppWindowsLocked(token); |
| 3954 | } |
| 3955 | } |
| 3956 | |
| 3957 | // Where to start adding? |
| 3958 | int pos = findWindowOffsetLocked(tokenPos); |
| 3959 | |
| 3960 | // And now add them back at the correct place. |
| 3961 | for (i=0; i<N; i++) { |
| 3962 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 3963 | if (token != null) { |
| 3964 | pos = reAddAppWindowsLocked(pos, token); |
| 3965 | } |
| 3966 | } |
| 3967 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3968 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 3969 | assignLayersLocked(); |
| 3970 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3971 | mLayoutNeeded = true; |
| 3972 | performLayoutAndPlaceSurfacesLocked(); |
| 3973 | |
| 3974 | //dump(); |
| 3975 | } |
| 3976 | |
| 3977 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 3978 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3979 | "moveAppTokensToTop()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3980 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3981 | } |
| 3982 | |
| 3983 | final long origId = Binder.clearCallingIdentity(); |
| 3984 | synchronized(mWindowMap) { |
| 3985 | removeAppTokensLocked(tokens); |
| 3986 | final int N = tokens.size(); |
| 3987 | for (int i=0; i<N; i++) { |
| 3988 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 3989 | if (wt != null) { |
| 3990 | mAppTokens.add(wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3991 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3992 | mToTopApps.remove(wt); |
| 3993 | mToBottomApps.remove(wt); |
| 3994 | mToTopApps.add(wt); |
| 3995 | wt.sendingToBottom = false; |
| 3996 | wt.sendingToTop = true; |
| 3997 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3998 | } |
| 3999 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4000 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4001 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4002 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4003 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4004 | } |
| 4005 | Binder.restoreCallingIdentity(origId); |
| 4006 | } |
| 4007 | |
| 4008 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4009 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4010 | "moveAppTokensToBottom()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4011 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4012 | } |
| 4013 | |
| 4014 | final long origId = Binder.clearCallingIdentity(); |
| 4015 | synchronized(mWindowMap) { |
| 4016 | removeAppTokensLocked(tokens); |
| 4017 | final int N = tokens.size(); |
| 4018 | int pos = 0; |
| 4019 | for (int i=0; i<N; i++) { |
| 4020 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4021 | if (wt != null) { |
| 4022 | mAppTokens.add(pos, wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4023 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4024 | mToTopApps.remove(wt); |
| 4025 | mToBottomApps.remove(wt); |
| 4026 | mToBottomApps.add(i, wt); |
| 4027 | wt.sendingToTop = false; |
| 4028 | wt.sendingToBottom = true; |
| 4029 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4030 | pos++; |
| 4031 | } |
| 4032 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4033 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4034 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4035 | moveAppWindowsLocked(tokens, 0); |
| 4036 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4037 | } |
| 4038 | Binder.restoreCallingIdentity(origId); |
| 4039 | } |
| 4040 | |
| 4041 | // ------------------------------------------------------------- |
| 4042 | // Misc IWindowSession methods |
| 4043 | // ------------------------------------------------------------- |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4044 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4045 | public void disableKeyguard(IBinder token, String tag) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4046 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4047 | != PackageManager.PERMISSION_GRANTED) { |
| 4048 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4049 | } |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 4050 | synchronized (mKeyguardTokenWatcher) { |
| 4051 | mKeyguardTokenWatcher.acquire(token, tag); |
Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4052 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4053 | } |
| 4054 | |
| 4055 | public void reenableKeyguard(IBinder token) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4056 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4057 | != PackageManager.PERMISSION_GRANTED) { |
| 4058 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4059 | } |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 4060 | synchronized (mKeyguardTokenWatcher) { |
| 4061 | mKeyguardTokenWatcher.release(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4062 | |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 4063 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4064 | // If we are the last one to reenable the keyguard wait until |
| 4065 | // we have actaully finished reenabling until returning. |
| 4066 | // It is possible that reenableKeyguard() can be called before |
| 4067 | // the previous disableKeyguard() is handled, in which case |
| 4068 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4069 | // be called. In that case mKeyguardDisabled will be false here |
| 4070 | // and we have nothing to wait for. |
| 4071 | while (mKeyguardDisabled) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4072 | try { |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 4073 | mKeyguardTokenWatcher.wait(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4074 | } catch (InterruptedException e) { |
| 4075 | Thread.currentThread().interrupt(); |
| 4076 | } |
| 4077 | } |
| 4078 | } |
| 4079 | } |
| 4080 | } |
| 4081 | |
| 4082 | /** |
| 4083 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4084 | */ |
| 4085 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4086 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4087 | != PackageManager.PERMISSION_GRANTED) { |
| 4088 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4089 | } |
| 4090 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4091 | public void onKeyguardExitResult(boolean success) { |
| 4092 | try { |
| 4093 | callback.onKeyguardExitResult(success); |
| 4094 | } catch (RemoteException e) { |
| 4095 | // Client has died, we don't care. |
| 4096 | } |
| 4097 | } |
| 4098 | }); |
| 4099 | } |
| 4100 | |
| 4101 | public boolean inKeyguardRestrictedInputMode() { |
| 4102 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4103 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4104 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4105 | public void closeSystemDialogs(String reason) { |
| 4106 | synchronized(mWindowMap) { |
| 4107 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 4108 | WindowState w = (WindowState)mWindows.get(i); |
| 4109 | if (w.mSurface != null) { |
| 4110 | try { |
| 4111 | w.mClient.closeSystemDialogs(reason); |
| 4112 | } catch (RemoteException e) { |
| 4113 | } |
| 4114 | } |
| 4115 | } |
| 4116 | } |
| 4117 | } |
| 4118 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4119 | static float fixScale(float scale) { |
| 4120 | if (scale < 0) scale = 0; |
| 4121 | else if (scale > 20) scale = 20; |
| 4122 | return Math.abs(scale); |
| 4123 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4124 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4125 | public void setAnimationScale(int which, float scale) { |
| 4126 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4127 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4128 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4129 | } |
| 4130 | |
| 4131 | if (scale < 0) scale = 0; |
| 4132 | else if (scale > 20) scale = 20; |
| 4133 | scale = Math.abs(scale); |
| 4134 | switch (which) { |
| 4135 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4136 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4137 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4138 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4139 | // Persist setting |
| 4140 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4141 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4142 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4143 | public void setAnimationScales(float[] scales) { |
| 4144 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4145 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4146 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4147 | } |
| 4148 | |
| 4149 | if (scales != null) { |
| 4150 | if (scales.length >= 1) { |
| 4151 | mWindowAnimationScale = fixScale(scales[0]); |
| 4152 | } |
| 4153 | if (scales.length >= 2) { |
| 4154 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4155 | } |
| 4156 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4157 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4158 | // Persist setting |
| 4159 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4160 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4161 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4162 | public float getAnimationScale(int which) { |
| 4163 | switch (which) { |
| 4164 | case 0: return mWindowAnimationScale; |
| 4165 | case 1: return mTransitionAnimationScale; |
| 4166 | } |
| 4167 | return 0; |
| 4168 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4169 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4170 | public float[] getAnimationScales() { |
| 4171 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 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 | public int getSwitchState(int sw) { |
| 4175 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4176 | "getSwitchState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4177 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4178 | } |
| 4179 | return KeyInputQueue.getSwitchState(sw); |
| 4180 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4181 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4182 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4183 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4184 | "getSwitchStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4185 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4186 | } |
| 4187 | return KeyInputQueue.getSwitchState(devid, sw); |
| 4188 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4189 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4190 | public int getScancodeState(int sw) { |
| 4191 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4192 | "getScancodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4193 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4194 | } |
Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4195 | return mQueue.getScancodeState(sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4196 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4197 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4198 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4199 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4200 | "getScancodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4201 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4202 | } |
Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4203 | return mQueue.getScancodeState(devid, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4204 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4205 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4206 | public int getTrackballScancodeState(int sw) { |
| 4207 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4208 | "getTrackballScancodeState()")) { |
| 4209 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4210 | } |
| 4211 | return mQueue.getTrackballScancodeState(sw); |
| 4212 | } |
| 4213 | |
| 4214 | public int getDPadScancodeState(int sw) { |
| 4215 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4216 | "getDPadScancodeState()")) { |
| 4217 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4218 | } |
| 4219 | return mQueue.getDPadScancodeState(sw); |
| 4220 | } |
| 4221 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4222 | public int getKeycodeState(int sw) { |
| 4223 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4224 | "getKeycodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4225 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4226 | } |
Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4227 | return mQueue.getKeycodeState(sw); |
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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4230 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4231 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4232 | "getKeycodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4233 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4234 | } |
Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4235 | return mQueue.getKeycodeState(devid, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4236 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4237 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4238 | public int getTrackballKeycodeState(int sw) { |
| 4239 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4240 | "getTrackballKeycodeState()")) { |
| 4241 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4242 | } |
| 4243 | return mQueue.getTrackballKeycodeState(sw); |
| 4244 | } |
| 4245 | |
| 4246 | public int getDPadKeycodeState(int sw) { |
| 4247 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4248 | "getDPadKeycodeState()")) { |
| 4249 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4250 | } |
| 4251 | return mQueue.getDPadKeycodeState(sw); |
| 4252 | } |
| 4253 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4254 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
| 4255 | return KeyInputQueue.hasKeys(keycodes, keyExists); |
| 4256 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4257 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4258 | public void enableScreenAfterBoot() { |
| 4259 | synchronized(mWindowMap) { |
| 4260 | if (mSystemBooted) { |
| 4261 | return; |
| 4262 | } |
| 4263 | mSystemBooted = true; |
| 4264 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4265 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4266 | performEnableScreen(); |
| 4267 | } |
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 | public void enableScreenIfNeededLocked() { |
| 4270 | if (mDisplayEnabled) { |
| 4271 | return; |
| 4272 | } |
| 4273 | if (!mSystemBooted) { |
| 4274 | return; |
| 4275 | } |
| 4276 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4277 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4278 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4279 | public void performEnableScreen() { |
| 4280 | synchronized(mWindowMap) { |
| 4281 | if (mDisplayEnabled) { |
| 4282 | return; |
| 4283 | } |
| 4284 | if (!mSystemBooted) { |
| 4285 | return; |
| 4286 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4287 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4288 | // Don't enable the screen until all existing windows |
| 4289 | // have been drawn. |
| 4290 | final int N = mWindows.size(); |
| 4291 | for (int i=0; i<N; i++) { |
| 4292 | WindowState w = (WindowState)mWindows.get(i); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 4293 | if (w.isVisibleLw() && !w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4294 | return; |
| 4295 | } |
| 4296 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4297 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4298 | mDisplayEnabled = true; |
| 4299 | if (false) { |
| 4300 | Log.i(TAG, "ENABLING SCREEN!"); |
| 4301 | StringWriter sw = new StringWriter(); |
| 4302 | PrintWriter pw = new PrintWriter(sw); |
| 4303 | this.dump(null, pw, null); |
| 4304 | Log.i(TAG, sw.toString()); |
| 4305 | } |
| 4306 | try { |
| 4307 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4308 | if (surfaceFlinger != null) { |
| 4309 | //Log.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
| 4310 | Parcel data = Parcel.obtain(); |
| 4311 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4312 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4313 | data, null, 0); |
| 4314 | data.recycle(); |
| 4315 | } |
| 4316 | } catch (RemoteException ex) { |
| 4317 | Log.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
| 4318 | } |
| 4319 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4320 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4321 | mPolicy.enableScreenAfterBoot(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4322 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4323 | // Make sure the last requested orientation has been applied. |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4324 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4325 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4326 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4327 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4328 | public void setInTouchMode(boolean mode) { |
| 4329 | synchronized(mWindowMap) { |
| 4330 | mInTouchMode = mode; |
| 4331 | } |
| 4332 | } |
| 4333 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4334 | public void setRotation(int rotation, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4335 | boolean alwaysSendConfiguration, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4336 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4337 | "setRotation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4338 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4339 | } |
| 4340 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4341 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4342 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4343 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4344 | public void setRotationUnchecked(int rotation, |
| 4345 | boolean alwaysSendConfiguration, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4346 | if(DEBUG_ORIENTATION) Log.v(TAG, |
| 4347 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4348 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4349 | long origId = Binder.clearCallingIdentity(); |
| 4350 | boolean changed; |
| 4351 | synchronized(mWindowMap) { |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4352 | changed = setRotationUncheckedLocked(rotation, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4353 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4354 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4355 | if (changed) { |
| 4356 | sendNewConfiguration(); |
| 4357 | synchronized(mWindowMap) { |
| 4358 | mLayoutNeeded = true; |
| 4359 | performLayoutAndPlaceSurfacesLocked(); |
| 4360 | } |
| 4361 | } else if (alwaysSendConfiguration) { |
| 4362 | //update configuration ignoring orientation change |
| 4363 | sendNewConfiguration(); |
| 4364 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4365 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4366 | Binder.restoreCallingIdentity(origId); |
| 4367 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4368 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4369 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4370 | boolean changed; |
| 4371 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4372 | rotation = mRequestedRotation; |
| 4373 | } else { |
| 4374 | mRequestedRotation = rotation; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4375 | mLastRotationFlags = animFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4376 | } |
| 4377 | 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] | 4378 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4379 | mRotation, mDisplayEnabled); |
| 4380 | if (DEBUG_ORIENTATION) Log.v(TAG, "new rotation is set to " + rotation); |
| 4381 | changed = mDisplayEnabled && mRotation != rotation; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4382 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4383 | if (changed) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4384 | if (DEBUG_ORIENTATION) Log.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4385 | "Rotation changed to " + rotation |
| 4386 | + " from " + mRotation |
| 4387 | + " (forceApp=" + mForcedAppOrientation |
| 4388 | + ", req=" + mRequestedRotation + ")"); |
| 4389 | mRotation = rotation; |
| 4390 | mWindowsFreezingScreen = true; |
| 4391 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 4392 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 4393 | 2000); |
| 4394 | startFreezingDisplayLocked(); |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4395 | Log.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4396 | mQueue.setOrientation(rotation); |
| 4397 | if (mDisplayEnabled) { |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4398 | Surface.setOrientation(0, rotation, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4399 | } |
| 4400 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 4401 | WindowState w = (WindowState)mWindows.get(i); |
| 4402 | if (w.mSurface != null) { |
| 4403 | w.mOrientationChanging = true; |
| 4404 | } |
| 4405 | } |
| 4406 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 4407 | try { |
| 4408 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 4409 | } catch (RemoteException e) { |
| 4410 | } |
| 4411 | } |
| 4412 | } //end if changed |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4414 | return changed; |
| 4415 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4416 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4417 | public int getRotation() { |
| 4418 | return mRotation; |
| 4419 | } |
| 4420 | |
| 4421 | public int watchRotation(IRotationWatcher watcher) { |
| 4422 | final IBinder watcherBinder = watcher.asBinder(); |
| 4423 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 4424 | public void binderDied() { |
| 4425 | synchronized (mWindowMap) { |
| 4426 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 4427 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 4428 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 4429 | if (removed != null) { |
| 4430 | removed.asBinder().unlinkToDeath(this, 0); |
| 4431 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4432 | i--; |
| 4433 | } |
| 4434 | } |
| 4435 | } |
| 4436 | } |
| 4437 | }; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4438 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4439 | synchronized (mWindowMap) { |
| 4440 | try { |
| 4441 | watcher.asBinder().linkToDeath(dr, 0); |
| 4442 | mRotationWatchers.add(watcher); |
| 4443 | } catch (RemoteException e) { |
| 4444 | // Client died, no cleanup needed. |
| 4445 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4446 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4447 | return mRotation; |
| 4448 | } |
| 4449 | } |
| 4450 | |
| 4451 | /** |
| 4452 | * Starts the view server on the specified port. |
| 4453 | * |
| 4454 | * @param port The port to listener to. |
| 4455 | * |
| 4456 | * @return True if the server was successfully started, false otherwise. |
| 4457 | * |
| 4458 | * @see com.android.server.ViewServer |
| 4459 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 4460 | */ |
| 4461 | public boolean startViewServer(int port) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4462 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4463 | return false; |
| 4464 | } |
| 4465 | |
| 4466 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 4467 | return false; |
| 4468 | } |
| 4469 | |
| 4470 | if (port < 1024) { |
| 4471 | return false; |
| 4472 | } |
| 4473 | |
| 4474 | if (mViewServer != null) { |
| 4475 | if (!mViewServer.isRunning()) { |
| 4476 | try { |
| 4477 | return mViewServer.start(); |
| 4478 | } catch (IOException e) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4479 | Log.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4480 | } |
| 4481 | } |
| 4482 | return false; |
| 4483 | } |
| 4484 | |
| 4485 | try { |
| 4486 | mViewServer = new ViewServer(this, port); |
| 4487 | return mViewServer.start(); |
| 4488 | } catch (IOException e) { |
| 4489 | Log.w(TAG, "View server did not start"); |
| 4490 | } |
| 4491 | return false; |
| 4492 | } |
| 4493 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4494 | private boolean isSystemSecure() { |
| 4495 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 4496 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 4497 | } |
| 4498 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4499 | /** |
| 4500 | * Stops the view server if it exists. |
| 4501 | * |
| 4502 | * @return True if the server stopped, false if it wasn't started or |
| 4503 | * couldn't be stopped. |
| 4504 | * |
| 4505 | * @see com.android.server.ViewServer |
| 4506 | */ |
| 4507 | public boolean stopViewServer() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4508 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4509 | return false; |
| 4510 | } |
| 4511 | |
| 4512 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 4513 | return false; |
| 4514 | } |
| 4515 | |
| 4516 | if (mViewServer != null) { |
| 4517 | return mViewServer.stop(); |
| 4518 | } |
| 4519 | return false; |
| 4520 | } |
| 4521 | |
| 4522 | /** |
| 4523 | * Indicates whether the view server is running. |
| 4524 | * |
| 4525 | * @return True if the server is running, false otherwise. |
| 4526 | * |
| 4527 | * @see com.android.server.ViewServer |
| 4528 | */ |
| 4529 | public boolean isViewServerRunning() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4530 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4531 | return false; |
| 4532 | } |
| 4533 | |
| 4534 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 4535 | return false; |
| 4536 | } |
| 4537 | |
| 4538 | return mViewServer != null && mViewServer.isRunning(); |
| 4539 | } |
| 4540 | |
| 4541 | /** |
| 4542 | * Lists all availble windows in the system. The listing is written in the |
| 4543 | * specified Socket's output stream with the following syntax: |
| 4544 | * windowHashCodeInHexadecimal windowName |
| 4545 | * Each line of the ouput represents a different window. |
| 4546 | * |
| 4547 | * @param client The remote client to send the listing to. |
| 4548 | * @return False if an error occured, true otherwise. |
| 4549 | */ |
| 4550 | boolean viewServerListWindows(Socket client) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4551 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4552 | return false; |
| 4553 | } |
| 4554 | |
| 4555 | boolean result = true; |
| 4556 | |
| 4557 | Object[] windows; |
| 4558 | synchronized (mWindowMap) { |
| 4559 | windows = new Object[mWindows.size()]; |
| 4560 | //noinspection unchecked |
| 4561 | windows = mWindows.toArray(windows); |
| 4562 | } |
| 4563 | |
| 4564 | BufferedWriter out = null; |
| 4565 | |
| 4566 | // Any uncaught exception will crash the system process |
| 4567 | try { |
| 4568 | OutputStream clientStream = client.getOutputStream(); |
| 4569 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 4570 | |
| 4571 | final int count = windows.length; |
| 4572 | for (int i = 0; i < count; i++) { |
| 4573 | final WindowState w = (WindowState) windows[i]; |
| 4574 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 4575 | out.write(' '); |
| 4576 | out.append(w.mAttrs.getTitle()); |
| 4577 | out.write('\n'); |
| 4578 | } |
| 4579 | |
| 4580 | out.write("DONE.\n"); |
| 4581 | out.flush(); |
| 4582 | } catch (Exception e) { |
| 4583 | result = false; |
| 4584 | } finally { |
| 4585 | if (out != null) { |
| 4586 | try { |
| 4587 | out.close(); |
| 4588 | } catch (IOException e) { |
| 4589 | result = false; |
| 4590 | } |
| 4591 | } |
| 4592 | } |
| 4593 | |
| 4594 | return result; |
| 4595 | } |
| 4596 | |
| 4597 | /** |
| 4598 | * Sends a command to a target window. The result of the command, if any, will be |
| 4599 | * written in the output stream of the specified socket. |
| 4600 | * |
| 4601 | * The parameters must follow this syntax: |
| 4602 | * windowHashcode extra |
| 4603 | * |
| 4604 | * Where XX is the length in characeters of the windowTitle. |
| 4605 | * |
| 4606 | * The first parameter is the target window. The window with the specified hashcode |
| 4607 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 4608 | * will be delivered to the target window and as parameters to the command itself. |
| 4609 | * |
| 4610 | * @param client The remote client to sent the result, if any, to. |
| 4611 | * @param command The command to execute. |
| 4612 | * @param parameters The command parameters. |
| 4613 | * |
| 4614 | * @return True if the command was successfully delivered, false otherwise. This does |
| 4615 | * not indicate whether the command itself was successful. |
| 4616 | */ |
| 4617 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4618 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4619 | return false; |
| 4620 | } |
| 4621 | |
| 4622 | boolean success = true; |
| 4623 | Parcel data = null; |
| 4624 | Parcel reply = null; |
| 4625 | |
| 4626 | // Any uncaught exception will crash the system process |
| 4627 | try { |
| 4628 | // Find the hashcode of the window |
| 4629 | int index = parameters.indexOf(' '); |
| 4630 | if (index == -1) { |
| 4631 | index = parameters.length(); |
| 4632 | } |
| 4633 | final String code = parameters.substring(0, index); |
| 4634 | int hashCode = "ffffffff".equals(code) ? -1 : Integer.parseInt(code, 16); |
| 4635 | |
| 4636 | // Extract the command's parameter after the window description |
| 4637 | if (index < parameters.length()) { |
| 4638 | parameters = parameters.substring(index + 1); |
| 4639 | } else { |
| 4640 | parameters = ""; |
| 4641 | } |
| 4642 | |
| 4643 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 4644 | if (window == null) { |
| 4645 | return false; |
| 4646 | } |
| 4647 | |
| 4648 | data = Parcel.obtain(); |
| 4649 | data.writeInterfaceToken("android.view.IWindow"); |
| 4650 | data.writeString(command); |
| 4651 | data.writeString(parameters); |
| 4652 | data.writeInt(1); |
| 4653 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 4654 | |
| 4655 | reply = Parcel.obtain(); |
| 4656 | |
| 4657 | final IBinder binder = window.mClient.asBinder(); |
| 4658 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 4659 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 4660 | |
| 4661 | reply.readException(); |
| 4662 | |
| 4663 | } catch (Exception e) { |
| 4664 | Log.w(TAG, "Could not send command " + command + " with parameters " + parameters, e); |
| 4665 | success = false; |
| 4666 | } finally { |
| 4667 | if (data != null) { |
| 4668 | data.recycle(); |
| 4669 | } |
| 4670 | if (reply != null) { |
| 4671 | reply.recycle(); |
| 4672 | } |
| 4673 | } |
| 4674 | |
| 4675 | return success; |
| 4676 | } |
| 4677 | |
| 4678 | private WindowState findWindow(int hashCode) { |
| 4679 | if (hashCode == -1) { |
| 4680 | return getFocusedWindow(); |
| 4681 | } |
| 4682 | |
| 4683 | synchronized (mWindowMap) { |
| 4684 | final ArrayList windows = mWindows; |
| 4685 | final int count = windows.size(); |
| 4686 | |
| 4687 | for (int i = 0; i < count; i++) { |
| 4688 | WindowState w = (WindowState) windows.get(i); |
| 4689 | if (System.identityHashCode(w) == hashCode) { |
| 4690 | return w; |
| 4691 | } |
| 4692 | } |
| 4693 | } |
| 4694 | |
| 4695 | return null; |
| 4696 | } |
| 4697 | |
| 4698 | /* |
| 4699 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 4700 | * that to config-changed listeners if appropriate. |
| 4701 | */ |
| 4702 | void sendNewConfiguration() { |
| 4703 | try { |
| 4704 | mActivityManager.updateConfiguration(null); |
| 4705 | } catch (RemoteException e) { |
| 4706 | } |
| 4707 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4708 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4709 | public Configuration computeNewConfiguration() { |
| 4710 | synchronized (mWindowMap) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4711 | return computeNewConfigurationLocked(); |
| 4712 | } |
| 4713 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4714 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4715 | Configuration computeNewConfigurationLocked() { |
| 4716 | Configuration config = new Configuration(); |
| 4717 | if (!computeNewConfigurationLocked(config)) { |
| 4718 | return null; |
| 4719 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4720 | return config; |
| 4721 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4722 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4723 | boolean computeNewConfigurationLocked(Configuration config) { |
| 4724 | if (mDisplay == null) { |
| 4725 | return false; |
| 4726 | } |
| 4727 | mQueue.getInputConfiguration(config); |
| 4728 | final int dw = mDisplay.getWidth(); |
| 4729 | final int dh = mDisplay.getHeight(); |
| 4730 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 4731 | if (dw < dh) { |
| 4732 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 4733 | } else if (dw > dh) { |
| 4734 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 4735 | } |
| 4736 | config.orientation = orientation; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4737 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4738 | DisplayMetrics dm = new DisplayMetrics(); |
| 4739 | mDisplay.getMetrics(dm); |
| 4740 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 4741 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4742 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4743 | // Note we only do this once because at this point we don't |
| 4744 | // expect the screen to change in this way at runtime, and want |
| 4745 | // to avoid all of this computation for every config change. |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4746 | int longSize = dw; |
| 4747 | int shortSize = dh; |
| 4748 | if (longSize < shortSize) { |
| 4749 | int tmp = longSize; |
| 4750 | longSize = shortSize; |
| 4751 | shortSize = tmp; |
| 4752 | } |
| 4753 | longSize = (int)(longSize/dm.density); |
| 4754 | shortSize = (int)(shortSize/dm.density); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4755 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4756 | // These semi-magic numbers define our compatibility modes for |
| 4757 | // applications with different screens. Don't change unless you |
| 4758 | // make sure to test lots and lots of apps! |
| 4759 | if (longSize < 470) { |
| 4760 | // This is shorter than an HVGA normal density screen (which |
| 4761 | // is 480 pixels on its long side). |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4762 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 4763 | | Configuration.SCREENLAYOUT_LONG_NO; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4764 | } else { |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4765 | // Is this a large screen? |
| 4766 | if (longSize > 640 && shortSize >= 480) { |
| 4767 | // VGA or larger screens at medium density are the point |
| 4768 | // at which we consider it to be a large screen. |
| 4769 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 4770 | } else { |
| 4771 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
| 4772 | |
| 4773 | // If this screen is wider than normal HVGA, or taller |
| 4774 | // than FWVGA, then for old apps we want to run in size |
| 4775 | // compatibility mode. |
| 4776 | if (shortSize > 321 || longSize > 570) { |
| 4777 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 4778 | } |
| 4779 | } |
| 4780 | |
| 4781 | // Is this a long screen? |
| 4782 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 4783 | // Anything wider than WVGA (5:3) is considering to be long. |
| 4784 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 4785 | } else { |
| 4786 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 4787 | } |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4788 | } |
| 4789 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4790 | config.screenLayout = mScreenLayout; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4791 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4792 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 4793 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 4794 | mPolicy.adjustConfigurationLw(config); |
| 4795 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4796 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4797 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4798 | // ------------------------------------------------------------- |
| 4799 | // Input Events and Focus Management |
| 4800 | // ------------------------------------------------------------- |
| 4801 | |
| 4802 | private final void wakeupIfNeeded(WindowState targetWin, int eventType) { |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4803 | long curTime = SystemClock.uptimeMillis(); |
| 4804 | |
Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 4805 | if (eventType == TOUCH_EVENT || eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) { |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4806 | if (mLastTouchEventType == eventType && |
| 4807 | (curTime - mLastUserActivityCallTime) < MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 4808 | return; |
| 4809 | } |
| 4810 | mLastUserActivityCallTime = curTime; |
| 4811 | mLastTouchEventType = eventType; |
| 4812 | } |
| 4813 | |
| 4814 | if (targetWin == null |
| 4815 | || targetWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) { |
| 4816 | mPowerManager.userActivity(curTime, false, eventType, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4817 | } |
| 4818 | } |
| 4819 | |
| 4820 | // tells if it's a cheek event or not -- this function is stateful |
| 4821 | private static final int EVENT_NONE = 0; |
| 4822 | private static final int EVENT_UNKNOWN = 0; |
| 4823 | private static final int EVENT_CHEEK = 0; |
| 4824 | private static final int EVENT_IGNORE_DURATION = 300; // ms |
| 4825 | private static final float CHEEK_THRESHOLD = 0.6f; |
| 4826 | private int mEventState = EVENT_NONE; |
| 4827 | private float mEventSize; |
Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4828 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4829 | private int eventType(MotionEvent ev) { |
| 4830 | float size = ev.getSize(); |
| 4831 | switch (ev.getAction()) { |
| 4832 | case MotionEvent.ACTION_DOWN: |
| 4833 | mEventSize = size; |
| 4834 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_EVENT; |
| 4835 | case MotionEvent.ACTION_UP: |
| 4836 | if (size > mEventSize) mEventSize = size; |
Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4837 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_UP_EVENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4838 | case MotionEvent.ACTION_MOVE: |
| 4839 | final int N = ev.getHistorySize(); |
| 4840 | if (size > mEventSize) mEventSize = size; |
| 4841 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 4842 | for (int i=0; i<N; i++) { |
| 4843 | size = ev.getHistoricalSize(i); |
| 4844 | if (size > mEventSize) mEventSize = size; |
| 4845 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 4846 | } |
| 4847 | if (ev.getEventTime() < ev.getDownTime() + EVENT_IGNORE_DURATION) { |
| 4848 | return TOUCH_EVENT; |
| 4849 | } else { |
Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4850 | return LONG_TOUCH_EVENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4851 | } |
| 4852 | default: |
| 4853 | // not good |
| 4854 | return OTHER_EVENT; |
| 4855 | } |
| 4856 | } |
| 4857 | |
| 4858 | /** |
| 4859 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4860 | */ |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4861 | 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] | 4862 | if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Log.v(TAG, |
| 4863 | "dispatchPointer " + ev); |
| 4864 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4865 | if (MEASURE_LATENCY) { |
| 4866 | lt.sample("3 Wait for last dispatch ", System.nanoTime() - qev.whenNano); |
| 4867 | } |
| 4868 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4869 | Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4870 | ev, true, false, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4871 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4872 | if (MEASURE_LATENCY) { |
| 4873 | lt.sample("3 Last dispatch finished ", System.nanoTime() - qev.whenNano); |
| 4874 | } |
| 4875 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4876 | int action = ev.getAction(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4877 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4878 | if (action == MotionEvent.ACTION_UP) { |
| 4879 | // let go of our target |
| 4880 | mKeyWaiter.mMotionTarget = null; |
| 4881 | mPowerManager.logPointerUpEvent(); |
| 4882 | } else if (action == MotionEvent.ACTION_DOWN) { |
| 4883 | mPowerManager.logPointerDownEvent(); |
| 4884 | } |
| 4885 | |
| 4886 | if (targetObj == null) { |
| 4887 | // In this case we are either dropping the event, or have received |
| 4888 | // a move or up without a down. It is common to receive move |
| 4889 | // events in such a way, since this means the user is moving the |
| 4890 | // pointer without actually pressing down. All other cases should |
| 4891 | // be atypical, so let's log them. |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4892 | if (action != MotionEvent.ACTION_MOVE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4893 | Log.w(TAG, "No window to dispatch pointer action " + ev.getAction()); |
| 4894 | } |
Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 4895 | synchronized (mWindowMap) { |
| 4896 | if (mSendingPointersToWallpaper) { |
| 4897 | Log.i(TAG, "Sending skipped pointer to wallpaper!"); |
| 4898 | sendPointerToWallpaperLocked(null, ev, ev.getEventTime()); |
| 4899 | } |
| 4900 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4901 | if (qev != null) { |
| 4902 | mQueue.recycleEvent(qev); |
| 4903 | } |
| 4904 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4905 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4906 | } |
| 4907 | if (targetObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 4908 | synchronized (mWindowMap) { |
| 4909 | if (mSendingPointersToWallpaper) { |
| 4910 | Log.i(TAG, "Sending skipped pointer to wallpaper!"); |
| 4911 | sendPointerToWallpaperLocked(null, ev, ev.getEventTime()); |
| 4912 | } |
| 4913 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4914 | if (qev != null) { |
| 4915 | mQueue.recycleEvent(qev); |
| 4916 | } |
| 4917 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4918 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4919 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4920 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4921 | WindowState target = (WindowState)targetObj; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4922 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4923 | final long eventTime = ev.getEventTime(); |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4924 | final long eventTimeNano = ev.getEventTimeNano(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4925 | |
| 4926 | //Log.i(TAG, "Sending " + ev + " to " + target); |
| 4927 | |
| 4928 | if (uid != 0 && uid != target.mSession.mUid) { |
| 4929 | if (mContext.checkPermission( |
| 4930 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 4931 | != PackageManager.PERMISSION_GRANTED) { |
| 4932 | Log.w(TAG, "Permission denied: injecting pointer event from pid " |
| 4933 | + pid + " uid " + uid + " to window " + target |
| 4934 | + " owned by uid " + target.mSession.mUid); |
| 4935 | if (qev != null) { |
| 4936 | mQueue.recycleEvent(qev); |
| 4937 | } |
| 4938 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4939 | return INJECT_NO_PERMISSION; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4940 | } |
| 4941 | } |
| 4942 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4943 | if (MEASURE_LATENCY) { |
| 4944 | lt.sample("4 in dispatchPointer ", System.nanoTime() - eventTimeNano); |
| 4945 | } |
| 4946 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4947 | if ((target.mAttrs.flags & |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4948 | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES) != 0) { |
| 4949 | //target wants to ignore fat touch events |
| 4950 | boolean cheekPress = mPolicy.isCheekPressedAgainstScreen(ev); |
| 4951 | //explicit flag to return without processing event further |
| 4952 | boolean returnFlag = false; |
| 4953 | if((action == MotionEvent.ACTION_DOWN)) { |
| 4954 | mFatTouch = false; |
| 4955 | if(cheekPress) { |
| 4956 | mFatTouch = true; |
| 4957 | returnFlag = true; |
| 4958 | } |
| 4959 | } else { |
| 4960 | if(action == MotionEvent.ACTION_UP) { |
| 4961 | if(mFatTouch) { |
| 4962 | //earlier even was invalid doesnt matter if current up is cheekpress or not |
| 4963 | mFatTouch = false; |
| 4964 | returnFlag = true; |
| 4965 | } else if(cheekPress) { |
| 4966 | //cancel the earlier event |
| 4967 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 4968 | action = MotionEvent.ACTION_CANCEL; |
| 4969 | } |
| 4970 | } else if(action == MotionEvent.ACTION_MOVE) { |
| 4971 | if(mFatTouch) { |
| 4972 | //two cases here |
| 4973 | //an invalid down followed by 0 or moves(valid or invalid) |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4974 | //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] | 4975 | returnFlag = true; |
| 4976 | } else if(cheekPress) { |
| 4977 | //valid down followed by invalid moves |
| 4978 | //an invalid move have to cancel earlier action |
| 4979 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 4980 | action = MotionEvent.ACTION_CANCEL; |
| 4981 | if (DEBUG_INPUT) Log.v(TAG, "Sending cancel for invalid ACTION_MOVE"); |
| 4982 | //note that the subsequent invalid moves will not get here |
| 4983 | mFatTouch = true; |
| 4984 | } |
| 4985 | } |
| 4986 | } //else if action |
| 4987 | if(returnFlag) { |
| 4988 | //recycle que, ev |
| 4989 | if (qev != null) { |
| 4990 | mQueue.recycleEvent(qev); |
| 4991 | } |
| 4992 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4993 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4994 | } |
| 4995 | } //end if target |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4996 | |
Michael Chan | 9f028e6 | 2009-08-04 17:37:46 -0700 | [diff] [blame] | 4997 | // Enable this for testing the "right" value |
| 4998 | if (false && action == MotionEvent.ACTION_DOWN) { |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4999 | int max_events_per_sec = 35; |
| 5000 | try { |
| 5001 | max_events_per_sec = Integer.parseInt(SystemProperties |
| 5002 | .get("windowsmgr.max_events_per_sec")); |
| 5003 | if (max_events_per_sec < 1) { |
| 5004 | max_events_per_sec = 35; |
| 5005 | } |
| 5006 | } catch (NumberFormatException e) { |
| 5007 | } |
| 5008 | mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec; |
| 5009 | } |
| 5010 | |
| 5011 | /* |
| 5012 | * Throttle events to minimize CPU usage when there's a flood of events |
| 5013 | * e.g. constant contact with the screen |
| 5014 | */ |
| 5015 | if (action == MotionEvent.ACTION_MOVE) { |
| 5016 | long nextEventTime = mLastTouchEventTime + mMinWaitTimeBetweenTouchEvents; |
| 5017 | long now = SystemClock.uptimeMillis(); |
| 5018 | if (now < nextEventTime) { |
| 5019 | try { |
| 5020 | Thread.sleep(nextEventTime - now); |
| 5021 | } catch (InterruptedException e) { |
| 5022 | } |
| 5023 | mLastTouchEventTime = nextEventTime; |
| 5024 | } else { |
| 5025 | mLastTouchEventTime = now; |
| 5026 | } |
| 5027 | } |
| 5028 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5029 | if (MEASURE_LATENCY) { |
| 5030 | lt.sample("5 in dispatchPointer ", System.nanoTime() - eventTimeNano); |
| 5031 | } |
| 5032 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5033 | synchronized(mWindowMap) { |
Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5034 | if (!target.isVisibleLw()) { |
| 5035 | // During this motion dispatch, the target window has become |
| 5036 | // invisible. |
| 5037 | if (mSendingPointersToWallpaper) { |
| 5038 | sendPointerToWallpaperLocked(null, ev, eventTime); |
| 5039 | } |
| 5040 | if (qev != null) { |
| 5041 | mQueue.recycleEvent(qev); |
| 5042 | } |
| 5043 | ev.recycle(); |
| 5044 | return INJECT_SUCCEEDED; |
| 5045 | } |
| 5046 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5047 | if (qev != null && action == MotionEvent.ACTION_MOVE) { |
| 5048 | mKeyWaiter.bindTargetWindowLocked(target, |
| 5049 | KeyWaiter.RETURN_PENDING_POINTER, qev); |
| 5050 | ev = null; |
| 5051 | } else { |
| 5052 | if (action == MotionEvent.ACTION_DOWN) { |
| 5053 | WindowState out = mKeyWaiter.mOutsideTouchTargets; |
| 5054 | if (out != null) { |
| 5055 | MotionEvent oev = MotionEvent.obtain(ev); |
| 5056 | oev.setAction(MotionEvent.ACTION_OUTSIDE); |
| 5057 | do { |
| 5058 | final Rect frame = out.mFrame; |
| 5059 | oev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 5060 | try { |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5061 | out.mClient.dispatchPointer(oev, eventTime, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5062 | } catch (android.os.RemoteException e) { |
| 5063 | Log.i(TAG, "WINDOW DIED during outside motion dispatch: " + out); |
| 5064 | } |
| 5065 | oev.offsetLocation((float)frame.left, (float)frame.top); |
| 5066 | out = out.mNextOutsideTouch; |
| 5067 | } while (out != null); |
| 5068 | mKeyWaiter.mOutsideTouchTargets = null; |
| 5069 | } |
| 5070 | } |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5071 | |
| 5072 | // If we are on top of the wallpaper, then the wallpaper also |
| 5073 | // gets to see this movement. |
Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5074 | if (mWallpaperTarget == target || mSendingPointersToWallpaper) { |
| 5075 | sendPointerToWallpaperLocked(null, ev, eventTime); |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5076 | } |
Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5077 | |
| 5078 | final Rect frame = target.mFrame; |
| 5079 | ev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 5080 | mKeyWaiter.bindTargetWindowLocked(target); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5081 | } |
| 5082 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5083 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5084 | // finally offset the event to the target's coordinate system and |
| 5085 | // dispatch the event. |
| 5086 | try { |
| 5087 | if (DEBUG_INPUT || DEBUG_FOCUS || WindowManagerPolicy.WATCH_POINTER) { |
| 5088 | Log.v(TAG, "Delivering pointer " + qev + " to " + target); |
| 5089 | } |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5090 | |
| 5091 | if (MEASURE_LATENCY) { |
| 5092 | lt.sample("6 before svr->client ipc ", System.nanoTime() - eventTimeNano); |
| 5093 | } |
| 5094 | |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5095 | target.mClient.dispatchPointer(ev, eventTime, true); |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5096 | |
| 5097 | if (MEASURE_LATENCY) { |
| 5098 | lt.sample("7 after svr->client ipc ", System.nanoTime() - eventTimeNano); |
| 5099 | } |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5100 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5101 | } catch (android.os.RemoteException e) { |
| 5102 | Log.i(TAG, "WINDOW DIED during motion dispatch: " + target); |
| 5103 | mKeyWaiter.mMotionTarget = null; |
| 5104 | try { |
| 5105 | removeWindow(target.mSession, target.mClient); |
| 5106 | } catch (java.util.NoSuchElementException ex) { |
| 5107 | // This will happen if the window has already been |
| 5108 | // removed. |
| 5109 | } |
| 5110 | } |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5111 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5112 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5113 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5114 | /** |
| 5115 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5116 | */ |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5117 | 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] | 5118 | if (DEBUG_INPUT) Log.v( |
| 5119 | TAG, "dispatchTrackball [" + ev.getAction() +"] <" + ev.getX() + ", " + ev.getY() + ">"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5120 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5121 | Object focusObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5122 | ev, false, false, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5123 | if (focusObj == null) { |
| 5124 | Log.w(TAG, "No focus window, dropping trackball: " + ev); |
| 5125 | if (qev != null) { |
| 5126 | mQueue.recycleEvent(qev); |
| 5127 | } |
| 5128 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5129 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5130 | } |
| 5131 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| 5132 | if (qev != null) { |
| 5133 | mQueue.recycleEvent(qev); |
| 5134 | } |
| 5135 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5136 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5137 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5138 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5139 | WindowState focus = (WindowState)focusObj; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5141 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 5142 | if (mContext.checkPermission( |
| 5143 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 5144 | != PackageManager.PERMISSION_GRANTED) { |
| 5145 | Log.w(TAG, "Permission denied: injecting key event from pid " |
| 5146 | + pid + " uid " + uid + " to window " + focus |
| 5147 | + " owned by uid " + focus.mSession.mUid); |
| 5148 | if (qev != null) { |
| 5149 | mQueue.recycleEvent(qev); |
| 5150 | } |
| 5151 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5152 | return INJECT_NO_PERMISSION; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5153 | } |
| 5154 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5155 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5156 | final long eventTime = ev.getEventTime(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5157 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5158 | synchronized(mWindowMap) { |
| 5159 | if (qev != null && ev.getAction() == MotionEvent.ACTION_MOVE) { |
| 5160 | mKeyWaiter.bindTargetWindowLocked(focus, |
| 5161 | KeyWaiter.RETURN_PENDING_TRACKBALL, qev); |
| 5162 | // We don't deliver movement events to the client, we hold |
| 5163 | // them and wait for them to call back. |
| 5164 | ev = null; |
| 5165 | } else { |
| 5166 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 5167 | } |
| 5168 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5169 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5170 | try { |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5171 | focus.mClient.dispatchTrackball(ev, eventTime, true); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5172 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5173 | } catch (android.os.RemoteException e) { |
| 5174 | Log.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| 5175 | try { |
| 5176 | removeWindow(focus.mSession, focus.mClient); |
| 5177 | } catch (java.util.NoSuchElementException ex) { |
| 5178 | // This will happen if the window has already been |
| 5179 | // removed. |
| 5180 | } |
| 5181 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5182 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5183 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5184 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5185 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5186 | /** |
| 5187 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5188 | */ |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5189 | private int dispatchKey(KeyEvent event, int pid, int uid) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5190 | if (DEBUG_INPUT) Log.v(TAG, "Dispatch key: " + event); |
| 5191 | |
| 5192 | Object focusObj = mKeyWaiter.waitForNextEventTarget(event, null, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5193 | null, false, false, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5194 | if (focusObj == null) { |
| 5195 | Log.w(TAG, "No focus window, dropping: " + event); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5196 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5197 | } |
| 5198 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5199 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5200 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5201 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5202 | // Okay we have finished waiting for the last event to be processed. |
| 5203 | // First off, if this is a repeat event, check to see if there is |
| 5204 | // a corresponding up event in the queue. If there is, we will |
| 5205 | // just drop the repeat, because it makes no sense to repeat after |
| 5206 | // the user has released a key. (This is especially important for |
| 5207 | // long presses.) |
| 5208 | if (event.getRepeatCount() > 0 && mQueue.hasKeyUpEvent(event)) { |
| 5209 | return INJECT_SUCCEEDED; |
| 5210 | } |
| 5211 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5212 | WindowState focus = (WindowState)focusObj; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5213 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5214 | if (DEBUG_INPUT) Log.v( |
| 5215 | TAG, "Dispatching to " + focus + ": " + event); |
| 5216 | |
| 5217 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 5218 | if (mContext.checkPermission( |
| 5219 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 5220 | != PackageManager.PERMISSION_GRANTED) { |
| 5221 | Log.w(TAG, "Permission denied: injecting key event from pid " |
| 5222 | + pid + " uid " + uid + " to window " + focus |
| 5223 | + " owned by uid " + focus.mSession.mUid); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5224 | return INJECT_NO_PERMISSION; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5225 | } |
| 5226 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5227 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5228 | synchronized(mWindowMap) { |
| 5229 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 5230 | } |
| 5231 | |
| 5232 | // NOSHIP extra state logging |
| 5233 | mKeyWaiter.recordDispatchState(event, focus); |
| 5234 | // END NOSHIP |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5235 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5236 | try { |
| 5237 | if (DEBUG_INPUT || DEBUG_FOCUS) { |
| 5238 | Log.v(TAG, "Delivering key " + event.getKeyCode() |
| 5239 | + " to " + focus); |
| 5240 | } |
| 5241 | focus.mClient.dispatchKey(event); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5242 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5243 | } catch (android.os.RemoteException e) { |
| 5244 | Log.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| 5245 | try { |
| 5246 | removeWindow(focus.mSession, focus.mClient); |
| 5247 | } catch (java.util.NoSuchElementException ex) { |
| 5248 | // This will happen if the window has already been |
| 5249 | // removed. |
| 5250 | } |
| 5251 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5252 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5253 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5254 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5255 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5256 | public void pauseKeyDispatching(IBinder _token) { |
| 5257 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5258 | "pauseKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5259 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5260 | } |
| 5261 | |
| 5262 | synchronized (mWindowMap) { |
| 5263 | WindowToken token = mTokenMap.get(_token); |
| 5264 | if (token != null) { |
| 5265 | mKeyWaiter.pauseDispatchingLocked(token); |
| 5266 | } |
| 5267 | } |
| 5268 | } |
| 5269 | |
| 5270 | public void resumeKeyDispatching(IBinder _token) { |
| 5271 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5272 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5273 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5274 | } |
| 5275 | |
| 5276 | synchronized (mWindowMap) { |
| 5277 | WindowToken token = mTokenMap.get(_token); |
| 5278 | if (token != null) { |
| 5279 | mKeyWaiter.resumeDispatchingLocked(token); |
| 5280 | } |
| 5281 | } |
| 5282 | } |
| 5283 | |
| 5284 | public void setEventDispatching(boolean enabled) { |
| 5285 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5286 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5287 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5288 | } |
| 5289 | |
| 5290 | synchronized (mWindowMap) { |
| 5291 | mKeyWaiter.setEventDispatchingLocked(enabled); |
| 5292 | } |
| 5293 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5294 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5295 | /** |
| 5296 | * Injects a keystroke event into the UI. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5297 | * |
| 5298 | * @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] | 5299 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5300 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5301 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5302 | */ |
| 5303 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 5304 | long downTime = ev.getDownTime(); |
| 5305 | long eventTime = ev.getEventTime(); |
| 5306 | |
| 5307 | int action = ev.getAction(); |
| 5308 | int code = ev.getKeyCode(); |
| 5309 | int repeatCount = ev.getRepeatCount(); |
| 5310 | int metaState = ev.getMetaState(); |
| 5311 | int deviceId = ev.getDeviceId(); |
| 5312 | int scancode = ev.getScanCode(); |
| 5313 | |
| 5314 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 5315 | if (downTime == 0) downTime = eventTime; |
| 5316 | |
| 5317 | 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] | 5318 | deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5319 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5320 | final int pid = Binder.getCallingPid(); |
| 5321 | final int uid = Binder.getCallingUid(); |
| 5322 | final long ident = Binder.clearCallingIdentity(); |
| 5323 | final int result = dispatchKey(newEvent, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5324 | if (sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5325 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5326 | } |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5327 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5328 | switch (result) { |
| 5329 | case INJECT_NO_PERMISSION: |
| 5330 | throw new SecurityException( |
| 5331 | "Injecting to another application requires INJECT_EVENT permission"); |
| 5332 | case INJECT_SUCCEEDED: |
| 5333 | return true; |
| 5334 | } |
| 5335 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5336 | } |
| 5337 | |
| 5338 | /** |
| 5339 | * Inject a pointer (touch) event into the UI. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5340 | * |
| 5341 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 5342 | * {@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] | 5343 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5344 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5345 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5346 | */ |
| 5347 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5348 | final int pid = Binder.getCallingPid(); |
| 5349 | final int uid = Binder.getCallingUid(); |
| 5350 | final long ident = Binder.clearCallingIdentity(); |
| 5351 | final int result = dispatchPointer(null, ev, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5352 | if (sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5353 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5354 | } |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5355 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5356 | switch (result) { |
| 5357 | case INJECT_NO_PERMISSION: |
| 5358 | throw new SecurityException( |
| 5359 | "Injecting to another application requires INJECT_EVENT permission"); |
| 5360 | case INJECT_SUCCEEDED: |
| 5361 | return true; |
| 5362 | } |
| 5363 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5364 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5365 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5366 | /** |
| 5367 | * Inject a trackball (navigation device) event into the UI. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5368 | * |
| 5369 | * @param ev A motion event describing the trackball action. (As noted in |
| 5370 | * {@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] | 5371 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5372 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5373 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5374 | */ |
| 5375 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5376 | final int pid = Binder.getCallingPid(); |
| 5377 | final int uid = Binder.getCallingUid(); |
| 5378 | final long ident = Binder.clearCallingIdentity(); |
| 5379 | final int result = dispatchTrackball(null, ev, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5380 | if (sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5381 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5382 | } |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5383 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5384 | switch (result) { |
| 5385 | case INJECT_NO_PERMISSION: |
| 5386 | throw new SecurityException( |
| 5387 | "Injecting to another application requires INJECT_EVENT permission"); |
| 5388 | case INJECT_SUCCEEDED: |
| 5389 | return true; |
| 5390 | } |
| 5391 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5392 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5393 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5394 | private WindowState getFocusedWindow() { |
| 5395 | synchronized (mWindowMap) { |
| 5396 | return getFocusedWindowLocked(); |
| 5397 | } |
| 5398 | } |
| 5399 | |
| 5400 | private WindowState getFocusedWindowLocked() { |
| 5401 | return mCurrentFocus; |
| 5402 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5403 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5404 | /** |
| 5405 | * This class holds the state for dispatching key events. This state |
| 5406 | * is protected by the KeyWaiter instance, NOT by the window lock. You |
| 5407 | * can be holding the main window lock while acquire the KeyWaiter lock, |
| 5408 | * but not the other way around. |
| 5409 | */ |
| 5410 | final class KeyWaiter { |
| 5411 | // NOSHIP debugging |
| 5412 | public class DispatchState { |
| 5413 | private KeyEvent event; |
| 5414 | private WindowState focus; |
| 5415 | private long time; |
| 5416 | private WindowState lastWin; |
| 5417 | private IBinder lastBinder; |
| 5418 | private boolean finished; |
| 5419 | private boolean gotFirstWindow; |
| 5420 | private boolean eventDispatching; |
| 5421 | private long timeToSwitch; |
| 5422 | private boolean wasFrozen; |
| 5423 | private boolean focusPaused; |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5424 | private WindowState curFocus; |
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 | DispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 5427 | focus = theFocus; |
| 5428 | event = theEvent; |
| 5429 | time = System.currentTimeMillis(); |
| 5430 | // snapshot KeyWaiter state |
| 5431 | lastWin = mLastWin; |
| 5432 | lastBinder = mLastBinder; |
| 5433 | finished = mFinished; |
| 5434 | gotFirstWindow = mGotFirstWindow; |
| 5435 | eventDispatching = mEventDispatching; |
| 5436 | timeToSwitch = mTimeToSwitch; |
| 5437 | wasFrozen = mWasFrozen; |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5438 | curFocus = mCurrentFocus; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5439 | // cache the paused state at ctor time as well |
| 5440 | if (theFocus == null || theFocus.mToken == null) { |
| 5441 | Log.i(TAG, "focus " + theFocus + " mToken is null at event dispatch!"); |
| 5442 | focusPaused = false; |
| 5443 | } else { |
| 5444 | focusPaused = theFocus.mToken.paused; |
| 5445 | } |
| 5446 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5447 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5448 | public String toString() { |
| 5449 | return "{{" + event + " to " + focus + " @ " + time |
| 5450 | + " lw=" + lastWin + " lb=" + lastBinder |
| 5451 | + " fin=" + finished + " gfw=" + gotFirstWindow |
| 5452 | + " ed=" + eventDispatching + " tts=" + timeToSwitch |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5453 | + " wf=" + wasFrozen + " fp=" + focusPaused |
| 5454 | + " mcf=" + mCurrentFocus + "}}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5455 | } |
| 5456 | }; |
| 5457 | private DispatchState mDispatchState = null; |
| 5458 | public void recordDispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 5459 | mDispatchState = new DispatchState(theEvent, theFocus); |
| 5460 | } |
| 5461 | // END NOSHIP |
| 5462 | |
| 5463 | public static final int RETURN_NOTHING = 0; |
| 5464 | public static final int RETURN_PENDING_POINTER = 1; |
| 5465 | public static final int RETURN_PENDING_TRACKBALL = 2; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5466 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5467 | final Object SKIP_TARGET_TOKEN = new Object(); |
| 5468 | final Object CONSUMED_EVENT_TOKEN = new Object(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5469 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5470 | private WindowState mLastWin = null; |
| 5471 | private IBinder mLastBinder = null; |
| 5472 | private boolean mFinished = true; |
| 5473 | private boolean mGotFirstWindow = false; |
| 5474 | private boolean mEventDispatching = true; |
| 5475 | private long mTimeToSwitch = 0; |
| 5476 | /* package */ boolean mWasFrozen = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5477 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5478 | // Target of Motion events |
| 5479 | WindowState mMotionTarget; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5480 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5481 | // Windows above the target who would like to receive an "outside" |
| 5482 | // touch event for any down events outside of them. |
| 5483 | WindowState mOutsideTouchTargets; |
| 5484 | |
| 5485 | /** |
| 5486 | * Wait for the last event dispatch to complete, then find the next |
| 5487 | * target that should receive the given event and wait for that one |
| 5488 | * to be ready to receive it. |
| 5489 | */ |
| 5490 | Object waitForNextEventTarget(KeyEvent nextKey, QueuedEvent qev, |
| 5491 | MotionEvent nextMotion, boolean isPointerEvent, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5492 | boolean failIfTimeout, int callingPid, int callingUid) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5493 | long startTime = SystemClock.uptimeMillis(); |
| 5494 | long keyDispatchingTimeout = 5 * 1000; |
| 5495 | long waitedFor = 0; |
| 5496 | |
| 5497 | while (true) { |
| 5498 | // Figure out which window we care about. It is either the |
| 5499 | // last window we are waiting to have process the event or, |
| 5500 | // if none, then the next window we think the event should go |
| 5501 | // to. Note: we retrieve mLastWin outside of the lock, so |
| 5502 | // it may change before we lock. Thus we must check it again. |
| 5503 | WindowState targetWin = mLastWin; |
| 5504 | boolean targetIsNew = targetWin == null; |
| 5505 | if (DEBUG_INPUT) Log.v( |
| 5506 | TAG, "waitForLastKey: mFinished=" + mFinished + |
| 5507 | ", mLastWin=" + mLastWin); |
| 5508 | if (targetIsNew) { |
| 5509 | Object target = findTargetWindow(nextKey, qev, nextMotion, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5510 | isPointerEvent, callingPid, callingUid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5511 | if (target == SKIP_TARGET_TOKEN) { |
| 5512 | // The user has pressed a special key, and we are |
| 5513 | // dropping all pending events before it. |
| 5514 | if (DEBUG_INPUT) Log.v(TAG, "Skipping: " + nextKey |
| 5515 | + " " + nextMotion); |
| 5516 | return null; |
| 5517 | } |
| 5518 | if (target == CONSUMED_EVENT_TOKEN) { |
| 5519 | if (DEBUG_INPUT) Log.v(TAG, "Consumed: " + nextKey |
| 5520 | + " " + nextMotion); |
| 5521 | return target; |
| 5522 | } |
| 5523 | targetWin = (WindowState)target; |
| 5524 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5525 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5526 | AppWindowToken targetApp = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5527 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5528 | // Now: is it okay to send the next event to this window? |
| 5529 | synchronized (this) { |
| 5530 | // First: did we come here based on the last window not |
| 5531 | // being null, but it changed by the time we got here? |
| 5532 | // If so, try again. |
| 5533 | if (!targetIsNew && mLastWin == null) { |
| 5534 | continue; |
| 5535 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5536 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5537 | // We never dispatch events if not finished with the |
| 5538 | // last one, or the display is frozen. |
| 5539 | if (mFinished && !mDisplayFrozen) { |
| 5540 | // If event dispatching is disabled, then we |
| 5541 | // just consume the events. |
| 5542 | if (!mEventDispatching) { |
| 5543 | if (DEBUG_INPUT) Log.v(TAG, |
| 5544 | "Skipping event; dispatching disabled: " |
| 5545 | + nextKey + " " + nextMotion); |
| 5546 | return null; |
| 5547 | } |
| 5548 | if (targetWin != null) { |
| 5549 | // If this is a new target, and that target is not |
| 5550 | // paused or unresponsive, then all looks good to |
| 5551 | // handle the event. |
| 5552 | if (targetIsNew && !targetWin.mToken.paused) { |
| 5553 | return targetWin; |
| 5554 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5555 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5556 | // If we didn't find a target window, and there is no |
| 5557 | // focused app window, then just eat the events. |
| 5558 | } else if (mFocusedApp == null) { |
| 5559 | if (DEBUG_INPUT) Log.v(TAG, |
| 5560 | "Skipping event; no focused app: " |
| 5561 | + nextKey + " " + nextMotion); |
| 5562 | return null; |
| 5563 | } |
| 5564 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5565 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5566 | if (DEBUG_INPUT) Log.v( |
| 5567 | TAG, "Waiting for last key in " + mLastBinder |
| 5568 | + " target=" + targetWin |
| 5569 | + " mFinished=" + mFinished |
| 5570 | + " mDisplayFrozen=" + mDisplayFrozen |
| 5571 | + " targetIsNew=" + targetIsNew |
| 5572 | + " paused=" |
| 5573 | + (targetWin != null ? targetWin.mToken.paused : false) |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5574 | + " mFocusedApp=" + mFocusedApp |
| 5575 | + " mCurrentFocus=" + mCurrentFocus); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5576 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5577 | targetApp = targetWin != null |
| 5578 | ? targetWin.mAppToken : mFocusedApp; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5579 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5580 | long curTimeout = keyDispatchingTimeout; |
| 5581 | if (mTimeToSwitch != 0) { |
| 5582 | long now = SystemClock.uptimeMillis(); |
| 5583 | if (mTimeToSwitch <= now) { |
| 5584 | // If an app switch key has been pressed, and we have |
| 5585 | // waited too long for the current app to finish |
| 5586 | // processing keys, then wait no more! |
| 5587 | doFinishedKeyLocked(true); |
| 5588 | continue; |
| 5589 | } |
| 5590 | long switchTimeout = mTimeToSwitch - now; |
| 5591 | if (curTimeout > switchTimeout) { |
| 5592 | curTimeout = switchTimeout; |
| 5593 | } |
| 5594 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5595 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5596 | try { |
| 5597 | // after that continue |
| 5598 | // processing keys, so we don't get stuck. |
| 5599 | if (DEBUG_INPUT) Log.v( |
| 5600 | TAG, "Waiting for key dispatch: " + curTimeout); |
| 5601 | wait(curTimeout); |
| 5602 | if (DEBUG_INPUT) Log.v(TAG, "Finished waiting @" |
| 5603 | + SystemClock.uptimeMillis() + " startTime=" |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5604 | + startTime + " switchTime=" + mTimeToSwitch |
| 5605 | + " target=" + targetWin + " mLW=" + mLastWin |
| 5606 | + " mLB=" + mLastBinder + " fin=" + mFinished |
| 5607 | + " mCurrentFocus=" + mCurrentFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5608 | } catch (InterruptedException e) { |
| 5609 | } |
| 5610 | } |
| 5611 | |
| 5612 | // If we were frozen during configuration change, restart the |
| 5613 | // timeout checks from now; otherwise look at whether we timed |
| 5614 | // out before awakening. |
| 5615 | if (mWasFrozen) { |
| 5616 | waitedFor = 0; |
| 5617 | mWasFrozen = false; |
| 5618 | } else { |
| 5619 | waitedFor = SystemClock.uptimeMillis() - startTime; |
| 5620 | } |
| 5621 | |
| 5622 | if (waitedFor >= keyDispatchingTimeout && mTimeToSwitch == 0) { |
| 5623 | IApplicationToken at = null; |
| 5624 | synchronized (this) { |
| 5625 | Log.w(TAG, "Key dispatching timed out sending to " + |
| 5626 | (targetWin != null ? targetWin.mAttrs.getTitle() |
| 5627 | : "<null>")); |
| 5628 | // NOSHIP debugging |
| 5629 | Log.w(TAG, "Dispatch state: " + mDispatchState); |
| 5630 | Log.w(TAG, "Current state: " + new DispatchState(nextKey, targetWin)); |
| 5631 | // END NOSHIP |
| 5632 | //dump(); |
| 5633 | if (targetWin != null) { |
| 5634 | at = targetWin.getAppToken(); |
| 5635 | } else if (targetApp != null) { |
| 5636 | at = targetApp.appToken; |
| 5637 | } |
| 5638 | } |
| 5639 | |
| 5640 | boolean abort = true; |
| 5641 | if (at != null) { |
| 5642 | try { |
| 5643 | long timeout = at.getKeyDispatchingTimeout(); |
| 5644 | if (timeout > waitedFor) { |
| 5645 | // we did not wait the proper amount of time for this application. |
| 5646 | // set the timeout to be the real timeout and wait again. |
| 5647 | keyDispatchingTimeout = timeout - waitedFor; |
| 5648 | continue; |
| 5649 | } else { |
| 5650 | abort = at.keyDispatchingTimedOut(); |
| 5651 | } |
| 5652 | } catch (RemoteException ex) { |
| 5653 | } |
| 5654 | } |
| 5655 | |
| 5656 | synchronized (this) { |
| 5657 | if (abort && (mLastWin == targetWin || targetWin == null)) { |
| 5658 | mFinished = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5659 | if (mLastWin != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5660 | if (DEBUG_INPUT) Log.v(TAG, |
| 5661 | "Window " + mLastWin + |
| 5662 | " timed out on key input"); |
| 5663 | if (mLastWin.mToken.paused) { |
| 5664 | Log.w(TAG, "Un-pausing dispatching to this window"); |
| 5665 | mLastWin.mToken.paused = false; |
| 5666 | } |
| 5667 | } |
| 5668 | if (mMotionTarget == targetWin) { |
| 5669 | mMotionTarget = null; |
| 5670 | } |
| 5671 | mLastWin = null; |
| 5672 | mLastBinder = null; |
| 5673 | if (failIfTimeout || targetWin == null) { |
| 5674 | return null; |
| 5675 | } |
| 5676 | } else { |
| 5677 | Log.w(TAG, "Continuing to wait for key to be dispatched"); |
| 5678 | startTime = SystemClock.uptimeMillis(); |
| 5679 | } |
| 5680 | } |
| 5681 | } |
| 5682 | } |
| 5683 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5684 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5685 | Object findTargetWindow(KeyEvent nextKey, QueuedEvent qev, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5686 | MotionEvent nextMotion, boolean isPointerEvent, |
| 5687 | int callingPid, int callingUid) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5688 | mOutsideTouchTargets = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5689 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5690 | if (nextKey != null) { |
| 5691 | // Find the target window for a normal key event. |
| 5692 | final int keycode = nextKey.getKeyCode(); |
| 5693 | final int repeatCount = nextKey.getRepeatCount(); |
| 5694 | final boolean down = nextKey.getAction() != KeyEvent.ACTION_UP; |
| 5695 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(keycode); |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5696 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5697 | if (!dispatch) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5698 | if (callingUid == 0 || |
| 5699 | mContext.checkPermission( |
| 5700 | android.Manifest.permission.INJECT_EVENTS, |
| 5701 | callingPid, callingUid) |
| 5702 | == PackageManager.PERMISSION_GRANTED) { |
| 5703 | mPolicy.interceptKeyTi(null, keycode, |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 5704 | nextKey.getMetaState(), down, repeatCount, |
| 5705 | nextKey.getFlags()); |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5706 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5707 | Log.w(TAG, "Event timeout during app switch: dropping " |
| 5708 | + nextKey); |
| 5709 | return SKIP_TARGET_TOKEN; |
| 5710 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5711 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5712 | // System.out.println("##### [" + SystemClock.uptimeMillis() + "] WindowManagerService.dispatchKey(" + keycode + ", " + down + ", " + repeatCount + ")"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5713 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5714 | WindowState focus = null; |
| 5715 | synchronized(mWindowMap) { |
| 5716 | focus = getFocusedWindowLocked(); |
| 5717 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5718 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5719 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5720 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5721 | if (callingUid == 0 || |
| 5722 | (focus != null && callingUid == focus.mSession.mUid) || |
| 5723 | mContext.checkPermission( |
| 5724 | android.Manifest.permission.INJECT_EVENTS, |
| 5725 | callingPid, callingUid) |
| 5726 | == PackageManager.PERMISSION_GRANTED) { |
| 5727 | if (mPolicy.interceptKeyTi(focus, |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 5728 | keycode, nextKey.getMetaState(), down, repeatCount, |
| 5729 | nextKey.getFlags())) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5730 | return CONSUMED_EVENT_TOKEN; |
| 5731 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5732 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5733 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5734 | return focus; |
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 | } else if (!isPointerEvent) { |
| 5737 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(-1); |
| 5738 | if (!dispatch) { |
| 5739 | Log.w(TAG, "Event timeout during app switch: dropping trackball " |
| 5740 | + nextMotion); |
| 5741 | return SKIP_TARGET_TOKEN; |
| 5742 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5743 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5744 | WindowState focus = null; |
| 5745 | synchronized(mWindowMap) { |
| 5746 | focus = getFocusedWindowLocked(); |
| 5747 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5748 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5749 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
| 5750 | return focus; |
| 5751 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5752 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5753 | if (nextMotion == null) { |
| 5754 | return SKIP_TARGET_TOKEN; |
| 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 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey( |
| 5758 | KeyEvent.KEYCODE_UNKNOWN); |
| 5759 | if (!dispatch) { |
| 5760 | Log.w(TAG, "Event timeout during app switch: dropping pointer " |
| 5761 | + nextMotion); |
| 5762 | return SKIP_TARGET_TOKEN; |
| 5763 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5764 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5765 | // Find the target window for a pointer event. |
| 5766 | int action = nextMotion.getAction(); |
| 5767 | final float xf = nextMotion.getX(); |
| 5768 | final float yf = nextMotion.getY(); |
| 5769 | final long eventTime = nextMotion.getEventTime(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5770 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5771 | final boolean screenWasOff = qev != null |
| 5772 | && (qev.flags&WindowManagerPolicy.FLAG_BRIGHT_HERE) != 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5773 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5774 | WindowState target = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5775 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5776 | synchronized(mWindowMap) { |
| 5777 | synchronized (this) { |
| 5778 | if (action == MotionEvent.ACTION_DOWN) { |
| 5779 | if (mMotionTarget != null) { |
| 5780 | // this is weird, we got a pen down, but we thought it was |
| 5781 | // already down! |
| 5782 | // XXX: We should probably send an ACTION_UP to the current |
| 5783 | // target. |
| 5784 | Log.w(TAG, "Pointer down received while already down in: " |
| 5785 | + mMotionTarget); |
| 5786 | mMotionTarget = null; |
| 5787 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5788 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5789 | // ACTION_DOWN is special, because we need to lock next events to |
| 5790 | // the window we'll land onto. |
| 5791 | final int x = (int)xf; |
| 5792 | final int y = (int)yf; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5793 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5794 | final ArrayList windows = mWindows; |
| 5795 | final int N = windows.size(); |
| 5796 | WindowState topErrWindow = null; |
| 5797 | final Rect tmpRect = mTempRect; |
| 5798 | for (int i=N-1; i>=0; i--) { |
| 5799 | WindowState child = (WindowState)windows.get(i); |
| 5800 | //Log.i(TAG, "Checking dispatch to: " + child); |
| 5801 | final int flags = child.mAttrs.flags; |
| 5802 | if ((flags & WindowManager.LayoutParams.FLAG_SYSTEM_ERROR) != 0) { |
| 5803 | if (topErrWindow == null) { |
| 5804 | topErrWindow = child; |
| 5805 | } |
| 5806 | } |
| 5807 | if (!child.isVisibleLw()) { |
| 5808 | //Log.i(TAG, "Not visible!"); |
| 5809 | continue; |
| 5810 | } |
| 5811 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 5812 | //Log.i(TAG, "Not touchable!"); |
| 5813 | if ((flags & WindowManager.LayoutParams |
| 5814 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 5815 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 5816 | mOutsideTouchTargets = child; |
| 5817 | } |
| 5818 | continue; |
| 5819 | } |
| 5820 | tmpRect.set(child.mFrame); |
| 5821 | if (child.mTouchableInsets == ViewTreeObserver |
| 5822 | .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) { |
| 5823 | // The touch is inside of the window if it is |
| 5824 | // inside the frame, AND the content part of that |
| 5825 | // frame that was given by the application. |
| 5826 | tmpRect.left += child.mGivenContentInsets.left; |
| 5827 | tmpRect.top += child.mGivenContentInsets.top; |
| 5828 | tmpRect.right -= child.mGivenContentInsets.right; |
| 5829 | tmpRect.bottom -= child.mGivenContentInsets.bottom; |
| 5830 | } else if (child.mTouchableInsets == ViewTreeObserver |
| 5831 | .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) { |
| 5832 | // The touch is inside of the window if it is |
| 5833 | // inside the frame, AND the visible part of that |
| 5834 | // frame that was given by the application. |
| 5835 | tmpRect.left += child.mGivenVisibleInsets.left; |
| 5836 | tmpRect.top += child.mGivenVisibleInsets.top; |
| 5837 | tmpRect.right -= child.mGivenVisibleInsets.right; |
| 5838 | tmpRect.bottom -= child.mGivenVisibleInsets.bottom; |
| 5839 | } |
| 5840 | final int touchFlags = flags & |
| 5841 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 5842 | |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 5843 | if (tmpRect.contains(x, y) || touchFlags == 0) { |
| 5844 | //Log.i(TAG, "Using this target!"); |
| 5845 | if (!screenWasOff || (flags & |
| 5846 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING) != 0) { |
| 5847 | mMotionTarget = child; |
| 5848 | } else { |
| 5849 | //Log.i(TAG, "Waking, skip!"); |
| 5850 | mMotionTarget = null; |
| 5851 | } |
| 5852 | break; |
| 5853 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5854 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5855 | if ((flags & WindowManager.LayoutParams |
| 5856 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 5857 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 5858 | mOutsideTouchTargets = child; |
| 5859 | //Log.i(TAG, "Adding to outside target list: " + child); |
| 5860 | } |
| 5861 | } |
| 5862 | |
| 5863 | // if there's an error window but it's not accepting |
| 5864 | // focus (typically because it is not yet visible) just |
| 5865 | // wait for it -- any other focused window may in fact |
| 5866 | // be in ANR state. |
| 5867 | if (topErrWindow != null && mMotionTarget != topErrWindow) { |
| 5868 | mMotionTarget = null; |
| 5869 | } |
| 5870 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5871 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5872 | target = mMotionTarget; |
| 5873 | } |
| 5874 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5875 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5876 | wakeupIfNeeded(target, eventType(nextMotion)); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5877 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5878 | // Pointer events are a little different -- if there isn't a |
| 5879 | // target found for any event, then just drop it. |
| 5880 | return target != null ? target : SKIP_TARGET_TOKEN; |
| 5881 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5882 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5883 | boolean checkShouldDispatchKey(int keycode) { |
| 5884 | synchronized (this) { |
| 5885 | if (mPolicy.isAppSwitchKeyTqTiLwLi(keycode)) { |
| 5886 | mTimeToSwitch = 0; |
| 5887 | return true; |
| 5888 | } |
| 5889 | if (mTimeToSwitch != 0 |
| 5890 | && mTimeToSwitch < SystemClock.uptimeMillis()) { |
| 5891 | return false; |
| 5892 | } |
| 5893 | return true; |
| 5894 | } |
| 5895 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5896 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5897 | void bindTargetWindowLocked(WindowState win, |
| 5898 | int pendingWhat, QueuedEvent pendingMotion) { |
| 5899 | synchronized (this) { |
| 5900 | bindTargetWindowLockedLocked(win, pendingWhat, pendingMotion); |
| 5901 | } |
| 5902 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5903 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5904 | void bindTargetWindowLocked(WindowState win) { |
| 5905 | synchronized (this) { |
| 5906 | bindTargetWindowLockedLocked(win, RETURN_NOTHING, null); |
| 5907 | } |
| 5908 | } |
| 5909 | |
| 5910 | void bindTargetWindowLockedLocked(WindowState win, |
| 5911 | int pendingWhat, QueuedEvent pendingMotion) { |
| 5912 | mLastWin = win; |
| 5913 | mLastBinder = win.mClient.asBinder(); |
| 5914 | mFinished = false; |
| 5915 | if (pendingMotion != null) { |
| 5916 | final Session s = win.mSession; |
| 5917 | if (pendingWhat == RETURN_PENDING_POINTER) { |
| 5918 | releasePendingPointerLocked(s); |
| 5919 | s.mPendingPointerMove = pendingMotion; |
| 5920 | s.mPendingPointerWindow = win; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5921 | if (DEBUG_INPUT) Log.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5922 | "bindTargetToWindow " + s.mPendingPointerMove); |
| 5923 | } else if (pendingWhat == RETURN_PENDING_TRACKBALL) { |
| 5924 | releasePendingTrackballLocked(s); |
| 5925 | s.mPendingTrackballMove = pendingMotion; |
| 5926 | s.mPendingTrackballWindow = win; |
| 5927 | } |
| 5928 | } |
| 5929 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5930 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5931 | void releasePendingPointerLocked(Session s) { |
| 5932 | if (DEBUG_INPUT) Log.v(TAG, |
| 5933 | "releasePendingPointer " + s.mPendingPointerMove); |
| 5934 | if (s.mPendingPointerMove != null) { |
| 5935 | mQueue.recycleEvent(s.mPendingPointerMove); |
| 5936 | s.mPendingPointerMove = null; |
| 5937 | } |
| 5938 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5939 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5940 | void releasePendingTrackballLocked(Session s) { |
| 5941 | if (s.mPendingTrackballMove != null) { |
| 5942 | mQueue.recycleEvent(s.mPendingTrackballMove); |
| 5943 | s.mPendingTrackballMove = null; |
| 5944 | } |
| 5945 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5946 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5947 | MotionEvent finishedKey(Session session, IWindow client, boolean force, |
| 5948 | int returnWhat) { |
| 5949 | if (DEBUG_INPUT) Log.v( |
| 5950 | TAG, "finishedKey: client=" + client + ", force=" + force); |
| 5951 | |
| 5952 | if (client == null) { |
| 5953 | return null; |
| 5954 | } |
| 5955 | |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5956 | MotionEvent res = null; |
| 5957 | QueuedEvent qev = null; |
| 5958 | WindowState win = null; |
| 5959 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5960 | synchronized (this) { |
| 5961 | if (DEBUG_INPUT) Log.v( |
| 5962 | TAG, "finishedKey: client=" + client.asBinder() |
| 5963 | + ", force=" + force + ", last=" + mLastBinder |
| 5964 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) + ")"); |
| 5965 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5966 | if (returnWhat == RETURN_PENDING_POINTER) { |
| 5967 | qev = session.mPendingPointerMove; |
| 5968 | win = session.mPendingPointerWindow; |
| 5969 | session.mPendingPointerMove = null; |
| 5970 | session.mPendingPointerWindow = null; |
| 5971 | } else if (returnWhat == RETURN_PENDING_TRACKBALL) { |
| 5972 | qev = session.mPendingTrackballMove; |
| 5973 | win = session.mPendingTrackballWindow; |
| 5974 | session.mPendingTrackballMove = null; |
| 5975 | session.mPendingTrackballWindow = null; |
| 5976 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5977 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5978 | if (mLastBinder == client.asBinder()) { |
| 5979 | if (DEBUG_INPUT) Log.v( |
| 5980 | TAG, "finishedKey: last paused=" |
| 5981 | + ((mLastWin != null) ? mLastWin.mToken.paused : "null")); |
| 5982 | if (mLastWin != null && (!mLastWin.mToken.paused || force |
| 5983 | || !mEventDispatching)) { |
| 5984 | doFinishedKeyLocked(false); |
| 5985 | } else { |
| 5986 | // Make sure to wake up anyone currently waiting to |
| 5987 | // dispatch a key, so they can re-evaluate their |
| 5988 | // current situation. |
| 5989 | mFinished = true; |
| 5990 | notifyAll(); |
| 5991 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5992 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5993 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5994 | if (qev != null) { |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5995 | res = (MotionEvent)qev.event; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5996 | if (DEBUG_INPUT) Log.v(TAG, |
| 5997 | "Returning pending motion: " + res); |
| 5998 | mQueue.recycleEvent(qev); |
| 5999 | if (win != null && returnWhat == RETURN_PENDING_POINTER) { |
| 6000 | res.offsetLocation(-win.mFrame.left, -win.mFrame.top); |
| 6001 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6002 | } |
Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 6003 | |
| 6004 | if (res != null && returnWhat == RETURN_PENDING_POINTER) { |
| 6005 | synchronized (mWindowMap) { |
| 6006 | if (mWallpaperTarget == win || mSendingPointersToWallpaper) { |
| 6007 | sendPointerToWallpaperLocked(win, res, res.getEventTime()); |
| 6008 | } |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6009 | } |
| 6010 | } |
| 6011 | } |
| 6012 | |
| 6013 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6014 | } |
| 6015 | |
| 6016 | void tickle() { |
| 6017 | synchronized (this) { |
| 6018 | notifyAll(); |
| 6019 | } |
| 6020 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6021 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6022 | void handleNewWindowLocked(WindowState newWindow) { |
| 6023 | if (!newWindow.canReceiveKeys()) { |
| 6024 | return; |
| 6025 | } |
| 6026 | synchronized (this) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6027 | if (DEBUG_INPUT) Log.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6028 | TAG, "New key dispatch window: win=" |
| 6029 | + newWindow.mClient.asBinder() |
| 6030 | + ", last=" + mLastBinder |
| 6031 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 6032 | + "), finished=" + mFinished + ", paused=" |
| 6033 | + newWindow.mToken.paused); |
| 6034 | |
| 6035 | // Displaying a window implicitly causes dispatching to |
| 6036 | // be unpaused. (This is to protect against bugs if someone |
| 6037 | // pauses dispatching but forgets to resume.) |
| 6038 | newWindow.mToken.paused = false; |
| 6039 | |
| 6040 | mGotFirstWindow = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6041 | |
| 6042 | if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) { |
| 6043 | if (DEBUG_INPUT) Log.v(TAG, |
| 6044 | "New SYSTEM_ERROR window; resetting state"); |
| 6045 | mLastWin = null; |
| 6046 | mLastBinder = null; |
| 6047 | mMotionTarget = null; |
| 6048 | mFinished = true; |
| 6049 | } else if (mLastWin != null) { |
| 6050 | // If the new window is above the window we are |
| 6051 | // waiting on, then stop waiting and let key dispatching |
| 6052 | // start on the new guy. |
| 6053 | if (DEBUG_INPUT) Log.v( |
| 6054 | TAG, "Last win layer=" + mLastWin.mLayer |
| 6055 | + ", new win layer=" + newWindow.mLayer); |
| 6056 | if (newWindow.mLayer >= mLastWin.mLayer) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6057 | // The new window is above the old; finish pending input to the last |
| 6058 | // window and start directing it to the new one. |
| 6059 | mLastWin.mToken.paused = false; |
| 6060 | doFinishedKeyLocked(true); // does a notifyAll() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6061 | } |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6062 | // Either the new window is lower, so there is no need to wake key waiters, |
| 6063 | // or we just finished key input to the previous window, which implicitly |
| 6064 | // notified the key waiters. In both cases, we don't need to issue the |
| 6065 | // notification here. |
| 6066 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6067 | } |
| 6068 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6069 | // Now that we've put a new window state in place, make the event waiter |
| 6070 | // take notice and retarget its attentions. |
| 6071 | notifyAll(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6072 | } |
| 6073 | } |
| 6074 | |
| 6075 | void pauseDispatchingLocked(WindowToken token) { |
| 6076 | synchronized (this) |
| 6077 | { |
| 6078 | if (DEBUG_INPUT) Log.v(TAG, "Pausing WindowToken " + token); |
| 6079 | token.paused = true; |
| 6080 | |
| 6081 | /* |
| 6082 | if (mLastWin != null && !mFinished && mLastWin.mBaseLayer <= layer) { |
| 6083 | mPaused = true; |
| 6084 | } else { |
| 6085 | if (mLastWin == null) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 6086 | 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] | 6087 | } else if (mFinished) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 6088 | 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] | 6089 | } else { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 6090 | 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] | 6091 | } |
| 6092 | } |
| 6093 | */ |
| 6094 | } |
| 6095 | } |
| 6096 | |
| 6097 | void resumeDispatchingLocked(WindowToken token) { |
| 6098 | synchronized (this) { |
| 6099 | if (token.paused) { |
| 6100 | if (DEBUG_INPUT) Log.v( |
| 6101 | TAG, "Resuming WindowToken " + token |
| 6102 | + ", last=" + mLastBinder |
| 6103 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 6104 | + "), finished=" + mFinished + ", paused=" |
| 6105 | + token.paused); |
| 6106 | token.paused = false; |
| 6107 | if (mLastWin != null && mLastWin.mToken == token && mFinished) { |
| 6108 | doFinishedKeyLocked(true); |
| 6109 | } else { |
| 6110 | notifyAll(); |
| 6111 | } |
| 6112 | } |
| 6113 | } |
| 6114 | } |
| 6115 | |
| 6116 | void setEventDispatchingLocked(boolean enabled) { |
| 6117 | synchronized (this) { |
| 6118 | mEventDispatching = enabled; |
| 6119 | notifyAll(); |
| 6120 | } |
| 6121 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6122 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6123 | void appSwitchComing() { |
| 6124 | synchronized (this) { |
| 6125 | // Don't wait for more than .5 seconds for app to finish |
| 6126 | // processing the pending events. |
| 6127 | long now = SystemClock.uptimeMillis() + 500; |
| 6128 | if (DEBUG_INPUT) Log.v(TAG, "appSwitchComing: " + now); |
| 6129 | if (mTimeToSwitch == 0 || now < mTimeToSwitch) { |
| 6130 | mTimeToSwitch = now; |
| 6131 | } |
| 6132 | notifyAll(); |
| 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 | private final void doFinishedKeyLocked(boolean doRecycle) { |
| 6137 | if (mLastWin != null) { |
| 6138 | releasePendingPointerLocked(mLastWin.mSession); |
| 6139 | releasePendingTrackballLocked(mLastWin.mSession); |
| 6140 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6141 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6142 | if (mLastWin == null || !mLastWin.mToken.paused |
| 6143 | || !mLastWin.isVisibleLw()) { |
| 6144 | // If the current window has been paused, we aren't -really- |
| 6145 | // finished... so let the waiters still wait. |
| 6146 | mLastWin = null; |
| 6147 | mLastBinder = null; |
| 6148 | } |
| 6149 | mFinished = true; |
| 6150 | notifyAll(); |
| 6151 | } |
| 6152 | } |
| 6153 | |
| 6154 | private class KeyQ extends KeyInputQueue |
| 6155 | implements KeyInputQueue.FilterCallback { |
| 6156 | PowerManager.WakeLock mHoldingScreen; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6157 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6158 | KeyQ() { |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 6159 | super(mContext, WindowManagerService.this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6160 | PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE); |
| 6161 | mHoldingScreen = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 6162 | "KEEP_SCREEN_ON_FLAG"); |
| 6163 | mHoldingScreen.setReferenceCounted(false); |
| 6164 | } |
| 6165 | |
| 6166 | @Override |
| 6167 | boolean preprocessEvent(InputDevice device, RawInputEvent event) { |
| 6168 | if (mPolicy.preprocessInputEventTq(event)) { |
| 6169 | return true; |
| 6170 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6171 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6172 | switch (event.type) { |
| 6173 | case RawInputEvent.EV_KEY: { |
| 6174 | // XXX begin hack |
| 6175 | if (DEBUG) { |
| 6176 | if (event.keycode == KeyEvent.KEYCODE_G) { |
| 6177 | if (event.value != 0) { |
| 6178 | // G down |
| 6179 | mPolicy.screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 6180 | } |
| 6181 | return false; |
| 6182 | } |
| 6183 | if (event.keycode == KeyEvent.KEYCODE_D) { |
| 6184 | if (event.value != 0) { |
| 6185 | //dump(); |
| 6186 | } |
| 6187 | return false; |
| 6188 | } |
| 6189 | } |
| 6190 | // XXX end hack |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6191 | |
Charles Mendis | 322591c | 2009-10-29 11:06:59 -0700 | [diff] [blame] | 6192 | boolean screenIsOff = !mPowerManager.isScreenOn(); |
| 6193 | boolean screenIsDim = !mPowerManager.isScreenBright(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6194 | int actions = mPolicy.interceptKeyTq(event, !screenIsOff); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6195 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6196 | if ((actions & WindowManagerPolicy.ACTION_GO_TO_SLEEP) != 0) { |
| 6197 | mPowerManager.goToSleep(event.when); |
| 6198 | } |
| 6199 | |
| 6200 | if (screenIsOff) { |
| 6201 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6202 | } |
| 6203 | if (screenIsDim) { |
| 6204 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6205 | } |
| 6206 | if ((actions & WindowManagerPolicy.ACTION_POKE_USER_ACTIVITY) != 0) { |
| 6207 | mPowerManager.userActivity(event.when, false, |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6208 | LocalPowerManager.BUTTON_EVENT, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6209 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6210 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6211 | if ((actions & WindowManagerPolicy.ACTION_PASS_TO_USER) != 0) { |
| 6212 | if (event.value != 0 && mPolicy.isAppSwitchKeyTqTiLwLi(event.keycode)) { |
| 6213 | filterQueue(this); |
| 6214 | mKeyWaiter.appSwitchComing(); |
| 6215 | } |
| 6216 | return true; |
| 6217 | } else { |
| 6218 | return false; |
| 6219 | } |
| 6220 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6221 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6222 | case RawInputEvent.EV_REL: { |
Charles Mendis | 322591c | 2009-10-29 11:06:59 -0700 | [diff] [blame] | 6223 | boolean screenIsOff = !mPowerManager.isScreenOn(); |
| 6224 | boolean screenIsDim = !mPowerManager.isScreenBright(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6225 | if (screenIsOff) { |
| 6226 | if (!mPolicy.isWakeRelMovementTq(event.deviceId, |
| 6227 | device.classes, event)) { |
| 6228 | //Log.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| 6229 | return false; |
| 6230 | } |
| 6231 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6232 | } |
| 6233 | if (screenIsDim) { |
| 6234 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6235 | } |
| 6236 | return true; |
| 6237 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6238 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6239 | case RawInputEvent.EV_ABS: { |
Charles Mendis | 322591c | 2009-10-29 11:06:59 -0700 | [diff] [blame] | 6240 | boolean screenIsOff = !mPowerManager.isScreenOn(); |
| 6241 | boolean screenIsDim = !mPowerManager.isScreenBright(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6242 | if (screenIsOff) { |
| 6243 | if (!mPolicy.isWakeAbsMovementTq(event.deviceId, |
| 6244 | device.classes, event)) { |
| 6245 | //Log.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| 6246 | return false; |
| 6247 | } |
| 6248 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6249 | } |
| 6250 | if (screenIsDim) { |
| 6251 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6252 | } |
| 6253 | return true; |
| 6254 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6255 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6256 | default: |
| 6257 | return true; |
| 6258 | } |
| 6259 | } |
| 6260 | |
| 6261 | public int filterEvent(QueuedEvent ev) { |
| 6262 | switch (ev.classType) { |
| 6263 | case RawInputEvent.CLASS_KEYBOARD: |
| 6264 | KeyEvent ke = (KeyEvent)ev.event; |
| 6265 | if (mPolicy.isMovementKeyTi(ke.getKeyCode())) { |
| 6266 | Log.w(TAG, "Dropping movement key during app switch: " |
| 6267 | + ke.getKeyCode() + ", action=" + ke.getAction()); |
| 6268 | return FILTER_REMOVE; |
| 6269 | } |
| 6270 | return FILTER_ABORT; |
| 6271 | default: |
| 6272 | return FILTER_KEEP; |
| 6273 | } |
| 6274 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6275 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6276 | /** |
| 6277 | * Must be called with the main window manager lock held. |
| 6278 | */ |
| 6279 | void setHoldScreenLocked(boolean holding) { |
| 6280 | boolean state = mHoldingScreen.isHeld(); |
| 6281 | if (holding != state) { |
| 6282 | if (holding) { |
| 6283 | mHoldingScreen.acquire(); |
| 6284 | } else { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6285 | mPolicy.screenOnStoppedLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6286 | mHoldingScreen.release(); |
| 6287 | } |
| 6288 | } |
| 6289 | } |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6290 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6291 | |
| 6292 | public boolean detectSafeMode() { |
| 6293 | mSafeMode = mPolicy.detectSafeMode(); |
| 6294 | return mSafeMode; |
| 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 | public void systemReady() { |
| 6298 | mPolicy.systemReady(); |
| 6299 | } |
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 | private final class InputDispatcherThread extends Thread { |
| 6302 | // Time to wait when there is nothing to do: 9999 seconds. |
| 6303 | static final int LONG_WAIT=9999*1000; |
| 6304 | |
| 6305 | public InputDispatcherThread() { |
| 6306 | super("InputDispatcher"); |
| 6307 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6308 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6309 | @Override |
| 6310 | public void run() { |
| 6311 | while (true) { |
| 6312 | try { |
| 6313 | process(); |
| 6314 | } catch (Exception e) { |
| 6315 | Log.e(TAG, "Exception in input dispatcher", e); |
| 6316 | } |
| 6317 | } |
| 6318 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6319 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6320 | private void process() { |
| 6321 | android.os.Process.setThreadPriority( |
| 6322 | android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6323 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6324 | // The last key event we saw |
| 6325 | KeyEvent lastKey = null; |
| 6326 | |
| 6327 | // Last keydown time for auto-repeating keys |
| 6328 | long lastKeyTime = SystemClock.uptimeMillis(); |
| 6329 | long nextKeyTime = lastKeyTime+LONG_WAIT; |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6330 | long downTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6331 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6332 | // How many successive repeats we generated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6333 | int keyRepeatCount = 0; |
| 6334 | |
| 6335 | // Need to report that configuration has changed? |
| 6336 | boolean configChanged = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6337 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6338 | while (true) { |
| 6339 | long curTime = SystemClock.uptimeMillis(); |
| 6340 | |
| 6341 | if (DEBUG_INPUT) Log.v( |
| 6342 | TAG, "Waiting for next key: now=" + curTime |
| 6343 | + ", repeat @ " + nextKeyTime); |
| 6344 | |
| 6345 | // Retrieve next event, waiting only as long as the next |
| 6346 | // repeat timeout. If the configuration has changed, then |
| 6347 | // don't wait at all -- we'll report the change as soon as |
| 6348 | // we have processed all events. |
| 6349 | QueuedEvent ev = mQueue.getEvent( |
| 6350 | (int)((!configChanged && curTime < nextKeyTime) |
| 6351 | ? (nextKeyTime-curTime) : 0)); |
| 6352 | |
| 6353 | if (DEBUG_INPUT && ev != null) Log.v( |
| 6354 | TAG, "Event: type=" + ev.classType + " data=" + ev.event); |
| 6355 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6356 | if (MEASURE_LATENCY) { |
| 6357 | lt.sample("2 got event ", System.nanoTime() - ev.whenNano); |
| 6358 | } |
| 6359 | |
Mike Lockwood | 3d0ea72 | 2009-10-21 22:58:29 -0400 | [diff] [blame] | 6360 | if (lastKey != null && !mPolicy.allowKeyRepeat()) { |
| 6361 | // cancel key repeat at the request of the policy. |
| 6362 | lastKey = null; |
| 6363 | downTime = 0; |
| 6364 | lastKeyTime = curTime; |
| 6365 | nextKeyTime = curTime + LONG_WAIT; |
| 6366 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6367 | try { |
| 6368 | if (ev != null) { |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6369 | curTime = SystemClock.uptimeMillis(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6370 | int eventType; |
| 6371 | if (ev.classType == RawInputEvent.CLASS_TOUCHSCREEN) { |
| 6372 | eventType = eventType((MotionEvent)ev.event); |
| 6373 | } else if (ev.classType == RawInputEvent.CLASS_KEYBOARD || |
| 6374 | ev.classType == RawInputEvent.CLASS_TRACKBALL) { |
| 6375 | eventType = LocalPowerManager.BUTTON_EVENT; |
| 6376 | } else { |
| 6377 | eventType = LocalPowerManager.OTHER_EVENT; |
| 6378 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6379 | try { |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6380 | if ((curTime - mLastBatteryStatsCallTime) |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6381 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6382 | mLastBatteryStatsCallTime = curTime; |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6383 | mBatteryStats.noteInputEvent(); |
| 6384 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6385 | } catch (RemoteException e) { |
| 6386 | // Ignore |
| 6387 | } |
Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 6388 | |
| 6389 | if (eventType != TOUCH_EVENT |
| 6390 | && eventType != LONG_TOUCH_EVENT |
| 6391 | && eventType != CHEEK_EVENT) { |
| 6392 | mPowerManager.userActivity(curTime, false, |
| 6393 | eventType, false); |
| 6394 | } else if (mLastTouchEventType != eventType |
| 6395 | || (curTime - mLastUserActivityCallTime) |
| 6396 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 6397 | mLastUserActivityCallTime = curTime; |
| 6398 | mLastTouchEventType = eventType; |
| 6399 | mPowerManager.userActivity(curTime, false, |
| 6400 | eventType, false); |
| 6401 | } |
| 6402 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6403 | switch (ev.classType) { |
| 6404 | case RawInputEvent.CLASS_KEYBOARD: |
| 6405 | KeyEvent ke = (KeyEvent)ev.event; |
| 6406 | if (ke.isDown()) { |
| 6407 | lastKey = ke; |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6408 | downTime = curTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6409 | keyRepeatCount = 0; |
| 6410 | lastKeyTime = curTime; |
| 6411 | nextKeyTime = lastKeyTime |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6412 | + ViewConfiguration.getLongPressTimeout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6413 | if (DEBUG_INPUT) Log.v( |
| 6414 | TAG, "Received key down: first repeat @ " |
| 6415 | + nextKeyTime); |
| 6416 | } else { |
| 6417 | lastKey = null; |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6418 | downTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6419 | // Arbitrary long timeout. |
| 6420 | lastKeyTime = curTime; |
| 6421 | nextKeyTime = curTime + LONG_WAIT; |
| 6422 | if (DEBUG_INPUT) Log.v( |
| 6423 | TAG, "Received key up: ignore repeat @ " |
| 6424 | + nextKeyTime); |
| 6425 | } |
| 6426 | dispatchKey((KeyEvent)ev.event, 0, 0); |
| 6427 | mQueue.recycleEvent(ev); |
| 6428 | break; |
| 6429 | case RawInputEvent.CLASS_TOUCHSCREEN: |
| 6430 | //Log.i(TAG, "Read next event " + ev); |
| 6431 | dispatchPointer(ev, (MotionEvent)ev.event, 0, 0); |
| 6432 | break; |
| 6433 | case RawInputEvent.CLASS_TRACKBALL: |
| 6434 | dispatchTrackball(ev, (MotionEvent)ev.event, 0, 0); |
| 6435 | break; |
| 6436 | case RawInputEvent.CLASS_CONFIGURATION_CHANGED: |
| 6437 | configChanged = true; |
| 6438 | break; |
| 6439 | default: |
| 6440 | mQueue.recycleEvent(ev); |
| 6441 | break; |
| 6442 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6443 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6444 | } else if (configChanged) { |
| 6445 | configChanged = false; |
| 6446 | sendNewConfiguration(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6447 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6448 | } else if (lastKey != null) { |
| 6449 | curTime = SystemClock.uptimeMillis(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6451 | // Timeout occurred while key was down. If it is at or |
| 6452 | // past the key repeat time, dispatch the repeat. |
| 6453 | if (DEBUG_INPUT) Log.v( |
| 6454 | TAG, "Key timeout: repeat=" + nextKeyTime |
| 6455 | + ", now=" + curTime); |
| 6456 | if (curTime < nextKeyTime) { |
| 6457 | continue; |
| 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 | lastKeyTime = nextKeyTime; |
| 6461 | nextKeyTime = nextKeyTime + KEY_REPEAT_DELAY; |
| 6462 | keyRepeatCount++; |
| 6463 | if (DEBUG_INPUT) Log.v( |
| 6464 | TAG, "Key repeat: count=" + keyRepeatCount |
| 6465 | + ", next @ " + nextKeyTime); |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6466 | KeyEvent newEvent; |
| 6467 | if (downTime != 0 && (downTime |
| 6468 | + ViewConfiguration.getLongPressTimeout()) |
| 6469 | <= curTime) { |
| 6470 | newEvent = KeyEvent.changeTimeRepeat(lastKey, |
| 6471 | curTime, keyRepeatCount, |
| 6472 | lastKey.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 6473 | downTime = 0; |
| 6474 | } else { |
| 6475 | newEvent = KeyEvent.changeTimeRepeat(lastKey, |
| 6476 | curTime, keyRepeatCount); |
| 6477 | } |
| 6478 | dispatchKey(newEvent, 0, 0); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6479 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6480 | } else { |
| 6481 | curTime = SystemClock.uptimeMillis(); |
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 | lastKeyTime = curTime; |
| 6484 | nextKeyTime = curTime + LONG_WAIT; |
| 6485 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6486 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6487 | } catch (Exception e) { |
| 6488 | Log.e(TAG, |
| 6489 | "Input thread received uncaught exception: " + e, e); |
| 6490 | } |
| 6491 | } |
| 6492 | } |
| 6493 | } |
| 6494 | |
| 6495 | // ------------------------------------------------------------- |
| 6496 | // Client Session State |
| 6497 | // ------------------------------------------------------------- |
| 6498 | |
| 6499 | private final class Session extends IWindowSession.Stub |
| 6500 | implements IBinder.DeathRecipient { |
| 6501 | final IInputMethodClient mClient; |
| 6502 | final IInputContext mInputContext; |
| 6503 | final int mUid; |
| 6504 | final int mPid; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6505 | final String mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6506 | SurfaceSession mSurfaceSession; |
| 6507 | int mNumWindow = 0; |
| 6508 | boolean mClientDead = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6509 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6510 | /** |
| 6511 | * Current pointer move event being dispatched to client window... must |
| 6512 | * hold key lock to access. |
| 6513 | */ |
| 6514 | QueuedEvent mPendingPointerMove; |
| 6515 | WindowState mPendingPointerWindow; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6516 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6517 | /** |
| 6518 | * Current trackball move event being dispatched to client window... must |
| 6519 | * hold key lock to access. |
| 6520 | */ |
| 6521 | QueuedEvent mPendingTrackballMove; |
| 6522 | WindowState mPendingTrackballWindow; |
| 6523 | |
| 6524 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 6525 | mClient = client; |
| 6526 | mInputContext = inputContext; |
| 6527 | mUid = Binder.getCallingUid(); |
| 6528 | mPid = Binder.getCallingPid(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6529 | StringBuilder sb = new StringBuilder(); |
| 6530 | sb.append("Session{"); |
| 6531 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 6532 | sb.append(" uid "); |
| 6533 | sb.append(mUid); |
| 6534 | sb.append("}"); |
| 6535 | mStringName = sb.toString(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6536 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6537 | synchronized (mWindowMap) { |
| 6538 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 6539 | IBinder b = ServiceManager.getService( |
| 6540 | Context.INPUT_METHOD_SERVICE); |
| 6541 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 6542 | } |
| 6543 | } |
| 6544 | long ident = Binder.clearCallingIdentity(); |
| 6545 | try { |
| 6546 | // Note: it is safe to call in to the input method manager |
| 6547 | // here because we are not holding our lock. |
| 6548 | if (mInputMethodManager != null) { |
| 6549 | mInputMethodManager.addClient(client, inputContext, |
| 6550 | mUid, mPid); |
| 6551 | } else { |
| 6552 | client.setUsingInputMethod(false); |
| 6553 | } |
| 6554 | client.asBinder().linkToDeath(this, 0); |
| 6555 | } catch (RemoteException e) { |
| 6556 | // The caller has died, so we can just forget about this. |
| 6557 | try { |
| 6558 | if (mInputMethodManager != null) { |
| 6559 | mInputMethodManager.removeClient(client); |
| 6560 | } |
| 6561 | } catch (RemoteException ee) { |
| 6562 | } |
| 6563 | } finally { |
| 6564 | Binder.restoreCallingIdentity(ident); |
| 6565 | } |
| 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 | @Override |
| 6569 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 6570 | throws RemoteException { |
| 6571 | try { |
| 6572 | return super.onTransact(code, data, reply, flags); |
| 6573 | } catch (RuntimeException e) { |
| 6574 | // Log all 'real' exceptions thrown to the caller |
| 6575 | if (!(e instanceof SecurityException)) { |
| 6576 | Log.e(TAG, "Window Session Crash", e); |
| 6577 | } |
| 6578 | throw e; |
| 6579 | } |
| 6580 | } |
| 6581 | |
| 6582 | public void binderDied() { |
| 6583 | // Note: it is safe to call in to the input method manager |
| 6584 | // here because we are not holding our lock. |
| 6585 | try { |
| 6586 | if (mInputMethodManager != null) { |
| 6587 | mInputMethodManager.removeClient(mClient); |
| 6588 | } |
| 6589 | } catch (RemoteException e) { |
| 6590 | } |
| 6591 | synchronized(mWindowMap) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 6592 | mClient.asBinder().unlinkToDeath(this, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6593 | mClientDead = true; |
| 6594 | killSessionLocked(); |
| 6595 | } |
| 6596 | } |
| 6597 | |
| 6598 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
| 6599 | int viewVisibility, Rect outContentInsets) { |
| 6600 | return addWindow(this, window, attrs, viewVisibility, outContentInsets); |
| 6601 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6602 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6603 | public void remove(IWindow window) { |
| 6604 | removeWindow(this, window); |
| 6605 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6606 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6607 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 6608 | int requestedWidth, int requestedHeight, int viewFlags, |
| 6609 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
| 6610 | Rect outVisibleInsets, Surface outSurface) { |
| 6611 | return relayoutWindow(this, window, attrs, |
| 6612 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
| 6613 | outFrame, outContentInsets, outVisibleInsets, outSurface); |
| 6614 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6615 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6616 | public void setTransparentRegion(IWindow window, Region region) { |
| 6617 | setTransparentRegionWindow(this, window, region); |
| 6618 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6619 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6620 | public void setInsets(IWindow window, int touchableInsets, |
| 6621 | Rect contentInsets, Rect visibleInsets) { |
| 6622 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 6623 | visibleInsets); |
| 6624 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6625 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6626 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 6627 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 6628 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6629 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6630 | public void finishDrawing(IWindow window) { |
| 6631 | if (localLOGV) Log.v( |
| 6632 | TAG, "IWindow finishDrawing called for " + window); |
| 6633 | finishDrawingWindow(this, window); |
| 6634 | } |
| 6635 | |
| 6636 | public void finishKey(IWindow window) { |
| 6637 | if (localLOGV) Log.v( |
| 6638 | TAG, "IWindow finishKey called for " + window); |
| 6639 | mKeyWaiter.finishedKey(this, window, false, |
| 6640 | KeyWaiter.RETURN_NOTHING); |
| 6641 | } |
| 6642 | |
| 6643 | public MotionEvent getPendingPointerMove(IWindow window) { |
| 6644 | if (localLOGV) Log.v( |
| 6645 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 6646 | return mKeyWaiter.finishedKey(this, window, false, |
| 6647 | KeyWaiter.RETURN_PENDING_POINTER); |
| 6648 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6649 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6650 | public MotionEvent getPendingTrackballMove(IWindow window) { |
| 6651 | if (localLOGV) Log.v( |
| 6652 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 6653 | return mKeyWaiter.finishedKey(this, window, false, |
| 6654 | KeyWaiter.RETURN_PENDING_TRACKBALL); |
| 6655 | } |
| 6656 | |
| 6657 | public void setInTouchMode(boolean mode) { |
| 6658 | synchronized(mWindowMap) { |
| 6659 | mInTouchMode = mode; |
| 6660 | } |
| 6661 | } |
| 6662 | |
| 6663 | public boolean getInTouchMode() { |
| 6664 | synchronized(mWindowMap) { |
| 6665 | return mInTouchMode; |
| 6666 | } |
| 6667 | } |
| 6668 | |
| 6669 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 6670 | boolean always) { |
| 6671 | synchronized(mWindowMap) { |
| 6672 | long ident = Binder.clearCallingIdentity(); |
| 6673 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6674 | return mPolicy.performHapticFeedbackLw( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6675 | windowForClientLocked(this, window), effectId, always); |
| 6676 | } finally { |
| 6677 | Binder.restoreCallingIdentity(ident); |
| 6678 | } |
| 6679 | } |
| 6680 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6681 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6682 | public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6683 | synchronized(mWindowMap) { |
| 6684 | long ident = Binder.clearCallingIdentity(); |
| 6685 | try { |
| 6686 | setWindowWallpaperPositionLocked(windowForClientLocked(this, window), |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6687 | x, y, xStep, yStep); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6688 | } finally { |
| 6689 | Binder.restoreCallingIdentity(ident); |
| 6690 | } |
| 6691 | } |
| 6692 | } |
| 6693 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6694 | public void wallpaperOffsetsComplete(IBinder window) { |
| 6695 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 6696 | } |
| 6697 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6698 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 6699 | int z, Bundle extras, boolean sync) { |
| 6700 | synchronized(mWindowMap) { |
| 6701 | long ident = Binder.clearCallingIdentity(); |
| 6702 | try { |
| 6703 | return sendWindowWallpaperCommandLocked( |
| 6704 | windowForClientLocked(this, window), |
| 6705 | action, x, y, z, extras, sync); |
| 6706 | } finally { |
| 6707 | Binder.restoreCallingIdentity(ident); |
| 6708 | } |
| 6709 | } |
| 6710 | } |
| 6711 | |
| 6712 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 6713 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 6714 | } |
| 6715 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6716 | void windowAddedLocked() { |
| 6717 | if (mSurfaceSession == null) { |
| 6718 | if (localLOGV) Log.v( |
| 6719 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 6720 | mSurfaceSession = new SurfaceSession(); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6721 | if (SHOW_TRANSACTIONS) Log.i( |
| 6722 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6723 | mSessions.add(this); |
| 6724 | } |
| 6725 | mNumWindow++; |
| 6726 | } |
| 6727 | |
| 6728 | void windowRemovedLocked() { |
| 6729 | mNumWindow--; |
| 6730 | killSessionLocked(); |
| 6731 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6732 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6733 | void killSessionLocked() { |
| 6734 | if (mNumWindow <= 0 && mClientDead) { |
| 6735 | mSessions.remove(this); |
| 6736 | if (mSurfaceSession != null) { |
| 6737 | if (localLOGV) Log.v( |
| 6738 | TAG, "Last window removed from " + this |
| 6739 | + ", destroying " + mSurfaceSession); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6740 | if (SHOW_TRANSACTIONS) Log.i( |
| 6741 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6742 | try { |
| 6743 | mSurfaceSession.kill(); |
| 6744 | } catch (Exception e) { |
| 6745 | Log.w(TAG, "Exception thrown when killing surface session " |
| 6746 | + mSurfaceSession + " in session " + this |
| 6747 | + ": " + e.toString()); |
| 6748 | } |
| 6749 | mSurfaceSession = null; |
| 6750 | } |
| 6751 | } |
| 6752 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6753 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6754 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6755 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 6756 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 6757 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
| 6758 | if (mPendingPointerWindow != null || mPendingPointerMove != null) { |
| 6759 | pw.print(prefix); |
| 6760 | pw.print("mPendingPointerWindow="); pw.print(mPendingPointerWindow); |
| 6761 | pw.print(" mPendingPointerMove="); pw.println(mPendingPointerMove); |
| 6762 | } |
| 6763 | if (mPendingTrackballWindow != null || mPendingTrackballMove != null) { |
| 6764 | pw.print(prefix); |
| 6765 | pw.print("mPendingTrackballWindow="); pw.print(mPendingTrackballWindow); |
| 6766 | pw.print(" mPendingTrackballMove="); pw.println(mPendingTrackballMove); |
| 6767 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6768 | } |
| 6769 | |
| 6770 | @Override |
| 6771 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6772 | return mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6773 | } |
| 6774 | } |
| 6775 | |
| 6776 | // ------------------------------------------------------------- |
| 6777 | // Client Window State |
| 6778 | // ------------------------------------------------------------- |
| 6779 | |
| 6780 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 6781 | final Session mSession; |
| 6782 | final IWindow mClient; |
| 6783 | WindowToken mToken; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6784 | WindowToken mRootToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6785 | AppWindowToken mAppToken; |
| 6786 | AppWindowToken mTargetAppToken; |
| 6787 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 6788 | final DeathRecipient mDeathRecipient; |
| 6789 | final WindowState mAttachedWindow; |
| 6790 | final ArrayList mChildWindows = new ArrayList(); |
| 6791 | final int mBaseLayer; |
| 6792 | final int mSubLayer; |
| 6793 | final boolean mLayoutAttached; |
| 6794 | final boolean mIsImWindow; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6795 | final boolean mIsWallpaper; |
| 6796 | final boolean mIsFloatingLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6797 | int mViewVisibility; |
| 6798 | boolean mPolicyVisibility = true; |
| 6799 | boolean mPolicyVisibilityAfterAnim = true; |
| 6800 | boolean mAppFreezing; |
| 6801 | Surface mSurface; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6802 | boolean mReportDestroySurface; |
| 6803 | boolean mSurfacePendingDestroy; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6804 | boolean mAttachedHidden; // is our parent window hidden? |
| 6805 | boolean mLastHidden; // was this window last hidden? |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6806 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6807 | int mRequestedWidth; |
| 6808 | int mRequestedHeight; |
| 6809 | int mLastRequestedWidth; |
| 6810 | int mLastRequestedHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6811 | int mLayer; |
| 6812 | int mAnimLayer; |
| 6813 | int mLastLayer; |
| 6814 | boolean mHaveFrame; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6815 | boolean mObscured; |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 6816 | boolean mTurnOnScreen; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6817 | |
| 6818 | WindowState mNextOutsideTouch; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6819 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6820 | // Actual frame shown on-screen (may be modified by animation) |
| 6821 | final Rect mShownFrame = new Rect(); |
| 6822 | final Rect mLastShownFrame = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6823 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6824 | /** |
| 6825 | * Insets that determine the actually visible area |
| 6826 | */ |
| 6827 | final Rect mVisibleInsets = new Rect(); |
| 6828 | final Rect mLastVisibleInsets = new Rect(); |
| 6829 | boolean mVisibleInsetsChanged; |
| 6830 | |
| 6831 | /** |
| 6832 | * Insets that are covered by system windows |
| 6833 | */ |
| 6834 | final Rect mContentInsets = new Rect(); |
| 6835 | final Rect mLastContentInsets = new Rect(); |
| 6836 | boolean mContentInsetsChanged; |
| 6837 | |
| 6838 | /** |
| 6839 | * Set to true if we are waiting for this window to receive its |
| 6840 | * given internal insets before laying out other windows based on it. |
| 6841 | */ |
| 6842 | boolean mGivenInsetsPending; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6843 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6844 | /** |
| 6845 | * These are the content insets that were given during layout for |
| 6846 | * this window, to be applied to windows behind it. |
| 6847 | */ |
| 6848 | final Rect mGivenContentInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6849 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6850 | /** |
| 6851 | * These are the visible insets that were given during layout for |
| 6852 | * this window, to be applied to windows behind it. |
| 6853 | */ |
| 6854 | final Rect mGivenVisibleInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6855 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6856 | /** |
| 6857 | * Flag indicating whether the touchable region should be adjusted by |
| 6858 | * the visible insets; if false the area outside the visible insets is |
| 6859 | * NOT touchable, so we must use those to adjust the frame during hit |
| 6860 | * tests. |
| 6861 | */ |
| 6862 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6863 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6864 | // Current transformation being applied. |
| 6865 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 6866 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 6867 | float mHScale=1, mVScale=1; |
| 6868 | float mLastHScale=1, mLastVScale=1; |
| 6869 | final Matrix mTmpMatrix = new Matrix(); |
| 6870 | |
| 6871 | // "Real" frame that the application sees. |
| 6872 | final Rect mFrame = new Rect(); |
| 6873 | final Rect mLastFrame = new Rect(); |
| 6874 | |
| 6875 | final Rect mContainingFrame = new Rect(); |
| 6876 | final Rect mDisplayFrame = new Rect(); |
| 6877 | final Rect mContentFrame = new Rect(); |
| 6878 | final Rect mVisibleFrame = new Rect(); |
| 6879 | |
| 6880 | float mShownAlpha = 1; |
| 6881 | float mAlpha = 1; |
| 6882 | float mLastAlpha = 1; |
| 6883 | |
| 6884 | // Set to true if, when the window gets displayed, it should perform |
| 6885 | // an enter animation. |
| 6886 | boolean mEnterAnimationPending; |
| 6887 | |
| 6888 | // Currently running animation. |
| 6889 | boolean mAnimating; |
| 6890 | boolean mLocalAnimating; |
| 6891 | Animation mAnimation; |
| 6892 | boolean mAnimationIsEntrance; |
| 6893 | boolean mHasTransformation; |
| 6894 | boolean mHasLocalTransformation; |
| 6895 | final Transformation mTransformation = new Transformation(); |
| 6896 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6897 | // If a window showing a wallpaper: the requested offset for the |
| 6898 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 6899 | float mWallpaperX = -1; |
| 6900 | float mWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6901 | |
| 6902 | // If a window showing a wallpaper: what fraction of the offset |
| 6903 | // range corresponds to a full virtual screen. |
| 6904 | float mWallpaperXStep = -1; |
| 6905 | float mWallpaperYStep = -1; |
| 6906 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6907 | // Wallpaper windows: pixels offset based on above variables. |
| 6908 | int mXOffset; |
| 6909 | int mYOffset; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6910 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6911 | // This is set after IWindowSession.relayout() has been called at |
| 6912 | // least once for the window. It allows us to detect the situation |
| 6913 | // where we don't yet have a surface, but should have one soon, so |
| 6914 | // we can give the window focus before waiting for the relayout. |
| 6915 | boolean mRelayoutCalled; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6916 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6917 | // This is set after the Surface has been created but before the |
| 6918 | // window has been drawn. During this time the surface is hidden. |
| 6919 | boolean mDrawPending; |
| 6920 | |
| 6921 | // This is set after the window has finished drawing for the first |
| 6922 | // time but before its surface is shown. The surface will be |
| 6923 | // displayed when the next layout is run. |
| 6924 | boolean mCommitDrawPending; |
| 6925 | |
| 6926 | // This is set during the time after the window's drawing has been |
| 6927 | // committed, and before its surface is actually shown. It is used |
| 6928 | // to delay showing the surface until all windows in a token are ready |
| 6929 | // to be shown. |
| 6930 | boolean mReadyToShow; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6931 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6932 | // Set when the window has been shown in the screen the first time. |
| 6933 | boolean mHasDrawn; |
| 6934 | |
| 6935 | // Currently running an exit animation? |
| 6936 | boolean mExiting; |
| 6937 | |
| 6938 | // Currently on the mDestroySurface list? |
| 6939 | boolean mDestroying; |
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 | // Completely remove from window manager after exit animation? |
| 6942 | boolean mRemoveOnExit; |
| 6943 | |
| 6944 | // Set when the orientation is changing and this window has not yet |
| 6945 | // been updated for the new orientation. |
| 6946 | boolean mOrientationChanging; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6947 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6948 | // Is this window now (or just being) removed? |
| 6949 | boolean mRemoved; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6950 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6951 | WindowState(Session s, IWindow c, WindowToken token, |
| 6952 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 6953 | int viewVisibility) { |
| 6954 | mSession = s; |
| 6955 | mClient = c; |
| 6956 | mToken = token; |
| 6957 | mAttrs.copyFrom(a); |
| 6958 | mViewVisibility = viewVisibility; |
| 6959 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 6960 | mAlpha = a.alpha; |
| 6961 | if (localLOGV) Log.v( |
| 6962 | TAG, "Window " + this + " client=" + c.asBinder() |
| 6963 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 6964 | try { |
| 6965 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 6966 | } catch (RemoteException e) { |
| 6967 | mDeathRecipient = null; |
| 6968 | mAttachedWindow = null; |
| 6969 | mLayoutAttached = false; |
| 6970 | mIsImWindow = false; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6971 | mIsWallpaper = false; |
| 6972 | mIsFloatingLayer = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6973 | mBaseLayer = 0; |
| 6974 | mSubLayer = 0; |
| 6975 | return; |
| 6976 | } |
| 6977 | mDeathRecipient = deathRecipient; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6978 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6979 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 6980 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 6981 | // The multiplier here is to reserve space for multiple |
| 6982 | // windows in the same type layer. |
| 6983 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 6984 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 6985 | + TYPE_LAYER_OFFSET; |
| 6986 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 6987 | mAttachedWindow = attachedWindow; |
| 6988 | mAttachedWindow.mChildWindows.add(this); |
| 6989 | mLayoutAttached = mAttrs.type != |
| 6990 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 6991 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 6992 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6993 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 6994 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6995 | } else { |
| 6996 | // The multiplier here is to reserve space for multiple |
| 6997 | // windows in the same type layer. |
| 6998 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 6999 | * TYPE_LAYER_MULTIPLIER |
| 7000 | + TYPE_LAYER_OFFSET; |
| 7001 | mSubLayer = 0; |
| 7002 | mAttachedWindow = null; |
| 7003 | mLayoutAttached = false; |
| 7004 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 7005 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7006 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 7007 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7008 | } |
| 7009 | |
| 7010 | WindowState appWin = this; |
| 7011 | while (appWin.mAttachedWindow != null) { |
| 7012 | appWin = mAttachedWindow; |
| 7013 | } |
| 7014 | WindowToken appToken = appWin.mToken; |
| 7015 | while (appToken.appWindowToken == null) { |
| 7016 | WindowToken parent = mTokenMap.get(appToken.token); |
| 7017 | if (parent == null || appToken == parent) { |
| 7018 | break; |
| 7019 | } |
| 7020 | appToken = parent; |
| 7021 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7022 | mRootToken = appToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7023 | mAppToken = appToken.appWindowToken; |
| 7024 | |
| 7025 | mSurface = null; |
| 7026 | mRequestedWidth = 0; |
| 7027 | mRequestedHeight = 0; |
| 7028 | mLastRequestedWidth = 0; |
| 7029 | mLastRequestedHeight = 0; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7030 | mXOffset = 0; |
| 7031 | mYOffset = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7032 | mLayer = 0; |
| 7033 | mAnimLayer = 0; |
| 7034 | mLastLayer = 0; |
| 7035 | } |
| 7036 | |
| 7037 | void attach() { |
| 7038 | if (localLOGV) Log.v( |
| 7039 | TAG, "Attaching " + this + " token=" + mToken |
| 7040 | + ", list=" + mToken.windows); |
| 7041 | mSession.windowAddedLocked(); |
| 7042 | } |
| 7043 | |
| 7044 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 7045 | mHaveFrame = true; |
| 7046 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7047 | final Rect container = mContainingFrame; |
| 7048 | container.set(pf); |
| 7049 | |
| 7050 | final Rect display = mDisplayFrame; |
| 7051 | display.set(df); |
| 7052 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7053 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7054 | container.intersect(mCompatibleScreenFrame); |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7055 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 7056 | display.intersect(mCompatibleScreenFrame); |
| 7057 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7058 | } |
| 7059 | |
| 7060 | final int pw = container.right - container.left; |
| 7061 | final int ph = container.bottom - container.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7062 | |
| 7063 | int w,h; |
| 7064 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 7065 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 7066 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 7067 | } else { |
| 7068 | w = mAttrs.width == mAttrs.FILL_PARENT ? pw : mRequestedWidth; |
| 7069 | h = mAttrs.height== mAttrs.FILL_PARENT ? ph : mRequestedHeight; |
| 7070 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7071 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7072 | final Rect content = mContentFrame; |
| 7073 | content.set(cf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7074 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7075 | final Rect visible = mVisibleFrame; |
| 7076 | visible.set(vf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7077 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7078 | final Rect frame = mFrame; |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7079 | final int fw = frame.width(); |
| 7080 | final int fh = frame.height(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7081 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7082 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 7083 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 7084 | |
| 7085 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 7086 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 7087 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 7088 | |
| 7089 | //System.out.println("Out: " + mFrame); |
| 7090 | |
| 7091 | // Now make sure the window fits in the overall display. |
| 7092 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7093 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7094 | // Make sure the content and visible frames are inside of the |
| 7095 | // final window frame. |
| 7096 | if (content.left < frame.left) content.left = frame.left; |
| 7097 | if (content.top < frame.top) content.top = frame.top; |
| 7098 | if (content.right > frame.right) content.right = frame.right; |
| 7099 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 7100 | if (visible.left < frame.left) visible.left = frame.left; |
| 7101 | if (visible.top < frame.top) visible.top = frame.top; |
| 7102 | if (visible.right > frame.right) visible.right = frame.right; |
| 7103 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7104 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7105 | final Rect contentInsets = mContentInsets; |
| 7106 | contentInsets.left = content.left-frame.left; |
| 7107 | contentInsets.top = content.top-frame.top; |
| 7108 | contentInsets.right = frame.right-content.right; |
| 7109 | contentInsets.bottom = frame.bottom-content.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7110 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7111 | final Rect visibleInsets = mVisibleInsets; |
| 7112 | visibleInsets.left = visible.left-frame.left; |
| 7113 | visibleInsets.top = visible.top-frame.top; |
| 7114 | visibleInsets.right = frame.right-visible.right; |
| 7115 | visibleInsets.bottom = frame.bottom-visible.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7116 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 7117 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 7118 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 7119 | mDisplay.getHeight(), false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7120 | } |
| 7121 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7122 | if (localLOGV) { |
| 7123 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 7124 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
| 7125 | Log.v(TAG, "Resolving (mRequestedWidth=" |
| 7126 | + mRequestedWidth + ", mRequestedheight=" |
| 7127 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 7128 | + "): frame=" + mFrame.toShortString() |
| 7129 | + " ci=" + contentInsets.toShortString() |
| 7130 | + " vi=" + visibleInsets.toShortString()); |
| 7131 | //} |
| 7132 | } |
| 7133 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7134 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7135 | public Rect getFrameLw() { |
| 7136 | return mFrame; |
| 7137 | } |
| 7138 | |
| 7139 | public Rect getShownFrameLw() { |
| 7140 | return mShownFrame; |
| 7141 | } |
| 7142 | |
| 7143 | public Rect getDisplayFrameLw() { |
| 7144 | return mDisplayFrame; |
| 7145 | } |
| 7146 | |
| 7147 | public Rect getContentFrameLw() { |
| 7148 | return mContentFrame; |
| 7149 | } |
| 7150 | |
| 7151 | public Rect getVisibleFrameLw() { |
| 7152 | return mVisibleFrame; |
| 7153 | } |
| 7154 | |
| 7155 | public boolean getGivenInsetsPendingLw() { |
| 7156 | return mGivenInsetsPending; |
| 7157 | } |
| 7158 | |
| 7159 | public Rect getGivenContentInsetsLw() { |
| 7160 | return mGivenContentInsets; |
| 7161 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7162 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7163 | public Rect getGivenVisibleInsetsLw() { |
| 7164 | return mGivenVisibleInsets; |
| 7165 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7166 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7167 | public WindowManager.LayoutParams getAttrs() { |
| 7168 | return mAttrs; |
| 7169 | } |
| 7170 | |
| 7171 | public int getSurfaceLayer() { |
| 7172 | return mLayer; |
| 7173 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7174 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7175 | public IApplicationToken getAppToken() { |
| 7176 | return mAppToken != null ? mAppToken.appToken : null; |
| 7177 | } |
| 7178 | |
| 7179 | public boolean hasAppShownWindows() { |
| 7180 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 7181 | } |
| 7182 | |
| 7183 | public boolean hasAppStartingIcon() { |
| 7184 | return mAppToken != null ? (mAppToken.startingData != null) : false; |
| 7185 | } |
| 7186 | |
| 7187 | public WindowManagerPolicy.WindowState getAppStartingWindow() { |
| 7188 | return mAppToken != null ? mAppToken.startingWindow : null; |
| 7189 | } |
| 7190 | |
| 7191 | public void setAnimation(Animation anim) { |
| 7192 | if (localLOGV) Log.v( |
| 7193 | TAG, "Setting animation in " + this + ": " + anim); |
| 7194 | mAnimating = false; |
| 7195 | mLocalAnimating = false; |
| 7196 | mAnimation = anim; |
| 7197 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 7198 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 7199 | } |
| 7200 | |
| 7201 | public void clearAnimation() { |
| 7202 | if (mAnimation != null) { |
| 7203 | mAnimating = true; |
| 7204 | mLocalAnimating = false; |
| 7205 | mAnimation = null; |
| 7206 | } |
| 7207 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7208 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7209 | Surface createSurfaceLocked() { |
| 7210 | if (mSurface == null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7211 | mReportDestroySurface = false; |
| 7212 | mSurfacePendingDestroy = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7213 | mDrawPending = true; |
| 7214 | mCommitDrawPending = false; |
| 7215 | mReadyToShow = false; |
| 7216 | if (mAppToken != null) { |
| 7217 | mAppToken.allDrawn = false; |
| 7218 | } |
| 7219 | |
| 7220 | int flags = 0; |
Mathias Agopian | 317a628 | 2009-08-13 17:29:02 -0700 | [diff] [blame] | 7221 | if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7222 | flags |= Surface.PUSH_BUFFERS; |
| 7223 | } |
| 7224 | |
| 7225 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 7226 | flags |= Surface.SECURE; |
| 7227 | } |
| 7228 | if (DEBUG_VISIBILITY) Log.v( |
| 7229 | TAG, "Creating surface in session " |
| 7230 | + mSession.mSurfaceSession + " window " + this |
| 7231 | + " w=" + mFrame.width() |
| 7232 | + " h=" + mFrame.height() + " format=" |
| 7233 | + mAttrs.format + " flags=" + flags); |
| 7234 | |
| 7235 | int w = mFrame.width(); |
| 7236 | int h = mFrame.height(); |
| 7237 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 7238 | // for a scaled surface, we always want the requested |
| 7239 | // size. |
| 7240 | w = mRequestedWidth; |
| 7241 | h = mRequestedHeight; |
| 7242 | } |
| 7243 | |
Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 7244 | // Something is wrong and SurfaceFlinger will not like this, |
| 7245 | // try to revert to sane values |
| 7246 | if (w <= 0) w = 1; |
| 7247 | if (h <= 0) h = 1; |
| 7248 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7249 | try { |
| 7250 | mSurface = new Surface( |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7251 | mSession.mSurfaceSession, mSession.mPid, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7252 | 0, w, h, mAttrs.format, flags); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7253 | if (SHOW_TRANSACTIONS) Log.i(TAG, " CREATE SURFACE " |
| 7254 | + mSurface + " IN SESSION " |
| 7255 | + mSession.mSurfaceSession |
| 7256 | + ": pid=" + mSession.mPid + " format=" |
| 7257 | + mAttrs.format + " flags=0x" |
| 7258 | + Integer.toHexString(flags)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7259 | } catch (Surface.OutOfResourcesException e) { |
| 7260 | Log.w(TAG, "OutOfResourcesException creating surface"); |
| 7261 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 7262 | return null; |
| 7263 | } catch (Exception e) { |
| 7264 | Log.e(TAG, "Exception creating surface", e); |
| 7265 | return null; |
| 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 (localLOGV) Log.v( |
| 7269 | TAG, "Got surface: " + mSurface |
| 7270 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 7271 | + ", animLayer=" + mAnimLayer); |
| 7272 | if (SHOW_TRANSACTIONS) { |
| 7273 | Log.i(TAG, ">>> OPEN TRANSACTION"); |
| 7274 | Log.i(TAG, " SURFACE " + mSurface + ": CREATE (" |
| 7275 | + mAttrs.getTitle() + ") pos=(" + |
| 7276 | mFrame.left + "," + mFrame.top + ") (" + |
| 7277 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 7278 | mAnimLayer + " HIDE"); |
| 7279 | } |
| 7280 | Surface.openTransaction(); |
| 7281 | try { |
| 7282 | try { |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7283 | mSurface.setPosition(mFrame.left + mXOffset, |
| 7284 | mFrame.top + mYOffset); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7285 | mSurface.setLayer(mAnimLayer); |
| 7286 | mSurface.hide(); |
| 7287 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7288 | if (SHOW_TRANSACTIONS) Log.i(TAG, " SURFACE " |
| 7289 | + mSurface + ": DITHER"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7290 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 7291 | Surface.SURFACE_DITHER); |
| 7292 | } |
| 7293 | } catch (RuntimeException e) { |
| 7294 | Log.w(TAG, "Error creating surface in " + w, e); |
| 7295 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 7296 | } |
| 7297 | mLastHidden = true; |
| 7298 | } finally { |
| 7299 | if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION"); |
| 7300 | Surface.closeTransaction(); |
| 7301 | } |
| 7302 | if (localLOGV) Log.v( |
| 7303 | TAG, "Created surface " + this); |
| 7304 | } |
| 7305 | return mSurface; |
| 7306 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7307 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7308 | void destroySurfaceLocked() { |
| 7309 | // Window is no longer on-screen, so can no longer receive |
| 7310 | // key events... if we were waiting for it to finish |
| 7311 | // handling a key event, the wait is over! |
| 7312 | mKeyWaiter.finishedKey(mSession, mClient, true, |
| 7313 | KeyWaiter.RETURN_NOTHING); |
| 7314 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 7315 | mKeyWaiter.releasePendingTrackballLocked(mSession); |
| 7316 | |
| 7317 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 7318 | mAppToken.startingDisplayed = false; |
| 7319 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7320 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7321 | if (mSurface != null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7322 | mDrawPending = false; |
| 7323 | mCommitDrawPending = false; |
| 7324 | mReadyToShow = false; |
| 7325 | |
| 7326 | int i = mChildWindows.size(); |
| 7327 | while (i > 0) { |
| 7328 | i--; |
| 7329 | WindowState c = (WindowState)mChildWindows.get(i); |
| 7330 | c.mAttachedHidden = true; |
| 7331 | } |
| 7332 | |
| 7333 | if (mReportDestroySurface) { |
| 7334 | mReportDestroySurface = false; |
| 7335 | mSurfacePendingDestroy = true; |
| 7336 | try { |
| 7337 | mClient.dispatchGetNewSurface(); |
| 7338 | // We'll really destroy on the next time around. |
| 7339 | return; |
| 7340 | } catch (RemoteException e) { |
| 7341 | } |
| 7342 | } |
| 7343 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7344 | try { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7345 | if (DEBUG_VISIBILITY) { |
| 7346 | RuntimeException e = new RuntimeException(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7347 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7348 | Log.w(TAG, "Window " + this + " destroying surface " |
| 7349 | + mSurface + ", session " + mSession, e); |
| 7350 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7351 | if (SHOW_TRANSACTIONS) { |
| 7352 | RuntimeException ex = new RuntimeException(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7353 | if (!HIDE_STACK_CRAWLS) ex.fillInStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7354 | Log.i(TAG, " SURFACE " + mSurface + ": DESTROY (" |
| 7355 | + mAttrs.getTitle() + ")", ex); |
| 7356 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7357 | mSurface.destroy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7358 | } catch (RuntimeException e) { |
| 7359 | Log.w(TAG, "Exception thrown when destroying Window " + this |
| 7360 | + " surface " + mSurface + " session " + mSession |
| 7361 | + ": " + e.toString()); |
| 7362 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7363 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7364 | mSurface = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7365 | } |
| 7366 | } |
| 7367 | |
| 7368 | boolean finishDrawingLocked() { |
| 7369 | if (mDrawPending) { |
| 7370 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Log.v( |
| 7371 | TAG, "finishDrawingLocked: " + mSurface); |
| 7372 | mCommitDrawPending = true; |
| 7373 | mDrawPending = false; |
| 7374 | return true; |
| 7375 | } |
| 7376 | return false; |
| 7377 | } |
| 7378 | |
| 7379 | // This must be called while inside a transaction. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7380 | boolean commitFinishDrawingLocked(long currentTime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7381 | //Log.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
| 7382 | if (!mCommitDrawPending) { |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7383 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7384 | } |
| 7385 | mCommitDrawPending = false; |
| 7386 | mReadyToShow = true; |
| 7387 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 7388 | final AppWindowToken atoken = mAppToken; |
| 7389 | if (atoken == null || atoken.allDrawn || starting) { |
| 7390 | performShowLocked(); |
| 7391 | } |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7392 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7393 | } |
| 7394 | |
| 7395 | // This must be called while inside a transaction. |
| 7396 | boolean performShowLocked() { |
| 7397 | if (DEBUG_VISIBILITY) { |
| 7398 | RuntimeException e = new RuntimeException(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7399 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7400 | Log.v(TAG, "performShow on " + this |
| 7401 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 7402 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 7403 | } |
| 7404 | if (mReadyToShow && isReadyForDisplay()) { |
| 7405 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Log.i( |
| 7406 | TAG, " SURFACE " + mSurface + ": SHOW (performShowLocked)"); |
| 7407 | if (DEBUG_VISIBILITY) Log.v(TAG, "Showing " + this |
| 7408 | + " during animation: policyVis=" + mPolicyVisibility |
| 7409 | + " attHidden=" + mAttachedHidden |
| 7410 | + " tok.hiddenRequested=" |
| 7411 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7412 | + " tok.hidden=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7413 | + (mAppToken != null ? mAppToken.hidden : false) |
| 7414 | + " animating=" + mAnimating |
| 7415 | + " tok animating=" |
| 7416 | + (mAppToken != null ? mAppToken.animating : false)); |
| 7417 | if (!showSurfaceRobustlyLocked(this)) { |
| 7418 | return false; |
| 7419 | } |
| 7420 | mLastAlpha = -1; |
| 7421 | mHasDrawn = true; |
| 7422 | mLastHidden = false; |
| 7423 | mReadyToShow = false; |
| 7424 | enableScreenIfNeededLocked(); |
| 7425 | |
| 7426 | applyEnterAnimationLocked(this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7427 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7428 | int i = mChildWindows.size(); |
| 7429 | while (i > 0) { |
| 7430 | i--; |
| 7431 | WindowState c = (WindowState)mChildWindows.get(i); |
| 7432 | if (c.mSurface != null && c.mAttachedHidden) { |
| 7433 | c.mAttachedHidden = false; |
| 7434 | c.performShowLocked(); |
| 7435 | } |
| 7436 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7437 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7438 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 7439 | && mAppToken != null) { |
| 7440 | mAppToken.firstWindowDrawn = true; |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7441 | |
| 7442 | if (mAppToken.startingData != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7443 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Log.v(TAG, |
| 7444 | "Finish starting " + mToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7445 | + ": first real window is shown, no animation"); |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7446 | // If this initial window is animating, stop it -- we |
| 7447 | // will do an animation to reveal it from behind the |
| 7448 | // starting window, so there is no need for it to also |
| 7449 | // be doing its own stuff. |
| 7450 | if (mAnimation != null) { |
| 7451 | mAnimation = null; |
| 7452 | // Make sure we clean up the animation. |
| 7453 | mAnimating = true; |
| 7454 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7455 | mFinishedStarting.add(mAppToken); |
| 7456 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7457 | } |
| 7458 | mAppToken.updateReportedVisibilityLocked(); |
| 7459 | } |
| 7460 | } |
| 7461 | return true; |
| 7462 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7463 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7464 | // This must be called while inside a transaction. Returns true if |
| 7465 | // there is more animation to run. |
| 7466 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| 7467 | if (!mDisplayFrozen) { |
| 7468 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7469 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7470 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 7471 | mHasTransformation = true; |
| 7472 | mHasLocalTransformation = true; |
| 7473 | if (!mLocalAnimating) { |
| 7474 | if (DEBUG_ANIM) Log.v( |
| 7475 | TAG, "Starting animation in " + this + |
| 7476 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 7477 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 7478 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 7479 | mAnimation.setStartTime(currentTime); |
| 7480 | mLocalAnimating = true; |
| 7481 | mAnimating = true; |
| 7482 | } |
| 7483 | mTransformation.clear(); |
| 7484 | final boolean more = mAnimation.getTransformation( |
| 7485 | currentTime, mTransformation); |
| 7486 | if (DEBUG_ANIM) Log.v( |
| 7487 | TAG, "Stepped animation in " + this + |
| 7488 | ": more=" + more + ", xform=" + mTransformation); |
| 7489 | if (more) { |
| 7490 | // we're not done! |
| 7491 | return true; |
| 7492 | } |
| 7493 | if (DEBUG_ANIM) Log.v( |
| 7494 | TAG, "Finished animation in " + this + |
| 7495 | " @ " + currentTime); |
| 7496 | mAnimation = null; |
| 7497 | //WindowManagerService.this.dump(); |
| 7498 | } |
| 7499 | mHasLocalTransformation = false; |
| 7500 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7501 | && mAppToken.animation != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7502 | // When our app token is animating, we kind-of pretend like |
| 7503 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 7504 | // part of this check means that we will only do this if |
| 7505 | // our window is not currently exiting, or it is not |
| 7506 | // locally animating itself. The idea being that one that |
| 7507 | // is exiting and doing a local animation should be removed |
| 7508 | // once that animation is done. |
| 7509 | mAnimating = true; |
| 7510 | mHasTransformation = true; |
| 7511 | mTransformation.clear(); |
| 7512 | return false; |
| 7513 | } else if (mHasTransformation) { |
| 7514 | // Little trick to get through the path below to act like |
| 7515 | // we have finished an animation. |
| 7516 | mAnimating = true; |
| 7517 | } else if (isAnimating()) { |
| 7518 | mAnimating = true; |
| 7519 | } |
| 7520 | } else if (mAnimation != null) { |
| 7521 | // If the display is frozen, and there is a pending animation, |
| 7522 | // clear it and make sure we run the cleanup code. |
| 7523 | mAnimating = true; |
| 7524 | mLocalAnimating = true; |
| 7525 | mAnimation = null; |
| 7526 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7527 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7528 | if (!mAnimating && !mLocalAnimating) { |
| 7529 | return false; |
| 7530 | } |
| 7531 | |
| 7532 | if (DEBUG_ANIM) Log.v( |
| 7533 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 7534 | + ", reportedVisible=" |
| 7535 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7536 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7537 | mAnimating = false; |
| 7538 | mLocalAnimating = false; |
| 7539 | mAnimation = null; |
| 7540 | mAnimLayer = mLayer; |
| 7541 | if (mIsImWindow) { |
| 7542 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7543 | } else if (mIsWallpaper) { |
| 7544 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7545 | } |
| 7546 | if (DEBUG_LAYERS) Log.v(TAG, "Stepping win " + this |
| 7547 | + " anim layer: " + mAnimLayer); |
| 7548 | mHasTransformation = false; |
| 7549 | mHasLocalTransformation = false; |
| 7550 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 7551 | mTransformation.clear(); |
| 7552 | if (mHasDrawn |
| 7553 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 7554 | && mAppToken != null |
| 7555 | && mAppToken.firstWindowDrawn |
| 7556 | && mAppToken.startingData != null) { |
| 7557 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Finish starting " |
| 7558 | + mToken + ": first real window done animating"); |
| 7559 | mFinishedStarting.add(mAppToken); |
| 7560 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7561 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7562 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7563 | finishExit(); |
| 7564 | |
| 7565 | if (mAppToken != null) { |
| 7566 | mAppToken.updateReportedVisibilityLocked(); |
| 7567 | } |
| 7568 | |
| 7569 | return false; |
| 7570 | } |
| 7571 | |
| 7572 | void finishExit() { |
| 7573 | if (DEBUG_ANIM) Log.v( |
| 7574 | TAG, "finishExit in " + this |
| 7575 | + ": exiting=" + mExiting |
| 7576 | + " remove=" + mRemoveOnExit |
| 7577 | + " windowAnimating=" + isWindowAnimating()); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7578 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7579 | final int N = mChildWindows.size(); |
| 7580 | for (int i=0; i<N; i++) { |
| 7581 | ((WindowState)mChildWindows.get(i)).finishExit(); |
| 7582 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7583 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7584 | if (!mExiting) { |
| 7585 | return; |
| 7586 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7587 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7588 | if (isWindowAnimating()) { |
| 7589 | return; |
| 7590 | } |
| 7591 | |
| 7592 | if (localLOGV) Log.v( |
| 7593 | TAG, "Exit animation finished in " + this |
| 7594 | + ": remove=" + mRemoveOnExit); |
| 7595 | if (mSurface != null) { |
| 7596 | mDestroySurface.add(this); |
| 7597 | mDestroying = true; |
| 7598 | if (SHOW_TRANSACTIONS) Log.i( |
| 7599 | TAG, " SURFACE " + mSurface + ": HIDE (finishExit)"); |
| 7600 | try { |
| 7601 | mSurface.hide(); |
| 7602 | } catch (RuntimeException e) { |
| 7603 | Log.w(TAG, "Error hiding surface in " + this, e); |
| 7604 | } |
| 7605 | mLastHidden = true; |
| 7606 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 7607 | } |
| 7608 | mExiting = false; |
| 7609 | if (mRemoveOnExit) { |
| 7610 | mPendingRemove.add(this); |
| 7611 | mRemoveOnExit = false; |
| 7612 | } |
| 7613 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7614 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7615 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 7616 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 7617 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 7618 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 7619 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 7620 | return true; |
| 7621 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7622 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7623 | void computeShownFrameLocked() { |
| 7624 | final boolean selfTransformation = mHasLocalTransformation; |
| 7625 | Transformation attachedTransformation = |
| 7626 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 7627 | ? mAttachedWindow.mTransformation : null; |
| 7628 | Transformation appTransformation = |
| 7629 | (mAppToken != null && mAppToken.hasTransformation) |
| 7630 | ? mAppToken.transformation : null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7631 | |
| 7632 | // Wallpapers are animated based on the "real" window they |
| 7633 | // are currently targeting. |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7634 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7635 | && mWallpaperTarget != null) { |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7636 | if (mWallpaperTarget.mHasLocalTransformation && |
| 7637 | mWallpaperTarget.mAnimation != null && |
| 7638 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7639 | attachedTransformation = mWallpaperTarget.mTransformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7640 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
| 7641 | Log.v(TAG, "WP target attached xform: " + attachedTransformation); |
| 7642 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7643 | } |
| 7644 | if (mWallpaperTarget.mAppToken != null && |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7645 | mWallpaperTarget.mAppToken.hasTransformation && |
| 7646 | mWallpaperTarget.mAppToken.animation != null && |
| 7647 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7648 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7649 | if (DEBUG_WALLPAPER && appTransformation != null) { |
| 7650 | Log.v(TAG, "WP target app xform: " + appTransformation); |
| 7651 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7652 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7653 | } |
| 7654 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7655 | if (selfTransformation || attachedTransformation != null |
| 7656 | || appTransformation != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7657 | // cache often used attributes locally |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7658 | final Rect frame = mFrame; |
| 7659 | final float tmpFloats[] = mTmpFloats; |
| 7660 | final Matrix tmpMatrix = mTmpMatrix; |
| 7661 | |
| 7662 | // Compute the desired transformation. |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7663 | tmpMatrix.setTranslate(0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7664 | if (selfTransformation) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7665 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7666 | } |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7667 | tmpMatrix.postTranslate(frame.left, frame.top); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7668 | if (attachedTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7669 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7670 | } |
| 7671 | if (appTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7672 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7673 | } |
| 7674 | |
| 7675 | // "convert" it into SurfaceFlinger's format |
| 7676 | // (a 2x2 matrix + an offset) |
| 7677 | // Here we must not transform the position of the surface |
| 7678 | // since it is already included in the transformation. |
| 7679 | //Log.i(TAG, "Transform: " + matrix); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7680 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7681 | tmpMatrix.getValues(tmpFloats); |
| 7682 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 7683 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 7684 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 7685 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7686 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 7687 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7688 | int w = frame.width(); |
| 7689 | int h = frame.height(); |
| 7690 | mShownFrame.set(x, y, x+w, y+h); |
| 7691 | |
| 7692 | // Now set the alpha... but because our current hardware |
| 7693 | // can't do alpha transformation on a non-opaque surface, |
| 7694 | // turn it off if we are running an animation that is also |
| 7695 | // transforming since it is more important to have that |
| 7696 | // animation be smooth. |
| 7697 | mShownAlpha = mAlpha; |
| 7698 | if (!mLimitedAlphaCompositing |
| 7699 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 7700 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 7701 | && x == frame.left && y == frame.top))) { |
| 7702 | //Log.i(TAG, "Applying alpha transform"); |
| 7703 | if (selfTransformation) { |
| 7704 | mShownAlpha *= mTransformation.getAlpha(); |
| 7705 | } |
| 7706 | if (attachedTransformation != null) { |
| 7707 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 7708 | } |
| 7709 | if (appTransformation != null) { |
| 7710 | mShownAlpha *= appTransformation.getAlpha(); |
| 7711 | } |
| 7712 | } else { |
| 7713 | //Log.i(TAG, "Not applying alpha transform"); |
| 7714 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7715 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7716 | if (localLOGV) Log.v( |
| 7717 | TAG, "Continuing animation in " + this + |
| 7718 | ": " + mShownFrame + |
| 7719 | ", alpha=" + mTransformation.getAlpha()); |
| 7720 | return; |
| 7721 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7722 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7723 | mShownFrame.set(mFrame); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7724 | if (mXOffset != 0 || mYOffset != 0) { |
| 7725 | mShownFrame.offset(mXOffset, mYOffset); |
| 7726 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7727 | mShownAlpha = mAlpha; |
| 7728 | mDsDx = 1; |
| 7729 | mDtDx = 0; |
| 7730 | mDsDy = 0; |
| 7731 | mDtDy = 1; |
| 7732 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7733 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7734 | /** |
| 7735 | * Is this window visible? It is not visible if there is no |
| 7736 | * surface, or we are in the process of running an exit animation |
| 7737 | * that will remove the surface, or its app token has been hidden. |
| 7738 | */ |
| 7739 | public boolean isVisibleLw() { |
| 7740 | final AppWindowToken atoken = mAppToken; |
| 7741 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7742 | && (atoken == null || !atoken.hiddenRequested) |
| 7743 | && !mExiting && !mDestroying; |
| 7744 | } |
| 7745 | |
| 7746 | /** |
Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7747 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 7748 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 7749 | * things like window flags that impact the keyguard. |
| 7750 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 7751 | * for this "hidden behind keyguard" state rather than overloading |
| 7752 | * mPolicyVisibility. Ungh. |
| 7753 | */ |
| 7754 | public boolean isVisibleOrBehindKeyguardLw() { |
| 7755 | final AppWindowToken atoken = mAppToken; |
| 7756 | return mSurface != null && !mAttachedHidden |
| 7757 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
| 7758 | && !mExiting && !mDestroying; |
| 7759 | } |
| 7760 | |
| 7761 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7762 | * Is this window visible, ignoring its app token? It is not visible |
| 7763 | * if there is no surface, or we are in the process of running an exit animation |
| 7764 | * that will remove the surface. |
| 7765 | */ |
| 7766 | public boolean isWinVisibleLw() { |
| 7767 | final AppWindowToken atoken = mAppToken; |
| 7768 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7769 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 7770 | && !mExiting && !mDestroying; |
| 7771 | } |
| 7772 | |
| 7773 | /** |
| 7774 | * The same as isVisible(), but follows the current hidden state of |
| 7775 | * the associated app token, not the pending requested hidden state. |
| 7776 | */ |
| 7777 | boolean isVisibleNow() { |
| 7778 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7779 | && !mRootToken.hidden && !mExiting && !mDestroying; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7780 | } |
| 7781 | |
| 7782 | /** |
| 7783 | * Same as isVisible(), but we also count it as visible between the |
| 7784 | * call to IWindowSession.add() and the first relayout(). |
| 7785 | */ |
| 7786 | boolean isVisibleOrAdding() { |
| 7787 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7788 | return ((mSurface != null && !mReportDestroySurface) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7789 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 7790 | && mPolicyVisibility && !mAttachedHidden |
| 7791 | && (atoken == null || !atoken.hiddenRequested) |
| 7792 | && !mExiting && !mDestroying; |
| 7793 | } |
| 7794 | |
| 7795 | /** |
| 7796 | * Is this window currently on-screen? It is on-screen either if it |
| 7797 | * is visible or it is currently running an animation before no longer |
| 7798 | * being visible. |
| 7799 | */ |
| 7800 | boolean isOnScreen() { |
| 7801 | final AppWindowToken atoken = mAppToken; |
| 7802 | if (atoken != null) { |
| 7803 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7804 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7805 | || mAnimation != null || atoken.animation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7806 | } else { |
| 7807 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7808 | && (!mAttachedHidden || mAnimation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7809 | } |
| 7810 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7811 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7812 | /** |
| 7813 | * Like isOnScreen(), but we don't return true if the window is part |
| 7814 | * of a transition that has not yet been started. |
| 7815 | */ |
| 7816 | boolean isReadyForDisplay() { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7817 | if (mRootToken.waitingToShow && |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7818 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7819 | return false; |
| 7820 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7821 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7822 | final boolean animating = atoken != null |
| 7823 | ? (atoken.animation != null) : false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7824 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7825 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 7826 | && !mRootToken.hidden) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7827 | || mAnimation != null || animating); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7828 | } |
| 7829 | |
| 7830 | /** Is the window or its container currently animating? */ |
| 7831 | boolean isAnimating() { |
| 7832 | final WindowState attached = mAttachedWindow; |
| 7833 | final AppWindowToken atoken = mAppToken; |
| 7834 | return mAnimation != null |
| 7835 | || (attached != null && attached.mAnimation != null) |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7836 | || (atoken != null && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7837 | (atoken.animation != null |
| 7838 | || atoken.inPendingTransaction)); |
| 7839 | } |
| 7840 | |
| 7841 | /** Is this window currently animating? */ |
| 7842 | boolean isWindowAnimating() { |
| 7843 | return mAnimation != null; |
| 7844 | } |
| 7845 | |
| 7846 | /** |
| 7847 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 7848 | * been drawn. |
| 7849 | */ |
| 7850 | public boolean isDisplayedLw() { |
| 7851 | final AppWindowToken atoken = mAppToken; |
| 7852 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7853 | && !mDrawPending && !mCommitDrawPending |
| 7854 | && ((!mAttachedHidden && |
| 7855 | (atoken == null || !atoken.hiddenRequested)) |
| 7856 | || mAnimating); |
| 7857 | } |
| 7858 | |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7859 | /** |
| 7860 | * Returns true if the window has a surface that it has drawn a |
| 7861 | * complete UI in to. |
| 7862 | */ |
| 7863 | public boolean isDrawnLw() { |
| 7864 | final AppWindowToken atoken = mAppToken; |
| 7865 | return mSurface != null && !mDestroying |
| 7866 | && !mDrawPending && !mCommitDrawPending; |
| 7867 | } |
| 7868 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7869 | public boolean fillsScreenLw(int screenWidth, int screenHeight, |
| 7870 | boolean shownFrame, boolean onlyOpaque) { |
| 7871 | if (mSurface == null) { |
| 7872 | return false; |
| 7873 | } |
| 7874 | if (mAppToken != null && !mAppToken.appFullscreen) { |
| 7875 | return false; |
| 7876 | } |
| 7877 | if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) { |
| 7878 | return false; |
| 7879 | } |
| 7880 | final Rect frame = shownFrame ? mShownFrame : mFrame; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7881 | |
| 7882 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| 7883 | return frame.left <= mCompatibleScreenFrame.left && |
| 7884 | frame.top <= mCompatibleScreenFrame.top && |
| 7885 | frame.right >= mCompatibleScreenFrame.right && |
| 7886 | frame.bottom >= mCompatibleScreenFrame.bottom; |
| 7887 | } else { |
| 7888 | return frame.left <= 0 && frame.top <= 0 |
| 7889 | && frame.right >= screenWidth |
| 7890 | && frame.bottom >= screenHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7891 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7892 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7893 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7894 | /** |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7895 | * Return true if the window is opaque and fully drawn. This indicates |
| 7896 | * it may obscure windows behind it. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7897 | */ |
| 7898 | boolean isOpaqueDrawn() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7899 | return (mAttrs.format == PixelFormat.OPAQUE |
| 7900 | || mAttrs.type == TYPE_WALLPAPER) |
| 7901 | && mSurface != null && mAnimation == null |
| 7902 | && (mAppToken == null || mAppToken.animation == null) |
| 7903 | && !mDrawPending && !mCommitDrawPending; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7904 | } |
| 7905 | |
| 7906 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 7907 | return |
| 7908 | // only if the application is requesting compatible window |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7909 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 7910 | // only if it's visible |
| 7911 | mHasDrawn && mViewVisibility == View.VISIBLE && |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7912 | // and only if the application fills the compatible screen |
| 7913 | mFrame.left <= mCompatibleScreenFrame.left && |
| 7914 | mFrame.top <= mCompatibleScreenFrame.top && |
| 7915 | mFrame.right >= mCompatibleScreenFrame.right && |
| 7916 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7917 | // and starting window do not need background filler |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7918 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7919 | } |
| 7920 | |
| 7921 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 7922 | return mFrame.left <= 0 && mFrame.top <= 0 && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7923 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7924 | } |
| 7925 | |
| 7926 | void removeLocked() { |
| 7927 | if (mAttachedWindow != null) { |
| 7928 | mAttachedWindow.mChildWindows.remove(this); |
| 7929 | } |
| 7930 | destroySurfaceLocked(); |
| 7931 | mSession.windowRemovedLocked(); |
| 7932 | try { |
| 7933 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 7934 | } catch (RuntimeException e) { |
| 7935 | // Ignore if it has already been removed (usually because |
| 7936 | // we are doing this as part of processing a death note.) |
| 7937 | } |
| 7938 | } |
| 7939 | |
| 7940 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 7941 | public void binderDied() { |
| 7942 | try { |
| 7943 | synchronized(mWindowMap) { |
| 7944 | WindowState win = windowForClientLocked(mSession, mClient); |
| 7945 | Log.i(TAG, "WIN DEATH: " + win); |
| 7946 | if (win != null) { |
| 7947 | removeWindowLocked(mSession, win); |
| 7948 | } |
| 7949 | } |
| 7950 | } catch (IllegalArgumentException ex) { |
| 7951 | // This will happen if the window has already been |
| 7952 | // removed. |
| 7953 | } |
| 7954 | } |
| 7955 | } |
| 7956 | |
| 7957 | /** Returns true if this window desires key events. */ |
| 7958 | public final boolean canReceiveKeys() { |
| 7959 | return isVisibleOrAdding() |
| 7960 | && (mViewVisibility == View.VISIBLE) |
| 7961 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 7962 | } |
| 7963 | |
| 7964 | public boolean hasDrawnLw() { |
| 7965 | return mHasDrawn; |
| 7966 | } |
| 7967 | |
| 7968 | public boolean showLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7969 | return showLw(doAnimation, true); |
| 7970 | } |
| 7971 | |
| 7972 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 7973 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 7974 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7975 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7976 | mPolicyVisibility = true; |
| 7977 | mPolicyVisibilityAfterAnim = true; |
| 7978 | if (doAnimation) { |
| 7979 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 7980 | } |
| 7981 | if (requestAnim) { |
| 7982 | requestAnimationLocked(0); |
| 7983 | } |
| 7984 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7985 | } |
| 7986 | |
| 7987 | public boolean hideLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7988 | return hideLw(doAnimation, true); |
| 7989 | } |
| 7990 | |
| 7991 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7992 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 7993 | : mPolicyVisibility; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7994 | if (!current) { |
| 7995 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7996 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7997 | if (doAnimation) { |
| 7998 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 7999 | if (mAnimation == null) { |
| 8000 | doAnimation = false; |
| 8001 | } |
| 8002 | } |
| 8003 | if (doAnimation) { |
| 8004 | mPolicyVisibilityAfterAnim = false; |
| 8005 | } else { |
| 8006 | mPolicyVisibilityAfterAnim = false; |
| 8007 | mPolicyVisibility = false; |
| 8008 | } |
| 8009 | if (requestAnim) { |
| 8010 | requestAnimationLocked(0); |
| 8011 | } |
| 8012 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8013 | } |
| 8014 | |
| 8015 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8016 | StringBuilder sb = new StringBuilder(64); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8017 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8018 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 8019 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 8020 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 8021 | if (mAttachedWindow != null || mLayoutAttached) { |
| 8022 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 8023 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 8024 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8025 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 8026 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 8027 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8028 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 8029 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8030 | } |
| 8031 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 8032 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 8033 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 8034 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 8035 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 8036 | pw.print("="); pw.print(mAnimLayer); |
| 8037 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 8038 | if (mSurface != null) { |
| 8039 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
| 8040 | } |
| 8041 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 8042 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 8043 | if (mAppToken != null) { |
| 8044 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 8045 | } |
| 8046 | if (mTargetAppToken != null) { |
| 8047 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 8048 | } |
| 8049 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 8050 | pw.print(Integer.toHexString(mViewVisibility)); |
| 8051 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8052 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 8053 | pw.print(" mObscured="); pw.println(mObscured); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8054 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 8055 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 8056 | pw.print(mPolicyVisibility); |
| 8057 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 8058 | pw.print(mPolicyVisibilityAfterAnim); |
| 8059 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 8060 | } |
| 8061 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8062 | pw.print(" h="); pw.println(mRequestedHeight); |
| 8063 | if (mXOffset != 0 || mYOffset != 0) { |
| 8064 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 8065 | pw.print(" y="); pw.println(mYOffset); |
| 8066 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8067 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 8068 | mGivenContentInsets.printShortString(pw); |
| 8069 | pw.print(" mGivenVisibleInsets="); |
| 8070 | mGivenVisibleInsets.printShortString(pw); |
| 8071 | pw.println(); |
| 8072 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 8073 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 8074 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 8075 | } |
| 8076 | pw.print(prefix); pw.print("mShownFrame="); |
| 8077 | mShownFrame.printShortString(pw); |
| 8078 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 8079 | pw.println(); |
| 8080 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 8081 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 8082 | pw.println(); |
| 8083 | pw.print(prefix); pw.print("mContainingFrame="); |
| 8084 | mContainingFrame.printShortString(pw); |
| 8085 | pw.print(" mDisplayFrame="); |
| 8086 | mDisplayFrame.printShortString(pw); |
| 8087 | pw.println(); |
| 8088 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 8089 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 8090 | pw.println(); |
| 8091 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 8092 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 8093 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 8094 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 8095 | pw.println(); |
| 8096 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 8097 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 8098 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 8099 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 8100 | } |
| 8101 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 8102 | || mAnimation != null) { |
| 8103 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 8104 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 8105 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 8106 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 8107 | } |
| 8108 | if (mHasTransformation || mHasLocalTransformation) { |
| 8109 | pw.print(prefix); pw.print("XForm: has="); |
| 8110 | pw.print(mHasTransformation); |
| 8111 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 8112 | pw.print(" "); mTransformation.printShortString(pw); |
| 8113 | pw.println(); |
| 8114 | } |
| 8115 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 8116 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 8117 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 8118 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 8119 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 8120 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 8121 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 8122 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 8123 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 8124 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8125 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8126 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 8127 | pw.print(mOrientationChanging); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8128 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 8129 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8130 | } |
Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 8131 | if (mHScale != 1 || mVScale != 1) { |
| 8132 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 8133 | pw.print(" mVScale="); pw.println(mVScale); |
| 8134 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 8135 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8136 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 8137 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 8138 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 8139 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 8140 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 8141 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 8142 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8143 | } |
| 8144 | |
| 8145 | @Override |
| 8146 | public String toString() { |
| 8147 | return "Window{" |
| 8148 | + Integer.toHexString(System.identityHashCode(this)) |
| 8149 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 8150 | } |
| 8151 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8152 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8153 | // ------------------------------------------------------------- |
| 8154 | // Window Token State |
| 8155 | // ------------------------------------------------------------- |
| 8156 | |
| 8157 | class WindowToken { |
| 8158 | // The actual token. |
| 8159 | final IBinder token; |
| 8160 | |
| 8161 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 8162 | final int windowType; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8163 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8164 | // Set if this token was explicitly added by a client, so should |
| 8165 | // not be removed when all windows are removed. |
| 8166 | final boolean explicit; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8167 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8168 | // For printing. |
| 8169 | String stringName; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8170 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8171 | // If this is an AppWindowToken, this is non-null. |
| 8172 | AppWindowToken appWindowToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8174 | // All of the windows associated with this token. |
| 8175 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 8176 | |
| 8177 | // Is key dispatching paused for this token? |
| 8178 | boolean paused = false; |
| 8179 | |
| 8180 | // Should this token's windows be hidden? |
| 8181 | boolean hidden; |
| 8182 | |
| 8183 | // Temporary for finding which tokens no longer have visible windows. |
| 8184 | boolean hasVisible; |
| 8185 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8186 | // Set to true when this token is in a pending transaction where it |
| 8187 | // will be shown. |
| 8188 | boolean waitingToShow; |
| 8189 | |
| 8190 | // Set to true when this token is in a pending transaction where it |
| 8191 | // will be hidden. |
| 8192 | boolean waitingToHide; |
| 8193 | |
| 8194 | // Set to true when this token is in a pending transaction where its |
| 8195 | // windows will be put to the bottom of the list. |
| 8196 | boolean sendingToBottom; |
| 8197 | |
| 8198 | // Set to true when this token is in a pending transaction where its |
| 8199 | // windows will be put to the top of the list. |
| 8200 | boolean sendingToTop; |
| 8201 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8202 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 8203 | token = _token; |
| 8204 | windowType = type; |
| 8205 | explicit = _explicit; |
| 8206 | } |
| 8207 | |
| 8208 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8209 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 8210 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 8211 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 8212 | pw.print(" hidden="); pw.print(hidden); |
| 8213 | pw.print(" hasVisible="); pw.println(hasVisible); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8214 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 8215 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 8216 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 8217 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 8218 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 8219 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8220 | } |
| 8221 | |
| 8222 | @Override |
| 8223 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8224 | if (stringName == null) { |
| 8225 | StringBuilder sb = new StringBuilder(); |
| 8226 | sb.append("WindowToken{"); |
| 8227 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8228 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8229 | stringName = sb.toString(); |
| 8230 | } |
| 8231 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8232 | } |
| 8233 | }; |
| 8234 | |
| 8235 | class AppWindowToken extends WindowToken { |
| 8236 | // Non-null only for application tokens. |
| 8237 | final IApplicationToken appToken; |
| 8238 | |
| 8239 | // All of the windows and child windows that are included in this |
| 8240 | // application token. Note this list is NOT sorted! |
| 8241 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 8242 | |
| 8243 | int groupId = -1; |
| 8244 | boolean appFullscreen; |
| 8245 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8246 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8247 | // These are used for determining when all windows associated with |
| 8248 | // an activity have been drawn, so they can be made visible together |
| 8249 | // at the same time. |
| 8250 | int lastTransactionSequence = mTransactionSequence-1; |
| 8251 | int numInterestingWindows; |
| 8252 | int numDrawnWindows; |
| 8253 | boolean inPendingTransaction; |
| 8254 | boolean allDrawn; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8255 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8256 | // Is this token going to be hidden in a little while? If so, it |
| 8257 | // won't be taken into account for setting the screen orientation. |
| 8258 | boolean willBeHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8259 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8260 | // Is this window's surface needed? This is almost like hidden, except |
| 8261 | // it will sometimes be true a little earlier: when the token has |
| 8262 | // been shown, but is still waiting for its app transition to execute |
| 8263 | // before making its windows shown. |
| 8264 | boolean hiddenRequested; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8265 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8266 | // Have we told the window clients to hide themselves? |
| 8267 | boolean clientHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8268 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8269 | // Last visibility state we reported to the app token. |
| 8270 | boolean reportedVisible; |
| 8271 | |
| 8272 | // Set to true when the token has been removed from the window mgr. |
| 8273 | boolean removed; |
| 8274 | |
| 8275 | // Have we been asked to have this token keep the screen frozen? |
| 8276 | boolean freezingScreen; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8277 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8278 | boolean animating; |
| 8279 | Animation animation; |
| 8280 | boolean hasTransformation; |
| 8281 | final Transformation transformation = new Transformation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8282 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8283 | // Offset to the window of all layers in the token, for use by |
| 8284 | // AppWindowToken animations. |
| 8285 | int animLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8286 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8287 | // Information about an application starting window if displayed. |
| 8288 | StartingData startingData; |
| 8289 | WindowState startingWindow; |
| 8290 | View startingView; |
| 8291 | boolean startingDisplayed; |
| 8292 | boolean startingMoved; |
| 8293 | boolean firstWindowDrawn; |
| 8294 | |
| 8295 | AppWindowToken(IApplicationToken _token) { |
| 8296 | super(_token.asBinder(), |
| 8297 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 8298 | appWindowToken = this; |
| 8299 | appToken = _token; |
| 8300 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8301 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8302 | public void setAnimation(Animation anim) { |
| 8303 | if (localLOGV) Log.v( |
| 8304 | TAG, "Setting animation in " + this + ": " + anim); |
| 8305 | animation = anim; |
| 8306 | animating = false; |
| 8307 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 8308 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 8309 | int zorder = anim.getZAdjustment(); |
| 8310 | int adj = 0; |
| 8311 | if (zorder == Animation.ZORDER_TOP) { |
| 8312 | adj = TYPE_LAYER_OFFSET; |
| 8313 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 8314 | adj = -TYPE_LAYER_OFFSET; |
| 8315 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8316 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8317 | if (animLayerAdjustment != adj) { |
| 8318 | animLayerAdjustment = adj; |
| 8319 | updateLayers(); |
| 8320 | } |
| 8321 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8322 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8323 | public void setDummyAnimation() { |
| 8324 | if (animation == null) { |
| 8325 | if (localLOGV) Log.v( |
| 8326 | TAG, "Setting dummy animation in " + this); |
| 8327 | animation = sDummyAnimation; |
| 8328 | } |
| 8329 | } |
| 8330 | |
| 8331 | public void clearAnimation() { |
| 8332 | if (animation != null) { |
| 8333 | animation = null; |
| 8334 | animating = true; |
| 8335 | } |
| 8336 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8337 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8338 | void updateLayers() { |
| 8339 | final int N = allAppWindows.size(); |
| 8340 | final int adj = animLayerAdjustment; |
| 8341 | for (int i=0; i<N; i++) { |
| 8342 | WindowState w = allAppWindows.get(i); |
| 8343 | w.mAnimLayer = w.mLayer + adj; |
| 8344 | if (DEBUG_LAYERS) Log.v(TAG, "Updating layer " + w + ": " |
| 8345 | + w.mAnimLayer); |
| 8346 | if (w == mInputMethodTarget) { |
| 8347 | setInputMethodAnimLayerAdjustment(adj); |
| 8348 | } |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8349 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8350 | setWallpaperAnimLayerAdjustmentLocked(adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8351 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8352 | } |
| 8353 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8354 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8355 | void sendAppVisibilityToClients() { |
| 8356 | final int N = allAppWindows.size(); |
| 8357 | for (int i=0; i<N; i++) { |
| 8358 | WindowState win = allAppWindows.get(i); |
| 8359 | if (win == startingWindow && clientHidden) { |
| 8360 | // Don't hide the starting window. |
| 8361 | continue; |
| 8362 | } |
| 8363 | try { |
| 8364 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 8365 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 8366 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 8367 | } catch (RemoteException e) { |
| 8368 | } |
| 8369 | } |
| 8370 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8371 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8372 | void showAllWindowsLocked() { |
| 8373 | final int NW = allAppWindows.size(); |
| 8374 | for (int i=0; i<NW; i++) { |
| 8375 | WindowState w = allAppWindows.get(i); |
| 8376 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 8377 | "performing show on: " + w); |
| 8378 | w.performShowLocked(); |
| 8379 | } |
| 8380 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8381 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8382 | // This must be called while inside a transaction. |
| 8383 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| 8384 | if (!mDisplayFrozen) { |
| 8385 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8386 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8387 | if (animation == sDummyAnimation) { |
| 8388 | // This guy is going to animate, but not yet. For now count |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8389 | // it as not animating for purposes of scheduling transactions; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8390 | // when it is really time to animate, this will be set to |
| 8391 | // a real animation and the next call will execute normally. |
| 8392 | return false; |
| 8393 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8394 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8395 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 8396 | if (!animating) { |
| 8397 | if (DEBUG_ANIM) Log.v( |
| 8398 | TAG, "Starting animation in " + this + |
| 8399 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 8400 | + " scale=" + mTransitionAnimationScale |
| 8401 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 8402 | animation.initialize(dw, dh, dw, dh); |
| 8403 | animation.setStartTime(currentTime); |
| 8404 | animating = true; |
| 8405 | } |
| 8406 | transformation.clear(); |
| 8407 | final boolean more = animation.getTransformation( |
| 8408 | currentTime, transformation); |
| 8409 | if (DEBUG_ANIM) Log.v( |
| 8410 | TAG, "Stepped animation in " + this + |
| 8411 | ": more=" + more + ", xform=" + transformation); |
| 8412 | if (more) { |
| 8413 | // we're done! |
| 8414 | hasTransformation = true; |
| 8415 | return true; |
| 8416 | } |
| 8417 | if (DEBUG_ANIM) Log.v( |
| 8418 | TAG, "Finished animation in " + this + |
| 8419 | " @ " + currentTime); |
| 8420 | animation = null; |
| 8421 | } |
| 8422 | } else if (animation != null) { |
| 8423 | // If the display is frozen, and there is a pending animation, |
| 8424 | // clear it and make sure we run the cleanup code. |
| 8425 | animating = true; |
| 8426 | animation = null; |
| 8427 | } |
| 8428 | |
| 8429 | hasTransformation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8430 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8431 | if (!animating) { |
| 8432 | return false; |
| 8433 | } |
| 8434 | |
| 8435 | clearAnimation(); |
| 8436 | animating = false; |
| 8437 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 8438 | moveInputMethodWindowsIfNeededLocked(true); |
| 8439 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8440 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8441 | if (DEBUG_ANIM) Log.v( |
| 8442 | TAG, "Animation done in " + this |
| 8443 | + ": reportedVisible=" + reportedVisible); |
| 8444 | |
| 8445 | transformation.clear(); |
| 8446 | if (animLayerAdjustment != 0) { |
| 8447 | animLayerAdjustment = 0; |
| 8448 | updateLayers(); |
| 8449 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8451 | final int N = windows.size(); |
| 8452 | for (int i=0; i<N; i++) { |
| 8453 | ((WindowState)windows.get(i)).finishExit(); |
| 8454 | } |
| 8455 | updateReportedVisibilityLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8456 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8457 | return false; |
| 8458 | } |
| 8459 | |
| 8460 | void updateReportedVisibilityLocked() { |
| 8461 | if (appToken == null) { |
| 8462 | return; |
| 8463 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8464 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8465 | int numInteresting = 0; |
| 8466 | int numVisible = 0; |
| 8467 | boolean nowGone = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8468 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8469 | if (DEBUG_VISIBILITY) Log.v(TAG, "Update reported visibility: " + this); |
| 8470 | final int N = allAppWindows.size(); |
| 8471 | for (int i=0; i<N; i++) { |
| 8472 | WindowState win = allAppWindows.get(i); |
| 8473 | if (win == startingWindow || win.mAppFreezing) { |
| 8474 | continue; |
| 8475 | } |
| 8476 | if (DEBUG_VISIBILITY) { |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8477 | Log.v(TAG, "Win " + win + ": isDrawn=" |
| 8478 | + win.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8479 | + ", isAnimating=" + win.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8480 | if (!win.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8481 | Log.v(TAG, "Not displayed: s=" + win.mSurface |
| 8482 | + " pv=" + win.mPolicyVisibility |
| 8483 | + " dp=" + win.mDrawPending |
| 8484 | + " cdp=" + win.mCommitDrawPending |
| 8485 | + " ah=" + win.mAttachedHidden |
| 8486 | + " th=" |
| 8487 | + (win.mAppToken != null |
| 8488 | ? win.mAppToken.hiddenRequested : false) |
| 8489 | + " a=" + win.mAnimating); |
| 8490 | } |
| 8491 | } |
| 8492 | numInteresting++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8493 | if (win.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8494 | if (!win.isAnimating()) { |
| 8495 | numVisible++; |
| 8496 | } |
| 8497 | nowGone = false; |
| 8498 | } else if (win.isAnimating()) { |
| 8499 | nowGone = false; |
| 8500 | } |
| 8501 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8502 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8503 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
| 8504 | if (DEBUG_VISIBILITY) Log.v(TAG, "VIS " + this + ": interesting=" |
| 8505 | + numInteresting + " visible=" + numVisible); |
| 8506 | if (nowVisible != reportedVisible) { |
| 8507 | if (DEBUG_VISIBILITY) Log.v( |
| 8508 | TAG, "Visibility changed in " + this |
| 8509 | + ": vis=" + nowVisible); |
| 8510 | reportedVisible = nowVisible; |
| 8511 | Message m = mH.obtainMessage( |
| 8512 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 8513 | nowVisible ? 1 : 0, |
| 8514 | nowGone ? 1 : 0, |
| 8515 | this); |
| 8516 | mH.sendMessage(m); |
| 8517 | } |
| 8518 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8519 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8520 | WindowState findMainWindow() { |
| 8521 | int j = windows.size(); |
| 8522 | while (j > 0) { |
| 8523 | j--; |
| 8524 | WindowState win = windows.get(j); |
| 8525 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 8526 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 8527 | return win; |
| 8528 | } |
| 8529 | } |
| 8530 | return null; |
| 8531 | } |
| 8532 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8533 | void dump(PrintWriter pw, String prefix) { |
| 8534 | super.dump(pw, prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8535 | if (appToken != null) { |
| 8536 | pw.print(prefix); pw.println("app=true"); |
| 8537 | } |
| 8538 | if (allAppWindows.size() > 0) { |
| 8539 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 8540 | } |
| 8541 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8542 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8543 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 8544 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 8545 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 8546 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 8547 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 8548 | if (paused || freezingScreen) { |
| 8549 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 8550 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 8551 | } |
| 8552 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 8553 | || inPendingTransaction || allDrawn) { |
| 8554 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 8555 | pw.print(numInterestingWindows); |
| 8556 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 8557 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 8558 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 8559 | } |
| 8560 | if (animating || animation != null) { |
| 8561 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 8562 | pw.print(" animation="); pw.println(animation); |
| 8563 | } |
| 8564 | if (animLayerAdjustment != 0) { |
| 8565 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 8566 | } |
| 8567 | if (hasTransformation) { |
| 8568 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 8569 | pw.print(" transformation="); transformation.printShortString(pw); |
| 8570 | pw.println(); |
| 8571 | } |
| 8572 | if (startingData != null || removed || firstWindowDrawn) { |
| 8573 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 8574 | pw.print(" removed="); pw.print(removed); |
| 8575 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 8576 | } |
| 8577 | if (startingWindow != null || startingView != null |
| 8578 | || startingDisplayed || startingMoved) { |
| 8579 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 8580 | pw.print(" startingView="); pw.print(startingView); |
| 8581 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 8582 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 8583 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8584 | } |
| 8585 | |
| 8586 | @Override |
| 8587 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8588 | if (stringName == null) { |
| 8589 | StringBuilder sb = new StringBuilder(); |
| 8590 | sb.append("AppWindowToken{"); |
| 8591 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8592 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8593 | stringName = sb.toString(); |
| 8594 | } |
| 8595 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8596 | } |
| 8597 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8598 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8599 | // ------------------------------------------------------------- |
| 8600 | // DummyAnimation |
| 8601 | // ------------------------------------------------------------- |
| 8602 | |
| 8603 | // This is an animation that does nothing: it just immediately finishes |
| 8604 | // itself every time it is called. It is used as a stub animation in cases |
| 8605 | // where we want to synchronize multiple things that may be animating. |
| 8606 | static final class DummyAnimation extends Animation { |
| 8607 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 8608 | return false; |
| 8609 | } |
| 8610 | } |
| 8611 | static final Animation sDummyAnimation = new DummyAnimation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8612 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8613 | // ------------------------------------------------------------- |
| 8614 | // Async Handler |
| 8615 | // ------------------------------------------------------------- |
| 8616 | |
| 8617 | static final class StartingData { |
| 8618 | final String pkg; |
| 8619 | final int theme; |
| 8620 | final CharSequence nonLocalizedLabel; |
| 8621 | final int labelRes; |
| 8622 | final int icon; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8623 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8624 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 8625 | int _labelRes, int _icon) { |
| 8626 | pkg = _pkg; |
| 8627 | theme = _theme; |
| 8628 | nonLocalizedLabel = _nonLocalizedLabel; |
| 8629 | labelRes = _labelRes; |
| 8630 | icon = _icon; |
| 8631 | } |
| 8632 | } |
| 8633 | |
| 8634 | private final class H extends Handler { |
| 8635 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 8636 | public static final int REPORT_LOSING_FOCUS = 3; |
| 8637 | public static final int ANIMATE = 4; |
| 8638 | public static final int ADD_STARTING = 5; |
| 8639 | public static final int REMOVE_STARTING = 6; |
| 8640 | public static final int FINISHED_STARTING = 7; |
| 8641 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8642 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 8643 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 8644 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 8645 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 8646 | public static final int FORCE_GC = 15; |
| 8647 | public static final int ENABLE_SCREEN = 16; |
| 8648 | public static final int APP_FREEZE_TIMEOUT = 17; |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8649 | public static final int COMPUTE_AND_SEND_NEW_CONFIGURATION = 18; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8650 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8651 | private Session mLastReportedHold; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8652 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8653 | public H() { |
| 8654 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8655 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8656 | @Override |
| 8657 | public void handleMessage(Message msg) { |
| 8658 | switch (msg.what) { |
| 8659 | case REPORT_FOCUS_CHANGE: { |
| 8660 | WindowState lastFocus; |
| 8661 | WindowState newFocus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8662 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8663 | synchronized(mWindowMap) { |
| 8664 | lastFocus = mLastFocus; |
| 8665 | newFocus = mCurrentFocus; |
| 8666 | if (lastFocus == newFocus) { |
| 8667 | // Focus is not changing, so nothing to do. |
| 8668 | return; |
| 8669 | } |
| 8670 | mLastFocus = newFocus; |
| 8671 | //Log.i(TAG, "Focus moving from " + lastFocus |
| 8672 | // + " to " + newFocus); |
| 8673 | if (newFocus != null && lastFocus != null |
| 8674 | && !newFocus.isDisplayedLw()) { |
| 8675 | //Log.i(TAG, "Delaying loss of focus..."); |
| 8676 | mLosingFocus.add(lastFocus); |
| 8677 | lastFocus = null; |
| 8678 | } |
| 8679 | } |
| 8680 | |
| 8681 | if (lastFocus != newFocus) { |
| 8682 | //System.out.println("Changing focus from " + lastFocus |
| 8683 | // + " to " + newFocus); |
| 8684 | if (newFocus != null) { |
| 8685 | try { |
| 8686 | //Log.i(TAG, "Gaining focus: " + newFocus); |
| 8687 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 8688 | } catch (RemoteException e) { |
| 8689 | // Ignore if process has died. |
| 8690 | } |
| 8691 | } |
| 8692 | |
| 8693 | if (lastFocus != null) { |
| 8694 | try { |
| 8695 | //Log.i(TAG, "Losing focus: " + lastFocus); |
| 8696 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 8697 | } catch (RemoteException e) { |
| 8698 | // Ignore if process has died. |
| 8699 | } |
| 8700 | } |
| 8701 | } |
| 8702 | } break; |
| 8703 | |
| 8704 | case REPORT_LOSING_FOCUS: { |
| 8705 | ArrayList<WindowState> losers; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8706 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8707 | synchronized(mWindowMap) { |
| 8708 | losers = mLosingFocus; |
| 8709 | mLosingFocus = new ArrayList<WindowState>(); |
| 8710 | } |
| 8711 | |
| 8712 | final int N = losers.size(); |
| 8713 | for (int i=0; i<N; i++) { |
| 8714 | try { |
| 8715 | //Log.i(TAG, "Losing delayed focus: " + losers.get(i)); |
| 8716 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 8717 | } catch (RemoteException e) { |
| 8718 | // Ignore if process has died. |
| 8719 | } |
| 8720 | } |
| 8721 | } break; |
| 8722 | |
| 8723 | case ANIMATE: { |
| 8724 | synchronized(mWindowMap) { |
| 8725 | mAnimationPending = false; |
| 8726 | performLayoutAndPlaceSurfacesLocked(); |
| 8727 | } |
| 8728 | } break; |
| 8729 | |
| 8730 | case ADD_STARTING: { |
| 8731 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8732 | final StartingData sd = wtoken.startingData; |
| 8733 | |
| 8734 | if (sd == null) { |
| 8735 | // Animation has been canceled... do nothing. |
| 8736 | return; |
| 8737 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8738 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8739 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Add starting " |
| 8740 | + wtoken + ": pkg=" + sd.pkg); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8741 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8742 | View view = null; |
| 8743 | try { |
| 8744 | view = mPolicy.addStartingWindow( |
| 8745 | wtoken.token, sd.pkg, |
| 8746 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 8747 | sd.icon); |
| 8748 | } catch (Exception e) { |
| 8749 | Log.w(TAG, "Exception when adding starting window", e); |
| 8750 | } |
| 8751 | |
| 8752 | if (view != null) { |
| 8753 | boolean abort = false; |
| 8754 | |
| 8755 | synchronized(mWindowMap) { |
| 8756 | if (wtoken.removed || wtoken.startingData == null) { |
| 8757 | // If the window was successfully added, then |
| 8758 | // we need to remove it. |
| 8759 | if (wtoken.startingWindow != null) { |
| 8760 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 8761 | "Aborted starting " + wtoken |
| 8762 | + ": removed=" + wtoken.removed |
| 8763 | + " startingData=" + wtoken.startingData); |
| 8764 | wtoken.startingWindow = null; |
| 8765 | wtoken.startingData = null; |
| 8766 | abort = true; |
| 8767 | } |
| 8768 | } else { |
| 8769 | wtoken.startingView = view; |
| 8770 | } |
| 8771 | if (DEBUG_STARTING_WINDOW && !abort) Log.v(TAG, |
| 8772 | "Added starting " + wtoken |
| 8773 | + ": startingWindow=" |
| 8774 | + wtoken.startingWindow + " startingView=" |
| 8775 | + wtoken.startingView); |
| 8776 | } |
| 8777 | |
| 8778 | if (abort) { |
| 8779 | try { |
| 8780 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 8781 | } catch (Exception e) { |
| 8782 | Log.w(TAG, "Exception when removing starting window", e); |
| 8783 | } |
| 8784 | } |
| 8785 | } |
| 8786 | } break; |
| 8787 | |
| 8788 | case REMOVE_STARTING: { |
| 8789 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8790 | IBinder token = null; |
| 8791 | View view = null; |
| 8792 | synchronized (mWindowMap) { |
| 8793 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Remove starting " |
| 8794 | + wtoken + ": startingWindow=" |
| 8795 | + wtoken.startingWindow + " startingView=" |
| 8796 | + wtoken.startingView); |
| 8797 | if (wtoken.startingWindow != null) { |
| 8798 | view = wtoken.startingView; |
| 8799 | token = wtoken.token; |
| 8800 | wtoken.startingData = null; |
| 8801 | wtoken.startingView = null; |
| 8802 | wtoken.startingWindow = null; |
| 8803 | } |
| 8804 | } |
| 8805 | if (view != null) { |
| 8806 | try { |
| 8807 | mPolicy.removeStartingWindow(token, view); |
| 8808 | } catch (Exception e) { |
| 8809 | Log.w(TAG, "Exception when removing starting window", e); |
| 8810 | } |
| 8811 | } |
| 8812 | } break; |
| 8813 | |
| 8814 | case FINISHED_STARTING: { |
| 8815 | IBinder token = null; |
| 8816 | View view = null; |
| 8817 | while (true) { |
| 8818 | synchronized (mWindowMap) { |
| 8819 | final int N = mFinishedStarting.size(); |
| 8820 | if (N <= 0) { |
| 8821 | break; |
| 8822 | } |
| 8823 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 8824 | |
| 8825 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 8826 | "Finished starting " + wtoken |
| 8827 | + ": startingWindow=" + wtoken.startingWindow |
| 8828 | + " startingView=" + wtoken.startingView); |
| 8829 | |
| 8830 | if (wtoken.startingWindow == null) { |
| 8831 | continue; |
| 8832 | } |
| 8833 | |
| 8834 | view = wtoken.startingView; |
| 8835 | token = wtoken.token; |
| 8836 | wtoken.startingData = null; |
| 8837 | wtoken.startingView = null; |
| 8838 | wtoken.startingWindow = null; |
| 8839 | } |
| 8840 | |
| 8841 | try { |
| 8842 | mPolicy.removeStartingWindow(token, view); |
| 8843 | } catch (Exception e) { |
| 8844 | Log.w(TAG, "Exception when removing starting window", e); |
| 8845 | } |
| 8846 | } |
| 8847 | } break; |
| 8848 | |
| 8849 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 8850 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8851 | |
| 8852 | boolean nowVisible = msg.arg1 != 0; |
| 8853 | boolean nowGone = msg.arg2 != 0; |
| 8854 | |
| 8855 | try { |
| 8856 | if (DEBUG_VISIBILITY) Log.v( |
| 8857 | TAG, "Reporting visible in " + wtoken |
| 8858 | + " visible=" + nowVisible |
| 8859 | + " gone=" + nowGone); |
| 8860 | if (nowVisible) { |
| 8861 | wtoken.appToken.windowsVisible(); |
| 8862 | } else { |
| 8863 | wtoken.appToken.windowsGone(); |
| 8864 | } |
| 8865 | } catch (RemoteException ex) { |
| 8866 | } |
| 8867 | } break; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8868 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8869 | case WINDOW_FREEZE_TIMEOUT: { |
| 8870 | synchronized (mWindowMap) { |
| 8871 | Log.w(TAG, "Window freeze timeout expired."); |
| 8872 | int i = mWindows.size(); |
| 8873 | while (i > 0) { |
| 8874 | i--; |
| 8875 | WindowState w = (WindowState)mWindows.get(i); |
| 8876 | if (w.mOrientationChanging) { |
| 8877 | w.mOrientationChanging = false; |
| 8878 | Log.w(TAG, "Force clearing orientation change: " + w); |
| 8879 | } |
| 8880 | } |
| 8881 | performLayoutAndPlaceSurfacesLocked(); |
| 8882 | } |
| 8883 | break; |
| 8884 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8885 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8886 | case HOLD_SCREEN_CHANGED: { |
| 8887 | Session oldHold; |
| 8888 | Session newHold; |
| 8889 | synchronized (mWindowMap) { |
| 8890 | oldHold = mLastReportedHold; |
| 8891 | newHold = (Session)msg.obj; |
| 8892 | mLastReportedHold = newHold; |
| 8893 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8894 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8895 | if (oldHold != newHold) { |
| 8896 | try { |
| 8897 | if (oldHold != null) { |
| 8898 | mBatteryStats.noteStopWakelock(oldHold.mUid, |
| 8899 | "window", |
| 8900 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8901 | } |
| 8902 | if (newHold != null) { |
| 8903 | mBatteryStats.noteStartWakelock(newHold.mUid, |
| 8904 | "window", |
| 8905 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8906 | } |
| 8907 | } catch (RemoteException e) { |
| 8908 | } |
| 8909 | } |
| 8910 | break; |
| 8911 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8912 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8913 | case APP_TRANSITION_TIMEOUT: { |
| 8914 | synchronized (mWindowMap) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8915 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8916 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 8917 | "*** APP TRANSITION TIMEOUT"); |
| 8918 | mAppTransitionReady = true; |
| 8919 | mAppTransitionTimeout = true; |
| 8920 | performLayoutAndPlaceSurfacesLocked(); |
| 8921 | } |
| 8922 | } |
| 8923 | break; |
| 8924 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8925 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8926 | case PERSIST_ANIMATION_SCALE: { |
| 8927 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8928 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 8929 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8930 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 8931 | break; |
| 8932 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8933 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8934 | case FORCE_GC: { |
| 8935 | synchronized(mWindowMap) { |
| 8936 | if (mAnimationPending) { |
| 8937 | // If we are animating, don't do the gc now but |
| 8938 | // delay a bit so we don't interrupt the animation. |
| 8939 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 8940 | 2000); |
| 8941 | return; |
| 8942 | } |
| 8943 | // If we are currently rotating the display, it will |
| 8944 | // schedule a new message when done. |
| 8945 | if (mDisplayFrozen) { |
| 8946 | return; |
| 8947 | } |
| 8948 | mFreezeGcPending = 0; |
| 8949 | } |
| 8950 | Runtime.getRuntime().gc(); |
| 8951 | break; |
| 8952 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8953 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8954 | case ENABLE_SCREEN: { |
| 8955 | performEnableScreen(); |
| 8956 | break; |
| 8957 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8958 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8959 | case APP_FREEZE_TIMEOUT: { |
| 8960 | synchronized (mWindowMap) { |
| 8961 | Log.w(TAG, "App freeze timeout expired."); |
| 8962 | int i = mAppTokens.size(); |
| 8963 | while (i > 0) { |
| 8964 | i--; |
| 8965 | AppWindowToken tok = mAppTokens.get(i); |
| 8966 | if (tok.freezingScreen) { |
| 8967 | Log.w(TAG, "Force clearing freeze: " + tok); |
| 8968 | unsetAppFreezingScreenLocked(tok, true, true); |
| 8969 | } |
| 8970 | } |
| 8971 | } |
| 8972 | break; |
| 8973 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8974 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8975 | case COMPUTE_AND_SEND_NEW_CONFIGURATION: { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 8976 | if (updateOrientationFromAppTokensUnchecked(null, null) != null) { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8977 | sendNewConfiguration(); |
| 8978 | } |
| 8979 | break; |
| 8980 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8981 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8982 | } |
| 8983 | } |
| 8984 | } |
| 8985 | |
| 8986 | // ------------------------------------------------------------- |
| 8987 | // IWindowManager API |
| 8988 | // ------------------------------------------------------------- |
| 8989 | |
| 8990 | public IWindowSession openSession(IInputMethodClient client, |
| 8991 | IInputContext inputContext) { |
| 8992 | if (client == null) throw new IllegalArgumentException("null client"); |
| 8993 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
| 8994 | return new Session(client, inputContext); |
| 8995 | } |
| 8996 | |
| 8997 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 8998 | synchronized (mWindowMap) { |
| 8999 | // The focus for the client is the window immediately below |
| 9000 | // where we would place the input method window. |
| 9001 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 9002 | WindowState imFocus; |
| 9003 | if (idx > 0) { |
| 9004 | imFocus = (WindowState)mWindows.get(idx-1); |
| 9005 | if (imFocus != null) { |
| 9006 | if (imFocus.mSession.mClient != null && |
| 9007 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 9008 | return true; |
| 9009 | } |
| 9010 | } |
| 9011 | } |
| 9012 | } |
| 9013 | return false; |
| 9014 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9015 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9016 | // ------------------------------------------------------------- |
| 9017 | // Internals |
| 9018 | // ------------------------------------------------------------- |
| 9019 | |
| 9020 | final WindowState windowForClientLocked(Session session, IWindow client) { |
| 9021 | return windowForClientLocked(session, client.asBinder()); |
| 9022 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9023 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9024 | final WindowState windowForClientLocked(Session session, IBinder client) { |
| 9025 | WindowState win = mWindowMap.get(client); |
| 9026 | if (localLOGV) Log.v( |
| 9027 | TAG, "Looking up client " + client + ": " + win); |
| 9028 | if (win == null) { |
| 9029 | RuntimeException ex = new RuntimeException(); |
| 9030 | Log.w(TAG, "Requested window " + client + " does not exist", ex); |
| 9031 | return null; |
| 9032 | } |
| 9033 | if (session != null && win.mSession != session) { |
| 9034 | RuntimeException ex = new RuntimeException(); |
| 9035 | Log.w(TAG, "Requested window " + client + " is in session " + |
| 9036 | win.mSession + ", not " + session, ex); |
| 9037 | return null; |
| 9038 | } |
| 9039 | |
| 9040 | return win; |
| 9041 | } |
| 9042 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9043 | final void rebuildAppWindowListLocked() { |
| 9044 | int NW = mWindows.size(); |
| 9045 | int i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9046 | int lastWallpaper = -1; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9047 | int numRemoved = 0; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9048 | |
| 9049 | // First remove all existing app windows. |
| 9050 | i=0; |
| 9051 | while (i < NW) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9052 | WindowState w = (WindowState)mWindows.get(i); |
| 9053 | if (w.mAppToken != null) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9054 | WindowState win = (WindowState)mWindows.remove(i); |
| 9055 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, |
| 9056 | "Rebuild removing window: " + win); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9057 | NW--; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9058 | numRemoved++; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9059 | continue; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9060 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 9061 | && lastWallpaper == i-1) { |
| 9062 | lastWallpaper = i; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9063 | } |
| 9064 | i++; |
| 9065 | } |
| 9066 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9067 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 9068 | // so skip them before adding app tokens. |
| 9069 | lastWallpaper++; |
| 9070 | i = lastWallpaper; |
| 9071 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9072 | // First add all of the exiting app tokens... these are no longer |
| 9073 | // in the main app list, but still have windows shown. We put them |
| 9074 | // in the back because now that the animation is over we no longer |
| 9075 | // will care about them. |
| 9076 | int NT = mExitingAppTokens.size(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9077 | for (int j=0; j<NT; j++) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9078 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 9079 | } |
| 9080 | |
| 9081 | // And add in the still active app tokens in Z order. |
| 9082 | NT = mAppTokens.size(); |
| 9083 | for (int j=0; j<NT; j++) { |
| 9084 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9085 | } |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9086 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9087 | i -= lastWallpaper; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9088 | if (i != numRemoved) { |
| 9089 | Log.w(TAG, "Rebuild removed " + numRemoved |
| 9090 | + " windows but added " + i); |
| 9091 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9092 | } |
| 9093 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9094 | private final void assignLayersLocked() { |
| 9095 | int N = mWindows.size(); |
| 9096 | int curBaseLayer = 0; |
| 9097 | int curLayer = 0; |
| 9098 | int i; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9099 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9100 | for (i=0; i<N; i++) { |
| 9101 | WindowState w = (WindowState)mWindows.get(i); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9102 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 9103 | || (i > 0 && w.mIsWallpaper)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9104 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 9105 | w.mLayer = curLayer; |
| 9106 | } else { |
| 9107 | curBaseLayer = curLayer = w.mBaseLayer; |
| 9108 | w.mLayer = curLayer; |
| 9109 | } |
| 9110 | if (w.mTargetAppToken != null) { |
| 9111 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 9112 | } else if (w.mAppToken != null) { |
| 9113 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 9114 | } else { |
| 9115 | w.mAnimLayer = w.mLayer; |
| 9116 | } |
| 9117 | if (w.mIsImWindow) { |
| 9118 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 9119 | } else if (w.mIsWallpaper) { |
| 9120 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9121 | } |
| 9122 | if (DEBUG_LAYERS) Log.v(TAG, "Assign layer " + w + ": " |
| 9123 | + w.mAnimLayer); |
| 9124 | //System.out.println( |
| 9125 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 9126 | } |
| 9127 | } |
| 9128 | |
| 9129 | private boolean mInLayout = false; |
| 9130 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 9131 | if (mInLayout) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 9132 | if (DEBUG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9133 | throw new RuntimeException("Recursive call!"); |
| 9134 | } |
| 9135 | Log.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
| 9136 | return; |
| 9137 | } |
| 9138 | |
| 9139 | boolean recoveringMemory = false; |
| 9140 | if (mForceRemoves != null) { |
| 9141 | recoveringMemory = true; |
| 9142 | // Wait a little it for things to settle down, and off we go. |
| 9143 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 9144 | WindowState ws = mForceRemoves.get(i); |
| 9145 | Log.i(TAG, "Force removing: " + ws); |
| 9146 | removeWindowInnerLocked(ws.mSession, ws); |
| 9147 | } |
| 9148 | mForceRemoves = null; |
| 9149 | Log.w(TAG, "Due to memory failure, waiting a bit for next layout"); |
| 9150 | Object tmp = new Object(); |
| 9151 | synchronized (tmp) { |
| 9152 | try { |
| 9153 | tmp.wait(250); |
| 9154 | } catch (InterruptedException e) { |
| 9155 | } |
| 9156 | } |
| 9157 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9158 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9159 | mInLayout = true; |
| 9160 | try { |
| 9161 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9162 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9163 | int i = mPendingRemove.size()-1; |
| 9164 | if (i >= 0) { |
| 9165 | while (i >= 0) { |
| 9166 | WindowState w = mPendingRemove.get(i); |
| 9167 | removeWindowInnerLocked(w.mSession, w); |
| 9168 | i--; |
| 9169 | } |
| 9170 | mPendingRemove.clear(); |
| 9171 | |
| 9172 | mInLayout = false; |
| 9173 | assignLayersLocked(); |
| 9174 | mLayoutNeeded = true; |
| 9175 | performLayoutAndPlaceSurfacesLocked(); |
| 9176 | |
| 9177 | } else { |
| 9178 | mInLayout = false; |
| 9179 | if (mLayoutNeeded) { |
| 9180 | requestAnimationLocked(0); |
| 9181 | } |
| 9182 | } |
| 9183 | } catch (RuntimeException e) { |
| 9184 | mInLayout = false; |
| 9185 | Log.e(TAG, "Unhandled exception while layout out windows", e); |
| 9186 | } |
| 9187 | } |
| 9188 | |
| 9189 | private final void performLayoutLockedInner() { |
| 9190 | final int dw = mDisplay.getWidth(); |
| 9191 | final int dh = mDisplay.getHeight(); |
| 9192 | |
| 9193 | final int N = mWindows.size(); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9194 | int repeats = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9195 | int i; |
| 9196 | |
| 9197 | // FIRST LOOP: Perform a layout, if needed. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9198 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9199 | while (mLayoutNeeded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9200 | mPolicy.beginLayoutLw(dw, dh); |
| 9201 | |
| 9202 | // First perform layout of any root windows (not attached |
| 9203 | // to another window). |
| 9204 | int topAttached = -1; |
| 9205 | for (i = N-1; i >= 0; i--) { |
| 9206 | WindowState win = (WindowState) mWindows.get(i); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9207 | |
| 9208 | // Don't do layout of a window if it is not visible, or |
| 9209 | // soon won't be visible, to avoid wasting time and funky |
| 9210 | // changes while a window is animating away. |
| 9211 | final AppWindowToken atoken = win.mAppToken; |
| 9212 | final boolean gone = win.mViewVisibility == View.GONE |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9213 | || !win.mRelayoutCalled |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9214 | || win.mRootToken.hidden |
| 9215 | || (atoken != null && atoken.hiddenRequested) |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9216 | || win.mAttachedHidden |
| 9217 | || win.mExiting || win.mDestroying; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9218 | |
| 9219 | // If this view is GONE, then skip it -- keep the current |
| 9220 | // frame, and let the caller know so they can ignore it |
| 9221 | // if they want. (We do the normal layout for INVISIBLE |
| 9222 | // windows, since that means "perform layout as normal, |
| 9223 | // just don't display"). |
| 9224 | if (!gone || !win.mHaveFrame) { |
| 9225 | if (!win.mLayoutAttached) { |
| 9226 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 9227 | } else { |
| 9228 | if (topAttached < 0) topAttached = i; |
| 9229 | } |
| 9230 | } |
| 9231 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9232 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9233 | // Now perform layout of attached windows, which usually |
| 9234 | // depend on the position of the window they are attached to. |
| 9235 | // XXX does not deal with windows that are attached to windows |
| 9236 | // that are themselves attached. |
| 9237 | for (i = topAttached; i >= 0; i--) { |
| 9238 | WindowState win = (WindowState) mWindows.get(i); |
| 9239 | |
| 9240 | // If this view is GONE, then skip it -- keep the current |
| 9241 | // frame, and let the caller know so they can ignore it |
| 9242 | // if they want. (We do the normal layout for INVISIBLE |
| 9243 | // windows, since that means "perform layout as normal, |
| 9244 | // just don't display"). |
| 9245 | if (win.mLayoutAttached) { |
| 9246 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 9247 | || !win.mHaveFrame) { |
| 9248 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 9249 | } |
| 9250 | } |
| 9251 | } |
| 9252 | |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9253 | int changes = mPolicy.finishLayoutLw(); |
| 9254 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 9255 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9256 | assignLayersLocked(); |
| 9257 | } |
| 9258 | } |
| 9259 | if (changes == 0) { |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9260 | mLayoutNeeded = false; |
| 9261 | } else if (repeats > 2) { |
| 9262 | Log.w(TAG, "Layout repeat aborted after too many iterations"); |
| 9263 | mLayoutNeeded = false; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9264 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 9265 | Configuration newConfig = updateOrientationFromAppTokensLocked( |
| 9266 | null, null); |
| 9267 | if (newConfig != null) { |
| 9268 | mLayoutNeeded = true; |
| 9269 | mH.sendEmptyMessage(H.COMPUTE_AND_SEND_NEW_CONFIGURATION); |
| 9270 | } |
| 9271 | } |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9272 | } else { |
| 9273 | repeats++; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9274 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 9275 | Configuration newConfig = updateOrientationFromAppTokensLocked( |
| 9276 | null, null); |
| 9277 | if (newConfig != null) { |
| 9278 | mH.sendEmptyMessage(H.COMPUTE_AND_SEND_NEW_CONFIGURATION); |
| 9279 | } |
| 9280 | } |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9281 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9282 | } |
| 9283 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9284 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9285 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 9286 | boolean recoveringMemory) { |
| 9287 | final long currentTime = SystemClock.uptimeMillis(); |
| 9288 | final int dw = mDisplay.getWidth(); |
| 9289 | final int dh = mDisplay.getHeight(); |
| 9290 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9291 | int i; |
| 9292 | |
| 9293 | // FIRST LOOP: Perform a layout, if needed. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9294 | performLayoutLockedInner(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9295 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9296 | if (mFxSession == null) { |
| 9297 | mFxSession = new SurfaceSession(); |
| 9298 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9299 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9300 | if (SHOW_TRANSACTIONS) Log.i(TAG, ">>> OPEN TRANSACTION"); |
| 9301 | |
| 9302 | // Initialize state of exiting tokens. |
| 9303 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9304 | mExitingTokens.get(i).hasVisible = false; |
| 9305 | } |
| 9306 | |
| 9307 | // Initialize state of exiting applications. |
| 9308 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9309 | mExitingAppTokens.get(i).hasVisible = false; |
| 9310 | } |
| 9311 | |
| 9312 | // SECOND LOOP: Execute animations and update visibility of windows. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9313 | boolean orientationChangeComplete = true; |
| 9314 | Session holdScreen = null; |
| 9315 | float screenBrightness = -1; |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame^] | 9316 | float buttonBrightness = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9317 | boolean focusDisplayed = false; |
| 9318 | boolean animating = false; |
| 9319 | |
| 9320 | Surface.openTransaction(); |
| 9321 | try { |
| 9322 | boolean restart; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9323 | boolean forceHiding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9324 | |
| 9325 | do { |
| 9326 | final int transactionSequence = ++mTransactionSequence; |
| 9327 | |
| 9328 | // Update animations of all applications, including those |
| 9329 | // associated with exiting/removed apps |
| 9330 | boolean tokensAnimating = false; |
| 9331 | final int NAT = mAppTokens.size(); |
| 9332 | for (i=0; i<NAT; i++) { |
| 9333 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9334 | tokensAnimating = true; |
| 9335 | } |
| 9336 | } |
| 9337 | final int NEAT = mExitingAppTokens.size(); |
| 9338 | for (i=0; i<NEAT; i++) { |
| 9339 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9340 | tokensAnimating = true; |
| 9341 | } |
| 9342 | } |
| 9343 | |
| 9344 | animating = tokensAnimating; |
| 9345 | restart = false; |
| 9346 | |
| 9347 | boolean tokenMayBeDrawn = false; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9348 | boolean wallpaperMayChange = false; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9349 | boolean focusMayChange = false; |
| 9350 | boolean wallpaperForceHidingChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9351 | |
| 9352 | mPolicy.beginAnimationLw(dw, dh); |
| 9353 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9354 | final int N = mWindows.size(); |
| 9355 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9356 | for (i=N-1; i>=0; i--) { |
| 9357 | WindowState w = (WindowState)mWindows.get(i); |
| 9358 | |
| 9359 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9360 | |
| 9361 | if (w.mSurface != null) { |
| 9362 | // Execute animation. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9363 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 9364 | if ((w.mAttrs.flags |
| 9365 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9366 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 9367 | "First draw done in potential wallpaper target " + w); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9368 | wallpaperMayChange = true; |
| 9369 | } |
| 9370 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9371 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9372 | boolean wasAnimating = w.mAnimating; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9373 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 9374 | animating = true; |
| 9375 | //w.dump(" "); |
| 9376 | } |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9377 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 9378 | wallpaperMayChange = true; |
| 9379 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9380 | |
| 9381 | if (mPolicy.doesForceHide(w, attrs)) { |
| 9382 | if (!wasAnimating && animating) { |
| 9383 | wallpaperForceHidingChanged = true; |
| 9384 | focusMayChange = true; |
| 9385 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 9386 | forceHiding = true; |
| 9387 | } |
| 9388 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9389 | boolean changed; |
| 9390 | if (forceHiding) { |
| 9391 | changed = w.hideLw(false, false); |
| 9392 | } else { |
| 9393 | changed = w.showLw(false, false); |
| 9394 | if (changed && wallpaperForceHidingChanged |
| 9395 | && w.isReadyForDisplay()) { |
| 9396 | // Assume we will need to animate. If |
| 9397 | // we don't (because the wallpaper will |
| 9398 | // stay with the lock screen), then we will |
| 9399 | // clean up later. |
| 9400 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 9401 | if (a != null) { |
| 9402 | w.setAnimation(a); |
| 9403 | } |
| 9404 | } |
| 9405 | } |
| 9406 | if (changed && (attrs.flags |
| 9407 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 9408 | wallpaperMayChange = true; |
| 9409 | } |
| 9410 | } |
| 9411 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9412 | mPolicy.animatingWindowLw(w, attrs); |
| 9413 | } |
| 9414 | |
| 9415 | final AppWindowToken atoken = w.mAppToken; |
| 9416 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 9417 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 9418 | atoken.lastTransactionSequence = transactionSequence; |
| 9419 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 9420 | atoken.startingDisplayed = false; |
| 9421 | } |
| 9422 | if ((w.isOnScreen() || w.mAttrs.type |
| 9423 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 9424 | && !w.mExiting && !w.mDestroying) { |
| 9425 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9426 | Log.v(TAG, "Eval win " + w + ": isDrawn=" |
| 9427 | + w.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9428 | + ", isAnimating=" + w.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9429 | if (!w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9430 | Log.v(TAG, "Not displayed: s=" + w.mSurface |
| 9431 | + " pv=" + w.mPolicyVisibility |
| 9432 | + " dp=" + w.mDrawPending |
| 9433 | + " cdp=" + w.mCommitDrawPending |
| 9434 | + " ah=" + w.mAttachedHidden |
| 9435 | + " th=" + atoken.hiddenRequested |
| 9436 | + " a=" + w.mAnimating); |
| 9437 | } |
| 9438 | } |
| 9439 | if (w != atoken.startingWindow) { |
| 9440 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 9441 | atoken.numInterestingWindows++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9442 | if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9443 | atoken.numDrawnWindows++; |
| 9444 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Log.v(TAG, |
| 9445 | "tokenMayBeDrawn: " + atoken |
| 9446 | + " freezingScreen=" + atoken.freezingScreen |
| 9447 | + " mAppFreezing=" + w.mAppFreezing); |
| 9448 | tokenMayBeDrawn = true; |
| 9449 | } |
| 9450 | } |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9451 | } else if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9452 | atoken.startingDisplayed = true; |
| 9453 | } |
| 9454 | } |
| 9455 | } else if (w.mReadyToShow) { |
| 9456 | w.performShowLocked(); |
| 9457 | } |
| 9458 | } |
| 9459 | |
| 9460 | if (mPolicy.finishAnimationLw()) { |
| 9461 | restart = true; |
| 9462 | } |
| 9463 | |
| 9464 | if (tokenMayBeDrawn) { |
| 9465 | // See if any windows have been drawn, so they (and others |
| 9466 | // associated with them) can now be shown. |
| 9467 | final int NT = mTokenList.size(); |
| 9468 | for (i=0; i<NT; i++) { |
| 9469 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 9470 | if (wtoken == null) { |
| 9471 | continue; |
| 9472 | } |
| 9473 | if (wtoken.freezingScreen) { |
| 9474 | int numInteresting = wtoken.numInterestingWindows; |
| 9475 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| 9476 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 9477 | "allDrawn: " + wtoken |
| 9478 | + " interesting=" + numInteresting |
| 9479 | + " drawn=" + wtoken.numDrawnWindows); |
| 9480 | wtoken.showAllWindowsLocked(); |
| 9481 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 9482 | orientationChangeComplete = true; |
| 9483 | } |
| 9484 | } else if (!wtoken.allDrawn) { |
| 9485 | int numInteresting = wtoken.numInterestingWindows; |
| 9486 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| 9487 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 9488 | "allDrawn: " + wtoken |
| 9489 | + " interesting=" + numInteresting |
| 9490 | + " drawn=" + wtoken.numDrawnWindows); |
| 9491 | wtoken.allDrawn = true; |
| 9492 | restart = true; |
| 9493 | |
| 9494 | // We can now show all of the drawn windows! |
| 9495 | if (!mOpeningApps.contains(wtoken)) { |
| 9496 | wtoken.showAllWindowsLocked(); |
| 9497 | } |
| 9498 | } |
| 9499 | } |
| 9500 | } |
| 9501 | } |
| 9502 | |
| 9503 | // If we are ready to perform an app transition, check through |
| 9504 | // all of the app tokens to be shown and see if they are ready |
| 9505 | // to go. |
| 9506 | if (mAppTransitionReady) { |
| 9507 | int NN = mOpeningApps.size(); |
| 9508 | boolean goodToGo = true; |
| 9509 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9510 | "Checking " + NN + " opening apps (frozen=" |
| 9511 | + mDisplayFrozen + " timeout=" |
| 9512 | + mAppTransitionTimeout + ")..."); |
| 9513 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 9514 | // If the display isn't frozen, wait to do anything until |
| 9515 | // all of the apps are ready. Otherwise just go because |
| 9516 | // we'll unfreeze the display when everyone is ready. |
| 9517 | for (i=0; i<NN && goodToGo; i++) { |
| 9518 | AppWindowToken wtoken = mOpeningApps.get(i); |
| 9519 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9520 | "Check opening app" + wtoken + ": allDrawn=" |
| 9521 | + wtoken.allDrawn + " startingDisplayed=" |
| 9522 | + wtoken.startingDisplayed); |
| 9523 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 9524 | && !wtoken.startingMoved) { |
| 9525 | goodToGo = false; |
| 9526 | } |
| 9527 | } |
| 9528 | } |
| 9529 | if (goodToGo) { |
| 9530 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "**** GOOD TO GO"); |
| 9531 | int transit = mNextAppTransition; |
| 9532 | if (mSkipAppTransitionAnimation) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9533 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9534 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9535 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9536 | mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9537 | mAppTransitionRunning = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9538 | mAppTransitionTimeout = false; |
| 9539 | mStartingIconInTransition = false; |
| 9540 | mSkipAppTransitionAnimation = false; |
| 9541 | |
| 9542 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 9543 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9544 | // If there are applications waiting to come to the |
| 9545 | // top of the stack, now is the time to move their windows. |
| 9546 | // (Note that we don't do apps going to the bottom |
| 9547 | // here -- we want to keep their windows in the old |
| 9548 | // Z-order until the animation completes.) |
| 9549 | if (mToTopApps.size() > 0) { |
| 9550 | NN = mAppTokens.size(); |
| 9551 | for (i=0; i<NN; i++) { |
| 9552 | AppWindowToken wtoken = mAppTokens.get(i); |
| 9553 | if (wtoken.sendingToTop) { |
| 9554 | wtoken.sendingToTop = false; |
| 9555 | moveAppWindowsLocked(wtoken, NN, false); |
| 9556 | } |
| 9557 | } |
| 9558 | mToTopApps.clear(); |
| 9559 | } |
| 9560 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9561 | WindowState oldWallpaper = mWallpaperTarget; |
| 9562 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9563 | adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9564 | wallpaperMayChange = false; |
| 9565 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9566 | // The top-most window will supply the layout params, |
| 9567 | // and we will determine it below. |
| 9568 | LayoutParams animLp = null; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9569 | AppWindowToken animToken = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9570 | int bestAnimLayer = -1; |
| 9571 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9572 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9573 | "New wallpaper target=" + mWallpaperTarget |
| 9574 | + ", lower target=" + mLowerWallpaperTarget |
| 9575 | + ", upper target=" + mUpperWallpaperTarget); |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9576 | int foundWallpapers = 0; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9577 | // Do a first pass through the tokens for two |
| 9578 | // things: |
| 9579 | // (1) Determine if both the closing and opening |
| 9580 | // app token sets are wallpaper targets, in which |
| 9581 | // case special animations are needed |
| 9582 | // (since the wallpaper needs to stay static |
| 9583 | // behind them). |
| 9584 | // (2) Find the layout params of the top-most |
| 9585 | // application window in the tokens, which is |
| 9586 | // what will control the animation theme. |
| 9587 | final int NC = mClosingApps.size(); |
| 9588 | NN = NC + mOpeningApps.size(); |
| 9589 | for (i=0; i<NN; i++) { |
| 9590 | AppWindowToken wtoken; |
| 9591 | int mode; |
| 9592 | if (i < NC) { |
| 9593 | wtoken = mClosingApps.get(i); |
| 9594 | mode = 1; |
| 9595 | } else { |
| 9596 | wtoken = mOpeningApps.get(i-NC); |
| 9597 | mode = 2; |
| 9598 | } |
| 9599 | if (mLowerWallpaperTarget != null) { |
| 9600 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 9601 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 9602 | foundWallpapers |= mode; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9603 | } |
| 9604 | } |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9605 | if (wtoken.appFullscreen) { |
| 9606 | WindowState ws = wtoken.findMainWindow(); |
| 9607 | if (ws != null) { |
| 9608 | // If this is a compatibility mode |
| 9609 | // window, we will always use its anim. |
| 9610 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 9611 | animLp = ws.mAttrs; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9612 | animToken = ws.mAppToken; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9613 | bestAnimLayer = Integer.MAX_VALUE; |
| 9614 | } else if (ws.mLayer > bestAnimLayer) { |
| 9615 | animLp = ws.mAttrs; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9616 | animToken = ws.mAppToken; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9617 | bestAnimLayer = ws.mLayer; |
| 9618 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9619 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9620 | } |
| 9621 | } |
| 9622 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9623 | if (foundWallpapers == 3) { |
| 9624 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9625 | "Wallpaper animation!"); |
| 9626 | switch (transit) { |
| 9627 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 9628 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 9629 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 9630 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 9631 | break; |
| 9632 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 9633 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 9634 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 9635 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 9636 | break; |
| 9637 | } |
| 9638 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9639 | "New transit: " + transit); |
| 9640 | } else if (oldWallpaper != null) { |
| 9641 | // We are transitioning from an activity with |
| 9642 | // a wallpaper to one without. |
| 9643 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
| 9644 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9645 | "New transit away from wallpaper: " + transit); |
| 9646 | } else if (mWallpaperTarget != null) { |
| 9647 | // We are transitioning from an activity without |
| 9648 | // a wallpaper to now showing the wallpaper |
| 9649 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
| 9650 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9651 | "New transit into wallpaper: " + transit); |
| 9652 | } |
| 9653 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9654 | if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) { |
| 9655 | mLastEnterAnimToken = animToken; |
| 9656 | mLastEnterAnimParams = animLp; |
| 9657 | } else if (mLastEnterAnimParams != null) { |
| 9658 | animLp = mLastEnterAnimParams; |
| 9659 | mLastEnterAnimToken = null; |
| 9660 | mLastEnterAnimParams = null; |
| 9661 | } |
| 9662 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9663 | NN = mOpeningApps.size(); |
| 9664 | for (i=0; i<NN; i++) { |
| 9665 | AppWindowToken wtoken = mOpeningApps.get(i); |
| 9666 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9667 | "Now opening app" + wtoken); |
| 9668 | wtoken.reportedVisible = false; |
| 9669 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9670 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9671 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9672 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9673 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9674 | wtoken.showAllWindowsLocked(); |
| 9675 | } |
| 9676 | NN = mClosingApps.size(); |
| 9677 | for (i=0; i<NN; i++) { |
| 9678 | AppWindowToken wtoken = mClosingApps.get(i); |
| 9679 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9680 | "Now closing app" + wtoken); |
| 9681 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9682 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9683 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9684 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9685 | wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9686 | // Force the allDrawn flag, because we want to start |
| 9687 | // this guy's animations regardless of whether it's |
| 9688 | // gotten drawn. |
| 9689 | wtoken.allDrawn = true; |
| 9690 | } |
| 9691 | |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 9692 | mNextAppTransitionPackage = null; |
| 9693 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9694 | mOpeningApps.clear(); |
| 9695 | mClosingApps.clear(); |
| 9696 | |
| 9697 | // This has changed the visibility of windows, so perform |
| 9698 | // a new layout to get them all up-to-date. |
| 9699 | mLayoutNeeded = true; |
Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 9700 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 9701 | assignLayersLocked(); |
| 9702 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9703 | performLayoutLockedInner(); |
| 9704 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9705 | focusMayChange = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9706 | |
| 9707 | restart = true; |
| 9708 | } |
| 9709 | } |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9710 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9711 | if (!animating && mAppTransitionRunning) { |
| 9712 | // We have finished the animation of an app transition. To do |
| 9713 | // this, we have delayed a lot of operations like showing and |
| 9714 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 9715 | // reflects the correct Z-order, but the window list may now |
| 9716 | // be out of sync with it. So here we will just rebuild the |
| 9717 | // entire app window list. Fun! |
| 9718 | mAppTransitionRunning = false; |
| 9719 | // Clear information about apps that were moving. |
| 9720 | mToBottomApps.clear(); |
| 9721 | |
| 9722 | rebuildAppWindowListLocked(); |
| 9723 | restart = true; |
| 9724 | moveInputMethodWindowsIfNeededLocked(false); |
| 9725 | wallpaperMayChange = true; |
| 9726 | mLayoutNeeded = true; |
Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 9727 | // Since the window list has been rebuilt, focus might |
| 9728 | // have to be recomputed since the actual order of windows |
| 9729 | // might have changed again. |
| 9730 | focusMayChange = true; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9731 | } |
| 9732 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9733 | int adjResult = 0; |
| 9734 | |
| 9735 | if (wallpaperForceHidingChanged) { |
| 9736 | // At this point, there was a window with a wallpaper that |
| 9737 | // was force hiding other windows behind it, but now it |
| 9738 | // is going away. This may be simple -- just animate |
| 9739 | // away the wallpaper and its window -- or it may be |
| 9740 | // hard -- the wallpaper now needs to be shown behind |
| 9741 | // something that was hidden. |
| 9742 | WindowState oldWallpaper = mWallpaperTarget; |
| 9743 | adjResult = adjustWallpaperWindowsLocked(); |
| 9744 | wallpaperMayChange = false; |
| 9745 | if (false) Log.v(TAG, "****** OLD: " + oldWallpaper |
| 9746 | + " NEW: " + mWallpaperTarget); |
| 9747 | if (mLowerWallpaperTarget == null) { |
| 9748 | // Whoops, we don't need a special wallpaper animation. |
| 9749 | // Clear them out. |
| 9750 | forceHiding = false; |
| 9751 | for (i=N-1; i>=0; i--) { |
| 9752 | WindowState w = (WindowState)mWindows.get(i); |
| 9753 | if (w.mSurface != null) { |
| 9754 | final WindowManager.LayoutParams attrs = w.mAttrs; |
Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 9755 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
| 9756 | if (DEBUG_FOCUS) Log.i(TAG, "win=" + w + " force hides other windows"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9757 | forceHiding = true; |
| 9758 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9759 | if (!w.mAnimating) { |
| 9760 | // We set the animation above so it |
| 9761 | // is not yet running. |
| 9762 | w.clearAnimation(); |
| 9763 | } |
| 9764 | } |
| 9765 | } |
| 9766 | } |
| 9767 | } |
| 9768 | } |
| 9769 | |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9770 | if (wallpaperMayChange) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9771 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 9772 | "Wallpaper may change! Adjusting"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9773 | adjResult = adjustWallpaperWindowsLocked(); |
| 9774 | } |
| 9775 | |
| 9776 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9777 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 9778 | "Wallpaper layer changed: assigning layers + relayout"); |
| 9779 | restart = true; |
| 9780 | mLayoutNeeded = true; |
| 9781 | assignLayersLocked(); |
| 9782 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
| 9783 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 9784 | "Wallpaper visibility changed: relayout"); |
| 9785 | restart = true; |
| 9786 | mLayoutNeeded = true; |
| 9787 | } |
| 9788 | |
| 9789 | if (focusMayChange) { |
| 9790 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9791 | restart = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9792 | adjResult = 0; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9793 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9794 | } |
| 9795 | |
| 9796 | if (mLayoutNeeded) { |
| 9797 | restart = true; |
| 9798 | performLayoutLockedInner(); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9799 | } |
| 9800 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9801 | } while (restart); |
| 9802 | |
| 9803 | // THIRD LOOP: Update the surfaces of all windows. |
| 9804 | |
| 9805 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 9806 | |
| 9807 | boolean obscured = false; |
| 9808 | boolean blurring = false; |
| 9809 | boolean dimming = false; |
| 9810 | boolean covered = false; |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9811 | boolean syswin = false; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9812 | boolean backgroundFillerShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9813 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9814 | final int N = mWindows.size(); |
| 9815 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9816 | for (i=N-1; i>=0; i--) { |
| 9817 | WindowState w = (WindowState)mWindows.get(i); |
| 9818 | |
| 9819 | boolean displayed = false; |
| 9820 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9821 | final int attrFlags = attrs.flags; |
| 9822 | |
| 9823 | if (w.mSurface != null) { |
| 9824 | w.computeShownFrameLocked(); |
| 9825 | if (localLOGV) Log.v( |
| 9826 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 9827 | + ": new=" + w.mShownFrame + ", old=" |
| 9828 | + w.mLastShownFrame); |
| 9829 | |
| 9830 | boolean resize; |
| 9831 | int width, height; |
| 9832 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 9833 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 9834 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 9835 | // for a scaled surface, we just want to use |
| 9836 | // the requested size. |
| 9837 | width = w.mRequestedWidth; |
| 9838 | height = w.mRequestedHeight; |
| 9839 | w.mLastRequestedWidth = width; |
| 9840 | w.mLastRequestedHeight = height; |
| 9841 | w.mLastShownFrame.set(w.mShownFrame); |
| 9842 | try { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9843 | if (SHOW_TRANSACTIONS) Log.i( |
| 9844 | TAG, " SURFACE " + w.mSurface |
| 9845 | + ": POS " + w.mShownFrame.left |
| 9846 | + ", " + w.mShownFrame.top); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9847 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 9848 | } catch (RuntimeException e) { |
| 9849 | Log.w(TAG, "Error positioning surface in " + w, e); |
| 9850 | if (!recoveringMemory) { |
| 9851 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 9852 | } |
| 9853 | } |
| 9854 | } else { |
| 9855 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 9856 | width = w.mShownFrame.width(); |
| 9857 | height = w.mShownFrame.height(); |
| 9858 | w.mLastShownFrame.set(w.mShownFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9859 | } |
| 9860 | |
| 9861 | if (resize) { |
| 9862 | if (width < 1) width = 1; |
| 9863 | if (height < 1) height = 1; |
| 9864 | if (w.mSurface != null) { |
| 9865 | try { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9866 | if (SHOW_TRANSACTIONS) Log.i( |
| 9867 | TAG, " SURFACE " + w.mSurface + ": POS " |
| 9868 | + w.mShownFrame.left + "," |
| 9869 | + w.mShownFrame.top + " SIZE " |
| 9870 | + w.mShownFrame.width() + "x" |
| 9871 | + w.mShownFrame.height()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9872 | w.mSurface.setSize(width, height); |
| 9873 | w.mSurface.setPosition(w.mShownFrame.left, |
| 9874 | w.mShownFrame.top); |
| 9875 | } catch (RuntimeException e) { |
| 9876 | // If something goes wrong with the surface (such |
| 9877 | // as running out of memory), don't take down the |
| 9878 | // entire system. |
| 9879 | Log.e(TAG, "Failure updating surface of " + w |
| 9880 | + "size=(" + width + "x" + height |
| 9881 | + "), pos=(" + w.mShownFrame.left |
| 9882 | + "," + w.mShownFrame.top + ")", e); |
| 9883 | if (!recoveringMemory) { |
| 9884 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 9885 | } |
| 9886 | } |
| 9887 | } |
| 9888 | } |
| 9889 | if (!w.mAppFreezing) { |
| 9890 | w.mContentInsetsChanged = |
| 9891 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 9892 | w.mVisibleInsetsChanged = |
| 9893 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9894 | if (!w.mLastFrame.equals(w.mFrame) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9895 | || w.mContentInsetsChanged |
| 9896 | || w.mVisibleInsetsChanged) { |
| 9897 | w.mLastFrame.set(w.mFrame); |
| 9898 | w.mLastContentInsets.set(w.mContentInsets); |
| 9899 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9900 | // If the screen is currently frozen, then keep |
| 9901 | // it frozen until this window draws at its new |
| 9902 | // orientation. |
| 9903 | if (mDisplayFrozen) { |
| 9904 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 9905 | "Resizing while display frozen: " + w); |
| 9906 | w.mOrientationChanging = true; |
| 9907 | if (mWindowsFreezingScreen) { |
| 9908 | mWindowsFreezingScreen = true; |
| 9909 | // XXX should probably keep timeout from |
| 9910 | // when we first froze the display. |
| 9911 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 9912 | mH.sendMessageDelayed(mH.obtainMessage( |
| 9913 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 9914 | } |
| 9915 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9916 | // If the orientation is changing, then we need to |
| 9917 | // hold off on unfreezing the display until this |
| 9918 | // window has been redrawn; to do that, we need |
| 9919 | // to go through the process of getting informed |
| 9920 | // by the application when it has finished drawing. |
| 9921 | if (w.mOrientationChanging) { |
| 9922 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 9923 | "Orientation start waiting for draw in " |
| 9924 | + w + ", surface " + w.mSurface); |
| 9925 | w.mDrawPending = true; |
| 9926 | w.mCommitDrawPending = false; |
| 9927 | w.mReadyToShow = false; |
| 9928 | if (w.mAppToken != null) { |
| 9929 | w.mAppToken.allDrawn = false; |
| 9930 | } |
| 9931 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9932 | if (DEBUG_ORIENTATION) Log.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9933 | "Resizing window " + w + " to " + w.mFrame); |
| 9934 | mResizingWindows.add(w); |
| 9935 | } else if (w.mOrientationChanging) { |
| 9936 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
| 9937 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 9938 | "Orientation not waiting for draw in " |
| 9939 | + w + ", surface " + w.mSurface); |
| 9940 | w.mOrientationChanging = false; |
| 9941 | } |
| 9942 | } |
| 9943 | } |
| 9944 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9945 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9946 | if (!w.mLastHidden) { |
| 9947 | //dump(); |
| 9948 | w.mLastHidden = true; |
| 9949 | if (SHOW_TRANSACTIONS) Log.i( |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9950 | TAG, " SURFACE " + w.mSurface + ": HIDE (performLayout)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9951 | if (w.mSurface != null) { |
| 9952 | try { |
| 9953 | w.mSurface.hide(); |
| 9954 | } catch (RuntimeException e) { |
| 9955 | Log.w(TAG, "Exception hiding surface in " + w); |
| 9956 | } |
| 9957 | } |
| 9958 | mKeyWaiter.releasePendingPointerLocked(w.mSession); |
| 9959 | } |
| 9960 | // If we are waiting for this window to handle an |
| 9961 | // orientation change, well, it is hidden, so |
| 9962 | // doesn't really matter. Note that this does |
| 9963 | // introduce a potential glitch if the window |
| 9964 | // becomes unhidden before it has drawn for the |
| 9965 | // new orientation. |
| 9966 | if (w.mOrientationChanging) { |
| 9967 | w.mOrientationChanging = false; |
| 9968 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 9969 | "Orientation change skips hidden " + w); |
| 9970 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9971 | } else if (w.mLastLayer != w.mAnimLayer |
| 9972 | || w.mLastAlpha != w.mShownAlpha |
| 9973 | || w.mLastDsDx != w.mDsDx |
| 9974 | || w.mLastDtDx != w.mDtDx |
| 9975 | || w.mLastDsDy != w.mDsDy |
| 9976 | || w.mLastDtDy != w.mDtDy |
| 9977 | || w.mLastHScale != w.mHScale |
| 9978 | || w.mLastVScale != w.mVScale |
| 9979 | || w.mLastHidden) { |
| 9980 | displayed = true; |
| 9981 | w.mLastAlpha = w.mShownAlpha; |
| 9982 | w.mLastLayer = w.mAnimLayer; |
| 9983 | w.mLastDsDx = w.mDsDx; |
| 9984 | w.mLastDtDx = w.mDtDx; |
| 9985 | w.mLastDsDy = w.mDsDy; |
| 9986 | w.mLastDtDy = w.mDtDy; |
| 9987 | w.mLastHScale = w.mHScale; |
| 9988 | w.mLastVScale = w.mVScale; |
| 9989 | if (SHOW_TRANSACTIONS) Log.i( |
| 9990 | TAG, " SURFACE " + w.mSurface + ": alpha=" |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9991 | + w.mShownAlpha + " layer=" + w.mAnimLayer |
| 9992 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 9993 | + "," + (w.mDtDx*w.mVScale) |
| 9994 | + "][" + (w.mDsDy*w.mHScale) |
| 9995 | + "," + (w.mDtDy*w.mVScale) + "]"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9996 | if (w.mSurface != null) { |
| 9997 | try { |
| 9998 | w.mSurface.setAlpha(w.mShownAlpha); |
| 9999 | w.mSurface.setLayer(w.mAnimLayer); |
| 10000 | w.mSurface.setMatrix( |
| 10001 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 10002 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 10003 | } catch (RuntimeException e) { |
| 10004 | Log.w(TAG, "Error updating surface in " + w, e); |
| 10005 | if (!recoveringMemory) { |
| 10006 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 10007 | } |
| 10008 | } |
| 10009 | } |
| 10010 | |
| 10011 | if (w.mLastHidden && !w.mDrawPending |
| 10012 | && !w.mCommitDrawPending |
| 10013 | && !w.mReadyToShow) { |
| 10014 | if (SHOW_TRANSACTIONS) Log.i( |
| 10015 | TAG, " SURFACE " + w.mSurface + ": SHOW (performLayout)"); |
| 10016 | if (DEBUG_VISIBILITY) Log.v(TAG, "Showing " + w |
| 10017 | + " during relayout"); |
| 10018 | if (showSurfaceRobustlyLocked(w)) { |
| 10019 | w.mHasDrawn = true; |
| 10020 | w.mLastHidden = false; |
| 10021 | } else { |
| 10022 | w.mOrientationChanging = false; |
| 10023 | } |
| 10024 | } |
| 10025 | if (w.mSurface != null) { |
| 10026 | w.mToken.hasVisible = true; |
| 10027 | } |
| 10028 | } else { |
| 10029 | displayed = true; |
| 10030 | } |
| 10031 | |
| 10032 | if (displayed) { |
| 10033 | if (!covered) { |
| 10034 | if (attrs.width == LayoutParams.FILL_PARENT |
| 10035 | && attrs.height == LayoutParams.FILL_PARENT) { |
| 10036 | covered = true; |
| 10037 | } |
| 10038 | } |
| 10039 | if (w.mOrientationChanging) { |
| 10040 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 10041 | orientationChangeComplete = false; |
| 10042 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 10043 | "Orientation continue waiting for draw in " + w); |
| 10044 | } else { |
| 10045 | w.mOrientationChanging = false; |
| 10046 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 10047 | "Orientation change complete in " + w); |
| 10048 | } |
| 10049 | } |
| 10050 | w.mToken.hasVisible = true; |
| 10051 | } |
| 10052 | } else if (w.mOrientationChanging) { |
| 10053 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 10054 | "Orientation change skips hidden " + w); |
| 10055 | w.mOrientationChanging = false; |
| 10056 | } |
| 10057 | |
| 10058 | final boolean canBeSeen = w.isDisplayedLw(); |
| 10059 | |
| 10060 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 10061 | focusDisplayed = true; |
| 10062 | } |
| 10063 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10064 | final boolean obscuredChanged = w.mObscured != obscured; |
| 10065 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10066 | // Update effect. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10067 | if (!(w.mObscured=obscured)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10068 | if (w.mSurface != null) { |
| 10069 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 10070 | holdScreen = w.mSession; |
| 10071 | } |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10072 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 10073 | && screenBrightness < 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10074 | screenBrightness = w.mAttrs.screenBrightness; |
| 10075 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame^] | 10076 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 10077 | && buttonBrightness < 0) { |
| 10078 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 10079 | } |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10080 | if (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 10081 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 10082 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR) { |
| 10083 | syswin = true; |
| 10084 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10085 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10086 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10087 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 10088 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10089 | // This window completely covers everything behind it, |
| 10090 | // so we want to leave all of them as unblurred (for |
| 10091 | // performance reasons). |
| 10092 | obscured = true; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10093 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
| 10094 | if (SHOW_TRANSACTIONS) Log.d(TAG, "showing background filler"); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10095 | // This window is in compatibility mode, and needs background filler. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10096 | obscured = true; |
| 10097 | if (mBackgroundFillerSurface == null) { |
| 10098 | try { |
| 10099 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
| 10100 | 0, dw, dh, |
| 10101 | PixelFormat.OPAQUE, |
| 10102 | Surface.FX_SURFACE_NORMAL); |
| 10103 | } catch (Exception e) { |
| 10104 | Log.e(TAG, "Exception creating filler surface", e); |
| 10105 | } |
| 10106 | } |
| 10107 | try { |
| 10108 | mBackgroundFillerSurface.setPosition(0, 0); |
| 10109 | mBackgroundFillerSurface.setSize(dw, dh); |
| 10110 | // Using the same layer as Dim because they will never be shown at the |
| 10111 | // same time. |
| 10112 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 10113 | mBackgroundFillerSurface.show(); |
| 10114 | } catch (RuntimeException e) { |
| 10115 | Log.e(TAG, "Exception showing filler surface"); |
| 10116 | } |
| 10117 | backgroundFillerShown = true; |
| 10118 | mBackgroundFillerShown = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10119 | } else if (canBeSeen && !obscured && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10120 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
| 10121 | if (localLOGV) Log.v(TAG, "Win " + w |
| 10122 | + ": blurring=" + blurring |
| 10123 | + " obscured=" + obscured |
| 10124 | + " displayed=" + displayed); |
| 10125 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 10126 | if (!dimming) { |
| 10127 | //Log.i(TAG, "DIM BEHIND: " + w); |
| 10128 | dimming = true; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10129 | if (mDimAnimator == null) { |
| 10130 | mDimAnimator = new DimAnimator(mFxSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10131 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10132 | mDimAnimator.show(dw, dh); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10133 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10134 | mDimAnimator.updateParameters(w, currentTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10135 | } |
| 10136 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 10137 | if (!blurring) { |
| 10138 | //Log.i(TAG, "BLUR BEHIND: " + w); |
| 10139 | blurring = true; |
| 10140 | mBlurShown = true; |
| 10141 | if (mBlurSurface == null) { |
| 10142 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " |
| 10143 | + mBlurSurface + ": CREATE"); |
| 10144 | try { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10145 | mBlurSurface = new Surface(mFxSession, 0, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10146 | -1, 16, 16, |
| 10147 | PixelFormat.OPAQUE, |
| 10148 | Surface.FX_SURFACE_BLUR); |
| 10149 | } catch (Exception e) { |
| 10150 | Log.e(TAG, "Exception creating Blur surface", e); |
| 10151 | } |
| 10152 | } |
| 10153 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " |
| 10154 | + mBlurSurface + ": SHOW pos=(0,0) (" + |
| 10155 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
| 10156 | if (mBlurSurface != null) { |
| 10157 | mBlurSurface.setPosition(0, 0); |
| 10158 | mBlurSurface.setSize(dw, dh); |
| 10159 | try { |
| 10160 | mBlurSurface.show(); |
| 10161 | } catch (RuntimeException e) { |
| 10162 | Log.w(TAG, "Failure showing blur surface", e); |
| 10163 | } |
| 10164 | } |
| 10165 | } |
| 10166 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 10167 | } |
| 10168 | } |
| 10169 | } |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10170 | |
| 10171 | if (obscuredChanged && mWallpaperTarget == w) { |
| 10172 | // This is the wallpaper target and its obscured state |
| 10173 | // changed... make sure the current wallaper's visibility |
| 10174 | // has been updated accordingly. |
| 10175 | updateWallpaperVisibilityLocked(); |
| 10176 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10177 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10178 | |
| 10179 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 10180 | mBackgroundFillerShown = false; |
| 10181 | if (SHOW_TRANSACTIONS) Log.d(TAG, "hiding background filler"); |
| 10182 | try { |
| 10183 | mBackgroundFillerSurface.hide(); |
| 10184 | } catch (RuntimeException e) { |
| 10185 | Log.e(TAG, "Exception hiding filler surface", e); |
| 10186 | } |
| 10187 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10188 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10189 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
| 10190 | animating |= mDimAnimator.updateSurface(dimming, currentTime, mDisplayFrozen); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10191 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10192 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10193 | if (!blurring && mBlurShown) { |
| 10194 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " + mBlurSurface |
| 10195 | + ": HIDE"); |
| 10196 | try { |
| 10197 | mBlurSurface.hide(); |
| 10198 | } catch (IllegalArgumentException e) { |
| 10199 | Log.w(TAG, "Illegal argument exception hiding blur surface"); |
| 10200 | } |
| 10201 | mBlurShown = false; |
| 10202 | } |
| 10203 | |
| 10204 | if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION"); |
| 10205 | } catch (RuntimeException e) { |
| 10206 | Log.e(TAG, "Unhandled exception in Window Manager", e); |
| 10207 | } |
| 10208 | |
| 10209 | Surface.closeTransaction(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10210 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10211 | if (DEBUG_ORIENTATION && mDisplayFrozen) Log.v(TAG, |
| 10212 | "With display frozen, orientationChangeComplete=" |
| 10213 | + orientationChangeComplete); |
| 10214 | if (orientationChangeComplete) { |
| 10215 | if (mWindowsFreezingScreen) { |
| 10216 | mWindowsFreezingScreen = false; |
| 10217 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10218 | } |
| 10219 | if (mAppsFreezingScreen == 0) { |
| 10220 | stopFreezingDisplayLocked(); |
| 10221 | } |
| 10222 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10223 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10224 | i = mResizingWindows.size(); |
| 10225 | if (i > 0) { |
| 10226 | do { |
| 10227 | i--; |
| 10228 | WindowState win = mResizingWindows.get(i); |
| 10229 | try { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10230 | if (DEBUG_ORIENTATION) Log.v(TAG, "Reporting new frame to " |
| 10231 | + win + ": " + win.mFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10232 | win.mClient.resized(win.mFrame.width(), |
| 10233 | win.mFrame.height(), win.mLastContentInsets, |
| 10234 | win.mLastVisibleInsets, win.mDrawPending); |
| 10235 | win.mContentInsetsChanged = false; |
| 10236 | win.mVisibleInsetsChanged = false; |
| 10237 | } catch (RemoteException e) { |
| 10238 | win.mOrientationChanging = false; |
| 10239 | } |
| 10240 | } while (i > 0); |
| 10241 | mResizingWindows.clear(); |
| 10242 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10243 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10244 | // Destroy the surface of any windows that are no longer visible. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10245 | boolean wallpaperDestroyed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10246 | i = mDestroySurface.size(); |
| 10247 | if (i > 0) { |
| 10248 | do { |
| 10249 | i--; |
| 10250 | WindowState win = mDestroySurface.get(i); |
| 10251 | win.mDestroying = false; |
| 10252 | if (mInputMethodWindow == win) { |
| 10253 | mInputMethodWindow = null; |
| 10254 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10255 | if (win == mWallpaperTarget) { |
| 10256 | wallpaperDestroyed = true; |
| 10257 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10258 | win.destroySurfaceLocked(); |
| 10259 | } while (i > 0); |
| 10260 | mDestroySurface.clear(); |
| 10261 | } |
| 10262 | |
| 10263 | // Time to remove any exiting tokens? |
| 10264 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 10265 | WindowToken token = mExitingTokens.get(i); |
| 10266 | if (!token.hasVisible) { |
| 10267 | mExitingTokens.remove(i); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10268 | if (token.windowType == TYPE_WALLPAPER) { |
| 10269 | mWallpaperTokens.remove(token); |
| 10270 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10271 | } |
| 10272 | } |
| 10273 | |
| 10274 | // Time to remove any exiting applications? |
| 10275 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10276 | AppWindowToken token = mExitingAppTokens.get(i); |
| 10277 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 10278 | // Make sure there is no animation running on this token, |
| 10279 | // so any windows associated with it will be removed as |
| 10280 | // soon as their animations are complete |
| 10281 | token.animation = null; |
| 10282 | token.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10283 | mAppTokens.remove(token); |
| 10284 | mExitingAppTokens.remove(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10285 | if (mLastEnterAnimToken == token) { |
| 10286 | mLastEnterAnimToken = null; |
| 10287 | mLastEnterAnimParams = null; |
| 10288 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10289 | } |
| 10290 | } |
| 10291 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10292 | boolean needRelayout = false; |
| 10293 | |
| 10294 | if (!animating && mAppTransitionRunning) { |
| 10295 | // We have finished the animation of an app transition. To do |
| 10296 | // this, we have delayed a lot of operations like showing and |
| 10297 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10298 | // reflects the correct Z-order, but the window list may now |
| 10299 | // be out of sync with it. So here we will just rebuild the |
| 10300 | // entire app window list. Fun! |
| 10301 | mAppTransitionRunning = false; |
| 10302 | needRelayout = true; |
| 10303 | rebuildAppWindowListLocked(); |
| 10304 | // Clear information about apps that were moving. |
| 10305 | mToBottomApps.clear(); |
| 10306 | } |
| 10307 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10308 | if (focusDisplayed) { |
| 10309 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 10310 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10311 | if (wallpaperDestroyed) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10312 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10313 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10314 | if (needRelayout) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10315 | requestAnimationLocked(0); |
| 10316 | } else if (animating) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10317 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 10318 | } |
| 10319 | mQueue.setHoldScreenLocked(holdScreen != null); |
| 10320 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 10321 | mPowerManager.setScreenBrightnessOverride(-1); |
| 10322 | } else { |
| 10323 | mPowerManager.setScreenBrightnessOverride((int) |
| 10324 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 10325 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame^] | 10326 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 10327 | mPowerManager.setButtonBrightnessOverride(-1); |
| 10328 | } else { |
| 10329 | mPowerManager.setButtonBrightnessOverride((int) |
| 10330 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 10331 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10332 | if (holdScreen != mHoldingScreenOn) { |
| 10333 | mHoldingScreenOn = holdScreen; |
| 10334 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 10335 | mH.sendMessage(m); |
| 10336 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10337 | |
| 10338 | if (mTurnOnScreen) { |
| 10339 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 10340 | LocalPowerManager.BUTTON_EVENT, true); |
| 10341 | mTurnOnScreen = false; |
| 10342 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10343 | } |
| 10344 | |
| 10345 | void requestAnimationLocked(long delay) { |
| 10346 | if (!mAnimationPending) { |
| 10347 | mAnimationPending = true; |
| 10348 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 10349 | } |
| 10350 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10351 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10352 | /** |
| 10353 | * Have the surface flinger show a surface, robustly dealing with |
| 10354 | * error conditions. In particular, if there is not enough memory |
| 10355 | * to show the surface, then we will try to get rid of other surfaces |
| 10356 | * in order to succeed. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10357 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10358 | * @return Returns true if the surface was successfully shown. |
| 10359 | */ |
| 10360 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 10361 | try { |
| 10362 | if (win.mSurface != null) { |
| 10363 | win.mSurface.show(); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10364 | if (win.mTurnOnScreen) { |
| 10365 | win.mTurnOnScreen = false; |
| 10366 | mTurnOnScreen = true; |
| 10367 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10368 | } |
| 10369 | return true; |
| 10370 | } catch (RuntimeException e) { |
| 10371 | Log.w(TAG, "Failure showing surface " + win.mSurface + " in " + win); |
| 10372 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10374 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10375 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10376 | return false; |
| 10377 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10378 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10379 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 10380 | final Surface surface = win.mSurface; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10381 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10382 | EventLog.writeEvent(LOG_WM_NO_SURFACE_MEMORY, win.toString(), |
| 10383 | win.mSession.mPid, operation); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10384 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10385 | if (mForceRemoves == null) { |
| 10386 | mForceRemoves = new ArrayList<WindowState>(); |
| 10387 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10388 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10389 | long callingIdentity = Binder.clearCallingIdentity(); |
| 10390 | try { |
| 10391 | // There was some problem... first, do a sanity check of the |
| 10392 | // window list to make sure we haven't left any dangling surfaces |
| 10393 | // around. |
| 10394 | int N = mWindows.size(); |
| 10395 | boolean leakedSurface = false; |
| 10396 | Log.i(TAG, "Out of memory for surface! Looking for leaks..."); |
| 10397 | for (int i=0; i<N; i++) { |
| 10398 | WindowState ws = (WindowState)mWindows.get(i); |
| 10399 | if (ws.mSurface != null) { |
| 10400 | if (!mSessions.contains(ws.mSession)) { |
| 10401 | Log.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
| 10402 | + ws + " surface=" + ws.mSurface |
| 10403 | + " token=" + win.mToken |
| 10404 | + " pid=" + ws.mSession.mPid |
| 10405 | + " uid=" + ws.mSession.mUid); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10406 | ws.mSurface.destroy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10407 | ws.mSurface = null; |
| 10408 | mForceRemoves.add(ws); |
| 10409 | i--; |
| 10410 | N--; |
| 10411 | leakedSurface = true; |
| 10412 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
| 10413 | Log.w(TAG, "LEAKED SURFACE (app token hidden): " |
| 10414 | + ws + " surface=" + ws.mSurface |
| 10415 | + " token=" + win.mAppToken); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10416 | ws.mSurface.destroy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10417 | ws.mSurface = null; |
| 10418 | leakedSurface = true; |
| 10419 | } |
| 10420 | } |
| 10421 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10422 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10423 | boolean killedApps = false; |
| 10424 | if (!leakedSurface) { |
| 10425 | Log.w(TAG, "No leaked surfaces; killing applicatons!"); |
| 10426 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 10427 | for (int i=0; i<N; i++) { |
| 10428 | WindowState ws = (WindowState)mWindows.get(i); |
| 10429 | if (ws.mSurface != null) { |
| 10430 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 10431 | } |
| 10432 | } |
| 10433 | if (pidCandidates.size() > 0) { |
| 10434 | int[] pids = new int[pidCandidates.size()]; |
| 10435 | for (int i=0; i<pids.length; i++) { |
| 10436 | pids[i] = pidCandidates.keyAt(i); |
| 10437 | } |
| 10438 | try { |
| 10439 | if (mActivityManager.killPidsForMemory(pids)) { |
| 10440 | killedApps = true; |
| 10441 | } |
| 10442 | } catch (RemoteException e) { |
| 10443 | } |
| 10444 | } |
| 10445 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10446 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10447 | if (leakedSurface || killedApps) { |
| 10448 | // We managed to reclaim some memory, so get rid of the trouble |
| 10449 | // surface and ask the app to request another one. |
| 10450 | Log.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry."); |
| 10451 | if (surface != null) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10452 | surface.destroy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10453 | win.mSurface = null; |
| 10454 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10455 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10456 | try { |
| 10457 | win.mClient.dispatchGetNewSurface(); |
| 10458 | } catch (RemoteException e) { |
| 10459 | } |
| 10460 | } |
| 10461 | } finally { |
| 10462 | Binder.restoreCallingIdentity(callingIdentity); |
| 10463 | } |
| 10464 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10465 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10466 | private boolean updateFocusedWindowLocked(int mode) { |
| 10467 | WindowState newFocus = computeFocusedWindowLocked(); |
| 10468 | if (mCurrentFocus != newFocus) { |
| 10469 | // This check makes sure that we don't already have the focus |
| 10470 | // change message pending. |
| 10471 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 10472 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
| 10473 | if (localLOGV) Log.v( |
| 10474 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 10475 | final WindowState oldFocus = mCurrentFocus; |
| 10476 | mCurrentFocus = newFocus; |
| 10477 | mLosingFocus.remove(newFocus); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10478 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10479 | final WindowState imWindow = mInputMethodWindow; |
| 10480 | if (newFocus != imWindow && oldFocus != imWindow) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10481 | if (moveInputMethodWindowsIfNeededLocked( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10482 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10483 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 10484 | mLayoutNeeded = true; |
| 10485 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10486 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 10487 | performLayoutLockedInner(); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10488 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 10489 | // Client will do the layout, but we need to assign layers |
| 10490 | // for handleNewWindowLocked() below. |
| 10491 | assignLayersLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10492 | } |
| 10493 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10494 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10495 | if (newFocus != null && mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 10496 | mKeyWaiter.handleNewWindowLocked(newFocus); |
| 10497 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10498 | return true; |
| 10499 | } |
| 10500 | return false; |
| 10501 | } |
| 10502 | |
| 10503 | private WindowState computeFocusedWindowLocked() { |
| 10504 | WindowState result = null; |
| 10505 | WindowState win; |
| 10506 | |
| 10507 | int i = mWindows.size() - 1; |
| 10508 | int nextAppIndex = mAppTokens.size()-1; |
| 10509 | WindowToken nextApp = nextAppIndex >= 0 |
| 10510 | ? mAppTokens.get(nextAppIndex) : null; |
| 10511 | |
| 10512 | while (i >= 0) { |
| 10513 | win = (WindowState)mWindows.get(i); |
| 10514 | |
| 10515 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 10516 | TAG, "Looking for focus: " + i |
| 10517 | + " = " + win |
| 10518 | + ", flags=" + win.mAttrs.flags |
| 10519 | + ", canReceive=" + win.canReceiveKeys()); |
| 10520 | |
| 10521 | AppWindowToken thisApp = win.mAppToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10522 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10523 | // If this window's application has been removed, just skip it. |
| 10524 | if (thisApp != null && thisApp.removed) { |
| 10525 | i--; |
| 10526 | continue; |
| 10527 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10528 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10529 | // If there is a focused app, don't allow focus to go to any |
| 10530 | // windows below it. If this is an application window, step |
| 10531 | // through the app tokens until we find its app. |
| 10532 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 10533 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 10534 | int origAppIndex = nextAppIndex; |
| 10535 | while (nextAppIndex > 0) { |
| 10536 | if (nextApp == mFocusedApp) { |
| 10537 | // Whoops, we are below the focused app... no focus |
| 10538 | // for you! |
| 10539 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 10540 | TAG, "Reached focused app: " + mFocusedApp); |
| 10541 | return null; |
| 10542 | } |
| 10543 | nextAppIndex--; |
| 10544 | nextApp = mAppTokens.get(nextAppIndex); |
| 10545 | if (nextApp == thisApp) { |
| 10546 | break; |
| 10547 | } |
| 10548 | } |
| 10549 | if (thisApp != nextApp) { |
| 10550 | // Uh oh, the app token doesn't exist! This shouldn't |
| 10551 | // happen, but if it does we can get totally hosed... |
| 10552 | // so restart at the original app. |
| 10553 | nextAppIndex = origAppIndex; |
| 10554 | nextApp = mAppTokens.get(nextAppIndex); |
| 10555 | } |
| 10556 | } |
| 10557 | |
| 10558 | // Dispatch to this window if it is wants key events. |
| 10559 | if (win.canReceiveKeys()) { |
| 10560 | if (DEBUG_FOCUS) Log.v( |
| 10561 | TAG, "Found focus @ " + i + " = " + win); |
| 10562 | result = win; |
| 10563 | break; |
| 10564 | } |
| 10565 | |
| 10566 | i--; |
| 10567 | } |
| 10568 | |
| 10569 | return result; |
| 10570 | } |
| 10571 | |
| 10572 | private void startFreezingDisplayLocked() { |
| 10573 | if (mDisplayFrozen) { |
Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 10574 | // Freezing the display also suspends key event delivery, to |
| 10575 | // keep events from going astray while the display is reconfigured. |
| 10576 | // If someone has changed orientation again while the screen is |
| 10577 | // still frozen, the events will continue to be blocked while the |
| 10578 | // successive orientation change is processed. To prevent spurious |
| 10579 | // ANRs, we reset the event dispatch timeout in this case. |
| 10580 | synchronized (mKeyWaiter) { |
| 10581 | mKeyWaiter.mWasFrozen = true; |
| 10582 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10583 | return; |
| 10584 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10585 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10586 | mScreenFrozenLock.acquire(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10587 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10588 | long now = SystemClock.uptimeMillis(); |
| 10589 | //Log.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
| 10590 | if (mFreezeGcPending != 0) { |
| 10591 | if (now > (mFreezeGcPending+1000)) { |
| 10592 | //Log.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| 10593 | mH.removeMessages(H.FORCE_GC); |
| 10594 | Runtime.getRuntime().gc(); |
| 10595 | mFreezeGcPending = now; |
| 10596 | } |
| 10597 | } else { |
| 10598 | mFreezeGcPending = now; |
| 10599 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10600 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10601 | mDisplayFrozen = true; |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 10602 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 10603 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10604 | mNextAppTransitionPackage = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10605 | mAppTransitionReady = true; |
| 10606 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10607 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10608 | if (PROFILE_ORIENTATION) { |
| 10609 | File file = new File("/data/system/frozen"); |
| 10610 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 10611 | } |
| 10612 | Surface.freezeDisplay(0); |
| 10613 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10614 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10615 | private void stopFreezingDisplayLocked() { |
| 10616 | if (!mDisplayFrozen) { |
| 10617 | return; |
| 10618 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10619 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10620 | mDisplayFrozen = false; |
| 10621 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 10622 | if (PROFILE_ORIENTATION) { |
| 10623 | Debug.stopMethodTracing(); |
| 10624 | } |
| 10625 | Surface.unfreezeDisplay(0); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10626 | |
Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 10627 | // Reset the key delivery timeout on unfreeze, too. We force a wakeup here |
| 10628 | // too because regular key delivery processing should resume immediately. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10629 | synchronized (mKeyWaiter) { |
| 10630 | mKeyWaiter.mWasFrozen = true; |
| 10631 | mKeyWaiter.notifyAll(); |
| 10632 | } |
| 10633 | |
| 10634 | // A little kludge: a lot could have happened while the |
| 10635 | // display was frozen, so now that we are coming back we |
| 10636 | // do a gc so that any remote references the system |
| 10637 | // processes holds on others can be released if they are |
| 10638 | // no longer needed. |
| 10639 | mH.removeMessages(H.FORCE_GC); |
| 10640 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 10641 | 2000); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10642 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10643 | mScreenFrozenLock.release(); |
| 10644 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10645 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10646 | @Override |
| 10647 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 10648 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 10649 | != PackageManager.PERMISSION_GRANTED) { |
| 10650 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 10651 | + Binder.getCallingPid() |
| 10652 | + ", uid=" + Binder.getCallingUid()); |
| 10653 | return; |
| 10654 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10655 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10656 | synchronized(mWindowMap) { |
| 10657 | pw.println("Current Window Manager state:"); |
| 10658 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 10659 | WindowState w = (WindowState)mWindows.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10660 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 10661 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10662 | w.dump(pw, " "); |
| 10663 | } |
| 10664 | if (mInputMethodDialogs.size() > 0) { |
| 10665 | pw.println(" "); |
| 10666 | pw.println(" Input method dialogs:"); |
| 10667 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 10668 | WindowState w = mInputMethodDialogs.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10669 | 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] | 10670 | } |
| 10671 | } |
| 10672 | if (mPendingRemove.size() > 0) { |
| 10673 | pw.println(" "); |
| 10674 | pw.println(" Remove pending for:"); |
| 10675 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 10676 | WindowState w = mPendingRemove.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10677 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 10678 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10679 | w.dump(pw, " "); |
| 10680 | } |
| 10681 | } |
| 10682 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 10683 | pw.println(" "); |
| 10684 | pw.println(" Windows force removing:"); |
| 10685 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 10686 | WindowState w = mForceRemoves.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10687 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 10688 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10689 | w.dump(pw, " "); |
| 10690 | } |
| 10691 | } |
| 10692 | if (mDestroySurface.size() > 0) { |
| 10693 | pw.println(" "); |
| 10694 | pw.println(" Windows waiting to destroy their surface:"); |
| 10695 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 10696 | WindowState w = mDestroySurface.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10697 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 10698 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10699 | w.dump(pw, " "); |
| 10700 | } |
| 10701 | } |
| 10702 | if (mLosingFocus.size() > 0) { |
| 10703 | pw.println(" "); |
| 10704 | pw.println(" Windows losing focus:"); |
| 10705 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 10706 | WindowState w = mLosingFocus.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10707 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 10708 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10709 | w.dump(pw, " "); |
| 10710 | } |
| 10711 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10712 | if (mResizingWindows.size() > 0) { |
| 10713 | pw.println(" "); |
| 10714 | pw.println(" Windows waiting to resize:"); |
| 10715 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 10716 | WindowState w = mResizingWindows.get(i); |
| 10717 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 10718 | pw.print(w); pw.println(":"); |
| 10719 | w.dump(pw, " "); |
| 10720 | } |
| 10721 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10722 | if (mSessions.size() > 0) { |
| 10723 | pw.println(" "); |
| 10724 | pw.println(" All active sessions:"); |
| 10725 | Iterator<Session> it = mSessions.iterator(); |
| 10726 | while (it.hasNext()) { |
| 10727 | Session s = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10728 | pw.print(" Session "); pw.print(s); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10729 | s.dump(pw, " "); |
| 10730 | } |
| 10731 | } |
| 10732 | if (mTokenMap.size() > 0) { |
| 10733 | pw.println(" "); |
| 10734 | pw.println(" All tokens:"); |
| 10735 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 10736 | while (it.hasNext()) { |
| 10737 | WindowToken token = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10738 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10739 | token.dump(pw, " "); |
| 10740 | } |
| 10741 | } |
| 10742 | if (mTokenList.size() > 0) { |
| 10743 | pw.println(" "); |
| 10744 | pw.println(" Window token list:"); |
| 10745 | for (int i=0; i<mTokenList.size(); i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10746 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 10747 | pw.println(mTokenList.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10748 | } |
| 10749 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10750 | if (mWallpaperTokens.size() > 0) { |
| 10751 | pw.println(" "); |
| 10752 | pw.println(" Wallpaper tokens:"); |
| 10753 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 10754 | WindowToken token = mWallpaperTokens.get(i); |
| 10755 | pw.print(" Wallpaper #"); pw.print(i); |
| 10756 | pw.print(' '); pw.print(token); pw.println(':'); |
| 10757 | token.dump(pw, " "); |
| 10758 | } |
| 10759 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10760 | if (mAppTokens.size() > 0) { |
| 10761 | pw.println(" "); |
| 10762 | pw.println(" Application tokens in Z order:"); |
| 10763 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10764 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 10765 | pw.println(mAppTokens.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10766 | } |
| 10767 | } |
| 10768 | if (mFinishedStarting.size() > 0) { |
| 10769 | pw.println(" "); |
| 10770 | pw.println(" Finishing start of application tokens:"); |
| 10771 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 10772 | WindowToken token = mFinishedStarting.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10773 | pw.print(" Finished Starting #"); pw.print(i); |
| 10774 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10775 | token.dump(pw, " "); |
| 10776 | } |
| 10777 | } |
| 10778 | if (mExitingTokens.size() > 0) { |
| 10779 | pw.println(" "); |
| 10780 | pw.println(" Exiting tokens:"); |
| 10781 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 10782 | WindowToken token = mExitingTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10783 | pw.print(" Exiting #"); pw.print(i); |
| 10784 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10785 | token.dump(pw, " "); |
| 10786 | } |
| 10787 | } |
| 10788 | if (mExitingAppTokens.size() > 0) { |
| 10789 | pw.println(" "); |
| 10790 | pw.println(" Exiting application tokens:"); |
| 10791 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10792 | WindowToken token = mExitingAppTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10793 | pw.print(" Exiting App #"); pw.print(i); |
| 10794 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10795 | token.dump(pw, " "); |
| 10796 | } |
| 10797 | } |
| 10798 | pw.println(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10799 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 10800 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 10801 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 10802 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 10803 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 10804 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10805 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 10806 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 10807 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 10808 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10809 | pw.print(" mInTouchMode="); pw.println(mInTouchMode); |
| 10810 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 10811 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 10812 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 10813 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10814 | if (mDimAnimator != null) { |
| 10815 | mDimAnimator.printTo(pw); |
| 10816 | } else { |
| 10817 | pw.print( " no DimAnimator "); |
| 10818 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10819 | pw.print(" mInputMethodAnimLayerAdjustment="); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 10820 | pw.print(mInputMethodAnimLayerAdjustment); |
| 10821 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 10822 | pw.println(mWallpaperAnimLayerAdjustment); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10823 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 10824 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10825 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 10826 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
| 10827 | pw.print(" mAppsFreezingScreen="); pw.println(mAppsFreezingScreen); |
| 10828 | pw.print(" mRotation="); pw.print(mRotation); |
| 10829 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 10830 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 10831 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 10832 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 10833 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 10834 | pw.print(" mNextAppTransition=0x"); |
| 10835 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 10836 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10837 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10838 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10839 | if (mNextAppTransitionPackage != null) { |
| 10840 | pw.print(" mNextAppTransitionPackage="); |
| 10841 | pw.print(mNextAppTransitionPackage); |
| 10842 | pw.print(", mNextAppTransitionEnter=0x"); |
| 10843 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 10844 | pw.print(", mNextAppTransitionExit=0x"); |
| 10845 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 10846 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10847 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 10848 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10849 | if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) { |
| 10850 | pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken); |
| 10851 | pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams); |
| 10852 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10853 | if (mOpeningApps.size() > 0) { |
| 10854 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 10855 | } |
| 10856 | if (mClosingApps.size() > 0) { |
| 10857 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 10858 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10859 | if (mToTopApps.size() > 0) { |
| 10860 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 10861 | } |
| 10862 | if (mToBottomApps.size() > 0) { |
| 10863 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 10864 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10865 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 10866 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10867 | pw.println(" KeyWaiter state:"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10868 | pw.print(" mLastWin="); pw.print(mKeyWaiter.mLastWin); |
| 10869 | pw.print(" mLastBinder="); pw.println(mKeyWaiter.mLastBinder); |
| 10870 | pw.print(" mFinished="); pw.print(mKeyWaiter.mFinished); |
| 10871 | pw.print(" mGotFirstWindow="); pw.print(mKeyWaiter.mGotFirstWindow); |
| 10872 | pw.print(" mEventDispatching="); pw.print(mKeyWaiter.mEventDispatching); |
| 10873 | pw.print(" mTimeToSwitch="); pw.println(mKeyWaiter.mTimeToSwitch); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10874 | } |
| 10875 | } |
| 10876 | |
| 10877 | public void monitor() { |
| 10878 | synchronized (mWindowMap) { } |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 10879 | synchronized (mKeyguardTokenWatcher) { } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10880 | synchronized (mKeyWaiter) { } |
| 10881 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10882 | |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 10883 | public void virtualKeyFeedback(KeyEvent event) { |
| 10884 | mPolicy.keyFeedbackFromInput(event); |
| 10885 | } |
| 10886 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10887 | /** |
| 10888 | * DimAnimator class that controls the dim animation. This holds the surface and |
| 10889 | * all state used for dim animation. |
| 10890 | */ |
| 10891 | private static class DimAnimator { |
| 10892 | Surface mDimSurface; |
| 10893 | boolean mDimShown = false; |
| 10894 | float mDimCurrentAlpha; |
| 10895 | float mDimTargetAlpha; |
| 10896 | float mDimDeltaPerMs; |
| 10897 | long mLastDimAnimTime; |
| 10898 | |
| 10899 | DimAnimator (SurfaceSession session) { |
| 10900 | if (mDimSurface == null) { |
| 10901 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 10902 | + mDimSurface + ": CREATE"); |
| 10903 | try { |
| 10904 | mDimSurface = new Surface(session, 0, -1, 16, 16, PixelFormat.OPAQUE, |
| 10905 | Surface.FX_SURFACE_DIM); |
| 10906 | } catch (Exception e) { |
| 10907 | Log.e(TAG, "Exception creating Dim surface", e); |
| 10908 | } |
| 10909 | } |
| 10910 | } |
| 10911 | |
| 10912 | /** |
| 10913 | * Show the dim surface. |
| 10914 | */ |
| 10915 | void show(int dw, int dh) { |
| 10916 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 10917 | dw + "x" + dh + ")"); |
| 10918 | mDimShown = true; |
| 10919 | try { |
| 10920 | mDimSurface.setPosition(0, 0); |
| 10921 | mDimSurface.setSize(dw, dh); |
| 10922 | mDimSurface.show(); |
| 10923 | } catch (RuntimeException e) { |
| 10924 | Log.w(TAG, "Failure showing dim surface", e); |
| 10925 | } |
| 10926 | } |
| 10927 | |
| 10928 | /** |
| 10929 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 10930 | * {@link updateSurface} after all windows are examined. |
| 10931 | */ |
| 10932 | void updateParameters(WindowState w, long currentTime) { |
| 10933 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 10934 | |
| 10935 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10936 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface |
| 10937 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10938 | if (mDimTargetAlpha != target) { |
| 10939 | // If the desired dim level has changed, then |
| 10940 | // start an animation to it. |
| 10941 | mLastDimAnimTime = currentTime; |
| 10942 | long duration = (w.mAnimating && w.mAnimation != null) |
| 10943 | ? w.mAnimation.computeDurationHint() |
| 10944 | : DEFAULT_DIM_DURATION; |
| 10945 | if (target > mDimTargetAlpha) { |
| 10946 | // This is happening behind the activity UI, |
| 10947 | // so we can make it run a little longer to |
| 10948 | // give a stronger impression without disrupting |
| 10949 | // the user. |
| 10950 | duration *= DIM_DURATION_MULTIPLIER; |
| 10951 | } |
| 10952 | if (duration < 1) { |
| 10953 | // Don't divide by zero |
| 10954 | duration = 1; |
| 10955 | } |
| 10956 | mDimTargetAlpha = target; |
| 10957 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 10958 | } |
| 10959 | } |
| 10960 | |
| 10961 | /** |
| 10962 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 10963 | * false when the animation is finished and the dim surface is hidden. |
| 10964 | */ |
| 10965 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 10966 | if (!dimming) { |
| 10967 | if (mDimTargetAlpha != 0) { |
| 10968 | mLastDimAnimTime = currentTime; |
| 10969 | mDimTargetAlpha = 0; |
| 10970 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 10971 | } |
| 10972 | } |
| 10973 | |
| 10974 | boolean animating = false; |
| 10975 | if (mLastDimAnimTime != 0) { |
| 10976 | mDimCurrentAlpha += mDimDeltaPerMs |
| 10977 | * (currentTime-mLastDimAnimTime); |
| 10978 | boolean more = true; |
| 10979 | if (displayFrozen) { |
| 10980 | // If the display is frozen, there is no reason to animate. |
| 10981 | more = false; |
| 10982 | } else if (mDimDeltaPerMs > 0) { |
| 10983 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 10984 | more = false; |
| 10985 | } |
| 10986 | } else if (mDimDeltaPerMs < 0) { |
| 10987 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 10988 | more = false; |
| 10989 | } |
| 10990 | } else { |
| 10991 | more = false; |
| 10992 | } |
| 10993 | |
| 10994 | // Do we need to continue animating? |
| 10995 | if (more) { |
| 10996 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 10997 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 10998 | mLastDimAnimTime = currentTime; |
| 10999 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11000 | animating = true; |
| 11001 | } else { |
| 11002 | mDimCurrentAlpha = mDimTargetAlpha; |
| 11003 | mLastDimAnimTime = 0; |
| 11004 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 11005 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 11006 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11007 | if (!dimming) { |
| 11008 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface |
| 11009 | + ": HIDE"); |
| 11010 | try { |
| 11011 | mDimSurface.hide(); |
| 11012 | } catch (RuntimeException e) { |
| 11013 | Log.w(TAG, "Illegal argument exception hiding dim surface"); |
| 11014 | } |
| 11015 | mDimShown = false; |
| 11016 | } |
| 11017 | } |
| 11018 | } |
| 11019 | return animating; |
| 11020 | } |
| 11021 | |
| 11022 | public void printTo(PrintWriter pw) { |
| 11023 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 11024 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 11025 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 11026 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 11027 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 11028 | } |
| 11029 | } |
| 11030 | |
| 11031 | /** |
| 11032 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 11033 | * This is used for opening/closing transition for apps in compatible mode. |
| 11034 | */ |
| 11035 | private static class FadeInOutAnimation extends Animation { |
| 11036 | int mWidth; |
| 11037 | boolean mFadeIn; |
| 11038 | |
| 11039 | public FadeInOutAnimation(boolean fadeIn) { |
| 11040 | setInterpolator(new AccelerateInterpolator()); |
| 11041 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 11042 | mFadeIn = fadeIn; |
| 11043 | } |
| 11044 | |
| 11045 | @Override |
| 11046 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 11047 | float x = interpolatedTime; |
| 11048 | if (!mFadeIn) { |
| 11049 | x = 1.0f - x; // reverse the interpolation for fade out |
| 11050 | } |
| 11051 | if (x < 0.5) { |
| 11052 | // move the window out of the screen. |
| 11053 | t.getMatrix().setTranslate(mWidth, 0); |
| 11054 | } else { |
| 11055 | t.getMatrix().setTranslate(0, 0);// show |
| 11056 | t.setAlpha((x - 0.5f) * 2); |
| 11057 | } |
| 11058 | } |
| 11059 | |
| 11060 | @Override |
| 11061 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 11062 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 11063 | mWidth = width; |
| 11064 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11065 | |
| 11066 | @Override |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 11067 | public int getZAdjustment() { |
| 11068 | return Animation.ZORDER_TOP; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11069 | } |
| 11070 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11071 | } |